// expected
}
}
public void testSetMaxSize() {
final EventList el = EventLists.eventList();
prefillWithIntegers(el, 10);
final RangedEventList rel = EventLists.rangedEventList(el);
assertEquals(10, el.size());
assertEquals(el.size(), rel.size());
ListEventListener lel = new ListEventListener() {
private int count = 0;
public void listChanged(final ListEvent listEvent) {
switch (count++) {
case 0:
assertEquals(ListEvent.createOther(rel), listEvent);
break;
case 1:
assertNull(listEvent);
break;
default:
fail("Unexpected: " + listEvent);
}
}
};
rel.addListEventListener(lel);
rel.setMaxSize(1000);
lel.listChanged(null);
assertEquals(el.size(), rel.size());
rel.removeListEventListener(lel);
lel = new ListEventListener() {
private int count = 0;
public void listChanged(final ListEvent listEvent) {
switch (count++) {
case 0:
assertEquals(ListEvent.createRemoved(rel, 5, 10), listEvent);
break;
case 1:
assertNull(listEvent);
break;
default:
fail("Unexpected: " + listEvent);
}
}
};
rel.addListEventListener(lel);
rel.setMaxSize(5);
lel.listChanged(null);
assertEquals(5, rel.size());
rel.removeListEventListener(lel);
lel = new ListEventListener() {
private int count = 0;
public void listChanged(final ListEvent listEvent) {
switch (count++) {
case 0:
assertEquals(ListEvent.createAdded(rel, 5, 8), listEvent);
break;
case 1:
assertNull(listEvent);
break;
default:
fail("Unexpected: " + listEvent);
}
}
};
rel.addListEventListener(lel);
rel.setMaxSize(8);
lel.listChanged(null);
assertEquals(8, rel.size());
rel.removeListEventListener(lel);
lel = new ListEventListener() {
private int count = 0;
public void listChanged(final ListEvent listEvent) {
switch (count++) {
case 0:
assertEquals(ListEvent.createAdded(rel, 8, 10), listEvent);
break;
case 1:
assertNull(listEvent);
break;
default:
fail("Unexpected: " + listEvent);
}
}
};
rel.addListEventListener(lel);
rel.setMaxSize(Integer.MAX_VALUE);
lel.listChanged(null);
assertEquals(el.size(), rel.size());
rel.removeListEventListener(lel);
try {
rel.setMaxSize(-1);
fail("Expected IllegalArgumentException.");