UALocationProvider { @WorkerThread void requestLocationUpdates(@NonNull LocationRequestOptions options) { connect(); if (availableAdapter == null) { Logger.debug("UALocationProvider - Ignoring request, connected adapter unavailable."); return; } Logger.verbose("UALocationProvider - Requesting location updates: %s", options); try { PendingIntent pendingIntent = getPendingIntent(availableAdapter, PendingIntent.FLAG_UPDATE_CURRENT); if (pendingIntent != null) { availableAdapter.requestLocationUpdates(context, options, pendingIntent); } else { Logger.error("Unable to request location updates. Null pending intent."); } } catch (Exception e) { Logger.error(e, "Unable to request location updates."); } } UALocationProvider(@NonNull Context context, @NonNull Intent locationUpdateIntent); @VisibleForTesting  UALocationProvider(@NonNull Context context, @NonNull Intent locationUpdateIntent, LocationAdapter... adapters);   }
@Test public void testRequestLocationUpdates() { when(mockAdapterTwo.isAvailable(context)).thenReturn(true); provider.requestLocationUpdates(options); verify(mockAdapterTwo).requestLocationUpdates(eq(context), eq(options), any(PendingIntent.class)); verify(mockAdapterOne, times(0)).requestLocationUpdates(eq(context), eq(options), any(PendingIntent.class)); }
@Test public void testRequestLocationUpdatesNoPermissions() { when(mockAdapterOne.isAvailable(context)).thenReturn(true); doThrow(new SecurityException("Nope")).when(mockAdapterOne).requestLocationUpdates(eq(context), eq(options), any(PendingIntent.class)); provider.requestLocationUpdates(options); }