VersionRecordServiceImpl implements VersionRecordService { @Override public List<VersionRecord> load(Path path) { final List<VersionRecord> records = loadVersionRecords(path); final List<VersionRecord> result = loadVersionRecords(util.getDotFilePath(path)); for (final VersionRecord record : records) { if (doesNotContainID(record.id(), result)) { result.add(record); } } Collections.sort( result, new VersionRecordComparator()); return result; } VersionRecordServiceImpl(); @Inject  VersionRecordServiceImpl(@Named("ioStrategy") IOService ioService,
                                    VersionUtil util); @Override List<VersionRecord> load(Path path); @Override List<VersionRecord> loadVersionRecords(Path path); @Override VersionRecord loadRecord(Path path);  }
@Test public void testSimple() throws Exception { ioService.setExistingPaths(pathToFile, pathToDotFile); VersionRecordServiceImpl versionRecordServiceImpl = new VersionRecordServiceImpl( ioService, new VersionUtil() ); List<VersionRecord> versions = versionRecordServiceImpl.load(pathToFile); assertEquals(5, versions.size()); assertEquals("id1", versions.get(0).id()); assertEquals("id2", versions.get(1).id()); assertEquals("id3", versions.get(2).id()); assertEquals("id4", versions.get(3).id()); assertEquals("id5", versions.get(4).id()); }
@Test public void testMainFileHasHigherPriorityWhenCommitTimeIsEqual() throws Exception { ioService.setExistingPaths(pathToFile, pathToDotFile); mainFileVersionRecords.clear(); dotFileVersionRecords.clear(); mainFileVersionRecords.add(makeVersionRecord("main file", "default: new Date(1))); dotFileVersionRecords.add(makeVersionRecord("dot1 file", "default: new Date(1))); VersionRecordServiceImpl versionRecordServiceImpl = new VersionRecordServiceImpl( ioService, new VersionUtil() ); List<VersionRecord> versions = versionRecordServiceImpl.load(pathToFile); assertEquals(2, versions.size()); assertEquals("main file", versions.get(0).id()); assertEquals("dot1 file", versions.get(1).id()); }
@Test public void testNoDotFile() throws Exception { ioService.setExistingPaths(pathToFile); VersionRecordServiceImpl versionRecordServiceImpl = new VersionRecordServiceImpl( ioService, new VersionUtil() ); List<VersionRecord> versions = versionRecordServiceImpl.load(pathToFile); assertEquals(3, versions.size()); assertEquals("id1", versions.get(0).id()); assertEquals("id3", versions.get(1).id()); assertEquals("id4", versions.get(2).id()); }