GoogleLocationAdapter implements CTLocationAdapter { private void applySettings(Context context) { CTGeofenceSettings geofenceSettings = CTGeofenceAPI.getInstance(context).getGeofenceSettings(); if (geofenceSettings == null) { geofenceSettings = CTGeofenceAPI.getInstance(context).initDefaultConfig(); } locationFetchMode = geofenceSettings.getLocationFetchMode(); backgroundLocationUpdatesEnabled = geofenceSettings.isBackgroundLocationUpdatesEnabled(); interval = geofenceSettings.getInterval(); fastestInterval = geofenceSettings.getFastestInterval(); smallestDisplacement = geofenceSettings.getSmallestDisplacement(); int accuracy = geofenceSettings.getLocationAccuracy(); switch (accuracy) { case 1: locationAccuracy = LocationRequest.PRIORITY_HIGH_ACCURACY; break; case 2: locationAccuracy = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY; break; case 3: locationAccuracy = LocationRequest.PRIORITY_LOW_POWER; break; } } GoogleLocationAdapter(@NonNull Context context); @WorkerThread @Override void getLastLocation(@NonNull final CTLocationCallback callback); @WorkerThread @Override void removeLocationUpdates(@Nullable PendingIntent pendingIntent); @WorkerThread @Override void requestLocationUpdates();  }
@Test public void testApplySettings() { CTGeofenceSettings ctGeofenceSettings = new CTGeofenceSettings.Builder() .setLocationFetchMode(CTGeofenceSettings.FETCH_LAST_LOCATION_PERIODIC) .enableBackgroundLocationUpdates(true) .setInterval(2000000) .setFastestInterval(2000000) .setLocationAccuracy(CTGeofenceSettings.ACCURACY_LOW) .setSmallestDisplacement(900) .build(); when(ctGeofenceAPI.getGeofenceSettings()).thenReturn(ctGeofenceSettings); final GoogleLocationAdapter locationAdapter = new GoogleLocationAdapter(application); try { WhiteboxImpl.invokeMethod(locationAdapter, "applySettings", application); LocationRequest actualLocationRequest = WhiteboxImpl.invokeMethod(locationAdapter, "getLocationRequest"); assertEquals(ctGeofenceSettings.getInterval(), actualLocationRequest.getInterval()); assertEquals(ctGeofenceSettings.getFastestInterval(), actualLocationRequest.getFastestInterval()); assertEquals(ctGeofenceSettings.getSmallestDisplacement(), actualLocationRequest.getSmallestDisplacement(), 0); assertEquals(LocationRequest.PRIORITY_LOW_POWER, actualLocationRequest.getPriority()); Field actualFetchMode = WhiteboxImpl.getField(GoogleLocationAdapter.class, "locationFetchMode"); Field actualLocationUpdateEnabled = WhiteboxImpl.getField(GoogleLocationAdapter.class, "backgroundLocationUpdatesEnabled"); assertEquals(ctGeofenceSettings.getLocationFetchMode(), actualFetchMode.getInt(locationAdapter)); assertEquals(ctGeofenceSettings.isBackgroundLocationUpdatesEnabled(), actualLocationUpdateEnabled.getBoolean(locationAdapter)); } catch (Exception e) { e.printStackTrace(); } }