### Question:
JavaMailJMSStatistics extends NotificationBroadcasterSupport implements JavaMailJMSStatisticsLocal, DynamicMBean { public void onFailure(MimeMessage mimeMessage, Address[] addresses, Exception ex) { MessageAndAddresses maa = new MessageAndAddresses(mimeMessage, addresses, ex); failureCounter.incrementAndGet(); lastFailMessage = maa; sendNotification(maa); }  @PostConstruct void registerInJMX(); @PreDestroy void unregisterFromJMX(); void onSuccess(MimeMessage mimeMessage, Address[] addresses); void onFailure(MimeMessage mimeMessage, Address[] addresses, Exception ex); @Override AttributeList getAttributes(String[] attributeNames); @Override Object getAttribute(String attribute); @Override void setAttribute(Attribute attribute); @Override AttributeList setAttributes(AttributeList attributes); @Override Object invoke(String actionName, Object[] params, String[] signature); @Override MBeanInfo getMBeanInfo(); static final String NOTIFICATION_TYPE_SUCCESS; static final String JAVA_MAIL_SEND_FAILURE; static final ObjectName JMX_OBJECT_NAME; }### Answer:
@Test public void testMessageInfo() throws Exception { javaMailJMSStatistics.onFailure(mimeMessage, addressesTo, new IllegalStateException()); CompositeData info = (CompositeData) getMbeanAttribute("lastFailureMailInfo"); assertTrue(info.get("date") instanceof Date); assertTrue(info.get("errorDescription").toString().contains("IllegalStateException")); TabularData tab = (TabularData) info.get("headers"); assertEquals(2, tab.size()); assertEquals("MessageId", info.get("messageId")); tab = (TabularData) info.get("toAddresses"); assertEquals(1, tab.size()); assertEquals("MessageSubject", info.get("subject")); }
@Test public void testOnFailure() throws Exception { javaMailJMSStatistics.onFailure(mimeMessage, addressesTo, new IllegalArgumentException()); assertEquals(1L, getMbeanAttribute("countFailure")); }