### Question:
SortLocationsComponent extends DelegatingComponent { @Override public List<Object[]> execute() { List<Object[]> tuples = delegate().execute(); if (tuples.size() > 1) { Collections.sort(tuples, sortingComparator); } return tuples; } SortLocationsComponent( ProcessingComponent delegate );  SortLocationsComponent( ProcessingComponent delegate,
                                   Comparator<Object[]> sortingComparator ); @Override List<Object[]> execute();  }### Answer:
@Test public void shouldReturnAllResultsInPathOrderForTuplesContainingOneLocation() { 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")); List<Object[]> expected = new ArrayList<Object[]>(); expected.add(inputTuples.get(0)); expected.add(inputTuples.get(2)); expected.add(inputTuples.get(3)); expected.add(inputTuples.get(1)); assertThat(component.execute(), is(expected)); }
@Test public void shouldReturnAllResultsInPathOrderForTuplesContainingOneLocationAndWithDuplicateTuples() { 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[]>(); expected.add(inputTuples.get(6)); expected.add(inputTuples.get(0)); expected.add(inputTuples.get(2)); expected.add(inputTuples.get(3)); expected.add(inputTuples.get(5)); expected.add(inputTuples.get(1)); expected.add(inputTuples.get(4)); assertThat(component.execute(), is(expected)); }
@Test public void shouldReturnEmptyResultsWhenDelegateReturnsEmptyResults() { assertThat(component.execute().isEmpty(), is(true)); }