@Test
    public void testExpiredIntermediateChain() throws Exception
    {
        // Setup fixture.
        final X509CertSelector selector = new X509CertSelector();
        selector.setSubject( expiredIntChain[0].getSubjectX500Principal() );
        final X509Certificate[] chain = expiredIntChain;

        // Execute system under test.
        CertPath result = null;
        CertPathBuilderException exception = null;

        try
        {
            result = trustManager.checkChainTrusted( selector, chain );
        }
        catch ( CertPathBuilderException ex)
        {
            exception = ex;
        }

        // Verify results
        if ( checkValidity )
        {
            Assert.assertNotNull( "Certificate validity is enforced. Validation should have thrown an exception.", exception );
        }
        else
        {
            Assert.assertNotNull( "Certificate validity is not checked. Validation should have succeeded.", result );
        }
    }
Verifies that providing chain for which an intermediate certificate is expired (but is otherwise valid)
throws a CertPathBuilderException only when the system under test is configured to enforce date validity.
xmppserver/src/test/java/org/jivesoftware/openfire/keystore/CheckChainTrustedTest.java