field.setAccessible(true);
field.set(testClass, mockMbs);
expect(mockConfig.getPoolName()).andReturn("poolName").anyTimes();
ObjectInstance mockInstance = EasyMock.createNiceMock(ObjectInstance.class);
expect(mockMbs.isRegistered((ObjectName)anyObject())).andReturn(false).anyTimes();
expect(mockMbs.registerMBean(anyObject(), (ObjectName)anyObject())).andReturn(mockInstance).once().andThrow(new InstanceAlreadyExistsException()).once();
replay(mockMbs, mockInstance, mockConfig);
testClass.registerUnregisterJMX(true);
verify(mockMbs);
}