@Test
public void shouldConnectToARemoteInstanceOfTheJmxBean() throws Exception {

    final String contextName = "my-context";
    final Class<SystemCommanderMBean> mBeanInterface = SystemCommanderMBean.class;
    final JMXConnector jmxConnector =  mock(JMXConnector.class);
    final ObjectName objectName = mock(ObjectName.class);
    final MBeanServerConnection connection = mock(MBeanServerConnection.class);
    final SystemCommanderMBean systemCommanderMBean = mock(SystemCommanderMBean.class);
    when(commandMBeanNameProvider.create(contextName)).thenReturn(objectName);
    when(jmxConnector.getMBeanServerConnection()).thenReturn(connection);
    when(connection.isRegistered(objectName)).thenReturn(true);
    when(remoteMBeanFactory.createRemote(connection, objectName, mBeanInterface)).thenReturn(systemCommanderMBean);
    assertThat(mBeanConnector.connect(contextName, mBeanInterface, jmxConnector), is(systemCommanderMBean));
}