#104 mod tests check repeatings
This commit is contained in:
parent
284a3f51e9
commit
ef521123dd
@ -138,8 +138,12 @@ public class TaskDto {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) {
|
||||||
if (o == null || getClass() != o.getClass()) return false;
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
TaskDto taskDto = (TaskDto) o;
|
TaskDto taskDto = (TaskDto) o;
|
||||||
return Objects.equals(id, taskDto.id) &&
|
return Objects.equals(id, taskDto.id) &&
|
||||||
Objects.equals(title, taskDto.title) &&
|
Objects.equals(title, taskDto.title) &&
|
||||||
|
@ -108,7 +108,7 @@ public class TaskService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void delete(Integer taskId) throws IOException {
|
public boolean delete(Integer taskId) throws IOException {
|
||||||
if (taskRepository.exists(taskId)) {
|
if (taskRepository.exists(taskId)) {
|
||||||
Task scheduleTask = taskRepository.findOne(taskId);
|
Task scheduleTask = taskRepository.findOne(taskId);
|
||||||
Scheduler sch = schedulerRepository.findOneByTask(scheduleTask);
|
Scheduler sch = schedulerRepository.findOneByTask(scheduleTask);
|
||||||
@ -116,7 +116,9 @@ public class TaskService {
|
|||||||
schedulerRepository.delete(sch.getId());
|
schedulerRepository.delete(sch.getId());
|
||||||
}
|
}
|
||||||
taskRepository.delete(taskId);
|
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.setTitle(task.getTitle());
|
||||||
newTask.setTags(tagService.saveOrCreate(task.getTags()));
|
newTask.setTags(tagService.saveOrCreate(task.getTags()));
|
||||||
newTask.setCreateDate(new Date());
|
newTask.setCreateDate(new Date());
|
||||||
newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS);
|
newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task copyTaskWithNewDates(Task task) {
|
private Task copyTaskWithNewDates(Task task) {
|
||||||
Task newTask = new Task();
|
Task newTask = new Task();
|
||||||
copyMainPart(newTask, task);
|
copyMainPart(newTask, task);
|
||||||
Calendar cal1 = DateUtils.getCalendar(newTask.getCreateDate());
|
Calendar cal1 = DateUtils.getCalendar(newTask.getCreateDate());
|
||||||
@ -157,7 +159,7 @@ public class TaskService {
|
|||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task copyTaskWithNewYear(Task task) {
|
private Task copyTaskWithNewYear(Task task) {
|
||||||
Task newTask = new Task();
|
Task newTask = new Task();
|
||||||
copyMainPart(newTask, task);
|
copyMainPart(newTask, task);
|
||||||
newTask.setDeadlines(newYearDeadlines(task.getDeadlines()));
|
newTask.setDeadlines(newYearDeadlines(task.getDeadlines()));
|
||||||
|
@ -7,11 +7,13 @@ import org.mockito.InjectMocks;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
import org.springframework.data.domain.Sort;
|
import org.springframework.data.domain.Sort;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
import ru.ulstu.deadline.model.Deadline;
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
import ru.ulstu.deadline.service.DeadlineService;
|
import ru.ulstu.deadline.service.DeadlineService;
|
||||||
import ru.ulstu.students.model.Task;
|
import ru.ulstu.students.model.Task;
|
||||||
import ru.ulstu.students.model.TaskDto;
|
import ru.ulstu.students.model.TaskDto;
|
||||||
import ru.ulstu.students.model.TaskFilterDto;
|
import ru.ulstu.students.model.TaskFilterDto;
|
||||||
|
import ru.ulstu.students.repository.SchedulerRepository;
|
||||||
import ru.ulstu.students.repository.TaskRepository;
|
import ru.ulstu.students.repository.TaskRepository;
|
||||||
import ru.ulstu.tags.model.Tag;
|
import ru.ulstu.tags.model.Tag;
|
||||||
import ru.ulstu.tags.service.TagService;
|
import ru.ulstu.tags.service.TagService;
|
||||||
@ -21,9 +23,12 @@ import java.io.IOException;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
@ -32,6 +37,9 @@ public class TaskServiceTest {
|
|||||||
@Mock
|
@Mock
|
||||||
TaskRepository taskRepository;
|
TaskRepository taskRepository;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
SchedulerRepository schedulerRepository;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private TagService tagService;
|
private TagService tagService;
|
||||||
|
|
||||||
@ -50,6 +58,7 @@ public class TaskServiceTest {
|
|||||||
private final static String TITLE = "title";
|
private final static String TITLE = "title";
|
||||||
private final static String DESCR = "descr";
|
private final static String DESCR = "descr";
|
||||||
private final static String TAG = "tag";
|
private final static String TAG = "tag";
|
||||||
|
private final static Date YEAR = DateUtils.clearTime(DateUtils.addYears(new Date(), 0));
|
||||||
|
|
||||||
private List<Task> tasks;
|
private List<Task> tasks;
|
||||||
private List<Tag> tags;
|
private List<Tag> tags;
|
||||||
@ -61,6 +70,7 @@ public class TaskServiceTest {
|
|||||||
private Tag tagNull;
|
private Tag tagNull;
|
||||||
private Deadline deadline;
|
private Deadline deadline;
|
||||||
private List<Deadline> deadlines;
|
private List<Deadline> deadlines;
|
||||||
|
private Set<Tag> repeatingTags;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -83,12 +93,17 @@ public class TaskServiceTest {
|
|||||||
deadline.setId(ID);
|
deadline.setId(ID);
|
||||||
deadlines.add(deadline);
|
deadlines.add(deadline);
|
||||||
|
|
||||||
|
task.setDeadlines(deadlines);
|
||||||
|
|
||||||
tags = new ArrayList<>();
|
tags = new ArrayList<>();
|
||||||
tags.add(tag);
|
tags.add(tag);
|
||||||
|
|
||||||
tasks.add(task);
|
tasks.add(task);
|
||||||
taskDto = new TaskDto(task);
|
taskDto = new TaskDto(task);
|
||||||
|
|
||||||
|
repeatingTags = new HashSet<>();
|
||||||
|
repeatingTags.add(tag);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -132,35 +147,26 @@ public class TaskServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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
|
assertTrue(taskService.delete(ID));
|
||||||
public void delete() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void save() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void copyMainPart() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void copyTaskWithNewDates() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void copyTaskWithNewYear() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void generateYearTasks() {
|
public void generateYearTasks() {
|
||||||
|
when(taskService.checkRepeatingTags(false)).thenReturn(repeatingTags);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void checkRepeatingTags() {
|
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
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user