AbstractListDataView extends AbstractDataView<T> implements ListDataView<T, AbstractListDataView<T>> { @Override public boolean contains(T item) { return getItems().anyMatch(nextItem -> equals(item, nextItem)); } AbstractListDataView(
            SerializableSupplier<? extends DataProvider<T, ?>> dataProviderSupplier,
            Component component); @Override int getItemCount(); @Override T getItem(int index); @Override Optional<T> getNextItem(T item); @Override Optional<T> getPreviousItem(T item); @Override AbstractListDataView<T> addFilter(SerializablePredicate<T> filter); @Override AbstractListDataView<T> removeFilters(); @Override AbstractListDataView<T> setFilter(SerializablePredicate<T> filter); @Override AbstractListDataView<T> setSortComparator(
            SerializableComparator<T> sortComparator); @Override AbstractListDataView<T> addSortComparator(
            SerializableComparator<T> sortComparator); @Override AbstractListDataView<T> removeSorting(); @Override AbstractListDataView<T> setSortOrder(
            ValueProvider<T, V1> valueProvider, SortDirection sortDirection); @Override AbstractListDataView<T> addSortOrder(
            ValueProvider<T, V1> valueProvider, SortDirection sortDirection); @Override boolean contains(T item); @Override AbstractListDataView<T> addItem(T item); @Override AbstractListDataView<T> addItems(Collection<T> items); @Override AbstractListDataView<T> addItemAfter(T item, T after); @Override AbstractListDataView<T> addItemBefore(T item, T before); @Override AbstractListDataView<T> addItemsAfter(Collection<T> items, T after); @Override AbstractListDataView<T> addItemsBefore(Collection<T> items,
            T before); @Override AbstractListDataView<T> removeItem(T item); @Override AbstractListDataView<T> removeItems(Collection<T> items);  }
@Test public void contains_itemPresentedInDataSet_itemFound() { Assert.assertTrue("Set item was not found in the data", dataView.contains("first")); }
@Test public void contains_itemNotPresentedInDataSet_itemNotFound() { Assert.assertFalse("Non existent item found in data", dataView.contains("absent item")); }
@Test public void setIdentifierProvider_defaultIdentity_equalsIsUsed() { Assert.assertTrue(beanDataView.contains( new Item(1L, "value1"))); Assert.assertFalse(beanDataView.contains( new Item(1L, "non present"))); Assert.assertFalse(beanDataView.contains( new Item(4L, "value1"))); }
@Test public void setIdentifierProvider_dataProviderIdentity_getIdIsUsed() { itemListDataProvider = new AbstractDataViewTest.CustomIdentityItemDataProvider(getTestItems()); Assert.assertTrue(beanDataView.contains( new Item(1L, "value1"))); Assert.assertTrue(beanDataView.contains( new Item(1L, "non present"))); Assert.assertFalse(beanDataView.contains( new Item(4L, "value1"))); }
@Test public void setIdentifierProvider_customIdentifierProvider_customIdentifierProviderIsUsed() { beanDataView.setIdentifierProvider(Item::getValue); Assert.assertTrue(beanDataView.contains( new Item(1L, "value1"))); Assert.assertFalse(beanDataView.contains( new Item(1L, "non present"))); Assert.assertTrue(beanDataView.contains( new Item(4L, "value1"))); }
@Test public void setIdentifierProvider_dataProviderHasChanged_newDataProviderIsUsed() { Assert.assertFalse(beanDataView.contains( new Item(1L, "non present"))); itemListDataProvider = new AbstractDataViewTest.CustomIdentityItemDataProvider(getTestItems()); Assert.assertTrue(beanDataView.contains( new Item(1L, "non present"))); itemListDataProvider = DataProvider.ofItems(new Item(10L, "description10")); Assert.assertFalse(beanDataView.contains( new Item(1L, "non present"))); Assert.assertTrue(beanDataView.contains(new Item(10L, "description10"))); }
@Test public void setIdentifierProvider_dataProviderHasChanged_identifierProviderRetained() { Assert.assertFalse(beanDataView.contains( new Item(4L, "non present", "descr1"))); beanDataView.setIdentifierProvider(Item::getDescription); Assert.assertTrue(beanDataView.contains( new Item(4L, "non present", "descr1"))); itemListDataProvider = new AbstractDataViewTest.CustomIdentityItemDataProvider(getTestItems()); Assert.assertTrue(beanDataView.contains( new Item(4L, "non present", "descr1"))); }