/** Tests method to retrieve sorted and filtered search results. */
  public void testGetSortedSearchResults() {
    // Create test search results.
    TestSearchResult testResult1 = new TestSearchResult("1", "xray");
    TestSearchResult testResult2 = new TestSearchResult("2", "zulu");
    TestSearchResult testResult3 = new TestSearchResult("3", "whiskey");
    TestSearchResult testResult4 = new TestSearchResult("4", "yankee");

    model.addSearchResult(testResult1);
    model.addSearchResult(testResult2);
    model.addSearchResult(testResult3);
    model.addSearchResult(testResult4);

    // Get sorted search results.
    model.setSelectedCategory(SearchCategory.ALL);
    List<VisualSearchResult> sortedList = model.getSortedSearchResults();

    // Verify unsorted order.
    String expectedReturn = "xray";
    String actualReturn = sortedList.get(0).getHeading();
    assertEquals("unsorted list", expectedReturn, actualReturn);

    // Apply sort option.
    model.setSortOption(SortOption.NAME);

    // Verify sorted order.
    expectedReturn = "whiskey";
    actualReturn = sortedList.get(0).getHeading();
    assertEquals("sorted list", expectedReturn, actualReturn);
  }
  /**
   * Constructs a BasicSearchResultsModel with the specified search details, search request object,
   * and services.
   */
  public BasicSearchResultsModel(
      SearchInfo searchInfo,
      Search search,
      PropertiableHeadings propertiableHeadings,
      DownloadListManager downloadListManager,
      SaveLocationExceptionHandler saveLocationExceptionHandler) {

    this.searchInfo = searchInfo;
    this.search = search;
    this.downloadListManager = downloadListManager;
    this.saveLocationExceptionHandler = saveLocationExceptionHandler;

    // Create list of all search results.
    allSearchResults = new BasicEventList<SearchResult>();

    // Create list of search results grouped by URN.
    GroupingList<SearchResult> groupingListUrns =
        GlazedListsFactory.groupingList(allSearchResults, new UrnComparator());

    // Create list of visual search results where each element represents
    // a single group.
    groupedUrnResults =
        GlazedListsFactory.functionList(
            groupingListUrns, new SearchResultGrouper(resultCount, propertiableHeadings));

    // Create observable list that fires an event when results are modified.
    observableList =
        GlazedListsFactory.observableElementList(
            groupedUrnResults, GlazedLists.beanConnector(VisualSearchResult.class));

    // Create filtered list.
    filteredResultList = GlazedListsFactory.filterList(observableList);

    // Initialize display category and sorted list.
    setSelectedCategory(searchInfo.getSearchCategory());
  }