GoogleGeofenceAdapter implements CTGeofenceAdapter { @SuppressWarnings("unchecked") @WorkerThread @Override public void addAllGeofence(@Nullable List<CTGeofence> fenceList, @NonNull final OnSuccessListener onSuccessListener) { if (fenceList == null || fenceList.isEmpty()) { return; } ArrayList<Geofence> googleFenceList = getGoogleGeofences(fenceList); Void aVoid = null; try { PendingIntent geofencePendingIntent = PendingIntentFactory.getPendingIntent(context, PendingIntentFactory.PENDING_INTENT_GEOFENCE, FLAG_UPDATE_CURRENT); @SuppressLint("MissingPermission") Task<Void> addGeofenceTask = geofencingClient .addGeofences(getGeofencingRequest(googleFenceList), geofencePendingIntent); aVoid = Tasks.await(addGeofenceTask); CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Geofence registered successfully"); } catch (Exception e) { CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Failed to add geofences for monitoring"); e.printStackTrace(); } finally { onSuccessListener.onSuccess(aVoid); } } 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 testAddAllGeofenceTC1() { GoogleGeofenceAdapter geofenceAdapter = new GoogleGeofenceAdapter(application); geofenceAdapter.addAllGeofence(null, onSuccessListener); verify(geofencingClient, never()).addGeofences(any(GeofencingRequest.class), any(PendingIntent.class)); }
@Test public void testAddAllGeofenceTC2() { GoogleGeofenceAdapter geofenceAdapter = new GoogleGeofenceAdapter(application); geofenceAdapter.addAllGeofence(new ArrayList<CTGeofence>(), onSuccessListener); verify(geofencingClient, never()).addGeofences(any(GeofencingRequest.class), any(PendingIntent.class)); }
@Test public void testAddAllGeofenceTC3() { List<CTGeofence> ctGeofences = CTGeofence.from(GeofenceJSON.getGeofence()); GoogleGeofenceAdapter geofenceAdapter = new GoogleGeofenceAdapter(application); when(geofencingClient.addGeofences(any(GeofencingRequest.class), any(PendingIntent.class))) .thenReturn(task); geofenceAdapter.addAllGeofence(ctGeofences, onSuccessListener); try { verifyStatic(Tasks.class); Tasks.await(task); verify(onSuccessListener).onSuccess(null); } catch (ExecutionException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } }