#104 mod tests generate task
This commit is contained in:
parent
ef521123dd
commit
82e454a50b
@ -186,7 +186,7 @@ public class TaskService {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void generateYearTasks() {
|
||||
public List<Task> generateYearTasks() {
|
||||
Set<Tag> tags = checkRepeatingTags(false);
|
||||
List<Task> tasks = new ArrayList<>();
|
||||
tags.forEach(tag -> {
|
||||
@ -202,7 +202,9 @@ public class TaskService {
|
||||
Task newTask = copyTaskWithNewYear(task);
|
||||
taskRepository.save(newTask);
|
||||
});
|
||||
return tasks;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
@ -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<Tag>(Arrays.asList(tag)), taskService.checkRepeatingTags(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user