#104 mod tests filter and create tasks

This commit is contained in:
ASH 2019-05-23 12:07:34 +04:00
parent 59bc0dbd34
commit 284a3f51e9
2 changed files with 201 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import ru.ulstu.tags.model.Tag;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@ -135,6 +136,25 @@ public class TaskDto {
this.tags = tags;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TaskDto taskDto = (TaskDto) o;
return Objects.equals(id, taskDto.id) &&
Objects.equals(title, taskDto.title) &&
Objects.equals(description, taskDto.description) &&
status == taskDto.status &&
Objects.equals(deadlines, taskDto.deadlines) &&
Objects.equals(tagIds, taskDto.tagIds) &&
Objects.equals(tags, taskDto.tags);
}
@Override
public int hashCode() {
return Objects.hash(id, title, description, status, deadlines, createDate, updateDate, tagIds, tags);
}
public String getTagsString() {
return StringUtils.abbreviate(tags
.stream()

View File

@ -0,0 +1,181 @@
package ru.ulstu.students.service;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.domain.Sort;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.students.model.Task;
import ru.ulstu.students.model.TaskDto;
import ru.ulstu.students.model.TaskFilterDto;
import ru.ulstu.students.repository.TaskRepository;
import ru.ulstu.tags.model.Tag;
import ru.ulstu.tags.service.TagService;
import ru.ulstu.timeline.service.EventService;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class TaskServiceTest {
@Mock
TaskRepository taskRepository;
@Mock
private TagService tagService;
@Mock
DeadlineService deadlineService;
@Mock
EventService eventService;
@InjectMocks
TaskService taskService;
private final static Sort SORT = new Sort(Sort.Direction.DESC, "createDate");
private final static Integer ID = 1;
private final static Task.TaskStatus STATUS = Task.TaskStatus.IN_WORK;
private final static String TITLE = "title";
private final static String DESCR = "descr";
private final static String TAG = "tag";
private List<Task> tasks;
private List<Tag> tags;
private Task task;
private TaskFilterDto filterDto;
private TaskDto taskDto;
private List<TaskDto> tasksDto;
private Tag tag;
private Tag tagNull;
private Deadline deadline;
private List<Deadline> deadlines;
@Before
public void setUp() throws Exception {
tasks = new ArrayList<>();
task = new Task();
task.setId(ID);
task.setTitle(TITLE);
task.setDescription(DESCR);
tag = new Tag();
tag.setId(ID);
tag.setTagName(TAG);
deadlines = new ArrayList<>();
deadline = new Deadline(new Date(), DESCR);
deadline.setId(ID);
deadlines.add(deadline);
tags = new ArrayList<>();
tags.add(tag);
tasks.add(task);
taskDto = new TaskDto(task);
}
@Test
public void findAll() {
when(taskRepository.findAll(SORT)).thenReturn(tasks);
assertEquals(Collections.singletonList(task), taskService.findAll());
}
@Test
public void filter() {
when(tagService.findById(ID)).thenReturn(tag);
when(taskRepository.filterNew(STATUS, tag)).thenReturn(tasks);
TaskFilterDto taskFilterDto = new TaskFilterDto();
taskFilterDto.setTag(ID);
taskFilterDto.setOrder("new");
taskFilterDto.setStatus(STATUS);
assertEquals(Collections.singletonList(taskDto), taskService.filter(taskFilterDto));
}
@Test
public void create() throws IOException {
when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags);
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
when(taskRepository.save(new Task())).thenReturn(task);
eventService.createFromTask(new Task());
taskDto.setTags(tags);
taskDto.setDeadlines(deadlines);
Task newTask = new Task();
task.setId(ID);
task.setTitle(TITLE);
task.setDescription(DESCR);
task.setTags(tags);
task.setDeadlines(deadlines);
assertEquals(task.getId(), taskService.create(taskDto));
}
@Test
public void update() {
}
@Test
public void delete() {
}
@Test
public void save() {
}
@Test
public void copyMainPart() {
}
@Test
public void copyTaskWithNewDates() {
}
@Test
public void copyTaskWithNewYear() {
}
@Test
public void generateYearTasks() {
}
@Test
public void checkRepeatingTags() {
}
@Test
public void getTaskStatuses() {
}
@Test
public void getTags() {
}
@Test
public void findTasksByTag() {
}
@Test
public void createPeriodTask() {
}
}