ListDataProvider extends AbstractDataProvider<T, SerializablePredicate<T>> implements InMemoryDataProvider<T> { @Override public void setFilter(SerializablePredicate<T> filter) { this.filter = filter; refreshAll(); } ListDataProvider(Collection<T> items); Collection<T> getItems(); @Override Stream<T> fetch(Query<T, SerializablePredicate<T>> query); @Override int size(Query<T, SerializablePredicate<T>> query); @Override SerializableComparator<T> getSortComparator(); @Override void setSortComparator(SerializableComparator<T> comparator); @Override SerializablePredicate<T> getFilter(); @Override void setFilter(SerializablePredicate<T> filter);  }
@Test public void setFilter() { dataProvider.setFilter(item -> item.getValue().equals("Foo")); Assert.assertEquals(36, sizeWithUnfilteredQuery()); dataProvider.setFilter(item -> !item.getValue().equals("Foo")); Assert.assertEquals( "Previous filter should be reset when setting a new one", 64, sizeWithUnfilteredQuery()); dataProvider.setFilter(null); Assert.assertEquals("Setting filter to null should remove all filters", 100, sizeWithUnfilteredQuery()); }
@Test public void setFilter_valueProvider() { dataProvider.setFilter(StrBean::getValue, "Foo"::equals); Assert.assertEquals(36, sizeWithUnfilteredQuery()); dataProvider.setFilter(StrBean::getValue, value -> !value.equals("Foo")); Assert.assertEquals( "Previous filter should be reset when setting a new one", 64, sizeWithUnfilteredQuery()); }
@Test public void addFilter_valueProvider() { dataProvider.setFilter(item -> item.getId() > 50); dataProvider.addFilter(StrBean::getValue, "Foo"::equals); Assert.assertEquals("Both filters should be used", 17, sizeWithUnfilteredQuery()); }
@Test public void addFilterEquals() { dataProvider.setFilter(item -> item.getId() > 50); dataProvider.addFilterByValue(StrBean::getValue, "Foo"); Assert.assertEquals("Both filters should be used", 17, sizeWithUnfilteredQuery()); }
@Test public void setFilter() { dataProvider.setFilter(item -> item.getValue().equals("Foo")); assertEquals(36, sizeWithUnfilteredQuery()); dataProvider.setFilter(item -> !item.getValue().equals("Foo")); assertEquals("Previous filter should be reset when setting a new one", 64, sizeWithUnfilteredQuery()); dataProvider.setFilter(null); assertEquals("Setting filter to null should remove all filters", 100, sizeWithUnfilteredQuery()); }
@Test public void setFilter_valueProvider() { dataProvider.setFilter(StrBean::getValue, "Foo"::equals); assertEquals(36, sizeWithUnfilteredQuery()); dataProvider.setFilter(StrBean::getValue, value -> !value.equals("Foo")); assertEquals("Previous filter should be reset when setting a new one", 64, sizeWithUnfilteredQuery()); }
@Test public void addFilter_valueProvider() { dataProvider.setFilter(item -> item.getId() > 50); dataProvider.addFilter(StrBean::getValue, "Foo"::equals); assertEquals("Both filters should be used", 17, sizeWithUnfilteredQuery()); }
@Test public void addFilterEquals() { dataProvider.setFilter(item -> item.getId() > 50); dataProvider.addFilterByValue(StrBean::getValue, "Foo"); assertEquals("Both filters should be used", 17, sizeWithUnfilteredQuery()); }