ImagesRepositoryImpl implements ImagesRepository { @Override public List<FindImagesResult> findImages(FindImagesRequest findImagesRequest) { QueryResult imagesResult = queryRepository.query(findImagesRequest.getPayload()); Data data = imagesResult.getData(); Map<String, FindImagesResult> resultsMap = new LinkedHashMap<>(); data.getRows().forEach(r -> { ValueFormatter vf = new ValueFormatter(data, r); String imageId = vf.getString("images.id"); FindImagesResult findImagesResult = resultsMap.getOrDefault(imageId, new FindImagesResult( vf.getString("images.id"), vf.getString("images.real_id"), vf.getString("images.name"), vf.getString("images.cloud_type"), vf.getString("images.state"), vf.getString("images.last_updated") )); String projectId = vf.getString("projects.id"); String projectName = vf.getString("projects.name"); findImagesResult.getProjectIds().add(projectId); findImagesResult.getProjectNames().add(projectName); resultsMap.put(imageId, findImagesResult); }); return new ArrayList<>(resultsMap.values()); }  @Override List<FindImagesResult> findImages(FindImagesRequest findImagesRequest); @Override Set<String> addImages(List<Image> images); @Override Set<String> deleteImages(Collection<String> imageIds);  }
@Test public void testFindImages() { Project project = EntityGenerator.getProject(); Image image = EntityGenerator.getImage(); QueryResult queryResult = createMockImagesResult(project, image); mockQueryRepository.addQueryResult(queryResult); FindImagesRequest findImagesRequest = requestProvider.get(FindImagesRequest.class); List<FindImagesResult> images = imagesRepository.findImages(findImagesRequest); assertThat(images, hasSize(1)); FindImagesResult result = images.get(0); assertThat(result.getId(), equalTo(image.getId())); assertThat(result.getRealId(), equalTo(image.getRealId())); assertThat(result.getName(), equalTo(image.getName())); assertThat(result.getCloudType(), equalTo(image.getCloudType())); assertThat(result.getState(), equalTo(image.getState().value())); assertThat(result.getLastUpdated(), is(notNullValue())); assertThat(result.getProjectIds(), contains(project.getId())); assertThat(result.getProjectNames(), contains(project.getName())); }