SpeciesPropertiesTrader { @PostConstruct public String refresh() throws IOException { try { LOGGER.info("Reading species properties..."); ImmutableSortedMap<String, SpeciesProperties> newMap = buildMap(); MapDifference<String, SpeciesProperties> diff = Maps.difference(nameToSpecies, newMap); nameToSpecies = newMap; LOGGER.info("Retrieved {} species properties", nameToSpecies.size()); return describeMapDifference(diff); } catch (IOException e) { LOGGER.error("Error reading species properties"); throw e; } }  @Inject void setSpeciesPropertiesDao(SpeciesPropertiesDao speciesPropertiesDao); @PostConstruct String refresh(); SpeciesProperties get(String speciesName); Collection<SpeciesProperties> getAll();  }
@Test public void refresh() throws IOException { Files.copy( SpeciesPropertiesTraderTest.class.getResourceAsStream("species-tyrannosaurus-rex.json"), location, REPLACE_EXISTING); subject.refresh(); assertThat(subject.getAll(), hasSize(1)); assertThat(subject.getAll().iterator().next().referenceName(), is("tyrannosaurus rex")); }
@Test public void refreshDescribesChanges() throws IOException { String refreshMessage = subject.refresh(); assertThat(refreshMessage, is("No changes were made to the reference species")); Files.copy( SpeciesPropertiesTraderTest.class.getResourceAsStream("species-tyrannosaurus-rex.json"), location, REPLACE_EXISTING); refreshMessage = subject.refresh(); Pattern removedSpeciesPattern = Pattern.compile(".*\\[(.+)\\] removed.*"); Matcher matcher = removedSpeciesPattern.matcher(refreshMessage); matcher.find(); assertThat(matcher.group(1).split(", ").length, is(speciesPropertiesCountBeforeRefresh)); assertThat(refreshMessage, containsString("[Tyrannosaurus_rex] added")); }