VersionRecordServiceImpl implements VersionRecordService { @Override public VersionRecord loadRecord(Path path) throws URISyntaxException { for (VersionRecord record : loadVersionRecords(util.getPath(path, "master"))) { String version = util.getVersion(path); if ("master".equals(version)) { return record; } else if (record.id().equals(version)) { return record; } } return null; } 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 testLoadRecord() throws Exception { ioService.setExistingPaths(pathToFile); VersionRecordServiceImpl versionRecordServiceImpl = new VersionRecordServiceImpl( ioService, new VersionUtil() { @Override public Path getPath(Path path, String version) throws URISyntaxException { return path; } @Override public String getVersion(Path path) { return "id3"; } } ); VersionRecord record = versionRecordServiceImpl.loadRecord(pathToFile); assertEquals(record.id(), "id3"); }
@Test public void testLoadRecordMaster() throws Exception { ioService.setExistingPaths(pathToFile); VersionRecordServiceImpl versionRecordServiceImpl = new VersionRecordServiceImpl( ioService, new VersionUtil() { @Override public Path getPath(Path path, String version) throws URISyntaxException { return path; } @Override public String getVersion(Path path) { return "master"; } } ); VersionRecord record = versionRecordServiceImpl.loadRecord(pathToFile); assertEquals(record.id(), "id1"); }