Skip to content

Commit

Permalink
Exclude unnecessary restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
mshabarov committed Sep 29, 2020
1 parent 4627d82 commit ec18d31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,6 @@ public boolean isItemActive(T item) {
* @throws IndexOutOfBoundsException
* requested index is outside of the filtered and sorted data
* set
* @throws IllegalStateException
* if the calls to data provider are disabled.
*/
@SuppressWarnings("unchecked")
public T getItem(int index) {
Expand Down Expand Up @@ -420,14 +418,6 @@ public T getItem(int index) {
}
}

if (fetchDisabled) {
throw new IllegalStateException(
"Data Communicator cannot fetch the item from Data "
+ "Provider when the fetch is disabled. Please "
+ "enable it by calling "
+ "'dataCommunicator.setFetchDisabled(false)'");
}

/*
* In case of undefined size we don't check the empty data or the
* item count, because item count = 0 may mean the flush (fetch)
Expand Down Expand Up @@ -559,8 +549,8 @@ public void setItemCountEstimateIncrease(int itemCountEstimateIncrease) {
"itemCountEstimateIncrease cannot be less than 1");
}
this.itemCountEstimateIncrease = itemCountEstimateIncrease;
this.countCallback = null;
this.definedSize = false;
countCallback = null;
definedSize = false;
}

/**
Expand Down Expand Up @@ -594,8 +584,8 @@ public int getItemCountEstimateIncrease() {
public void setDefinedSize(boolean definedSize) {
if (this.definedSize != definedSize) {
this.definedSize = definedSize;
this.countCallback = null;
this.skipCountIncreaseUntilReset = false;
countCallback = null;
skipCountIncreaseUntilReset = false;
if (definedSize) {
// Always fetch explicit count from data provider
requestFlush();
Expand Down Expand Up @@ -747,21 +737,10 @@ public void setFetchDisabled(boolean fetchDisabled) {
* overridden by a subclass that uses a specific type of DataProvider and/or
* query.
*
* @throws IllegalStateException
* if the calls to data provider are disabled.
*
* @return the size of data provider with current filter
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
protected int getDataProviderSize() {
if (fetchDisabled) {
throw new IllegalStateException(
"Data Communicator cannot get the items count from Data "
+ "Provider when the fetch is disabled. Please "
+ "enable it by calling "
+ "'dataCommunicator.setFetchDisabled(false)'");
}

assert definedSize : "This method should never be called when using undefined size";
if (countCallback != null) {
return countCallback.count(new Query(getFilter()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1278,30 +1278,22 @@ public void fetchFromProvider_backendRunsOutOfItems_secondPageRequestSkipped() {
}

@Test
public void fetchDisabled_getItemCount_throws() {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage(
"Data Communicator cannot get the items count from Data "
+ "Provider when the fetch is disabled. Please "
+ "enable it by calling "
+ "'dataCommunicator.setFetchDisabled(false)'");

public void fetchDisabled_getItemCount_stillReturnsItemsCount() {
dataCommunicator.setFetchDisabled(true);
dataCommunicator.getItemCount();
Assert.assertEquals(0, dataCommunicator.getItemCount());

// data provider stores 100 items
dataCommunicator.setDataProvider(createDataProvider(), null);
Assert.assertEquals(100, dataCommunicator.getItemCount());
}

@Test
public void fetchDisabled_getItem_throws() {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage(
"Data Communicator cannot fetch the item from Data "
+ "Provider when the fetch is disabled. Please "
+ "enable it by calling "
+ "'dataCommunicator.setFetchDisabled(false)'");

public void fetchDisabled_getItem_stillReturnsItem() {
dataCommunicator.setFetchDisabled(true);
dataCommunicator.setItemCountEstimate(42);
dataCommunicator.getItem(10);

// data provider stores 100 items
dataCommunicator.setDataProvider(createDataProvider(), null);
Assert.assertNotNull(dataCommunicator.getItem(42));
}

@Test
Expand Down

0 comments on commit ec18d31

Please sign in to comment.