ServiceStateMBeanHandler implements MBeanHandler { public void open() { serviceStateMBean = new ServiceState(bundleContext, stateConfig, logger); try { mbean = new RegistrableStandardEmitterMBean(serviceStateMBean, ServiceStateMBean.class); } catch (NotCompliantMBeanException e) { logger.log(LogService.LOG_ERROR, "Failed to instantiate MBean for " + ServiceStateMBean.class.getName(), e); } agentContext.registerMBean(this); } ServiceStateMBeanHandler(JMXAgentContext agentContext, StateConfig stateConfig); void open(); StandardMBean getMbean(); String getName(); void close();  }
@Test public void testOpen() throws Exception { BundleContext context = mock(BundleContext.class); when(context.getProperty(Constants.FRAMEWORK_UUID)).thenReturn("some-uuid"); Logger logger = mock(Logger.class); Bundle mockSystemBundle = mock(Bundle.class); when(mockSystemBundle.getSymbolicName()).thenReturn("the.sytem.bundle"); when(context.getBundle(0)).thenReturn(mockSystemBundle); JMXAgent agent = mock(JMXAgent.class); JMXAgentContext agentContext = new JMXAgentContext(context, agent, logger); ServiceStateMBeanHandler handler = new ServiceStateMBeanHandler(agentContext, new StateConfig()); handler.open(); assertNotNull(handler.getMbean()); }