### Question:
OpenfireX509TrustManager implements X509TrustManager { @Override public void checkClientTrusted( X509Certificate[] chain, String authType ) throws CertificateException { final X509Certificate endEntityCert = CertificateUtils.identifyEndEntityCertificate( Arrays.asList( chain ) ); final X509CertSelector selector = new X509CertSelector(); selector.setCertificate( endEntityCert ); try { checkChainTrusted( selector, chain ); } catch ( InvalidAlgorithmParameterException | NoSuchAlgorithmException | CertPathBuilderException ex ) { throw new CertificateException( ex ); } } OpenfireX509TrustManager( KeyStore trustStore, boolean acceptSelfSigned, boolean checkValidity ); @Override void checkClientTrusted( X509Certificate[] chain, String authType ); @Override void checkServerTrusted( X509Certificate[] chain, String authType ); @Override X509Certificate[] getAcceptedIssuers();  }### Answer:
@Test public void testValidChain() throws Exception { systemUnderTest.checkClientTrusted( validChain, "RSA" ); }
@Test(expected = CertificateException.class) public void testInvalidChainExpiredIntermediate() throws Exception { systemUnderTest.checkClientTrusted( expiredIntChain, "RSA" ); }
@Test(expected = CertificateException.class) public void testInvalidChainExpiredTrustAnchor() throws Exception { systemUnderTest.checkClientTrusted( expiredRootChain, "RSA" ); }
@Test(expected = CertificateException.class) public void testInvalidChainMissingIntermediate() throws Exception { assert validChain.length == 4; final X509Certificate[] input = new X509Certificate[ 3 ]; input[ 0 ] = validChain[ 0 ]; input[ 1 ] = validChain[ 2 ]; input[ 2 ] = validChain[ 3 ]; systemUnderTest.checkClientTrusted( input, "RSA" ); }
@Test(expected = CertificateException.class) public void testInvalidChainCAnotTrusted() throws Exception { systemUnderTest.checkClientTrusted( untrustedCAChain, "RSA" ); }