diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index 379314d..d080d37 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -186,7 +186,7 @@ public class TaskService { } @Transactional - public void generateYearTasks() { + public List generateYearTasks() { Set tags = checkRepeatingTags(false); List tasks = new ArrayList<>(); tags.forEach(tag -> { @@ -202,7 +202,9 @@ public class TaskService { Task newTask = copyTaskWithNewYear(task); taskRepository.save(newTask); }); + return tasks; } + return null; } diff --git a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java index 19eff12..1ba04c4 100644 --- a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java +++ b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java @@ -21,6 +21,7 @@ import ru.ulstu.timeline.service.EventService; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.HashSet; @@ -157,16 +158,35 @@ public class TaskServiceTest { @Test 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 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); - assertEquals(tag, taskService.checkRepeatingTags(false)); + assertEquals(new HashSet(Arrays.asList(tag)), taskService.checkRepeatingTags(false)); } @Test