CoexpressedGenesDao { public ImmutableList<String> coexpressedGenesFor(String experiment, String identifier) { try { String result = jdbcTemplate.queryForObject(CE_GENES_SQL_QUERY_TEMPLATE, String.class, experiment, identifier); return ImmutableList.copyOf( Stream.of(result.split(",")) .filter(geneId -> !geneId.equalsIgnoreCase(identifier)) .collect(toList())); } catch (IncorrectResultSizeDataAccessException e) { return ImmutableList.of(); } } CoexpressedGenesDao(JdbcTemplate jdbcTemplate); ImmutableList<String> coexpressedGenesFor(String experiment, String identifier);  }
@Test public void noResultsReturnsEmptyList() { when(jdbcTemplate.queryForObject(CE_GENES_SQL_QUERY_TEMPLATE, String.class, "E-FOOBAR", "ENSGFOOBAR")) .thenThrow(new EmptyResultDataAccessException(1)); assertThat(subject.coexpressedGenesFor("E-FOOBAR", "ENSGFOOBAR")).isEmpty(); }
@Test public void originalGeneIdIsFilteredOut() { when(jdbcTemplate.queryForObject(CE_GENES_SQL_QUERY_TEMPLATE, String.class, "E-FOOBAR", "ENSGFOOBAR")) .thenReturn("ENSGFOOBAR, ENSGFOOBAR1, ENSGFOOBAR2, ENSGFOOBAR3"); assertThat(subject.coexpressedGenesFor("E-FOOBAR", "ENSGFOOBAR")) .hasSize(3) .doesNotContain("ENSGFOOBAR"); }