@Test public void testConnect() throws Exception { when(mMockBluetoothManager.getRemoteDevice(anyString())).thenReturn(mMockBluetoothDevice); when(mMockBluetoothConnector.connect( isA(BluetoothDevice.class), isA(PeerProperties.class))).thenReturn(true); assertThat("Returns true if connected", connectionManager.connect(mMockPeerProperties), is(true)); when(mMockBluetoothConnector.connect( isA(BluetoothDevice.class), isA(PeerProperties.class))).thenReturn(false); assertThat("Returns false if cannot connect", connectionManager.connect(mMockPeerProperties), is(false)); assertThat("Returns false if the peer to connect to is null", connectionManager.connect(null), is(false)); }
public synchronized boolean connect(PeerProperties peerToConnectTo) { boolean success = false; if (peerToConnectTo != null) { Log.i(TAG, "connect: " + peerToConnectTo.toString()); try { BluetoothDevice device = mBluetoothManager.getRemoteDevice(peerToConnectTo.getBluetoothMacAddress()); success = mBluetoothConnector.connect(device, peerToConnectTo); } catch (NullPointerException e) { Log.e(TAG, "connect: Failed to start connecting to peer " + peerToConnectTo.toString() + ": " + e.getMessage(), e); } } else { Log.e(TAG, "connect: The given device is null!"); } return success; }
ConnectionManager extends AbstractBluetoothConnectivityAgent implements
        BluetoothConnector.BluetoothConnectorListener,
        ConnectionManagerSettings.Listener,
        DiscoveryManagerSettings.Listener { public synchronized boolean connect(PeerProperties peerToConnectTo) { boolean success = false; if (peerToConnectTo != null) { Log.i(TAG, "connect: " + peerToConnectTo.toString()); try { BluetoothDevice device = mBluetoothManager.getRemoteDevice(peerToConnectTo.getBluetoothMacAddress()); success = mBluetoothConnector.connect(device, peerToConnectTo); } catch (NullPointerException e) { Log.e(TAG, "connect: Failed to start connecting to peer " + peerToConnectTo.toString() + ": " + e.getMessage(), e); } } else { Log.e(TAG, "connect: The given device is null!"); } return success; } }
ConnectionManager extends AbstractBluetoothConnectivityAgent implements
        BluetoothConnector.BluetoothConnectorListener,
        ConnectionManagerSettings.Listener,
        DiscoveryManagerSettings.Listener { public synchronized boolean connect(PeerProperties peerToConnectTo) { boolean success = false; if (peerToConnectTo != null) { Log.i(TAG, "connect: " + peerToConnectTo.toString()); try { BluetoothDevice device = mBluetoothManager.getRemoteDevice(peerToConnectTo.getBluetoothMacAddress()); success = mBluetoothConnector.connect(device, peerToConnectTo); } catch (NullPointerException e) { Log.e(TAG, "connect: Failed to start connecting to peer " + peerToConnectTo.toString() + ": " + e.getMessage(), e); } } else { Log.e(TAG, "connect: The given device is null!"); } return success; } 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 { public synchronized boolean connect(PeerProperties peerToConnectTo) { boolean success = false; if (peerToConnectTo != null) { Log.i(TAG, "connect: " + peerToConnectTo.toString()); try { BluetoothDevice device = mBluetoothManager.getRemoteDevice(peerToConnectTo.getBluetoothMacAddress()); success = mBluetoothConnector.connect(device, peerToConnectTo); } catch (NullPointerException e) { Log.e(TAG, "connect: Failed to start connecting to peer " + peerToConnectTo.toString() + ": " + e.getMessage(), e); } } else { Log.e(TAG, "connect: The given device is null!"); } return success; } 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 { public synchronized boolean connect(PeerProperties peerToConnectTo) { boolean success = false; if (peerToConnectTo != null) { Log.i(TAG, "connect: " + peerToConnectTo.toString()); try { BluetoothDevice device = mBluetoothManager.getRemoteDevice(peerToConnectTo.getBluetoothMacAddress()); success = mBluetoothConnector.connect(device, peerToConnectTo); } catch (NullPointerException e) { Log.e(TAG, "connect: Failed to start connecting to peer " + peerToConnectTo.toString() + ": " + e.getMessage(), e); } } else { Log.e(TAG, "connect: The given device is null!"); } return success; } 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);  }