### Question:
DistinctComponent extends DelegatingComponent { @Override public List<Object[]> execute() { List<Object[]> tuples = delegate().execute(); if (tuples.size() > 1) { Iterator<Object[]> iter = tuples.iterator(); int locationCount = getColumns().getLocationCount(); int firstLocationIndex = getColumns().getColumnCount(); if (locationCount == 1) { Set<Location> found = new HashSet<Location>(); while (iter.hasNext()) { Location location = (Location)iter.next()[firstLocationIndex]; if (!found.add(location)) { iter.remove(); } } } else { assert locationCount > 1; Set<Location[]> found = new HashSet<Location[]>(); while (iter.hasNext()) { Object[] tuple = iter.next(); Location[] locations = new Location[locationCount]; System.arraycopy(tuple, firstLocationIndex, locations, 0, locationCount); if (!found.add(locations)) { iter.remove(); } } } } return tuples; } DistinctComponent( ProcessingComponent delegate ); @Override List<Object[]> execute();  }### Answer:
@Test public void shouldReturnAllResultsIfThereAreNoDuplicatesInTuplesContainingOneLocation() { inputTuples.add(tuple(columns, "/a/b/c1", "v1", "v2", "v3")); inputTuples.add(tuple(columns, "/a/b/c4", "v1", "v2", "v3")); inputTuples.add(tuple(columns, "/a/b/c2", "v1", "v2", "v3")); inputTuples.add(tuple(columns, "/a/b/c3", "v1", "v2", "v3")); assertThat(component.execute(), is(inputTuples)); }
@Test public void shouldReturnNoDuplicatesFromTuplesContainingOneLocation() { inputTuples.add(tuple(columns, "/a/b/c1", "v1", "v2", "v3")); inputTuples.add(tuple(columns, "/a/b/c4", "v1", "v2", "v3")); inputTuples.add(tuple(columns, "/a/b/c2", "v1", "v2", "v3")); inputTuples.add(tuple(columns, "/a/b/c3", "v1", "v2", "v3")); inputTuples.add(tuple(columns, "/a/b/c4", "v1", "v2", "v3")); inputTuples.add(tuple(columns, "/a/b/c3", "v1", "v2", "v3")); inputTuples.add(tuple(columns, "/a/b/c0", "v1", "v2", "v3")); List<Object[]> expected = new ArrayList<Object[]>(inputTuples); expected.remove(5); expected.remove(4); assertThat(component.execute(), is(expected)); }
@Test public void shouldReturnEmptyResultsWhenDelegateReturnsEmptyResults() { assertThat(component.execute().isEmpty(), is(true)); }