### Question:
InstallationId { public String get() { synchronized (lock) { if (installationId == null) { try { installationId = ParseFileUtils.readFileToString(file, "UTF-8"); } catch (FileNotFoundException e) { PLog.i(TAG, "Couldn't find existing installationId file. Creating one instead."); } catch (IOException e) { PLog.e(TAG, "Unexpected exception reading installation id from disk", e); } } if (installationId == null) { setInternal(UUID.randomUUID().toString()); } } return installationId; } InstallationId(File file); String get(); void set(String newInstallationId);  }### Answer:
@Test public void testGetGeneratesInstallationIdAndFile() throws Exception{ File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); InstallationId installationId = new InstallationId(installationIdFile); String installationIdString = installationId.get(); assertNotNull(installationIdString); assertEquals(installationIdString, ParseFileUtils.readFileToString(installationIdFile, "UTF-8")); }
@Test public void testGetGeneratesInstallationIdAndFile() throws Exception { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); InstallationId installationId = new InstallationId(installationIdFile); String installationIdString = installationId.get(); assertNotNull(installationIdString); assertEquals(installationIdString, ParseFileUtils.readFileToString(installationIdFile, "UTF-8")); }
@Test public void testGetReadsInstallationIdFromFile() throws Exception { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); InstallationId installationId = new InstallationId(installationIdFile); ParseFileUtils.writeStringToFile(installationIdFile, "test_installation_id", "UTF-8"); assertEquals("test_installation_id", installationId.get()); }
@Test public void testInstallationIdIsCachedInMemory() { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); InstallationId installationId = new InstallationId(installationIdFile); String installationIdString = installationId.get(); ParseFileUtils.deleteQuietly(installationIdFile); assertEquals(installationIdString, installationId.get()); }
@Test public void testInstallationIdIsRandom() { File installationIdFile = new File(temporaryFolder.getRoot(), "installationId"); String installationIdString = new InstallationId(installationIdFile).get(); ParseFileUtils.deleteQuietly(installationIdFile); assertFalse(installationIdString.equals(new InstallationId(installationIdFile).get())); }