### Question:
PersistDataStep { public List<Task<NodeDataRequest>> persist( final List<Task<NodeDataRequest>> tasks, final BlockHeader blockHeader, final WorldDownloadState downloadState) { final Updater updater = worldStateStorage.updater(); tasks.stream() .map(Task::getData) .filter(request -> request.getData() != null) .forEach( request -> { if (isRootState(blockHeader, request)) { downloadState.setRootNodeData(request.getData()); } else { request.persist(updater); } }); updater.commit(); return tasks; } PersistDataStep(final WorldStateStorage worldStateStorage); List<Task<NodeDataRequest>> persist(
      final List<Task<NodeDataRequest>> tasks,
      final BlockHeader blockHeader,
      final WorldDownloadState downloadState);  }### Answer:
@Test public void shouldPersistDataWhenPresent() { final List<Task<NodeDataRequest>> tasks = asList( createTaskWithData(1, 2, 3), createTaskWithData(4, 5, 6), createTaskWithData(7, 8, 9), createTaskWithData(10, 11, 12)); final List<Task<NodeDataRequest>> result = persistDataStep.persist(tasks, blockHeader, downloadState); assertThat(result).isSameAs(tasks); assertDataPersisted(tasks); }
@Test public void shouldSkipPersistingTasksWithNoData() { final Task<NodeDataRequest> withData = createTaskWithData(1, 2, 3); final StubTask withoutData = createTaskWithoutData(4, 5, 6); final List<Task<NodeDataRequest>> tasks = asList(withData, withoutData); final List<Task<NodeDataRequest>> result = persistDataStep.persist(tasks, blockHeader, downloadState); assertThat(result).isSameAs(tasks); assertThat(worldStateStorage.contains(withData.getData().getHash())).isTrue(); assertThat(worldStateStorage.contains(withoutData.getData().getHash())).isFalse(); }
@Test public void shouldStoreRootNodeDataInDownloadStateInsteadOfPersisting() { final Task<NodeDataRequest> rootNode = createTaskWithData(rootNodeData); final List<Task<NodeDataRequest>> tasks = singletonList(rootNode); final List<Task<NodeDataRequest>> result = persistDataStep.persist(tasks, blockHeader, downloadState); assertThat(result).isSameAs(tasks); assertThat(worldStateStorage.contains(rootNode.getData().getHash())).isFalse(); verify(downloadState).setRootNodeData(rootNode.getData().getData()); }