@Test public void testSetAsyncWithCurrentInstallation() throws Exception { InstallationId installationId = mock(InstallationId.class); //noinspection unchecked ParseObjectStore<ParseInstallation> store = mock(ParseObjectStore.class); // Create test controller CachedCurrentInstallationController controller = new CachedCurrentInstallationController(store, installationId); ParseInstallation currentInstallation = mock(ParseInstallation.class); when(currentInstallation.getInstallationId()).thenReturn("testInstallationId"); controller.currentInstallation = currentInstallation; ParseTaskUtils.wait(controller.setAsync(currentInstallation)); // Verify that we persist it verify(store, times(1)).setAsync(currentInstallation); // Make sure installationId is updated verify(installationId, times(1)).set("testInstallationId"); }
@Test public void testGetAsyncFromStore() throws Exception { // Mock installationId InstallationId installationId = mock(InstallationId.class); //noinspection unchecked ParseObjectStore<ParseInstallation> store = mock(ParseObjectStore.class); ParseInstallation installation = mock(ParseInstallation.class); when(installation.getInstallationId()).thenReturn("testInstallationId"); when(store.getAsync()).thenReturn(Task.forResult(installation)); // Create test controller CachedCurrentInstallationController controller = new CachedCurrentInstallationController(store, installationId); ParseInstallation currentInstallation = ParseTaskUtils.wait(controller.getAsync()); verify(store, times(1)).getAsync(); // Make sure installationId is updated verify(installationId, times(1)).set("testInstallationId"); // Make sure controller state is update to date assertSame(installation, controller.currentInstallation); // Make sure the installation we get is correct assertSame(installation, currentInstallation); }
@Test public void testSetSameDoesNotWriteToDisk() { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); InstallationId installationId = new InstallationId(installationIdFile); String installationIdString = installationId.get(); ParseFileUtils.deleteQuietly(installationIdFile); installationId.set(installationIdString); assertFalse(installationIdFile.exists()); }
@Test public void testSetThenGet() { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); InstallationId installationId = new InstallationId(installationIdFile); installationId.set("test_installation_id"); assertEquals("test_installation_id", installationId.get()); }
@Test public void testSetWritesInstallationIdToFile() throws Exception { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); InstallationId installationId = new InstallationId(installationIdFile); installationId.set("test_installation_id"); assertEquals("test_installation_id", ParseFileUtils.readFileToString(installationIdFile, "UTF-8")); }
@Test public void testSetEmptyStringDoesNotPersist() { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); InstallationId installationId = new InstallationId(installationIdFile); String installationIdString = installationId.get(); installationId.set(""); assertEquals(installationIdString, installationId.get()); } }
@Test public void testSetNullDoesNotPersist() { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); InstallationId installationId = new InstallationId(installationIdFile); String installationIdString = installationId.get(); installationId.set(null); assertEquals(installationIdString, installationId.get()); }