From bde9cb51fb20944b340792e8bb54b8d6cbec329a Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Thu, 16 May 2019 15:55:29 +0400 Subject: [PATCH] #104 some methods fixed --- .../conference/service/ConferenceService.java | 8 ++-- src/main/java/ru/ulstu/paper/model/Paper.java | 12 ++++-- .../ru/ulstu/ping/service/PingService.java | 4 +- .../service/ConferenceServiceTest.java | 38 ++++++++++++------- 4 files changed, 41 insertions(+), 21 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 7162d37..633fa2e 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -16,6 +16,7 @@ import ru.ulstu.deadline.service.DeadlineService; import ru.ulstu.name.BaseService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; +import ru.ulstu.ping.model.Ping; import ru.ulstu.ping.service.PingService; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; @@ -240,9 +241,10 @@ public class ConferenceService extends BaseService { } @Transactional - public int ping(ConferenceDto conferenceDto) throws IOException { - pingService.addPing(findOne(conferenceDto.getId())); - return conferenceRepository.updatePingConference(conferenceDto.getId()); + public Ping ping(ConferenceDto conferenceDto) throws IOException { + Ping ping = pingService.addPing(findOne(conferenceDto.getId())); + conferenceRepository.updatePingConference(conferenceDto.getId()); + return ping; } private Conference findOne(Integer conferenceId) { diff --git a/src/main/java/ru/ulstu/paper/model/Paper.java b/src/main/java/ru/ulstu/paper/model/Paper.java index 2624b66..15ee4b4 100644 --- a/src/main/java/ru/ulstu/paper/model/Paper.java +++ b/src/main/java/ru/ulstu/paper/model/Paper.java @@ -268,9 +268,15 @@ public class Paper extends BaseEntity implements UserContainer { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + if (!super.equals(o)) { + return false; + } Paper paper = (Paper) o; return Objects.equals(title, paper.title) && status == paper.status && diff --git a/src/main/java/ru/ulstu/ping/service/PingService.java b/src/main/java/ru/ulstu/ping/service/PingService.java index f7156f0..6666fdd 100644 --- a/src/main/java/ru/ulstu/ping/service/PingService.java +++ b/src/main/java/ru/ulstu/ping/service/PingService.java @@ -23,10 +23,10 @@ public class PingService { } @Transactional - public void addPing(Conference conference) throws IOException { + public Ping addPing(Conference conference) throws IOException { Ping newPing = new Ping(new Date(), userService.getCurrentUser()); newPing.setConference(conference); - pingRepository.save(newPing); + return pingRepository.save(newPing); } public Integer countPingYesterday(Conference conference, Calendar calendar) { diff --git a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java index 3a58cbb..5925aed 100644 --- a/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java +++ b/src/test/java/ru/ulstu/conference/service/ConferenceServiceTest.java @@ -16,6 +16,7 @@ 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.ping.model.Ping; import ru.ulstu.ping.service.PingService; import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; @@ -65,6 +66,7 @@ public class ConferenceServiceTest { private final Integer INDEX = 0; private final String NAME = "Name"; private final boolean DISABLED = true; + private final Integer YEAR = 2019; private List conferences; private List deadlines; @@ -127,19 +129,27 @@ public class ConferenceServiceTest { @Test public void getExistConferenceById() { - when(conferenceRepository.findOne(1)).thenReturn(conferenceWithId); + when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); when(userService.getCurrentUser()).thenReturn(user); - conferenceDto.setDisabledTakePart(true); - assertEquals(conferenceDto, conferenceService.getExistConferenceById(1)); + ConferenceDto newConferenceDto = new ConferenceDto(conferenceWithId); + newConferenceDto.setNotSelectedPapers(papers); + newConferenceDto.setDisabledTakePart(!DISABLED); + ConferenceDto result = conferenceService.getExistConferenceById(ID); + assertEquals(newConferenceDto.getId(), result.getId()); + assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers()); + assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart()); } @Test public void getNewConference() { + when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); ConferenceDto newConferenceDto = new ConferenceDto(); newConferenceDto.setNotSelectedPapers(papers); - when(paperService.findAllNotSelect(new ArrayList<>())).thenReturn(papers); - assertEquals(newConferenceDto, conferenceService.getNewConference()); + ConferenceDto result = conferenceService.getNewConference(); + assertEquals(newConferenceDto.getId(), result.getId()); + assertEquals(newConferenceDto.getNotSelectedPapers(), result.getNotSelectedPapers()); + assertEquals(newConferenceDto.isDisabledTakePart(), result.isDisabledTakePart()); } @Test @@ -239,23 +249,25 @@ public class ConferenceServiceTest { @Test public void filter() { ConferenceFilterDto conferenceFilterDto = new ConferenceFilterDto(); - conferenceFilterDto.setFilterUserId(1); - conferenceFilterDto.setYear(2019); - when(userService.findById(1)).thenReturn(user); - when(conferenceRepository.findByUserAndYear(user, 2019)).thenReturn(conferences); + conferenceFilterDto.setFilterUserId(ID); + conferenceFilterDto.setYear(YEAR); + when(userService.findById(ID)).thenReturn(user); + when(conferenceRepository.findByUserAndYear(user, YEAR)).thenReturn(conferences); assertEquals(Collections.singletonList(conferenceDto), conferenceService.filter(conferenceFilterDto)); } @Test public void isAttachedToConference() { - when(conferenceRepository.isPaperAttached(1)).thenReturn(true); - assertTrue(conferenceService.isAttachedToConference(1)); + when(conferenceRepository.isPaperAttached(ID)).thenReturn(true); + assertTrue(conferenceService.isAttachedToConference(ID)); } @Test public void ping() throws IOException { + Ping ping = new Ping(); when(conferenceRepository.findOne(ID)).thenReturn(conferenceWithId); - when(conferenceRepository.updatePingConference(1)).thenReturn(1); - assertEquals(1, conferenceService.ping(conferenceDto)); + when(pingService.addPing(conferenceWithId)).thenReturn(ping); + when(conferenceRepository.updatePingConference(ID)).thenReturn(INDEX); + assertEquals(ping, conferenceService.ping(conferenceDto)); } } \ No newline at end of file