@Test public void testOnIsServerStartedChanged() throws Exception { Field stateField = connectionManager.getClass().getDeclaredField("mState"); stateField.setAccessible(true); Field shouldBeStartedField = connectionManager.getClass().getDeclaredField("mShouldBeStarted"); shouldBeStartedField.setAccessible(true); shouldBeStartedField.setBoolean(connectionManager, true); connectionManager.onIsServerStartedChanged(true); assertThat(connectionManager.getState(), is(ConnectionManager.ConnectionManagerState.RUNNING)); stateField.set(connectionManager, ConnectionManager.ConnectionManagerState.WAITING_FOR_SERVICES_TO_BE_ENABLED); connectionManager.onIsServerStartedChanged(true); assertThat("state changed to running if waiting for Bluetooth to be enabled", connectionManager.getState(), is(ConnectionManager.ConnectionManagerState.RUNNING)); stateField.set(connectionManager, ConnectionManager.ConnectionManagerState.NOT_STARTED); connectionManager.onIsServerStartedChanged(true); assertThat("state changed to started if not started", connectionManager.getState(), is(ConnectionManager.ConnectionManagerState.RUNNING)); stateField.set(connectionManager, ConnectionManager.ConnectionManagerState.RUNNING); connectionManager.onIsServerStartedChanged(true); assertThat("state remains running if running", connectionManager.getState(), is(ConnectionManager.ConnectionManagerState.RUNNING)); stateField.set(connectionManager, ConnectionManager.ConnectionManagerState.WAITING_FOR_SERVICES_TO_BE_ENABLED); connectionManager.onIsServerStartedChanged(false); assertThat("state not changed if waiting for Bluetooth to be enabled", connectionManager.getState(), is(ConnectionManager.ConnectionManagerState.WAITING_FOR_SERVICES_TO_BE_ENABLED)); stateField.set(connectionManager, ConnectionManager.ConnectionManagerState.RUNNING); connectionManager.onIsServerStartedChanged(false); assertThat("state changed if running", connectionManager.getState(), is(ConnectionManager.ConnectionManagerState.WAITING_FOR_SERVICES_TO_BE_ENABLED)); stateField.set(connectionManager, ConnectionManager.ConnectionManagerState.RUNNING); when(mMockBluetoothManager.isBluetoothEnabled()).thenReturn(true); connectionManager.onIsServerStartedChanged(false); assertThat("state changed if running", connectionManager.getState(), is(ConnectionManager.ConnectionManagerState.NOT_STARTED)); stateField.set(connectionManager, ConnectionManager.ConnectionManagerState.NOT_STARTED); connectionManager.onIsServerStartedChanged(false); assertThat("state still not started if not started", connectionManager.getState(), is(ConnectionManager.ConnectionManagerState.NOT_STARTED)); }
@Override public void onIsServerStartedChanged(boolean isStarted) { Log.d(TAG, "onIsServerStartedChanged: " + isStarted); mIsServerStarted = isStarted; updateState(); }
ConnectionManager extends AbstractBluetoothConnectivityAgent implements
        BluetoothConnector.BluetoothConnectorListener,
        ConnectionManagerSettings.Listener,
        DiscoveryManagerSettings.Listener { @Override public void onIsServerStartedChanged(boolean isStarted) { Log.d(TAG, "onIsServerStartedChanged: " + isStarted); mIsServerStarted = isStarted; updateState(); } }
ConnectionManager extends AbstractBluetoothConnectivityAgent implements
        BluetoothConnector.BluetoothConnectorListener,
        ConnectionManagerSettings.Listener,
        DiscoveryManagerSettings.Listener { @Override public void onIsServerStartedChanged(boolean isStarted) { Log.d(TAG, "onIsServerStartedChanged: " + isStarted); mIsServerStarted = isStarted; updateState(); } ConnectionManager(
            Context context, ConnectionManagerListener listener,
            UUID myUuid, String myName);  ConnectionManager(
            Context context, ConnectionManagerListener listener,
            UUID myUuid, String myName, BluetoothManager bluetoothManager,
            SharedPreferences preferences); }
ConnectionManager extends AbstractBluetoothConnectivityAgent implements
        BluetoothConnector.BluetoothConnectorListener,
        ConnectionManagerSettings.Listener,
        DiscoveryManagerSettings.Listener { @Override public void onIsServerStartedChanged(boolean isStarted) { Log.d(TAG, "onIsServerStartedChanged: " + isStarted); mIsServerStarted = isStarted; 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); }
ConnectionManager extends AbstractBluetoothConnectivityAgent implements
        BluetoothConnector.BluetoothConnectorListener,
        ConnectionManagerSettings.Listener,
        DiscoveryManagerSettings.Listener { @Override public void onIsServerStartedChanged(boolean isStarted) { Log.d(TAG, "onIsServerStartedChanged: " + isStarted); mIsServerStarted = isStarted; 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);  }