### Question:
MapboxFusedLocationEngineImpl extends AndroidLocationEngineImpl { @SuppressLint("MissingPermission") @Override public void requestLocationUpdates(@NonNull LocationEngineRequest request, @NonNull LocationListener listener, @Nullable Looper looper) throws SecurityException { super.requestLocationUpdates(request, listener, looper); if (shouldStartNetworkProvider(request.getPriority())) { try { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, request.getInterval(), request.getDisplacement(), listener, looper); } catch (IllegalArgumentException iae) { iae.printStackTrace(); } } } MapboxFusedLocationEngineImpl(@NonNull Context context); @NonNull @Override LocationListener createListener(LocationEngineCallback<LocationEngineResult> callback); @Override void getLastLocation(@NonNull LocationEngineCallback<LocationEngineResult> callback); @SuppressLint("MissingPermission") @Override void requestLocationUpdates(@NonNull LocationEngineRequest request,
                                     @NonNull LocationListener listener,
                                     @Nullable Looper looper); @SuppressLint("MissingPermission") @Override void requestLocationUpdates(@NonNull LocationEngineRequest request,
                                     @NonNull PendingIntent pendingIntent);  }### Answer:
@Test public void requestLocationUpdatesOutdoors() { LocationEngineRequest request = new LocationEngineRequest.Builder(10) .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY).build(); LocationEngineCallback<LocationEngineResult> callback = mock(LocationEngineCallback.class); Looper looper = mock(Looper.class); when(locationManagerMock.getBestProvider(any(Criteria.class), anyBoolean())).thenReturn("gps"); engine.requestLocationUpdates(request, callback, looper); verify(locationManagerMock, times(2)).requestLocationUpdates(anyString(), anyLong(), anyFloat(), any(LocationListener.class), any(Looper.class)); }
@Test public void requestLocationUpdatesIndoors() { LocationEngineRequest request = new LocationEngineRequest.Builder(10) .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY).build(); LocationEngineCallback<LocationEngineResult> callback = mock(LocationEngineCallback.class); Looper looper = mock(Looper.class); when(locationManagerMock.getBestProvider(any(Criteria.class), anyBoolean())).thenReturn("network"); engine.requestLocationUpdates(request, callback, looper); verify(locationManagerMock, times(1)).requestLocationUpdates(anyString(), anyLong(), anyFloat(), any(LocationListener.class), any(Looper.class)); }
@Test public void requestLocationUpdatesOutdoorsWithPendingIntent() { LocationEngineRequest request = new LocationEngineRequest.Builder(10) .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY).build(); PendingIntent pendingIntent = mock(PendingIntent.class); when(locationManagerMock.getBestProvider(any(Criteria.class), anyBoolean())).thenReturn("gps"); engine.requestLocationUpdates(request, pendingIntent); verify(locationManagerMock, times(2)).requestLocationUpdates(anyString(), anyLong(), anyFloat(), any(PendingIntent.class)); }
@Test public void requestLocationUpdatesIndoorsWithPendingIntent() { LocationEngineRequest request = new LocationEngineRequest.Builder(10) .setPriority(LocationEngineRequest.PRIORITY_HIGH_ACCURACY).build(); PendingIntent pendingIntent = mock(PendingIntent.class); when(locationManagerMock.getBestProvider(any(Criteria.class), anyBoolean())).thenReturn("network"); engine.requestLocationUpdates(request, pendingIntent); verify(locationManagerMock, times(1)).requestLocationUpdates(anyString(), anyLong(), anyFloat(), any(PendingIntent.class)); }
@Test(expected = NullPointerException.class) public void requestLocationUpdatesNullCallback() { engine.requestLocationUpdates(null, null, null); }