From 11cab955b4d51bbc3b11413a0e0d844b05edfb5a Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Tue, 14 May 2019 18:51:03 +0400 Subject: [PATCH] #104 test create --- .../ulstu/conference/model/ConferenceDto.java | 11 ++-- .../module_test/ConferenceServiceTest.java | 52 +++++++++++++++---- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index 944cd9d..76dbb90 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -221,8 +221,12 @@ public class ConferenceDto { @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; + } ConferenceDto that = (ConferenceDto) o; return ping == that.ping && disabledTakePart == that.disabledTakePart && @@ -243,6 +247,7 @@ public class ConferenceDto { @Override public int hashCode() { - return Objects.hash(id, title, description, url, ping, beginDate, endDate, deadlines, removedDeadlineIds, userIds, paperIds, papers, notSelectedPapers, users, disabledTakePart); + return Objects.hash(id, title, description, url, ping, beginDate, endDate, deadlines, removedDeadlineIds, + userIds, paperIds, papers, notSelectedPapers, users, disabledTakePart); } } diff --git a/src/test/java/conference/module_test/ConferenceServiceTest.java b/src/test/java/conference/module_test/ConferenceServiceTest.java index 6f2146b..200b6f1 100644 --- a/src/test/java/conference/module_test/ConferenceServiceTest.java +++ b/src/test/java/conference/module_test/ConferenceServiceTest.java @@ -11,12 +11,14 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; +import ru.ulstu.conference.service.ConferenceNotificationService; import ru.ulstu.conference.service.ConferenceService; import ru.ulstu.conference.service.ConferenceUserService; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; @@ -26,6 +28,7 @@ import java.util.Date; import java.util.List; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) @@ -46,6 +49,12 @@ public class ConferenceServiceTest { @Mock UserService userService; + @Mock + ConferenceNotificationService conferenceNotificationService; + + @Mock + EventService eventService; + @InjectMocks ConferenceService conferenceService; @@ -53,7 +62,9 @@ public class ConferenceServiceTest { private List deadlines; private List papers; private List conferenceUsers; - private Conference conference; + + private Conference conferenceWithId; + private Conference conferenceWithoutId; private ConferenceUser conferenceUser; private Paper paperWithId; @@ -66,10 +77,15 @@ public class ConferenceServiceTest { @Before public void setUp() throws Exception { conferences = new ArrayList<>(); - conference = new Conference(); + conferenceWithId = new Conference(); + conferenceWithoutId = new Conference(); - conference.setTitle("Название"); - conference.setDescription("Описание"); + conferenceWithId.setId(1); + conferenceWithId.setTitle("Название"); + conferenceWithId.setDescription("Описание"); + + conferenceWithoutId.setTitle("Название"); + conferenceWithoutId.setDescription("Описание"); paperWithId = new Paper(); paperWithId.setId(1); @@ -97,12 +113,16 @@ public class ConferenceServiceTest { conferenceUsers = new ArrayList<>(); conferenceUsers.add(conferenceUser); - conference.setPapers(papers); - conference.setDeadlines(deadlines); - conference.setUsers(conferenceUsers); + conferenceWithId.setPapers(papers); + conferenceWithId.setDeadlines(deadlines); + conferenceWithId.setUsers(conferenceUsers); - conferences.add(conference); - conferenceDto = new ConferenceDto(conference); + conferenceWithoutId.setPapers(papers); + conferenceWithoutId.setDeadlines(deadlines); + conferenceWithoutId.setUsers(conferenceUsers); + + conferences.add(conferenceWithId); + conferenceDto = new ConferenceDto(conferenceWithId); } @Test @@ -117,7 +137,7 @@ public class ConferenceServiceTest { when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId); when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines); when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers); - assertEquals(conference, conferenceService.copyFromDto(new Conference(), conferenceDto)); + assertEquals(conferenceWithoutId, conferenceService.copyFromDto(new Conference(), conferenceDto)); } @Test @@ -136,7 +156,17 @@ public class ConferenceServiceTest { @Test public void testFindOneDto() throws IOException { - when(conferenceRepository.findOne(1)).thenReturn(conference); + when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId); assertEquals(conferenceDto, conferenceService.findOneDto(1)); } + + @Test + public void testCreate() throws IOException { + when(paperService.findPaperById(paperWithId.getId())).thenReturn(paperWithId); + when(paperService.create(paperWithoutId)).thenReturn(paperWithoutId); + when(deadlineService.saveOrCreate(conferenceDto.getDeadlines())).thenReturn(deadlines); + when(conferenceUserService.saveOrCreate(conferenceDto.getUsers())).thenReturn(conferenceUsers); + when(conferenceRepository.save(conferenceWithoutId)).thenReturn(conferenceWithoutId); + assertNull(conferenceService.create(conferenceDto)); + } }