GoogleGeofenceAdapter implements CTGeofenceAdapter { @WorkerThread @Override public void stopGeofenceMonitoring(@Nullable final PendingIntent pendingIntent) { if (pendingIntent == null) { CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Can't stop geofence monitoring since provided pendingIntent is null"); return; } try { Task<Void> removeGeofenceTask = geofencingClient.removeGeofences(pendingIntent); Tasks.await(removeGeofenceTask); pendingIntent.cancel(); CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Geofence removed successfully"); } catch (Exception e) { CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Failed to remove registered geofences"); e.printStackTrace(); } } GoogleGeofenceAdapter(@NonNull Context context); @SuppressWarnings("unchecked") @WorkerThread @Override void addAllGeofence(@Nullable List<CTGeofence> fenceList,
            @NonNull final OnSuccessListener onSuccessListener); @SuppressWarnings("unchecked") @WorkerThread @Override void removeAllGeofence(@Nullable List<String> fenceIdList,
            @NonNull final OnSuccessListener onSuccessListener); @WorkerThread @Override void stopGeofenceMonitoring(@Nullable final PendingIntent pendingIntent);  }
@Test public void testStopGeofenceMonitoringTC1() { GoogleGeofenceAdapter geofenceAdapter = new GoogleGeofenceAdapter(application); geofenceAdapter.stopGeofenceMonitoring(null); verify(geofencingClient, never()).removeGeofences(any(PendingIntent.class)); }
@Test public void testStopGeofenceMonitoringTC2() { GoogleGeofenceAdapter geofenceAdapter = new GoogleGeofenceAdapter(application); when(geofencingClient.removeGeofences(pendingIntent)).thenReturn(task); geofenceAdapter.stopGeofenceMonitoring(pendingIntent); try { verifyStatic(Tasks.class); Tasks.await(task); verify(pendingIntent).cancel(); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }