public void testAddListChangeEvent() throws Exception { ListChangeEventTracker listener = new ListChangeEventTracker(); list.addListChangeListener(listener); assertEquals(0, listener.count); String element = "1"; list.add(element); assertEquals(1, listener.count); ListChangeEvent event = listener.event; assertSame(list, event.getObservableList()); assertDiff(event.diff, Collections.EMPTY_LIST, Collections.singletonList("1")); }
public void testAddAllListChangEvent() throws Exception { List elements = Arrays.asList(new String[] {"1", "2"}); assertEquals(0, list.size()); ListChangeEventTracker listener = new ListChangeEventTracker(); list.addListChangeListener(listener); assertEquals(0, listener.count); list.addAll(elements); assertEquals(1, listener.count); ListChangeEvent event = listener.event; assertSame(list, event.getObservableList()); assertDiff(event.diff, Collections.EMPTY_LIST, Arrays.asList(new String[] {"1", "2"})); }
public void testSetListChangeEvent() throws Exception { String oldElement = "old"; String newElement = "new"; list.add(oldElement); ListChangeEventTracker listener = ListChangeEventTracker.observe(list); assertEquals(0, listener.count); list.set(0, newElement); assertEquals(1, listener.count); ListChangeEvent event = listener.event; assertSame(list, event.getObservableList()); assertDiff( event.diff, Collections.singletonList(oldElement), Collections.singletonList(newElement)); }
public void testRetainAllListChangeEvent() throws Exception { List elements = Arrays.asList(new String[] {"0", "1", "2", "3"}); list.addAll(elements); ListChangeEventTracker listener = new ListChangeEventTracker(); list.addListChangeListener(listener); assertEquals(0, listener.count); list.retainAll(elements.subList(0, 2)); assertEquals(1, listener.count); ListChangeEvent event = listener.event; assertSame(list, event.getObservableList()); assertDiff( event.diff, Arrays.asList(new Object[] {"0", "1", "2", "3"}), Arrays.asList(new Object[] {"0", "1"})); }
@Override public void handleListChange(ListChangeEvent event) { assertThat(event.getObservable(), sameInstance((IObservable) fixture)); diff = event.diff; }