TeeRepository extends MergeableRepository { @Override public RepositoryDTO fetchInstallableApplications() { final Map<Repository, RepositoryDTO> repositoriesMap = Arrays.asList(leftRepository, rightRepository).stream() .collect(Collectors.toMap(source -> source, Repository::fetchInstallableApplications)); return mergeRepositories(repositoriesMap, Arrays.asList(leftRepository, rightRepository)); } TeeRepository(Repository leftRepository, Repository rightRepository); @Override RepositoryDTO fetchInstallableApplications(); @Override void onDelete(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void testFetchInstallableApplicationsOnlyCategoriesNoCollapseNumberOfResultIsCorrect() { final Repository leftSource = () -> new RepositoryDTO.Builder() .withTypes(Collections.singletonList( new TypeDTO.Builder().withId("Type 1") .withCategories(Arrays.asList( new CategoryDTO.Builder().withId("Category 1").build(), new CategoryDTO.Builder().withId("Category 2").build())) .build())) .build(); final Repository rightSource = () -> new RepositoryDTO.Builder() .withTypes(Collections.singletonList( new TypeDTO.Builder().withId("Type 1") .withCategories( Arrays.asList(new CategoryDTO.Builder().withId("Category 3").build(), new CategoryDTO.Builder().withId("Category 4").build(), new CategoryDTO.Builder().withId("Category 5").build())) .build())) .build(); final Repository teeSource = new TeeRepository(leftSource, rightSource); assertEquals(5, teeSource.fetchInstallableApplications().getTypes().get(0).getCategories().size()); }
@Test public void testFetchInstallableApplicationsOnlyCategoriesCollapseNumberOfResultIsCorrect() { final Repository leftSource = () -> new RepositoryDTO.Builder() .withTypes(Collections.singletonList( new TypeDTO.Builder().withId("Type 1") .withCategories( Arrays.asList( new CategoryDTO.Builder().withId("Category 1").build(), new CategoryDTO.Builder().withId("Category 2").build())) .build())) .build(); final Repository rightSource = () -> new RepositoryDTO.Builder() .withTypes(Collections.singletonList( new TypeDTO.Builder().withId("Type 1") .withCategories( Arrays.asList( new CategoryDTO.Builder().withId("Category 2").build(), new CategoryDTO.Builder().withId("Category 4").build(), new CategoryDTO.Builder().withId("Category 5").build())) .build())) .build(); final Repository teeSource = new TeeRepository(leftSource, rightSource); assertEquals(4, teeSource.fetchInstallableApplications().getTypes().get(0).getCategories().size()); }