### Question:
ResultsSorter { private void sortChanged(ObservableValue<? extends String> observable, String oldValue, String newValue) { myEvent = true; if (SearchModel.RELEVANCE_SORT.equals(newValue)) { myModel.getShownResults().sort(this::compareRelevance); } else if (SearchModel.NAME_SORT.equals(newValue)) { myModel.getShownResults().sort(this::compareName); } myEvent = false; } ResultsSorter(SearchModel model); void close();  }### Answer:
@Test public void testSortChanged() { 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)); model.getSortType().set(SearchModel.NAME_SORT); assertEquals(highConfidence, model.getShownResults().get(1)); assertEquals(lowConfidence, model.getShownResults().get(0)); sorter.close(); model.getSortType().set(SearchModel.RELEVANCE_SORT); assertEquals(highConfidence, model.getShownResults().get(1)); assertEquals(lowConfidence, model.getShownResults().get(0)); }