@Test
public void shouldThrowExceptionIfMBeanNameNotCorrect() throws Exception {

    final String contextName = "people";
    final ObjectName realObjectName = createARealObjectName(contextName);
    final Class<SystemCommanderMBean> mBeanInterface = SystemCommanderMBean.class;
    final JMXConnector jmxConnector =  mock(JMXConnector.class);
    final MBeanServerConnection connection = mock(MBeanServerConnection.class);
    when(commandMBeanNameProvider.create(contextName)).thenReturn(realObjectName);
    when(jmxConnector.getMBeanServerConnection()).thenReturn(connection);
    when(connection.isRegistered(realObjectName)).thenReturn(false);
    try {
        mBeanConnector.connect(contextName, mBeanInterface, jmxConnector);
        fail();
    } catch (final MBeanClientException expected) {
        assertThat(expected.getMessage(), is("No JMX bean found with name 'people-system-command-handler-mbean'. Is your context name of 'people' correct?"));
    }
}