/** Tests method to set filter editor with filter text. */ public void testSetFilterEditor() { // 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 all search results. List<VisualSearchResult> filteredList = model.getCategorySearchResults(SearchCategory.ALL); // Verify unfiltered list. int expectedSize = 4; int actualSize = filteredList.size(); assertEquals("unfiltered list size", expectedSize, actualSize); // Apply filter editor. TextMatcherEditor<VisualSearchResult> editor = new TextMatcherEditor<VisualSearchResult>(new VisualSearchResultTextFilterator()); editor.setFilterText(new String[] {"z"}); model.setFilterEditor(editor); // Verify filtered list. expectedSize = 1; actualSize = filteredList.size(); assertEquals("filtered list size", expectedSize, actualSize); }
public void testAddRemoveListener() { final TextMatcherEditor<String> textMatcherEditor = new TextMatcherEditor<String>(); MatcherEditor<String> weakMatcherEditor = Matchers.weakReferenceProxy(textMatcherEditor); final CountingMatcherEditorListener<String> counter = new CountingMatcherEditorListener<String>(); weakMatcherEditor.addMatcherEditorListener(counter); counter.assertCounterState(0, 0, 0, 0, 0); textMatcherEditor.setFilterText(new String[] {"booblah"}); counter.assertCounterState(0, 0, 0, 1, 0); weakMatcherEditor.removeMatcherEditorListener(counter); textMatcherEditor.setFilterText(new String[] {"bibbety"}); counter.assertCounterState(0, 0, 0, 1, 0); }
public void testGarbageCollectWeakReferenceProxy() { final TextMatcherEditor<String> textMatcherEditor = new TextMatcherEditor<String>(); MatcherEditor<String> weakMatcherEditor = Matchers.weakReferenceProxy(textMatcherEditor); final CountingMatcherEditorListener<String> counter = new CountingMatcherEditorListener<String>(); weakMatcherEditor.addMatcherEditorListener(counter); counter.assertCounterState(0, 0, 0, 0, 0); textMatcherEditor.setFilterText(new String[] {"booblah"}); counter.assertCounterState(0, 0, 0, 1, 0); // removing the only hard reference to weakMatcherEditor should make it gc'able weakMatcherEditor = null; System.gc(); textMatcherEditor.setFilterText(new String[] {"bibbety"}); counter.assertCounterState(0, 0, 0, 1, 0); }