### Question:
X509CertificateEvaluator implements ExpressionEvaluator { public Object evaluate(String expression, MuleMessage message) { try { String value = null; if (EXPR_SENDERID.equals(expression)) { value = getSenderIdFromCertificate(message, "PEER_CERTIFICATES"); if (log.isDebugEnabled()) { String me = getSenderIdFromCertificate(message, "LOCAL_CERTIFICATES"); log.debug("{} validates sender id: {}", me, value); } } return value; } catch (Exception e) { log.error(e.getMessage()); throw new RuntimeException(e); } }  String getName(); void setPropertyName(String propertyName); void setName(String name); Object evaluate(String expression, MuleMessage message); static final String NAME; static final String EXPR_SENDERID; }### Answer:
@Test public void evaluate() { MuleMessage muleMessageMock = mock(MuleMessage.class); X509Certificate certMock = mock(X509Certificate.class); X500Principal principal = new X500Principal("CN=Duke, OU=JavaSoft, O=Sun Microsystems, C=US"); Certificate[] certificateChain = new Certificate[] {certMock}; when(muleMessageMock.getOutboundProperty("PEER_CERTIFICATES")).thenReturn(certificateChain); when(certMock.getSubjectX500Principal()).thenReturn(principal); Object senderId = evaluator.evaluate(X509CertificateEvaluator.EXPR_SENDERID, muleMessageMock); assertNotNull(senderId); assertEquals("Duke", senderId); }
@Test public void evaluateNoClientCertException() { MuleMessage muleMessge = mock(MuleMessage.class); try { evaluator.evaluate(X509CertificateEvaluator.EXPR_SENDERID, muleMessge); fail(); } catch(Exception e) { assertEquals("No certificate chain found from client", e.getCause().getMessage()); } }