fix tests

This commit is contained in:
Anton Romanov 2019-06-22 11:58:01 +04:00
parent 36c4e52e37
commit 24f447aed7
5 changed files with 23 additions and 24 deletions

View File

@ -130,6 +130,6 @@ dependencies {
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test' testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test'
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.3.1' 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: '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'
} }

View File

@ -5,8 +5,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.test.context.junit4.SpringRunner;
import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.Conference;
import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceDto;
import ru.ulstu.conference.model.ConferenceFilterDto; 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.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class) @RunWith(SpringRunner.class)
public class ConferenceServiceTest { public class ConferenceServiceTest {
@Mock @Mock
@ -124,7 +124,7 @@ public class ConferenceServiceTest {
@Test @Test
public void getExistConferenceById() { public void getExistConferenceById() {
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); when(conferenceRepository.getOne(ID)).thenReturn(conferenceWithId);
when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers);
when(userService.getCurrentUser()).thenReturn(user); when(userService.getCurrentUser()).thenReturn(user);
@ -185,8 +185,8 @@ public class ConferenceServiceTest {
@Test @Test
public void delete() { public void delete() {
when(conferenceRepository.exists(ID)).thenReturn(true); when(conferenceRepository.existsById(ID)).thenReturn(true);
when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); when(conferenceRepository.getOne(ID)).thenReturn(conferenceWithId);
assertTrue(conferenceService.delete(ID)); assertTrue(conferenceService.delete(ID));
} }

View File

@ -7,7 +7,7 @@ import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; 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.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.grant.model.Grant; 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.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class) @RunWith(SpringRunner.class)
public class GrantServiceTest { public class GrantServiceTest {
@Mock @Mock
@ -123,7 +123,7 @@ public class GrantServiceTest {
@Test @Test
public void getExistGrantById() { public void getExistGrantById() {
when(grantRepository.findOne(ID)).thenReturn(grantWithId); when(grantRepository.getOne(ID)).thenReturn(grantWithId);
GrantDto newGrantDto = new GrantDto(grantWithId); GrantDto newGrantDto = new GrantDto(grantWithId);
GrantDto result = grantService.getExistGrantById(ID); GrantDto result = grantService.getExistGrantById(ID);
@ -179,7 +179,7 @@ public class GrantServiceTest {
@Test @Test
public void delete() throws IOException { public void delete() throws IOException {
when(grantRepository.findOne(ID)).thenReturn(grantWithId); when(grantRepository.getOne(ID)).thenReturn(grantWithId);
assertTrue(grantService.delete(grantWithId.getId())); assertTrue(grantService.delete(grantWithId.getId()));
} }
@ -195,7 +195,7 @@ public class GrantServiceTest {
@Test @Test
public void findById() { public void findById() {
when(grantRepository.findOne(ID)).thenReturn(grantWithId); when(grantRepository.getOne(ID)).thenReturn(grantWithId);
Grant findGrant = grantService.findById(ID); Grant findGrant = grantService.findById(ID);
assertEquals(grantWithId.getId(), findGrant.getId()); assertEquals(grantWithId.getId(), findGrant.getId());
@ -203,7 +203,7 @@ public class GrantServiceTest {
@Test @Test
public void attachPaper() { public void attachPaper() {
when(grantRepository.findOne(ID)).thenReturn(grantWithId); when(grantRepository.getOne(ID)).thenReturn(grantWithId);
when(paperService.findAllSelect(Collections.singletonList(ID))).thenReturn(paperDtos); when(paperService.findAllSelect(Collections.singletonList(ID))).thenReturn(paperDtos);
GrantDto newGrantDto = new GrantDto(grantWithId); GrantDto newGrantDto = new GrantDto(grantWithId);
@ -219,7 +219,7 @@ public class GrantServiceTest {
@Test @Test
public void filterEmptyDeadlines() { public void filterEmptyDeadlines() {
when(grantRepository.findOne(ID)).thenReturn(grantWithId); when(grantRepository.getOne(ID)).thenReturn(grantWithId);
GrantDto newGrantDto = new GrantDto(grantWithId); GrantDto newGrantDto = new GrantDto(grantWithId);
newGrantDto.setDeadlines(newGrantDto.getDeadlines().stream() newGrantDto.setDeadlines(newGrantDto.getDeadlines().stream()

View File

@ -5,7 +5,7 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; 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.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.file.model.FileData; 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.junit.Assert.assertEquals;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class) @RunWith(SpringRunner.class)
public class ProjectServiceTest { public class ProjectServiceTest {
@Mock @Mock
@ -118,8 +118,8 @@ public class ProjectServiceTest {
@Test @Test
public void delete() throws IOException { public void delete() throws IOException {
when(projectRepository.exists(ID)).thenReturn(true); when(projectRepository.existsById(ID)).thenReturn(true);
when(projectRepository.findOne(ID)).thenReturn(project); when(projectRepository.getOne(ID)).thenReturn(project);
assertTrue(projectService.delete(ID)); assertTrue(projectService.delete(ID));
} }
@ -134,7 +134,7 @@ public class ProjectServiceTest {
@Test @Test
public void findById() { public void findById() {
when(projectRepository.findOne(ID)).thenReturn(project); when(projectRepository.getOne(ID)).thenReturn(project);
assertEquals(project, projectService.findById(ID)); assertEquals(project, projectService.findById(ID));
} }

View File

@ -5,8 +5,8 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.InjectMocks; import org.mockito.InjectMocks;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.data.domain.Sort; import org.springframework.data.domain.Sort;
import org.springframework.test.context.junit4.SpringRunner;
import ru.ulstu.core.util.DateUtils; 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;
@ -32,7 +32,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class) @RunWith(SpringRunner.class)
public class TaskServiceTest { public class TaskServiceTest {
@Mock @Mock
@ -113,7 +113,6 @@ public class TaskServiceTest {
@Test @Test
public void findAll() { public void findAll() {
when(taskRepository.findAll(SORT)).thenReturn(tasks); when(taskRepository.findAll(SORT)).thenReturn(tasks);
assertEquals(Collections.singletonList(task), taskService.findAll()); assertEquals(Collections.singletonList(task), taskService.findAll());
} }
@ -153,8 +152,8 @@ public class TaskServiceTest {
@Test @Test
public void delete() throws IOException { public void delete() throws IOException {
when(taskRepository.exists(ID)).thenReturn(true); when(taskRepository.existsById(ID)).thenReturn(true);
when(taskRepository.findOne(ID)).thenReturn(task); when(taskRepository.getOne(ID)).thenReturn(task);
when(schedulerRepository.findOneByTask(task)).thenReturn(null); when(schedulerRepository.findOneByTask(task)).thenReturn(null);
assertTrue(taskService.delete(ID)); assertTrue(taskService.delete(ID));