From ce7b4c9c7a81d0752efc61a94a9216828aa5afd9 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 16 May 2019 13:33:26 +0400 Subject: [PATCH] #104 addDeadline, removeDeadline fixed --- .../ru/ulstu/deadline/model/Deadline.java | 5 ++++ .../service/ConferenceServiceTest.java | 25 +++++++++++++------ 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/main/java/ru/ulstu/deadline/model/Deadline.java b/src/main/java/ru/ulstu/deadline/model/Deadline.java index 148697c..6c564aa 100644 --- a/src/main/java/ru/ulstu/deadline/model/Deadline.java +++ b/src/main/java/ru/ulstu/deadline/model/Deadline.java @@ -65,6 +65,11 @@ public class Deadline extends BaseEntity { return false; } Deadline deadline = (Deadline) o; + if (getId() == null && deadline.getId() == null && + description == null && deadline.description == null && + date == null && deadline.date == null) { + return true; + } return getId().equals(deadline.getId()) && description.equals(deadline.description) && date.equals(deadline.date); diff --git a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java index af583f9..25c6d1b 100644 --- a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java +++ b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java @@ -61,6 +61,9 @@ public class ConferenceServiceTest { @InjectMocks ConferenceService conferenceService; + private final Integer ID = 1; + private final Integer ROMOVE_INDEX = 0; + private List conferences; private List deadlines; private List papers; @@ -171,20 +174,26 @@ public class ConferenceServiceTest { @Test public void delete() { - when(conferenceRepository.exists(1)).thenReturn(true); - assertTrue(conferenceService.delete(1)); + when(conferenceRepository.exists(ID)).thenReturn(true); + when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); + assertTrue(conferenceService.delete(ID)); } @Test public void addDeadline() { - ConferenceDto newConferenceDto = conferenceService.addDeadline(conferenceDto); - assertEquals(conferenceDto, newConferenceDto); + ConferenceDto newConferenceDto = new ConferenceDto(); + newConferenceDto.getDeadlines().add(new Deadline()); + conferenceDto.getDeadlines().clear(); + assertEquals(newConferenceDto.getDeadlines(), conferenceService.addDeadline(conferenceDto).getDeadlines()); } @Test public void removeDeadline() throws IOException { - ConferenceDto newConferenceDto = conferenceService.removeDeadline(conferenceDto, 0); - assertEquals(conferenceDto, newConferenceDto); + ConferenceDto newConferenceDto = new ConferenceDto(); + newConferenceDto.getRemovedDeadlineIds().add(ID); + ConferenceDto result = conferenceService.removeDeadline(conferenceDto, ROMOVE_INDEX); + assertEquals(newConferenceDto.getDeadlines(), result.getDeadlines()); + assertEquals(newConferenceDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds()); } @Test @@ -196,7 +205,7 @@ public class ConferenceServiceTest { @Test public void removePaper() throws IOException { - ConferenceDto newConferenceDto = conferenceService.removePaper(conferenceDto, 0); + ConferenceDto newConferenceDto = conferenceService.removePaper(conferenceDto, ROMOVE_INDEX); assertEquals(conferenceDto, newConferenceDto); } @@ -234,7 +243,7 @@ public class ConferenceServiceTest { @Test public void ping() throws IOException { - when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId); + when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); when(conferenceRepository.updatePingConference(1)).thenReturn(1); assertEquals(1, conferenceService.ping(conferenceDto)); }