SpeciesPropertiesDao { public ImmutableList<SpeciesProperties> fetchAll() throws IOException { ImmutableList.Builder<SpeciesProperties> allSpeciesPropertiesBuilder = ImmutableList.builder(); try (JsonReader reader = speciesPropertiesJsonFile.get()) { reader.beginArray(); while (reader.hasNext()) { allSpeciesPropertiesBuilder.add(readSpeciesProperties(reader)); } reader.endArray(); } return allSpeciesPropertiesBuilder.build(); } @Inject  SpeciesPropertiesDao(Path speciesPropertiesFilePath); ImmutableList<SpeciesProperties> fetchAll();  }
@Test public void fetchAll() throws Exception { subject = new SpeciesPropertiesDao( createSpeciesPropertiesFile( SpeciesPropertiesDaoTest.class.getResourceAsStream("species-properties.json"))); assertThat(subject.fetchAll(), hasSize(greaterThan(50))); }
@Test public void unknownFieldsAreIgnored() throws Exception { subject = new SpeciesPropertiesDao( createSpeciesPropertiesFile(toInputStream( SPECIES_PROPERTIES_JSON_WITH_UNKNOWN_FIELD, StandardCharsets.UTF_8))); assertThat(subject.fetchAll(), hasSize(1)); }
@Test(expected = IOException.class) public void invalidJsonThrowsException() throws Exception { subject = new SpeciesPropertiesDao( createSpeciesPropertiesFile(toInputStream("invalid JSON contents", StandardCharsets.UTF_8))); subject.fetchAll(); }