GeneSearchService { public Map<String, Map<String, List<String>>> getCellIdsInExperiments(String... geneIds) { return fetchInParallel( ImmutableSet.copyOf(geneIds), geneId -> geneSearchDao.fetchCellIds(geneId)); } GeneSearchService(GeneSearchDao geneSearchDao, TsnePlotSettingsService tsnePlotSettingsService); Map<String, Map<String, List<String>>> getCellIdsInExperiments(String... geneIds); Map<String, Map<String, List<String>>> getFacets(List<String> cellIds); Map<String, Map<String, Map<Integer, List<Integer>>>> getMarkerGeneProfile(String... geneIds);  }
@Test void returnsCellIdsPerExperiment() { String experimentAccession1 = generateRandomExperimentAccession(); String experimentAccession2 = generateRandomExperimentAccession(); String experimentAccession3 = generateRandomExperimentAccession(); String geneId = generateRandomEnsemblGeneId(); Map<String, List<String>> ensg00000104957Cells = ImmutableMap.of( experimentAccession1, ImmutableList.of("cell_id_1", "cell_id_2", "cell_id_3", "cell_id_4", "cell_id_5"), experimentAccession2, ImmutableList.of("cell_id_6", "cell_id_7", "cell_id_8"), experimentAccession3 , ImmutableList.of("cell_id_9", "cell_id_10")); when(geneSearchDaoMock.fetchCellIds(geneId)).thenReturn(ensg00000104957Cells); Map<String, Map<String, List<String>>> result = subject.getCellIdsInExperiments(geneId); assertThat(result) .containsOnlyKeys(geneId) .containsAllEntriesOf(ImmutableMap.of(geneId, ensg00000104957Cells)); }
@Test void cellIdsPerExperimentForMultipleGeneIds() { String experimentAccession1 = generateRandomExperimentAccession(); String experimentAccession2 = generateRandomExperimentAccession(); String experimentAccession3 = generateRandomExperimentAccession(); String experimentAccession4 = generateRandomExperimentAccession(); String experimentAccession5 = generateRandomExperimentAccession(); String geneId1 = generateRandomEnsemblGeneId(); String geneId2 = generateRandomEnsemblGeneId(); Map<String, List<String>> ensfoobar1Cells = ImmutableMap.of( experimentAccession1, ImmutableList.of("cell_id_1", "cell_id_2", "cell_id_3", "cell_id_4", "cell_id_5"), experimentAccession2, ImmutableList.of("cell_id_6", "cell_id_7", "cell_id_8"), experimentAccession3, ImmutableList.of("cell_id_9", "cell_id_10")); Map<String, List<String>> ensfoobar2Cells = ImmutableMap.of( experimentAccession4, ImmutableList.of("cell_id_11", "cell_id_12", "cell_id_13"), experimentAccession5, ImmutableList.of("cell_id_14", "cell_id_15")); when(geneSearchDaoMock.fetchCellIds(geneId1)).thenReturn(ensfoobar1Cells); when(geneSearchDaoMock.fetchCellIds(geneId2)).thenReturn(ensfoobar2Cells); assertThat(subject.getCellIdsInExperiments(geneId1, geneId2)) .containsAllEntriesOf(ImmutableMap.of(geneId1, ensfoobar1Cells, geneId2, ensfoobar2Cells)); }
@Test void exceptionsThrownInParallelTasksAreWrapped() { doThrow(new UncheckedIOException(new IOException())).when(geneSearchDaoMock).fetchCellIds(anyString()); assertThatExceptionOfType(RuntimeException.class).isThrownBy( () -> subject.getCellIdsInExperiments(generateRandomExperimentAccession())) .withCauseInstanceOf(ExecutionException.class); }