WebMBeanServerAdapter { public Set<String> getMBeanNames() { Set<String> nameSet = new TreeSet<String>(); for (ObjectInstance instance : mBeanServer.queryMBeans(null, null)) { nameSet.add(sanitizer.escapeValue(instance.getObjectName().getCanonicalName())); } return nameSet; } WebMBeanServerAdapter(MBeanServer mBeanServer); Set<String> getMBeanNames(); WebMBeanAdapter createWebMBeanAdapter(String mBeanName, String encoding);  }
@Test public void testGetMBeanNames() throws Exception { String name1 = "com.test:type=objectName,value=1"; String name2 = "com.test:type=objectName,value=2"; ObjectName objectName1 = new ObjectName(name1); ObjectInstance object1 = createMock(ObjectInstance.class); expect(object1.getObjectName()).andReturn(objectName1); ObjectName objectName2 = new ObjectName(name2); ObjectInstance object2 = createMock(ObjectInstance.class); expect(object2.getObjectName()).andReturn(objectName2); Set<ObjectInstance> objectInstanceList = new HashSet<ObjectInstance>(); objectInstanceList.add(object1); objectInstanceList.add(object2); expect(mockMbeanServer.queryMBeans(null, null)).andReturn(objectInstanceList); expect(mockSanitizer.escapeValue(name1)).andReturn(name1); expect(mockSanitizer.escapeValue(name2)).andReturn(name2); replay(mockMbeanServer, mockSanitizer, object1, object2); Set<String> resultSet = webMBeanServerAdapter.getMBeanNames(); assertEquals(2, resultSet.size()); assertTrue(resultSet.contains(name1)); assertTrue(resultSet.contains(name2)); verify(mockMbeanServer, mockSanitizer, object1, object2); }