### Question:
SamplerImpl implements Sampler { @Timed @Override public Optional<Set<SimilaritySet>> sample() { return IteratorUtils.next(left) .map(this::sample); }  @Timed @Override Set<SimilaritySet> processRecommendations(Collection<IntArrayPair> recommendations); @Timed @Override Optional<Set<SimilaritySet>> sample();  }### Answer:
@Test public void test() { Collection<int[]> left = ImmutableList.<int[]>builder() .add(new int[]{0, 0}) .build(); when(leftRecords.iterator()).thenReturn(left.iterator()); 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}); Optional<Set<SimilaritySet>> similaritySets = sampler.sample(); Assert.assertThat(similaritySets, isPresentAnd(hasSize(2))); Assert.assertThat(similaritySets, isPresentAnd(hasItem(new SimilaritySet(new double[]{1.0, 0.5})))); Assert.assertThat(similaritySets, isPresentAnd(hasItem(new SimilaritySet(new double[]{0.0, 0.3})))); }
@Test public void testMultiple() { Collection<int[]> left = ImmutableList.<int[]>builder() .add(new int[]{0, 0}) .build(); when(leftRecords.iterator()).thenReturn(left.iterator()); 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}); sampler.sample(); Optional<Set<SimilaritySet>> similaritySets = sampler.sample(); assertThat(similaritySets).isEmpty(); }