MBeanServer server = MBeanServerFactory.newMBeanServer();
assertTrue("Only one domain at the start", server.getDomains().length == 1);
assertEquals(server.getDomains()[0], "JMImplementation");
server.registerMBean(new Test(), new ObjectName("Domain1:test=test1"));
server.registerMBean(new Test(), new ObjectName("Domain1:test=test2"));
server.registerMBean(new Test(), new ObjectName("Domain2:test=test1"));
server.registerMBean(new Test(), new ObjectName("Domain3:test=test1"));
assertTrue("Now four domains", server.getDomains().length == 4);
List domains = Arrays.asList(server.getDomains());
assertTrue("server has JMImplementation", domains.contains("JMImplementation"));
assertTrue("server has Domain1", domains.contains("Domain1"));