private static class Always implements Matcher<Integer> {
@Override
public boolean matches(Integer i) {
return true;
}
}
private static class Never implements Matcher<Integer> {
@Override
public boolean matches(Integer i) {
return false;
}
}
/**
* Matcher rejecting all: strange behaviour in batch mode
*/
@Test
public void testFilteredKeepNoneBatch() {
ObservableList<Integer> original = FXCollections.observableArrayList(
0, 1, 2, 3, 4 ,5, 6, 7, 8, 9
);
FilteredList list = new FilteredList(original, new Never(), FilterMode.BATCH);
list.filter();
assertEquals("must have null size, matcher rejects all " + list, 0, list.size());
}
/**
* okay if set after some filtering has happened
*/
@Test
public void testFilteredBatchChangeMatcher() {
ObservableList<Integer> original = FXCollections.observableArrayList(
0, 1, 2, 3, 4 ,5, 6, 7, 8, 9
);
FilteredList list = new FilteredList(original, new Always(), FilterMode.BATCH);
list.filter();
assertEquals(original.size(), list.size());
list.setMatcher(new Never());
list.filter();
assertEquals(0, list.size());
}
/**
* Filter okay in Live mode
*/
@Test
public void testFilteredKeepNoneLive() {
ObservableList<Integer> original = FXCollections.observableArrayList(
0, 1, 2, 3, 4 ,5, 6, 7, 8, 9
);
FilteredList list = new FilteredList(original, new Never());
assertEquals(0, list.size());
}