#104 mod tests check repeatings

This commit is contained in:
ASH 2019-05-23 14:31:34 +04:00
parent 284a3f51e9
commit ef521123dd
3 changed files with 38 additions and 26 deletions

View File

@ -138,8 +138,12 @@ public class TaskDto {
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
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) &&

View File

@ -108,7 +108,7 @@ public class TaskService {
}
@Transactional
public void delete(Integer taskId) throws IOException {
public boolean delete(Integer taskId) throws IOException {
if (taskRepository.exists(taskId)) {
Task scheduleTask = taskRepository.findOne(taskId);
Scheduler sch = schedulerRepository.findOneByTask(scheduleTask);
@ -116,7 +116,9 @@ public class TaskService {
schedulerRepository.delete(sch.getId());
}
taskRepository.delete(taskId);
return true;
}
return false;
}
@ -128,14 +130,14 @@ public class TaskService {
}
}
public void copyMainPart(Task newTask, Task task) {
private void copyMainPart(Task newTask, Task task) {
newTask.setTitle(task.getTitle());
newTask.setTags(tagService.saveOrCreate(task.getTags()));
newTask.setCreateDate(new Date());
newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS);
}
public Task copyTaskWithNewDates(Task task) {
private Task copyTaskWithNewDates(Task task) {
Task newTask = new Task();
copyMainPart(newTask, task);
Calendar cal1 = DateUtils.getCalendar(newTask.getCreateDate());
@ -157,7 +159,7 @@ public class TaskService {
}).collect(Collectors.toList());
}
public Task copyTaskWithNewYear(Task task) {
private Task copyTaskWithNewYear(Task task) {
Task newTask = new Task();
copyMainPart(newTask, task);
newTask.setDeadlines(newYearDeadlines(task.getDeadlines()));

View File

@ -7,11 +7,13 @@ import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
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.Task;
import ru.ulstu.students.model.TaskDto;
import ru.ulstu.students.model.TaskFilterDto;
import ru.ulstu.students.repository.SchedulerRepository;
import ru.ulstu.students.repository.TaskRepository;
import ru.ulstu.tags.model.Tag;
import ru.ulstu.tags.service.TagService;
@ -21,9 +23,12 @@ import java.io.IOException;
import java.util.ArrayList;
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;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
@ -32,6 +37,9 @@ public class TaskServiceTest {
@Mock
TaskRepository taskRepository;
@Mock
SchedulerRepository schedulerRepository;
@Mock
private TagService tagService;
@ -50,6 +58,7 @@ public class TaskServiceTest {
private final static String TITLE = "title";
private final static String DESCR = "descr";
private final static String TAG = "tag";
private final static Date YEAR = DateUtils.clearTime(DateUtils.addYears(new Date(), 0));
private List<Task> tasks;
private List<Tag> tags;
@ -61,6 +70,7 @@ public class TaskServiceTest {
private Tag tagNull;
private Deadline deadline;
private List<Deadline> deadlines;
private Set<Tag> repeatingTags;
@Before
@ -83,12 +93,17 @@ public class TaskServiceTest {
deadline.setId(ID);
deadlines.add(deadline);
task.setDeadlines(deadlines);
tags = new ArrayList<>();
tags.add(tag);
tasks.add(task);
taskDto = new TaskDto(task);
repeatingTags = new HashSet<>();
repeatingTags.add(tag);
}
@Test
@ -132,35 +147,26 @@ public class TaskServiceTest {
}
@Test
public void update() {
}
public void delete() throws IOException {
when(taskRepository.exists(ID)).thenReturn(true);
when(taskRepository.findOne(ID)).thenReturn(task);
when(schedulerRepository.findOneByTask(task)).thenReturn(null);
@Test
public void delete() {
}
@Test
public void save() {
}
@Test
public void copyMainPart() {
}
@Test
public void copyTaskWithNewDates() {
}
@Test
public void copyTaskWithNewYear() {
assertTrue(taskService.delete(ID));
}
@Test
public void generateYearTasks() {
when(taskService.checkRepeatingTags(false)).thenReturn(repeatingTags);
}
@Test
public void checkRepeatingTags() {
when(tagService.findById(ID)).thenReturn(tag);
when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks);
assertEquals(tag, taskService.checkRepeatingTags(false));
}
@Test