public void testSetViaDeeperList() {
final EventList el = EventLists.eventList();
prefillWithIntegers(el, 6);
final FilteredEventList fel = createBackedFilteredEventList(el);
fel.setFilter(EVEN_FILTER);
ListEventListener lel = 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(lel);
assertFalse(EVEN_FILTER.accept(Integer.valueOf(-1)));
el.set(1, Integer.valueOf(-1));
lel.listChanged(null);
assertEquals(3, fel.size());
fel.removeListEventListener(lel);
lel = new ListEventListener() {
private int count = 0;
public void listChanged(final ListEvent listEvent) {
switch (count++) {
case 0:
assertEquals(ListEvent.createChanged(fel, 1), listEvent);
break;
case 1:
assertNull("listEvent: " + listEvent, listEvent);
break;
default:
fail("Unexpected: " + listEvent);
}
}
};
fel.addListEventListener(lel);
assertTrue(EVEN_FILTER.accept(Integer.valueOf(-2)));
el.set(2, Integer.valueOf(-2));
lel.listChanged(null);
assertEquals(3, fel.size());
fel.removeListEventListener(lel);
lel = new ListEventListener() {
private int count = 0;
public void listChanged(final ListEvent listEvent) {
switch (count++) {
case 0:
assertEquals(ListEvent.createAdded(fel, 2), listEvent);
break;
case 1:
assertNull("listEvent: " + listEvent, listEvent);
break;
default:
fail("Unexpected: " + listEvent);
}
}
};
fel.addListEventListener(lel);
assertTrue(EVEN_FILTER.accept(Integer.valueOf(30)));
el.set(3, Integer.valueOf(30));
lel.listChanged(null);
assertEquals(4, fel.size());
fel.removeListEventListener(lel);
lel = new ListEventListener() {
private int count = 0;
public void listChanged(final ListEvent listEvent) {
switch (count++) {
case 0:
assertEquals(ListEvent.createRemoved(fel, 2), listEvent);
break;
case 1:
assertNull("listEvent: " + listEvent, listEvent);
break;
default:
fail("Unexpected: " + listEvent);
}
}
};
fel.addListEventListener(lel);
assertFalse(EVEN_FILTER.accept(Integer.valueOf(3)));
el.set(3, Integer.valueOf(3));
lel.listChanged(null);
assertEquals(3, fel.size());
fel.removeListEventListener(lel);
}