@Test( expected = CertPathBuilderException.class )
    public void testIncompleteChain() throws Exception
    {
        // Setup fixture.
        final X509CertSelector selector = new X509CertSelector();
        selector.setSubject( validChain[0].getSubjectX500Principal() );

        // Copy all but the second certificate of a valid chain to a chain that's used for testing.
        final List<X509Certificate> copy = new ArrayList<>( Arrays.asList( validChain ) ); // wrapping needed to support remove function.
        copy.remove( 1 );
        final X509Certificate[] chain = copy.toArray(new X509Certificate[0]);

        // Execute system under test.
        trustManager.checkChainTrusted( selector, chain );

        // Verify results
        // (verified by 'expected' parameter of @Test annotation).
    }
Verifies that providing a chain that does not contain an intermediate certificate throws an exception
(selection criteria during this test: match on subject).
xmppserver/src/test/java/org/jivesoftware/openfire/keystore/CheckChainTrustedTest.java