#104 mod tests generate task

This commit is contained in:
ASH 2019-05-23 16:17:04 +04:00
parent ef521123dd
commit 82e454a50b
2 changed files with 26 additions and 4 deletions

View File

@ -186,7 +186,7 @@ public class TaskService {
} }
@Transactional @Transactional
public void generateYearTasks() { public List<Task> generateYearTasks() {
Set<Tag> tags = checkRepeatingTags(false); Set<Tag> tags = checkRepeatingTags(false);
List<Task> tasks = new ArrayList<>(); List<Task> tasks = new ArrayList<>();
tags.forEach(tag -> { tags.forEach(tag -> {
@ -202,7 +202,9 @@ public class TaskService {
Task newTask = copyTaskWithNewYear(task); Task newTask = copyTaskWithNewYear(task);
taskRepository.save(newTask); taskRepository.save(newTask);
}); });
return tasks;
} }
return null;
} }

View File

@ -21,6 +21,7 @@ import ru.ulstu.timeline.service.EventService;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
@ -157,16 +158,35 @@ public class TaskServiceTest {
@Test @Test
public void generateYearTasks() { public void generateYearTasks() {
when(taskService.checkRepeatingTags(false)).thenReturn(repeatingTags); when(tagService.getTags()).thenReturn(tags);
tasks.get(0).setTags(tags);
when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks);
tasks.get(0).setCreateDate(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)));
when(taskRepository.findByTag(tag)).thenReturn(tasks);
Task newTask = new Task();
newTask.setTitle(tasks.get(0).getTitle());
newTask.setTags(tasks.get(0).getTags());
newTask.setCreateDate(new Date());
newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS);
Deadline newDeadline = new Deadline();
newDeadline.setDescription(deadline.getDescription());
newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1));
newTask.setDeadlines(Arrays.asList(newDeadline));
when(taskRepository.save(newTask)).thenReturn(task);
assertEquals(Arrays.asList(task), taskService.generateYearTasks());
} }
@Test @Test
public void checkRepeatingTags() { public void checkRepeatingTags() {
when(tagService.findById(ID)).thenReturn(tag); when(tagService.getTags()).thenReturn(tags);
tasks.get(0).setTags(tags);
when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks); when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks);
assertEquals(tag, taskService.checkRepeatingTags(false)); assertEquals(new HashSet<Tag>(Arrays.asList(tag)), taskService.checkRepeatingTags(false));
} }
@Test @Test