private void updateTimezone() { String zone = TimeZone.getDefault().getID(); if ((zone.indexOf('/') > 0 || zone.equals("GMT")) && !zone.equals(get(KEY_TIME_ZONE))) { performPut(KEY_TIME_ZONE, zone); } }
@Test public void testGetAsyncWithNoInstallation() throws Exception { // Mock installationId InstallationId installationId = mock(InstallationId.class); when(installationId.get()).thenReturn("testInstallationId"); //noinspection unchecked ParseObjectStore<ParseInstallation> store = mock(ParseObjectStore.class); when(store.getAsync()).thenReturn(Task.<ParseInstallation>forResult(null)); // Create test controller CachedCurrentInstallationController controller = new CachedCurrentInstallationController(store, installationId); ParseInstallation currentInstallation = ParseTaskUtils.wait(controller.getAsync()); verify(store, times(1)).getAsync(); // Make sure controller state is update to date assertSame(controller.currentInstallation, currentInstallation); // Make sure device info is updated assertEquals("testInstallationId", currentInstallation.getInstallationId()); assertEquals("android", currentInstallation.get(KEY_DEVICE_TYPE)); }
private void updateLocaleIdentifier() { final Locale locale = Locale.getDefault(); String language = locale.getLanguage(); String country = locale.getCountry(); if (TextUtils.isEmpty(language)) { return; } // rewrite depreciated two-letter codes if (language.equals("iw")) language = "he"; // Hebrew if (language.equals("in")) language = "id"; // Indonesian if (language.equals("ji")) language = "yi"; // Yiddish String localeString = language; if (!TextUtils.isEmpty(country)) { localeString = String.format(Locale.US, "%s-%s", language, country); } if (!localeString.equals(get(KEY_LOCALE))) { performPut(KEY_LOCALE, localeString); } }
@Test public void testGetAsyncWithNoInstallationRaceCondition() throws ParseException { // Mock installationId InstallationId installationId = mock(InstallationId.class); when(installationId.get()).thenReturn("testInstallationId"); //noinspection unchecked ParseObjectStore<ParseInstallation> store = mock(ParseObjectStore.class); TaskCompletionSource<ParseInstallation> tcs = new TaskCompletionSource(); when(store.getAsync()).thenReturn(tcs.getTask()); // Create test controller CachedCurrentInstallationController controller = new CachedCurrentInstallationController(store, installationId); Task<ParseInstallation> taskA = controller.getAsync(); Task<ParseInstallation> taskB = controller.getAsync(); tcs.setResult(null); ParseInstallation installationA = ParseTaskUtils.wait(taskA); ParseInstallation installationB = ParseTaskUtils.wait(taskB); verify(store, times(1)).getAsync(); assertSame(controller.currentInstallation, installationA); assertSame(controller.currentInstallation, installationB); // Make sure device info is updated assertEquals("testInstallationId", installationA.getInstallationId()); assertEquals("android", installationA.get(KEY_DEVICE_TYPE)); }
private void updateVersionInfo() { synchronized (mutex) { try { Context context = Parse.getApplicationContext(); String packageName = context.getPackageName(); PackageManager pm = context.getPackageManager(); PackageInfo pkgInfo = pm.getPackageInfo(packageName, 0); String appVersion = pkgInfo.versionName; String appName = pm.getApplicationLabel(pm.getApplicationInfo(packageName, 0)).toString(); if (packageName != null && !packageName.equals(get(KEY_APP_IDENTIFIER))) { performPut(KEY_APP_IDENTIFIER, packageName); } if (appName != null && !appName.equals(get(KEY_APP_NAME))) { performPut(KEY_APP_NAME, appName); } if (appVersion != null && !appVersion.equals(get(KEY_APP_VERSION))) { performPut(KEY_APP_VERSION, appVersion); } } catch (PackageManager.NameNotFoundException e) { PLog.w(TAG, "Cannot load package info; will not be saved to installation"); } } }
/* package */ void updateDeviceInfo(InstallationId installationId) { /* * If we don't have an installationId, use the one that comes from the installationId file on * disk. This should be impossible since we set the installationId in setDefaultValues. */ if (!has(KEY_INSTALLATION_ID)) { performPut(KEY_INSTALLATION_ID, installationId.get()); } String deviceType = "android"; if (!deviceType.equals(get(KEY_DEVICE_TYPE))) { performPut(KEY_DEVICE_TYPE, deviceType); } }
@Test public void testHandleSaveResultAsync() throws Exception { // Mock currentInstallationController to make setAsync work ParseCurrentInstallationController controller = mock(ParseCurrentInstallationController.class); when(controller.setAsync(any(ParseInstallation.class))).thenReturn(Task.<Void>forResult(null)); ParseCorePlugins.getInstance().registerCurrentInstallationController(controller); // Mock return state ParseInstallation.State state = new ParseInstallation.State.Builder("_Installation") .put("key", "value") .build(); ParseInstallation installation = new ParseInstallation(); installation.put("keyAgain", "valueAgain"); ParseOperationSet operationSet = installation.startSave(); ParseTaskUtils.wait(installation.handleSaveResultAsync(state, operationSet)); // Make sure the installation data is correct assertEquals("value", installation.get("key")); assertEquals("valueAgain", installation.get("keyAgain")); // Make sure we set the currentInstallation verify(controller, times(1)).setAsync(installation); }
@Test public void testHandleFetchResultAsync() throws Exception { // Mock currentInstallationController to make setAsync work ParseCurrentInstallationController controller = mock(ParseCurrentInstallationController.class); when(controller.setAsync(any(ParseInstallation.class))).thenReturn(Task.<Void>forResult(null)); ParseCorePlugins.getInstance().registerCurrentInstallationController(controller); // Mock return state ParseInstallation.State state = new ParseInstallation.State.Builder("_Installation") .put("key", "value") .isComplete(true) .build(); ParseInstallation installation = new ParseInstallation(); ParseTaskUtils.wait(installation.handleFetchResultAsync(state)); // Make sure the installation data is correct assertEquals("value", installation.get("key")); // Make sure we set the currentInstallation verify(controller, times(1)).setAsync(installation); }