FileIDMigrator extends AbstractIDMigrator { @Override public String toStringID(long longID) { return longToString.get(longID); } FileIDMigrator(File dataFile);  FileIDMigrator(File dataFile, long minReloadIntervalMS); @Override String toStringID(long longID); @Override void refresh(Collection<Refreshable> alreadyRefreshed); @Override String toString(); static final long DEFAULT_MIN_RELOAD_INTERVAL_MS; }
@Test 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)); }
@Test public void testNoRefreshAfterFileUpdate() throws Exception { IDMigrator migrator = new FileIDMigrator(testFile, 0L); long dogAsLong = migrator.toLongID("dog"); migrator.toStringID(dogAsLong); Thread.sleep(2000L); writeLines(testFile, UPDATED_STRING_IDS); long cowAsLong = migrator.toLongID("cow"); long donkeyAsLong = migrator.toLongID("donkey"); assertEquals("dog", migrator.toStringID(dogAsLong)); assertEquals("cow", migrator.toStringID(cowAsLong)); assertNull(migrator.toStringID(donkeyAsLong)); }