@Test
  public void registerMBean()
      throws MalformedObjectNameException, NotCompliantMBeanException,
          InstanceAlreadyExistsException, MBeanRegistrationException, InstanceNotFoundException {
    MBeanServer jolokiaServer = JolokiaMBeanServerUtil.getJolokiaMBeanServer();

    Dummy test = new Dummy();
    ObjectName name = new ObjectName("jolokia.test:name=test");
    JolokiaMBeanServerUtil.registerMBean(test, name);
    assertTrue(jolokiaServer.isRegistered(name));
    JolokiaMBeanServerUtil.unregisterMBean(name);
    Assert.assertFalse(jolokiaServer.isRegistered(name));
  }
 @Test
 public void checkNotRegistered() throws MalformedObjectNameException {
   MBeanServer jolokiaServer = JolokiaMBeanServerUtil.getJolokiaMBeanServer();
   Assert.assertNotEquals(ManagementFactory.getPlatformMBeanServer(), jolokiaServer);
   for (MBeanServer server : MBeanServerFactory.findMBeanServer(null)) {
     Assert.assertNotEquals(server, jolokiaServer);
   }
 }
  @Test(expectedExceptions = IllegalStateException.class)
  void registerMBeanFailed()
      throws NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanException,
          MalformedObjectNameException, AttributeNotFoundException, ReflectionException,
          InstanceNotFoundException {
    MBeanServer server = EasyMock.createMock(MBeanServer.class);
    ObjectName oName = new ObjectName(JolokiaMBeanServerHolderMBean.OBJECT_NAME);
    EasyMock.expect(server.registerMBean(EasyMock.anyObject(), EasyMock.eq(oName)))
        .andThrow(new MBeanRegistrationException(new Exception()));
    EasyMock.replay(server);

    MBeanServer m = JolokiaMBeanServerUtil.registerJolokiaMBeanServerHolderMBean(server);
  }
  @Test
  void registerMBean2()
      throws NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanException,
          MalformedObjectNameException, AttributeNotFoundException, ReflectionException,
          InstanceNotFoundException {
    MBeanServer server = EasyMock.createMock(MBeanServer.class);
    MBeanServer ret = MBeanServerFactory.newMBeanServer();
    ObjectName oName = new ObjectName(JolokiaMBeanServerHolderMBean.OBJECT_NAME);
    EasyMock.expect(server.registerMBean(EasyMock.anyObject(), EasyMock.eq(oName)))
        .andThrow(new InstanceAlreadyExistsException());
    EasyMock.expect(
            server.getAttribute(
                EasyMock.eq(oName), eq(JolokiaMBeanServerUtil.JOLOKIA_MBEAN_SERVER_ATTRIBUTE)))
        .andReturn(ret);
    EasyMock.replay(server);

    MBeanServer m = JolokiaMBeanServerUtil.registerJolokiaMBeanServerHolderMBean(server);
    Assert.assertEquals(ret, m);
  }