From 24f447aed7bf7eab09b80b6d9b03b8b794b68761 Mon Sep 17 00:00:00 2001 From: Anton Romanov Date: Sat, 22 Jun 2019 11:58:01 +0400 Subject: [PATCH] fix tests --- build.gradle | 4 ++-- .../conference/service/ConferenceServiceTest.java | 10 +++++----- .../ru/ulstu/grant/service/GrantServiceTest.java | 14 +++++++------- .../ulstu/project/service/ProjectServiceTest.java | 10 +++++----- .../ru/ulstu/students/service/TaskServiceTest.java | 9 ++++----- 5 files changed, 23 insertions(+), 24 deletions(-) diff --git a/build.gradle b/build.gradle index 0373cfc..959c4a2 100644 --- a/build.gradle +++ b/build.gradle @@ -130,6 +130,6 @@ dependencies { testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1' testCompile group: 'org.seleniumhq.selenium', name: 'selenium-support', version: '3.3.1' - testCompile group: 'com.google.guava', name: 'guava', version: '21.0' - + //testCompile group: 'com.google.guava', name: 'guava', version: '21.0' + testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19' } \ No newline at end of file diff --git a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java index d4640b1..56756a3 100644 --- a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java +++ b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java @@ -5,8 +5,8 @@ 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 org.springframework.test.context.junit4.SpringRunner; import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceFilterDto; @@ -31,7 +31,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@RunWith(SpringRunner.class) public class ConferenceServiceTest { @Mock @@ -124,7 +124,7 @@ public class ConferenceServiceTest { @Test public void getExistConferenceById() { - when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); + when(conferenceRepository.getOne(ID)).thenReturn(conferenceWithId); when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); when(userService.getCurrentUser()).thenReturn(user); @@ -185,8 +185,8 @@ public class ConferenceServiceTest { @Test public void delete() { - when(conferenceRepository.exists(ID)).thenReturn(true); - when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); + when(conferenceRepository.existsById(ID)).thenReturn(true); + when(conferenceRepository.getOne(ID)).thenReturn(conferenceWithId); assertTrue(conferenceService.delete(ID)); } diff --git a/src/test/java/ru/ulstu/grant/service/GrantServiceTest.java b/src/test/java/ru/ulstu/grant/service/GrantServiceTest.java index 99d7ef6..98f39e1 100644 --- a/src/test/java/ru/ulstu/grant/service/GrantServiceTest.java +++ b/src/test/java/ru/ulstu/grant/service/GrantServiceTest.java @@ -7,7 +7,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; +import org.springframework.test.context.junit4.SpringRunner; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.grant.model.Grant; @@ -34,7 +34,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@RunWith(SpringRunner.class) public class GrantServiceTest { @Mock @@ -123,7 +123,7 @@ public class GrantServiceTest { @Test public void getExistGrantById() { - when(grantRepository.findOne(ID)).thenReturn(grantWithId); + when(grantRepository.getOne(ID)).thenReturn(grantWithId); GrantDto newGrantDto = new GrantDto(grantWithId); GrantDto result = grantService.getExistGrantById(ID); @@ -179,7 +179,7 @@ public class GrantServiceTest { @Test public void delete() throws IOException { - when(grantRepository.findOne(ID)).thenReturn(grantWithId); + when(grantRepository.getOne(ID)).thenReturn(grantWithId); assertTrue(grantService.delete(grantWithId.getId())); } @@ -195,7 +195,7 @@ public class GrantServiceTest { @Test public void findById() { - when(grantRepository.findOne(ID)).thenReturn(grantWithId); + when(grantRepository.getOne(ID)).thenReturn(grantWithId); Grant findGrant = grantService.findById(ID); assertEquals(grantWithId.getId(), findGrant.getId()); @@ -203,7 +203,7 @@ public class GrantServiceTest { @Test public void attachPaper() { - when(grantRepository.findOne(ID)).thenReturn(grantWithId); + when(grantRepository.getOne(ID)).thenReturn(grantWithId); when(paperService.findAllSelect(Collections.singletonList(ID))).thenReturn(paperDtos); GrantDto newGrantDto = new GrantDto(grantWithId); @@ -219,7 +219,7 @@ public class GrantServiceTest { @Test public void filterEmptyDeadlines() { - when(grantRepository.findOne(ID)).thenReturn(grantWithId); + when(grantRepository.getOne(ID)).thenReturn(grantWithId); GrantDto newGrantDto = new GrantDto(grantWithId); newGrantDto.setDeadlines(newGrantDto.getDeadlines().stream() diff --git a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java index 25a201b..878fcda 100644 --- a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java +++ b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java @@ -5,7 +5,7 @@ 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.test.context.junit4.SpringRunner; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.file.model.FileData; @@ -29,7 +29,7 @@ import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@RunWith(SpringRunner.class) public class ProjectServiceTest { @Mock @@ -118,8 +118,8 @@ public class ProjectServiceTest { @Test public void delete() throws IOException { - when(projectRepository.exists(ID)).thenReturn(true); - when(projectRepository.findOne(ID)).thenReturn(project); + when(projectRepository.existsById(ID)).thenReturn(true); + when(projectRepository.getOne(ID)).thenReturn(project); assertTrue(projectService.delete(ID)); } @@ -134,7 +134,7 @@ public class ProjectServiceTest { @Test public void findById() { - when(projectRepository.findOne(ID)).thenReturn(project); + when(projectRepository.getOne(ID)).thenReturn(project); assertEquals(project, projectService.findById(ID)); } diff --git a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java index d3db954..97b9990 100644 --- a/src/test/java/ru/ulstu/students/service/TaskServiceTest.java +++ b/src/test/java/ru/ulstu/students/service/TaskServiceTest.java @@ -5,8 +5,8 @@ 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 org.springframework.test.context.junit4.SpringRunner; import ru.ulstu.core.util.DateUtils; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; @@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; -@RunWith(MockitoJUnitRunner.class) +@RunWith(SpringRunner.class) public class TaskServiceTest { @Mock @@ -113,7 +113,6 @@ public class TaskServiceTest { @Test public void findAll() { - when(taskRepository.findAll(SORT)).thenReturn(tasks); assertEquals(Collections.singletonList(task), taskService.findAll()); } @@ -153,8 +152,8 @@ public class TaskServiceTest { @Test public void delete() throws IOException { - when(taskRepository.exists(ID)).thenReturn(true); - when(taskRepository.findOne(ID)).thenReturn(task); + when(taskRepository.existsById(ID)).thenReturn(true); + when(taskRepository.getOne(ID)).thenReturn(task); when(schedulerRepository.findOneByTask(task)).thenReturn(null); assertTrue(taskService.delete(ID));