### Question:
JavaMailJMSStatistics extends NotificationBroadcasterSupport implements JavaMailJMSStatisticsLocal, DynamicMBean { @Override public AttributeList getAttributes(String[] attributeNames) { AttributeList resultList = new AttributeList(); if (attributeNames.length == 0) { return resultList; } for (String attributeName : attributeNames) { try { Object value = getAttribute(attributeName); resultList.add(new Attribute(attributeName, value)); } catch (Exception e) { throw new IllegalStateException("Cannot get attribute " + attributeName, e); } } return resultList; }  @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 testGetAttributes() throws Exception { List<String> attrNames = Arrays.asList("countSuccessful", "countFailure"); MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); AttributeList attributeList = platformMBeanServer.getAttributes(JavaMailJMSStatistics.JMX_OBJECT_NAME, attrNames.toArray(new String[attrNames.size()])); List<Attribute> list = attributeList.asList(); for(Attribute attribute : list) { if (attrNames.contains(attribute.getName())) { Object val = attribute.getValue(); assertTrue(val instanceof Number); continue; } fail("There is more attributes then expected - " + attribute); } }
@Test public void testGetAttributesEmpty() throws Exception { AttributeList attributeList = javaMailJMSStatistics.getAttributes(new String[0]); assertEquals(0, attributeList.size()); }
@Test(expected = Exception.class) public void testGetAttributesNotFound() throws Exception { javaMailJMSStatistics.getAttributes(new String[] {"NotExistingProperty"}); }