ConnectionManager extends AbstractBluetoothConnectivityAgent implements
        BluetoothConnector.BluetoothConnectorListener,
        ConnectionManagerSettings.Listener,
        DiscoveryManagerSettings.Listener { public synchronized void stopListeningForIncomingConnections() { if (mState != ConnectionManagerState.NOT_STARTED) { Log.i(TAG, "stopListeningForIncomingConnections"); } mShouldBeStarted = false; mBluetoothConnector.stopListeningForIncomingConnections(); mBluetoothManager.release(this); updateState(); } ConnectionManager(
            Context context, ConnectionManagerListener listener,
            UUID myUuid, String myName);  ConnectionManager(
            Context context, ConnectionManagerListener listener,
            UUID myUuid, String myName, BluetoothManager bluetoothManager,
            SharedPreferences preferences); ConnectionManagerState getState(); synchronized boolean startListeningForIncomingConnections(); synchronized void stopListeningForIncomingConnections(); synchronized boolean connect(PeerProperties peerToConnectTo); synchronized boolean cancelConnectionAttempt(PeerProperties peerConnectingTo); synchronized void cancelAllConnectionAttempts(); @Override void dispose(); @Override void onConnectionManagerSettingsChanged(); @Override void onHandshakeRequiredSettingChanged(boolean handshakeRequired); @Override void onBluetoothAdapterScanModeChanged(int mode); @Override void onBluetoothAdapterStateChanged(int state); @Override void onIsServerStartedChanged(boolean isStarted); @Override void onConnecting(String bluetoothDeviceName, String bluetoothDeviceAddress); @Override void onConnected(
            final BluetoothSocket bluetoothSocket, final boolean isIncoming,
            final PeerProperties peerProperties); @Override void onConnectionTimeout(final PeerProperties peerProperties); @Override void onConnectionFailed(final PeerProperties peerProperties, final String errorMessage); @Override void onDiscoveryModeChanged(DiscoveryManager.DiscoveryMode discoveryMode, boolean startIfNotRunning); @Override void onPeerExpirationSettingChanged(long peerExpirationInMilliseconds); @Override void onAdvertiseScanSettingsChanged(); @Override void onPeerExtraInfoChanged(int newExtraInfo); @Override boolean setExtraInfo(int extraInfo);  }
@Test public void testStopListeningForIncomingConnections() throws Exception { assertThat(connectionManager, is(notNullValue())); connectionManager.stopListeningForIncomingConnections(); verify(mMockBluetoothConnector, atLeastOnce()) .stopListeningForIncomingConnections(); verify(mMockBluetoothManager, atLeastOnce()) .release(isA(BluetoothManager.BluetoothManagerListener.class)); Field stateField = connectionManager.getClass().getDeclaredField("mState"); stateField.setAccessible(true); stateField.set(connectionManager, ConnectionManager.ConnectionManagerState .WAITING_FOR_SERVICES_TO_BE_ENABLED); connectionManager.stopListeningForIncomingConnections(); verify(mMockBluetoothConnector, atLeastOnce()) .stopListeningForIncomingConnections(); verify(mMockBluetoothManager, atLeastOnce()) .release(isA(BluetoothManager.BluetoothManagerListener.class)); assertThat("when waiting for Bluetooth the state is changed manually", connectionManager.getState(), is(equalTo(ConnectionManager.ConnectionManagerState .NOT_STARTED))); }