DataCommunicator implements Serializable { public void fireItemCountEvent(int itemCount) { if (lastSent != itemCount) { final Optional<Component> component = Element.get(stateNode) .getComponent(); if (component.isPresent()) { ComponentUtil.fireEvent(component.get(), new ItemCountChangeEvent<>(component.get(), itemCount, !(isDefinedSize() || skipCountIncreaseUntilReset))); } lastSent = itemCount; } } DataCommunicator(DataGenerator<T> dataGenerator,
            ArrayUpdater arrayUpdater,
            SerializableConsumer<JsonArray> dataUpdater, StateNode stateNode);  DataCommunicator(DataGenerator<T> dataGenerator,
            ArrayUpdater arrayUpdater,
            SerializableConsumer<JsonArray> dataUpdater, StateNode stateNode,
            boolean fetchEnabled); void setRequestedRange(int start, int length); void reset(); void refresh(T data); void confirmUpdate(int updateId); DataProvider<T, ?> getDataProvider(); SerializableConsumer<F> setDataProvider(
            DataProvider<T, F> dataProvider, F initialFilter); int getItemCount(); boolean isItemActive(T item); @SuppressWarnings("unchecked") T getItem(int index); Query buildQuery(int offset, int limit); void setPageSize(int pageSize); int getPageSize(); void setCountCallback(
            CallbackDataProvider.CountCallback<T, ?> countCallback); void setItemCountEstimate(int itemCountEstimate); int getItemCountEstimate(); void setItemCountEstimateIncrease(int itemCountEstimateIncrease); int getItemCountEstimateIncrease(); void setDefinedSize(boolean definedSize); boolean isDefinedSize(); DataKeyMapper<T> getKeyMapper(); void setInMemorySorting(SerializableComparator<T> comparator); SerializableComparator<T> getInMemorySorting(); void setBackEndSorting(List<QuerySortOrder> sortOrder); List<QuerySortOrder> getBackEndSorting(); boolean isPagingEnabled(); void setPagingEnabled(boolean pagingEnabled); boolean isFetchEnabled(); void setFetchEnabled(boolean fetchEnabled); void fireItemCountEvent(int itemCount); static final int DEFAULT_PAGE_INCREASE_COUNT; }
@Test public void fireItemCountEvent_sameItemCountObtained_eventNotFired() { final TestComponent component = initDataCommunicatorWithTestComponent(); final AtomicReference<ItemCountChangeEvent<?>> cachedEvent = addItemCountChangeListener( component); dataCommunicator.fireItemCountEvent(1); cachedEvent.set(null); dataCommunicator.fireItemCountEvent(1); ItemCountChangeEvent<?> event = cachedEvent.get(); Assert.assertNull("Event fired, but not expected", event); }
@Test public void fireItemCountEvent_emptyComponent_returnsNormally() { dataCommunicator.fireItemCountEvent(42); }