super.testRemove();
final EventList el = EventLists.eventList();
prefillWithIntegers(el, 6);
final FilteredEventList fel = createBackedFilteredEventList(el);
fel.setFilter(EVEN_FILTER);
final List even = new ArrayList(fel);
ListEventListener flel = new ListEventListener() {
private int count = 0;
public void listChanged(final ListEvent listEvent) {
switch (count++) {
case 0:
assertNull("listEvent: " + listEvent, listEvent);
break;
default:
fail("Unexpected: " + listEvent);
}
}
};
fel.addListEventListener(flel);
assertFalse(EVEN_FILTER.accept(el.get(1)));
assertEquals(3, fel.size());
Object removed = el.remove(1);
assertEquals(3, fel.size());
flel.listChanged(null);
fel.removeListEventListener(flel);
el.add(1, removed);
flel = new ListEventListener() {
private int count = 0;
public void listChanged(final ListEvent listEvent) {
switch (count++) {
case 0:
assertEquals(ListEvent.createRemoved(fel, 1), listEvent);
break;
case 1:
assertNull("listEvent: " + listEvent, listEvent);
break;
default:
fail("Unexpected: " + listEvent);
}
}
};
fel.addListEventListener(flel);
assertTrue(EVEN_FILTER.accept(el.get(2)));
assertEquals(3, fel.size());
removed = el.remove(2);
assertEquals(2, fel.size());
flel.listChanged(null);
fel.removeListEventListener(flel);
assertTrue(even.containsAll(fel));
el.add(2, removed);
ListEventListener lel = new ListEventListener() {
private int count = 0;
public void listChanged(final ListEvent listEvent) {
switch (count++) {
case 0:
assertEquals(ListEvent.createRemoved(el, 2), listEvent);
break;
case 1:
assertNull("listEvent: " + listEvent, listEvent);
break;
default:
fail("Unexpected: " + listEvent);
}
}
};
flel = new ListEventListener() {
private int count = 0;
public void listChanged(final ListEvent listEvent) {
switch (count++) {
case 0:
assertEquals(ListEvent.createRemoved(fel, 1), listEvent);
break;
case 1:
assertNull("listEvent: " + listEvent, listEvent);
break;
default:
fail("Unexpected: " + listEvent);
}
}
};
el.addListEventListener(lel);
fel.addListEventListener(flel);
assertTrue(EVEN_FILTER.accept(el.get(2)));
assertEquals(3, fel.size());
fel.remove(1);
assertEquals(2, fel.size());
lel.listChanged(null);
flel.listChanged(null);
fel.removeListEventListener(flel);
}