Utils { @SuppressWarnings("BooleanMethodIsAlwaysInverted") @WorkerThread static boolean initCTGeofenceApiIfRequired(@NonNull Context context) { CTGeofenceAPI ctGeofenceAPI = CTGeofenceAPI.getInstance(context); if (ctGeofenceAPI.getCleverTapApi() == null) { CTGeofenceSettings ctGeofenceSettings = Utils.readSettingsFromFile(context); if (ctGeofenceSettings == null) { CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Could not initialize CT instance! Dropping this call"); return false; } CleverTapAPI cleverTapAPI = CleverTapAPI.getGlobalInstance(context, ctGeofenceSettings.getId()); if (cleverTapAPI == null) { CTGeofenceAPI.getLogger().debug(CTGeofenceAPI.GEOFENCE_LOG_TAG, "Critical issue :: After calling CleverTapAPI.getGlobalInstance also init is failed! Dropping this call"); return false; } ctGeofenceAPI.init(ctGeofenceSettings, cleverTapAPI); } return true; }    }
@Test public void testInitCTGeofenceApiIfRequired() { mockStatic(FileUtils.class); when(FileUtils.readFromFile(any(Context.class), anyString())).thenReturn(""); when(FileUtils.getCachedFullPath(any(Context.class), anyString())).thenReturn(""); boolean actualWhenSettingsAndCTApiIsNull = Utils.initCTGeofenceApiIfRequired(application); assertFalse("Must be false when cleverTapApi and settings is null", actualWhenSettingsAndCTApiIsNull); when(FileUtils.readFromFile(any(Context.class), anyString())).thenReturn(CTGeofenceSettingsFake.getSettingsJsonString()); boolean actualWhenSettingsNonNullAndCTApiIsNull = Utils.initCTGeofenceApiIfRequired(application); assertFalse("Must be false when cleverTapApi is null and settings is not null", actualWhenSettingsNonNullAndCTApiIsNull); mockStatic(CleverTapAPI.class); CleverTapAPI cleverTapAPI = Mockito.mock(CleverTapAPI.class); when(CleverTapAPI.getGlobalInstance(any(Context.class), anyString())) .thenReturn(cleverTapAPI); boolean actualWhenSettingsNonNullAndCTApiNonNull = Utils.initCTGeofenceApiIfRequired(application); assertTrue("Must be true when cleverTapApi is not null and settings is not null", actualWhenSettingsNonNullAndCTApiNonNull); WhiteboxImpl.setInternalState(ctGeofenceAPI, "cleverTapAPI", cleverTapAPI); boolean actualWhenCTApiNonNull = Utils.initCTGeofenceApiIfRequired(application); assertTrue("Must be true when cleverTapApi is not null", actualWhenCTApiNonNull); }