From 98e9f58d74aa725e9d568ccd1b75939d054e7198 Mon Sep 17 00:00:00 2001 From: LeandroSilva Date: Thu, 4 Apr 2024 10:41:16 +0200 Subject: [PATCH] fix: * extract the given object creation to smaller methods as commented on the PR. --- .../service/session/SessionServiceTest.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/test/java/de/caritas/cob/userservice/api/service/session/SessionServiceTest.java b/src/test/java/de/caritas/cob/userservice/api/service/session/SessionServiceTest.java index 66b03656a..085ac374f 100644 --- a/src/test/java/de/caritas/cob/userservice/api/service/session/SessionServiceTest.java +++ b/src/test/java/de/caritas/cob/userservice/api/service/session/SessionServiceTest.java @@ -805,19 +805,14 @@ void initializeSession_Should_initializePeerChat_When_consultingTypeSettingsHasP void getAllowedSessionsByConsultantAndGroupOrFeedbackGroupIds_should_only_return_the_sessions_the_consultant_can_see() { //given - Session allowedSession = - createAnonymousNewEnquiryWithConsultingType(AGENCY_DTO_SUCHT.getConsultingType()); - Session notAllowedSession = - createAnonymousNewEnquiryWithConsultingType(AGENCY_DTO_SUCHT.getConsultingType()); List sessions = new ArrayList<>(); - sessions.add(notAllowedSession); - sessions.add(allowedSession); ConsultantAgency agency = new ConsultantAgency(); agency.setAgencyId(4711L); var consultant = createConsultantWithAgencies(agency); - allowedSession.setConsultant(consultant); - allowedSession.setId(1L); - notAllowedSession.setId(2L); + var allowedSession = giveAllowedSessionWithID(1L, consultant); + var unhallowedSession = giveUnhallowedSessionWithID(2L); + sessions.add(unhallowedSession); + sessions.add(allowedSession); when(sessionRepository.findByGroupOrFeedbackGroupIds(singleton("rcGroupId"))) .thenReturn(sessions); //when @@ -911,6 +906,21 @@ private List getSomeUserId(String someUserId, Session an someUserId, singleton(anonymousEnquiry.getId()), singleton(UserRole.ANONYMOUS.getValue())); } + private Session giveAllowedSessionWithID(Long id, Consultant consultant){ + Session allowedSession = + createAnonymousNewEnquiryWithConsultingType(AGENCY_DTO_SUCHT.getConsultingType()); + allowedSession.setId(id); + allowedSession.setConsultant(consultant); + return allowedSession; + } + + private Session giveUnhallowedSessionWithID(Long id){ + Session unhallowedSession = + createAnonymousNewEnquiryWithConsultingType(AGENCY_DTO_SUCHT.getConsultingType()); + unhallowedSession.setId(id); + return unhallowedSession; + } + private Session createAnonymousNewEnquiryWithConsultingType(int consultingTypeId) { var session = easyRandom.nextObject(Session.class); session.setAgencyId(null);