UALocationProvider { @WorkerThread void cancelRequests() { Logger.verbose("UALocationProvider - Canceling location requests."); connect(); if (availableAdapter == null) { Logger.debug("UALocationProvider - Ignoring request, connected adapter unavailable."); return; } try { PendingIntent pendingIntent = getPendingIntent(availableAdapter, PendingIntent.FLAG_NO_CREATE); if (pendingIntent != null) { availableAdapter.cancelLocationUpdates(context, pendingIntent); } } catch (Exception e) { Logger.error(e, "Unable to cancel location updates."); } } UALocationProvider(@NonNull Context context, @NonNull Intent locationUpdateIntent); @VisibleForTesting  UALocationProvider(@NonNull Context context, @NonNull Intent locationUpdateIntent, LocationAdapter... adapters);   }
@Test public void testCancelRequests() { when(mockAdapterOne.isAvailable(context)).thenReturn(false); when(mockAdapterTwo.isAvailable(context)).thenReturn(true); provider.requestLocationUpdates(options); provider.cancelRequests(); verify(mockAdapterOne, times(1)).isAvailable(context); verify(mockAdapterTwo, times(1)).isAvailable(context); verify(mockAdapterOne, times(0)).cancelLocationUpdates(eq(context), any(PendingIntent.class)); verify(mockAdapterTwo, times(1)).cancelLocationUpdates(eq(context), any(PendingIntent.class)); }
@Test public void testCancelLocationUpdatesNoPermissions() { when(mockAdapterOne.isAvailable(context)).thenReturn(true); doThrow(new SecurityException("Nope")).when(mockAdapterOne).cancelLocationUpdates(eq(context), any(PendingIntent.class)); provider.cancelRequests(); }