@Test public void testGarbageCollectWeakListener() { final TextMatcherEditor<String> textMatcherEditor = new TextMatcherEditor<>(); MatcherEditor<String> weakMatcherEditor = Matchers.weakReferenceProxy(textMatcherEditor); CountingMatcherEditorListener<String> counter = new CountingMatcherEditorListener<>(); final WeakReference<CountingMatcherEditorListener> weakRef = new WeakReference<>(counter); weakMatcherEditor.addMatcherEditorListener(counter); counter.assertCounterState(0, 0, 0, 0, 0); textMatcherEditor.setFilterText(new String[] {"booblah"}); counter.assertCounterState(0, 0, 0, 1, 0); counter = null; System.gc(); textMatcherEditor.setFilterText(new String[] {"bibbety"}); assertNull(weakRef.get()); }
@Override public synchronized void addMatcherEditorListener(Listener<E> listener) { this.listenerList.add(new WeakMatcherEditorListener<>(this, listener)); }
WeakReferenceMatcherEditor implements MatcherEditor<E>, MatcherEditor.Listener<E> { @Override public synchronized void addMatcherEditorListener(Listener<E> listener) { this.listenerList.add(new WeakMatcherEditorListener<>(this, listener)); } }
WeakReferenceMatcherEditor implements MatcherEditor<E>, MatcherEditor.Listener<E> { @Override public synchronized void addMatcherEditorListener(Listener<E> listener) { this.listenerList.add(new WeakMatcherEditorListener<>(this, listener)); } WeakReferenceMatcherEditor(MatcherEditor<E> source); }
WeakReferenceMatcherEditor implements MatcherEditor<E>, MatcherEditor.Listener<E> { @Override public synchronized void addMatcherEditorListener(Listener<E> listener) { this.listenerList.add(new WeakMatcherEditorListener<>(this, listener)); } WeakReferenceMatcherEditor(MatcherEditor<E> source); @Override Matcher<E> getMatcher(); @Override synchronized void addMatcherEditorListener(Listener<E> listener); @Override synchronized void removeMatcherEditorListener(Listener<E> listener); @Override synchronized void changedMatcher(Event<E> matcherEvent); }
WeakReferenceMatcherEditor implements MatcherEditor<E>, MatcherEditor.Listener<E> { @Override public synchronized void addMatcherEditorListener(Listener<E> listener) { this.listenerList.add(new WeakMatcherEditorListener<>(this, listener)); } WeakReferenceMatcherEditor(MatcherEditor<E> source); @Override Matcher<E> getMatcher(); @Override synchronized void addMatcherEditorListener(Listener<E> listener); @Override synchronized void removeMatcherEditorListener(Listener<E> listener); @Override synchronized void changedMatcher(Event<E> matcherEvent);  }