I need to mock following code:
final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
mbs.registerMBean(testMBean, new ObjectName("testObjectName");
I am usign PowerMock to mock ManagementFactory with following code snippet:
At class level, I configured:
@RunWith(PowerMockRunner.class) @PrepareForTest({ ManagementFactory.class })
Create Mock MBeanServer class:
MBeanServer mockMBeanServer = createMock(MBeanServer.class);
create Expetation using EasyMock:
EasyMock.expect( ManagementFactory.getPlatformMBeanServer() ).andReturn(mockMBeanServer);
In above code, I am getting following error:
java.lang.IllegalStateException: incompatible return value type at org.easymock.internal.MocksControl.andReturn(MocksControl.java:218)
Finally, after tried a lot, I need to ignore this class:
@PowerMockIgnore( {
"org.apache.commons.logging.*",
"javax.management.*",
})
My test cases are working, except mocking and testing MBean classes. Any better option?