UALocationProvider { @Nullable @WorkerThread Cancelable requestSingleLocation(@NonNull LocationRequestOptions options, ResultCallback<Location> resultCallback) { connect(); if (availableAdapter == null) { Logger.debug("UALocationProvider - Ignoring request, connected adapter unavailable."); } Logger.verbose("UALocationProvider - Requesting single location update: %s", options); try { return availableAdapter.requestSingleLocation(context, options, resultCallback); } catch (Exception e) { Logger.error(e, "Unable to request location."); } return null; } UALocationProvider(@NonNull Context context, @NonNull Intent locationUpdateIntent); @VisibleForTesting  UALocationProvider(@NonNull Context context, @NonNull Intent locationUpdateIntent, LocationAdapter... adapters);   }
@Test public void testSingleLocationRequest() { when(mockAdapterTwo.isAvailable(context)).thenReturn(true); provider.requestSingleLocation(options, locationCallback); verify(mockAdapterTwo).requestSingleLocation(eq(context), eq(options), eq(locationCallback)); verify(mockAdapterOne, times(0)).requestSingleLocation(eq(context), eq(options), eq(locationCallback)); }
@Test public void testSingleLocationNoPermissions() { when(mockAdapterOne.isAvailable(context)).thenReturn(true); doThrow(new SecurityException("Nope")).when(mockAdapterOne).requestSingleLocation(context, options, locationCallback); }