DownloadBatchStatusFilter { boolean shouldFilterOut(DownloadBatchStatus currentDownloadBatchStatus) { if (!(currentDownloadBatchStatus instanceof InternalDownloadBatchStatus)) { Logger.w(currentDownloadBatchStatus.getClass() + " is not an instance of " + InternalDownloadBatchStatus.class); return true; } InternalDownloadBatchStatus copiedStatus = ((InternalDownloadBatchStatus) currentDownloadBatchStatus).copy(); if (copiedStatus.equals(currentStatus)) { Logger.v("Failed filter. " + "ID: " + currentDownloadBatchStatus.getDownloadBatchId().rawId() + " Status: " + currentDownloadBatchStatus.status().toRawValue() ); return true; } Logger.v( "Passes filter. " + "ID: " + currentDownloadBatchStatus.getDownloadBatchId().rawId() + " Status: " + currentDownloadBatchStatus.status().toRawValue() ); currentStatus = copiedStatus; return false; }    }
@Test public void returnsFalse_whenPercentageDoesNotMatchPrevious() { givenPreviousUpdate(firstPercentageStatus); boolean shouldFilterOut = downloadBatchStatusFilter.shouldFilterOut(secondPercentageStatus); assertThat(shouldFilterOut).isFalse(); }
@Test public void returnsTrue_whenPercentageIsUnchanged() { givenPreviousUpdate(firstPercentageStatus); boolean shouldFilterOut = downloadBatchStatusFilter.shouldFilterOut(firstPercentageStatus); assertThat(shouldFilterOut).isTrue(); }
@Test public void returnsFalse_whenErrorDoesNotMatchPrevious() { givenPreviousUpdate(firstErrorStatus); boolean shouldFilterOut = downloadBatchStatusFilter.shouldFilterOut(secondErrorStatus); assertThat(shouldFilterOut).isFalse(); }
@Test public void returnsTrue_whenErrorIsUnchanged() { givenPreviousUpdate(firstErrorStatus); boolean shouldFilterOut = downloadBatchStatusFilter.shouldFilterOut(firstErrorStatus); assertThat(shouldFilterOut).isTrue(); }
@Test public void returnsFalse_whenStatusDoesNotMatchPrevious() { givenPreviousUpdate(firstStatus); boolean shouldFilterOut = downloadBatchStatusFilter.shouldFilterOut(secondStatus); assertThat(shouldFilterOut).isFalse(); }
@Test public void returnsTrue_whenStatusIsUnchanged() { givenPreviousUpdate(firstStatus); boolean shouldFilterOut = downloadBatchStatusFilter.shouldFilterOut(firstStatus); assertThat(shouldFilterOut).isTrue(); }