### Question:
SamplerImpl implements Sampler { @Timed @Override public Set<SimilaritySet> processRecommendations(Collection<IntArrayPair> recommendations) { return StreamUtils.stream(recommendations, parallel) .map(this::calculateSimilaritySet) .collect(Collectors.toSet()); }  @Timed @Override Set<SimilaritySet> processRecommendations(Collection<IntArrayPair> recommendations); @Timed @Override Optional<Set<SimilaritySet>> sample();  }### Answer:
@Test public void testDuplicateRecommendations() { when(leftRecords.iterator()).thenReturn(Collections.emptyIterator()); Sampler sampler = createSampler(); doReturn(Double.valueOf(1.0)).when(col1).getSimilarity(new int[]{0, 0}, new int[]{0, 0}); doReturn(Double.valueOf(0.5)).when(col2).getSimilarity(new int[]{0, 0}, new int[]{0, 0}); Collection<SimilaritySet> similaritySets = sampler .processRecommendations( Arrays.asList(new IntArrayPair(new int[]{0, 0}, new int[]{0, 0}), new IntArrayPair(new int[]{0, 0}, new int[]{0, 0}))); assertThat(similaritySets).hasSize(1); assertThat(similaritySets).contains(new SimilaritySet(new double[]{1.0, 0.5})); }
@Test public void testWithRecommendations() { when(leftRecords.iterator()).thenReturn(Collections.emptyIterator()); Sampler sampler = createSampler(); doReturn(Double.valueOf(1.0)).when(col1).getSimilarity(new int[]{0, 0}, new int[]{0, 0}); doReturn(Double.valueOf(0.0)).when(col1).getSimilarity(new int[]{0, 0}, new int[]{1, 1}); doReturn(Double.valueOf(0.5)).when(col2).getSimilarity(new int[]{0, 0}, new int[]{0, 0}); doReturn(Double.valueOf(0.3)).when(col2).getSimilarity(new int[]{0, 0}, new int[]{1, 1}); Collection<SimilaritySet> similaritySets = sampler .processRecommendations( Arrays.asList(new IntArrayPair(new int[]{0, 0}, new int[]{0, 0}), new IntArrayPair(new int[]{0, 0}, new int[]{1, 1}))); assertThat(similaritySets).hasSize(2); assertThat(similaritySets).contains(new SimilaritySet(new double[]{1.0, 0.5})); assertThat(similaritySets).contains(new SimilaritySet(new double[]{0.0, 0.3})); }