Utils { @WorkerThread static void writeSettingsToFile(Context context, @NonNull CTGeofenceSettings ctGeofenceSettings) { CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Writing new settings to file..."); JSONObject settings = new JSONObject(); try { settings.put(CTGeofenceConstants.KEY_LAST_ACCURACY, ctGeofenceSettings.getLocationAccuracy()); settings.put(CTGeofenceConstants.KEY_LAST_FETCH_MODE, ctGeofenceSettings.getLocationFetchMode()); settings.put(CTGeofenceConstants.KEY_LAST_BG_LOCATION_UPDATES, ctGeofenceSettings.isBackgroundLocationUpdatesEnabled()); settings.put(CTGeofenceConstants.KEY_LAST_LOG_LEVEL, ctGeofenceSettings.getLogLevel()); settings.put(CTGeofenceConstants.KEY_LAST_GEO_COUNT, ctGeofenceSettings.getGeofenceMonitoringCount()); settings.put(CTGeofenceConstants.KEY_LAST_INTERVAL, ctGeofenceSettings.getInterval()); settings.put(CTGeofenceConstants.KEY_LAST_FASTEST_INTERVAL, ctGeofenceSettings.getFastestInterval()); settings.put(CTGeofenceConstants.KEY_LAST_DISPLACEMENT, ctGeofenceSettings.getSmallestDisplacement()); settings.put(CTGeofenceConstants.KEY_ID, CTGeofenceAPI.getInstance(context).getAccountId()); boolean writeJsonToFile = FileUtils.writeJsonToFile(context, FileUtils.getCachedDirName(context), CTGeofenceConstants.SETTINGS_FILE_NAME, settings); if (writeJsonToFile) { CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "New settings successfully written to file"); } else { CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Failed to write new settings to file"); } } catch (JSONException e) { CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Failed to write new settings to file while parsing json"); } catch (Exception e) { CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Failed to write new settings to file"); } }    }
@Test public void testWriteSettingsToFile() { mockStatic(FileUtils.class); WhiteboxImpl.setInternalState(ctGeofenceAPI, "accountId", "4RW-Z6Z-485Z"); when(FileUtils.getCachedDirName(application)).thenReturn(""); Utils.writeSettingsToFile(application, CTGeofenceSettingsFake.getSettings(CTGeofenceSettingsFake.getSettingsJsonObject())); verifyStatic(FileUtils.class); FileUtils.writeJsonToFile(application, FileUtils.getCachedDirName(application), CTGeofenceConstants.SETTINGS_FILE_NAME, CTGeofenceSettingsFake.getSettingsJsonObject()); }