diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index d080d37..e89aedf 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -249,8 +249,9 @@ public class TaskService { } @Transactional - public void createPeriodTask(Scheduler scheduler) { + public Task createPeriodTask(Scheduler scheduler) { Task newTask = copyTaskWithNewDates(scheduler.getTask()); taskRepository.save(newTask); + return newTask; } } diff --git a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java index 1ba04c4..8edfc77 100644 --- a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java +++ b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java @@ -10,6 +10,7 @@ import org.springframework.data.domain.Sort; import ru.ulstu.core.util.DateUtils; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.students.model.Scheduler; import ru.ulstu.students.model.Task; import ru.ulstu.students.model.TaskDto; import ru.ulstu.students.model.TaskFilterDto; @@ -26,7 +27,6 @@ import java.util.Collections; import java.util.Date; import java.util.HashSet; import java.util.List; -import java.util.Set; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -64,14 +64,12 @@ public class TaskServiceTest { private List tasks; private List tags; private Task task; - private TaskFilterDto filterDto; + private Task taskForSchedule; private TaskDto taskDto; - private List tasksDto; private Tag tag; - private Tag tagNull; private Deadline deadline; private List deadlines; - private Set repeatingTags; + private Scheduler scheduler; @Before @@ -102,8 +100,14 @@ public class TaskServiceTest { tasks.add(task); taskDto = new TaskDto(task); - repeatingTags = new HashSet<>(); - repeatingTags.add(tag); + taskForSchedule = new Task(); + taskForSchedule.setTitle(TITLE); + taskForSchedule.setDescription(DESCR); + + scheduler = new Scheduler(); + scheduler.setDate(new Date()); + scheduler.setTask(taskForSchedule); + } @@ -171,8 +175,10 @@ public class TaskServiceTest { newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS); Deadline newDeadline = new Deadline(); + newDeadline.setId(ID); newDeadline.setDescription(deadline.getDescription()); newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1)); + when(deadlineService.create(newDeadline)).thenReturn(newDeadline); newTask.setDeadlines(Arrays.asList(newDeadline)); when(taskRepository.save(newTask)).thenReturn(task); @@ -189,19 +195,22 @@ public class TaskServiceTest { assertEquals(new HashSet(Arrays.asList(tag)), taskService.checkRepeatingTags(false)); } - @Test - public void getTaskStatuses() { - } - - @Test - public void getTags() { - } - - @Test - public void findTasksByTag() { - } - @Test public void createPeriodTask() { + Task newTask = new Task(); + newTask.setTitle(scheduler.getTask().getTitle()); + newTask.setTags(scheduler.getTask().getTags()); + newTask.setCreateDate(new Date()); + + Deadline newDeadline = new Deadline(); + newDeadline.setId(ID); + newDeadline.setDescription(deadline.getDescription()); + newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1)); + when(deadlineService.create(newDeadline)).thenReturn(newDeadline); + newTask.setDeadlines(Arrays.asList(newDeadline)); + + when(taskRepository.save(newTask)).thenReturn(taskForSchedule); + + assertEquals(taskForSchedule, taskService.createPeriodTask(scheduler)); } } \ No newline at end of file