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);
  }