@Test
public void shouldUnregisterMBeans() throws Exception {

    final String contextName = "my-context";
    final ObjectName objectName = mock(ObjectName.class, "mBeanName");
    when(mbeanServer.isRegistered(objectName)).thenReturn(true);
    when(contextNameProvider.getContextName()).thenReturn(contextName);
    when(commandMBeanNameProvider.create(contextName)).thenReturn(objectName);
    mBeanInstantiator.unregisterMBeans();
    verify(mbeanServer).unregisterMBean(objectName);
    verify(logger).info("Unregistering SystemCommander MBean using name 'mBeanName'");
}