### Question:
CompleteTaskStep { public void markAsCompleteOrFailed( final BlockHeader header, final WorldDownloadState downloadState, final Task<NodeDataRequest> task) { if (task.getData().getData() != null) { enqueueChildren(task, header, downloadState); completedRequestsCounter.inc(); task.markCompleted(); downloadState.checkCompletion(worldStateStorage, header); } else { retriedRequestsCounter.inc(); task.markFailed(); downloadState.notifyTaskAvailable(); } } CompleteTaskStep(
      final WorldStateStorage worldStateStorage,
      final MetricsSystem metricsSystem,
      final LongSupplier worldStatePendingRequestsCurrentSupplier); void markAsCompleteOrFailed(
      final BlockHeader header,
      final WorldDownloadState downloadState,
      final Task<NodeDataRequest> task); double computeWorldStateSyncProgress();  }### Answer:
@Test public void shouldMarkTaskAsFailedIfItDoesNotHaveData() { final StubTask task = new StubTask(NodeDataRequest.createAccountDataRequest(ROOT_HASH)); completeTaskStep.markAsCompleteOrFailed(blockHeader, downloadState, task); assertThat(task.isCompleted()).isFalse(); assertThat(task.isFailed()).isTrue(); verify(downloadState).notifyTaskAvailable(); verify(downloadState, never()).checkCompletion(worldStateStorage, blockHeader); }
@Test public void shouldEnqueueChildrenAndMarkCompleteWhenTaskHasData() { final StubTask task = validTask(); completeTaskStep.markAsCompleteOrFailed(blockHeader, downloadState, task); assertThat(task.isCompleted()).isTrue(); assertThat(task.isFailed()).isFalse(); verify(downloadState).enqueueRequests(streamCaptor.capture()); assertThat(streamCaptor.getValue()) .usingRecursiveFieldByFieldElementComparator() .containsExactlyInAnyOrderElementsOf(() -> task.getData().getChildRequests().iterator()); verify(downloadState).checkCompletion(worldStateStorage, blockHeader); }