### Question:
X509TrustManagerImpl implements X509TrustManager { @Override public void checkServerTrusted(X509Certificate[] certs, String arg1) throws CertificateException { boolean verified = false; if (certs !=null){ for (X509Certificate cert : certs) { if (cert.equals(controllerCert)) { verified = true; break; } } } if (!verified) throw new CertificateException(); } X509TrustManagerImpl(Certificate controllerCert); @Override void checkServerTrusted(X509Certificate[] certs, String arg1); @Override void checkClientTrusted(X509Certificate[] certs, String arg1); @Override X509Certificate[] getAcceptedIssuers();  }### Answer:
@Test (expected = CertificateException.class) public void throwsExceptionWhenCertificateIsNullInCheckServerTrusted() throws CertificateException { x509TrustManager.checkServerTrusted(null, null); }
@Test (expected = CertificateException.class) public void throwsExceptionWhenCertificateIsNotEqualInCheckServerTrusted() throws CertificateException { x509TrustManager.checkServerTrusted(certificates, "args"); }
@Test public void testCheckServerTrusted() { try { certificate = x509Certificate; x509TrustManager = spy(new X509TrustManagerImpl(certificate)); x509TrustManager.checkServerTrusted(certificates, "args"); } catch (CertificateException e) { fail("This should not happen"); } }