@Test public void testAddLocation() throws IOException { String fixturePath = "fixtures/animals/pets"; fixtureStore.addLocation(new Location(fixturePath)); assertTrue(fixtureStore.getFixtureLocations().contains(new Location(fixturePath))); List<String> fileNames = new ArrayList<>(); for(File file : fixtureStore.getFixtureFiles()) { fileNames.add(file.getName()); } assertTrue(fileNames.contains("cat.yml")); assertTrue(fileNames.contains("dog.yml")); }
@Override public void addLocation(Location location) { if (fixtureLocations.contains(location)) { logger.debug(location.getDescriptor() + " is already added."); return; } List<File> files = fixtureScanner.scan(location); if (files.size() == 0) { logger.warn("can not find any fixture file in " + location.getDescriptor()); return; } Map<String, FixtureMap> parsed = new HashMap<>(); for (File file : files) { if (fixtureFiles.contains(file)) continue; String fixtureStr; try { fixtureStr = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath()))); } catch (IOException e) { throw new RuntimeException("can not read " + file.getAbsolutePath(), e); } parsed.putAll(fixtureParser.parse(fixtureStr)); } fixtureFiles.addAll(files); fixtureLocations.add(location); fixtureMaps.putAll(parsed); }
DefaultFixturesStore implements FixturesStore { @Override public void addLocation(Location location) { if (fixtureLocations.contains(location)) { logger.debug(location.getDescriptor() + " is already added."); return; } List<File> files = fixtureScanner.scan(location); if (files.size() == 0) { logger.warn("can not find any fixture file in " + location.getDescriptor()); return; } Map<String, FixtureMap> parsed = new HashMap<>(); for (File file : files) { if (fixtureFiles.contains(file)) continue; String fixtureStr; try { fixtureStr = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath()))); } catch (IOException e) { throw new RuntimeException("can not read " + file.getAbsolutePath(), e); } parsed.putAll(fixtureParser.parse(fixtureStr)); } fixtureFiles.addAll(files); fixtureLocations.add(location); fixtureMaps.putAll(parsed); } }
DefaultFixturesStore implements FixturesStore { @Override public void addLocation(Location location) { if (fixtureLocations.contains(location)) { logger.debug(location.getDescriptor() + " is already added."); return; } List<File> files = fixtureScanner.scan(location); if (files.size() == 0) { logger.warn("can not find any fixture file in " + location.getDescriptor()); return; } Map<String, FixtureMap> parsed = new HashMap<>(); for (File file : files) { if (fixtureFiles.contains(file)) continue; String fixtureStr; try { fixtureStr = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath()))); } catch (IOException e) { throw new RuntimeException("can not read " + file.getAbsolutePath(), e); } parsed.putAll(fixtureParser.parse(fixtureStr)); } fixtureFiles.addAll(files); fixtureLocations.add(location); fixtureMaps.putAll(parsed); } DefaultFixturesStore();  DefaultFixturesStore(FixtureScanner fixtureScanner, FixtureParser fixtureParser); }
DefaultFixturesStore implements FixturesStore { @Override public void addLocation(Location location) { if (fixtureLocations.contains(location)) { logger.debug(location.getDescriptor() + " is already added."); return; } List<File> files = fixtureScanner.scan(location); if (files.size() == 0) { logger.warn("can not find any fixture file in " + location.getDescriptor()); return; } Map<String, FixtureMap> parsed = new HashMap<>(); for (File file : files) { if (fixtureFiles.contains(file)) continue; String fixtureStr; try { fixtureStr = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath()))); } catch (IOException e) { throw new RuntimeException("can not read " + file.getAbsolutePath(), e); } parsed.putAll(fixtureParser.parse(fixtureStr)); } fixtureFiles.addAll(files); fixtureLocations.add(location); fixtureMaps.putAll(parsed); } DefaultFixturesStore();  DefaultFixturesStore(FixtureScanner fixtureScanner, FixtureParser fixtureParser); @Override FixtureMap get(String fixtureKey); @Override FixtureMap reproduce(String fixtureKey); @Override boolean exists(String fixtureKey); @Override void addLocation(Location location); @Override void reset(); Set<Location> getFixtureLocations(); Set<File> getFixtureFiles(); Map<String, FixtureMap> getFixtureMaps(); }
DefaultFixturesStore implements FixturesStore { @Override public void addLocation(Location location) { if (fixtureLocations.contains(location)) { logger.debug(location.getDescriptor() + " is already added."); return; } List<File> files = fixtureScanner.scan(location); if (files.size() == 0) { logger.warn("can not find any fixture file in " + location.getDescriptor()); return; } Map<String, FixtureMap> parsed = new HashMap<>(); for (File file : files) { if (fixtureFiles.contains(file)) continue; String fixtureStr; try { fixtureStr = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath()))); } catch (IOException e) { throw new RuntimeException("can not read " + file.getAbsolutePath(), e); } parsed.putAll(fixtureParser.parse(fixtureStr)); } fixtureFiles.addAll(files); fixtureLocations.add(location); fixtureMaps.putAll(parsed); } DefaultFixturesStore();  DefaultFixturesStore(FixtureScanner fixtureScanner, FixtureParser fixtureParser); @Override FixtureMap get(String fixtureKey); @Override FixtureMap reproduce(String fixtureKey); @Override boolean exists(String fixtureKey); @Override void addLocation(Location location); @Override void reset(); Set<Location> getFixtureLocations(); Set<File> getFixtureFiles(); Map<String, FixtureMap> getFixtureMaps();  }