@Test
    public void testSelfSigned() throws Exception
    {
        // Setup fixture.
        final X509Certificate[] chain = new X509Certificate[] { KeystoreTestUtils.generateSelfSignedCertificate().getCertificate() };
        final X509CertSelector selector = new X509CertSelector();
        selector.setSubject( chain[ 0 ].getSubjectX500Principal() );

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

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

        // Verify results
        if ( acceptSelfSigned )
        {
            Assert.assertNotNull( "Self-signed certificates are accepted. Validation should have succeeded.", result );
        }
        else
        {
            Assert.assertNotNull( "Self-signed certificates are not accepted. Validation should have thrown an exception.", exception );
        }
    }
Verifies that self-signed certificates are accepted, but only when explicitly configured to do so.
xmppserver/src/test/java/org/jivesoftware/openfire/keystore/CheckChainTrustedTest.java