public void testLoadFromFile() throws Exception { IDMigrator migrator = new FileIDMigrator(testFile); long dogAsLong = migrator.toLongID("dog"); long cowAsLong = migrator.toLongID("cow"); long donkeyAsLong = migrator.toLongID("donkey"); assertEquals("dog", migrator.toStringID(dogAsLong)); assertEquals("cow", migrator.toStringID(cowAsLong)); assertNull(migrator.toStringID(donkeyAsLong)); }
public void testNoRefreshAfterFileUpdate() throws Exception { IDMigrator migrator = new FileIDMigrator(testFile, 0L); /* call a method to make sure the original file is loaded */ long dogAsLong = migrator.toLongID("dog"); migrator.toStringID(dogAsLong); /* change the underlying file, * we have to wait at least a second to see the change in the file's lastModified timestamp */ Thread.sleep(2000L); writeLines(testFile, UPDATED_STRING_IDS); /* we shouldn't see any changes in the data as we have not yet refreshed */ long cowAsLong = migrator.toLongID("cow"); long donkeyAsLong = migrator.toLongID("donkey"); assertEquals("dog", migrator.toStringID(dogAsLong)); assertEquals("cow", migrator.toStringID(cowAsLong)); assertNull(migrator.toStringID(donkeyAsLong)); }