ExperimentSearchService { public ImmutableSet<Experiment> searchPublicExperimentsByAccession(String accessionSubstring) { return experimentTrader.getPublicExperiments() .stream() .filter(experiment -> containsIgnoreCase(experiment.getAccession(), accessionSubstring)) .collect(toImmutableSet()); } ExperimentSearchService(ExperimentTrader experimentTrader); ImmutableSet<Experiment> searchPublicExperimentsBySpecies(String speciesSubstring); ImmutableSet<Experiment> searchPublicExperimentsByAccession(String accessionSubstring);  }
@Test void searchByAccession() { assertThat(subject.searchPublicExperimentsByAccession(ACCESSION_PATTERN)) .size() .isBetween(1, MATCH_EXPERIMENTS_COUNT); String searchPattern = ACCESSION_PATTERN.substring(0, RNG.nextInt(1, ACCESSION_PATTERN.length())); assertThat(subject.searchPublicExperimentsByAccession(searchPattern)) .size() .isGreaterThanOrEqualTo(MATCH_EXPERIMENTS_COUNT); }
@Test void searchByAccessionIsCaseInsensitive() { assertThat(subject.searchPublicExperimentsByAccession(ACCESSION_PATTERN.toLowerCase())) .containsExactlyElementsOf(subject.searchPublicExperimentsByAccession(ACCESSION_PATTERN.toUpperCase())); String searchPattern = ACCESSION_PATTERN.substring(0, RNG.nextInt(1, ACCESSION_PATTERN.length())); assertThat(subject.searchPublicExperimentsByAccession(searchPattern.toLowerCase())) .containsExactlyElementsOf(subject.searchPublicExperimentsByAccession(searchPattern.toUpperCase())); }
@Test void returnsEmptyIfNoAccessionMatches() { assertThat(subject.searchPublicExperimentsByAccession(ACCESSION_PATTERN + randomAlphabetic(1))) .isEmpty(); }