    @Test
    public void testStopListeningForIncomingConnections() throws Exception {

        Field serverThreadField = mBluetoothConnector.getClass()
                .getDeclaredField("mServerThread");
        serverThreadField.setAccessible(true);

        Field stoppingServerField = mBluetoothConnector.getClass()
                .getDeclaredField("mIsStoppingServer");
        stoppingServerField.setAccessible(true);

        stoppingServerField.set(mBluetoothConnector, false);
        mBluetoothConnector.stopListeningForIncomingConnections();

        assertThat("Server thread remains null as it was not started",
                serverThreadField.get(mBluetoothConnector),
                is(nullValue()));

        assertThat("It remains false as the listener was not stopped",
                (Boolean) stoppingServerField.get(mBluetoothConnector),
                is(false));

        // stopping listening for incoming connections
        stoppingServerField.set(mBluetoothConnector, false);
        serverThreadField.set(mBluetoothConnector, mMockServerThread);

        mBluetoothConnector.stopListeningForIncomingConnections();

        verify(mMockServerThread, times(1))
                .shutdown();

        assertThat("Server thread is null as it was stopped",
                serverThreadField.get(mBluetoothConnector),
                is(nullValue()));

        assertThat("It is true as the listener was stopped",
                (Boolean) stoppingServerField.get(mBluetoothConnector),
                is(true));
    }