### Question:
ResultsSorter { public void close() { myModel.getShownResults().removeListener(myListListener); myModel.getSortType().removeListener(mySortTypeListener); } ResultsSorter(SearchModel model); void close();  }### Answer:
@Test public void testSortDefault() { SearchResult lowConfidence = new SearchResult(); lowConfidence.setConfidence(.4f); lowConfidence.setText("A"); SearchResult highConfidence = new SearchResult(); highConfidence.setConfidence(.9f); highConfidence.setText("Z"); SearchModel model = new SearchModel(); model.getShownResults().addAll(New.list(lowConfidence, highConfidence)); ResultsSorter sorter = new ResultsSorter(model); assertEquals(highConfidence, model.getShownResults().get(0)); assertEquals(lowConfidence, model.getShownResults().get(1)); sorter.close(); model.getSortType().set(SearchModel.NAME_SORT); assertEquals(highConfidence, model.getShownResults().get(0)); assertEquals(lowConfidence, model.getShownResults().get(1)); }
@Test public void testSortNewItems() { SearchResult lowConfidence = new SearchResult(); lowConfidence.setConfidence(.4f); lowConfidence.setText("A"); SearchResult highConfidence = new SearchResult(); highConfidence.setConfidence(.9f); highConfidence.setText("Z"); SearchModel model = new SearchModel(); ResultsSorter sorter = new ResultsSorter(model); model.getShownResults().addAll(New.list(lowConfidence, highConfidence)); assertEquals(highConfidence, model.getShownResults().get(0)); assertEquals(lowConfidence, model.getShownResults().get(1)); sorter.close(); model.getSortType().set(SearchModel.NAME_SORT); assertEquals(highConfidence, model.getShownResults().get(0)); assertEquals(lowConfidence, model.getShownResults().get(1)); }