From a2db75de9039f29bff2c09d22e01ddb48fd07a89 Mon Sep 17 00:00:00 2001 From: Ben Edwards <147524406+Ben-Edwards-cgi@users.noreply.github.com> Date: Fri, 23 Aug 2024 18:08:25 +0100 Subject: [PATCH] Remove JurorPoolUtils.getSingleActiveJurorPool() and replace with jurorPoolSerive.getActiveRecordFromUser() (#744) * Updated the way we retrieve juror pools to prevent non-unique entry errors * Applied review comments * Fixed styles / merged stabilisation13 --- build.gradle | 2 +- .../DeceasedResponseControllerITest.java | 6 +- .../DeferralMaintenanceControllerITest.java | 5 +- .../ExcusalResponseControllerITest.java | 34 +- .../JurorPaperResponseControllerITest.java | 32 +- .../JurorRecordControllerITest.java | 10 +- .../UndeliverableResponseControllerITest.java | 9 +- .../api/juror/service/JurorServiceImpl.java | 13 +- .../service/StraightThroughProcessorImpl.java | 3 +- .../moj/exception/JurorRecordException.java | 16 - .../RestResponseEntityExceptionHandler.java | 1 - .../JurorPaperResponseServiceImpl.java | 19 +- .../api/moj/service/JurorPoolServiceImpl.java | 5 +- .../moj/service/ReissueLetterServiceImpl.java | 4 +- .../StraightThroughProcessorServiceImpl.java | 3 +- .../SummonsReplyStatusUpdateServiceImpl.java | 11 +- .../UndeliverableResponseServiceImpl.java | 7 +- .../juror/api/moj/utils/JurorPoolUtils.java | 49 -- .../uk/gov/hmcts/juror/api/TestUtils.java | 14 +- .../juror/service/JurorServiceImplTest.java | 18 +- .../StraightThroughProcessorImplTest.java | 18 +- .../JurorPaperResponseServiceImplTest.java | 43 +- .../moj/service/JurorRecordServiceTest.java | 2 + ...orResponseStatusUpdateServiceImplTest.java | 23 +- ...raightThroughProcessorServiceImplTest.java | 127 +-- ...mmonsReplyStatusUpdateServiceImplTest.java | 788 ++++++++---------- .../UndeliverableResponseServiceTest.java | 68 +- .../api/moj/utils/JurorPoolUtilsTest.java | 75 -- .../hmcts/juror/api/utils/TestConstants.java | 2 +- 29 files changed, 548 insertions(+), 859 deletions(-) diff --git a/build.gradle b/build.gradle index 1001b427d..3d60d8c5f 100644 --- a/build.gradle +++ b/build.gradle @@ -287,7 +287,7 @@ pmdTest { maxFailures = 292 } pmdMain { - maxFailures = 771 + maxFailures = 763 } pmd { maxFailures = 0 diff --git a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/DeceasedResponseControllerITest.java b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/DeceasedResponseControllerITest.java index e322c40e8..3f4454b11 100644 --- a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/DeceasedResponseControllerITest.java +++ b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/DeceasedResponseControllerITest.java @@ -26,6 +26,7 @@ import uk.gov.hmcts.juror.api.moj.repository.ContactLogRepository; import uk.gov.hmcts.juror.api.moj.repository.JurorHistoryRepository; import uk.gov.hmcts.juror.api.moj.repository.JurorPoolRepository; +import uk.gov.hmcts.juror.api.moj.repository.JurorRepository; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorPaperResponseRepositoryMod; import uk.gov.hmcts.juror.api.moj.utils.DataUtils; import uk.gov.hmcts.juror.api.moj.utils.JurorPoolUtils; @@ -42,6 +43,7 @@ */ @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@SuppressWarnings("PMD.ExcessiveImports") public class DeceasedResponseControllerITest extends AbstractIntegrationTest { private HttpHeaders httpHeaders; @@ -58,6 +60,8 @@ public class DeceasedResponseControllerITest extends AbstractIntegrationTest { private ContactLogRepository contactLogRepository; @Autowired private JurorPaperResponseRepositoryMod jurorPaperResponseRepository; + @Autowired + private JurorRepository jurorRepository; @Before public void setUp() throws Exception { @@ -155,7 +159,7 @@ public void markJurorAsDeceased_BureauUser_paperResponseDoesNotExists() { executeInTransaction(() -> { // verify the status of the juror record has been updated - Juror juror = JurorPoolUtils.getActiveJurorRecord(jurorPoolRepository, jurorNumber); + Juror juror = jurorRepository.findByJurorNumber(jurorNumber); CourtLocation courtLocation = new CourtLocation(); courtLocation.setLocCode("415"); JurorPool jurorPool = JurorPoolUtils.getActiveJurorPool(jurorPoolRepository, jurorNumber, courtLocation); diff --git a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/DeferralMaintenanceControllerITest.java b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/DeferralMaintenanceControllerITest.java index 2de281136..e7c2df4dd 100644 --- a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/DeferralMaintenanceControllerITest.java +++ b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/DeferralMaintenanceControllerITest.java @@ -40,7 +40,6 @@ import uk.gov.hmcts.juror.api.moj.repository.JurorRepository; import uk.gov.hmcts.juror.api.moj.repository.PoolRequestRepository; import uk.gov.hmcts.juror.api.moj.utils.DateUtils; -import uk.gov.hmcts.juror.api.moj.utils.JurorPoolUtils; import java.net.URI; import java.time.LocalDate; @@ -853,7 +852,7 @@ void bureauProcessJurorActivePoolPaper() { verifyActivePoolOldRecord(jurorPools.get(0)); // grab new record to verify it has been created and the properties have been updated correctly - Juror newJurorRecord = JurorPoolUtils.getActiveJurorRecord(jurorPoolRepository, JUROR_555555561); + Juror newJurorRecord = jurorRepository.findByJurorNumber(JUROR_555555561); verifyActiveJurorNewRecord(newJurorRecord, deferralReasonRequestDto.getPoolNumber(), deferralReasonRequestDto.getDeferralDate()); @@ -900,7 +899,7 @@ void courtProcessJurorActivePoolDigital() { verifyActivePoolOldRecord(jurorPools.get(0)); // grab new record to verify it has been created and the properties have been updated correctly - Juror newJurorRecord = JurorPoolUtils.getActiveJurorRecord(jurorPoolRepository, JUROR_555555558); + Juror newJurorRecord = jurorRepository.findByJurorNumber(JUROR_555555558); verifyActiveJurorNewRecord(newJurorRecord, deferralReasonRequestDto.getPoolNumber(), deferralReasonRequestDto.getDeferralDate()); diff --git a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/ExcusalResponseControllerITest.java b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/ExcusalResponseControllerITest.java index d434dbcd8..5ff69ce97 100644 --- a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/ExcusalResponseControllerITest.java +++ b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/ExcusalResponseControllerITest.java @@ -39,7 +39,6 @@ import uk.gov.hmcts.juror.api.moj.repository.UserRepository; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorDigitalResponseRepositoryMod; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorPaperResponseRepositoryMod; -import uk.gov.hmcts.juror.api.moj.utils.JurorPoolUtils; import java.net.URI; import java.time.LocalDate; @@ -110,7 +109,8 @@ public void refuseExcusalRequest_paperResponse_bureauUser_bureauOwner() throws E PaperResponse jurorPaperResponse = jurorPaperResponseRepository.findByJurorNumber(jurorNumber); validatePaperResponseExcusal(jurorPaperResponse, login); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); validateRefuseExcusal(jurorPool, excusalDecisionDto, login); validateExcusalDeniedLetter(); }); @@ -137,7 +137,8 @@ public void refuseExcusalRequest_paperResponse_courtUser_courtOwner() throws Exc jurorPaperResponseRepository.findByJurorNumber(jurorNumber); validatePaperResponseExcusal(jurorPaperResponse, login); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); validateRefuseExcusal(jurorPool, excusalDecisionDto, login); Iterable bulkPrintDataIterable = bulkPrintDataRepository.findAll(); @@ -178,7 +179,8 @@ public void grantExcusalRequest_paperResponse_bureauUser_bureauOwner() throws Ex jurorPaperResponseRepository.findByJurorNumber(jurorNumber); validatePaperResponseExcusal(jurorPaperResponse, login); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); validateExcusal(jurorPool, excusalDecisionDto, login); validateExcusalLetter(excusalDecisionDto.getExcusalReasonCode()); @@ -207,7 +209,8 @@ public void grantExcusalRequest_paperResponse_courtUser_courtOwner() throws Exce jurorPaperResponseRepository.findByJurorNumber(jurorNumber); validatePaperResponseExcusal(jurorPaperResponse, login); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); validateExcusal(jurorPool, excusalDecisionDto, login); }); } @@ -233,7 +236,8 @@ public void refuseExcusalRequest_digitalResponse_bureauUser_bureauOwner() throws DigitalResponse jurorResponse = jurorResponseRepository.findByJurorNumber(jurorNumber); validateDigitalResponseExcusal(jurorResponse, login); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); validateRefuseExcusal(jurorPool, excusalDecisionDto, login); validateExcusalDeniedLetter(); }); @@ -260,7 +264,8 @@ public void refuseExcusalRequest_digitalResponse_courtUser_courtOwner() throws E DigitalResponse jurorResponse = jurorResponseRepository.findByJurorNumber(jurorNumber); validateDigitalResponseExcusal(jurorResponse, login); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); validateRefuseExcusal(jurorPool, excusalDecisionDto, login); Iterable bulkPrintDataIterable = bulkPrintDataRepository.findAll(); List bulkPrintData = new ArrayList<>(); @@ -300,7 +305,8 @@ public void grantExcusalRequest_digitalResponse_bureauUser_bureauOwner() throws DigitalResponse jurorResponse = jurorResponseRepository.findByJurorNumber(jurorNumber); validateDigitalResponseExcusal(jurorResponse, login); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); validateExcusal(jurorPool, excusalDecisionDto, login); validateExcusalLetter(excusalDecisionDto.getExcusalReasonCode()); }); @@ -328,7 +334,8 @@ public void grantExcusalRequest_digitalResponse_courtUser_courtOwner() throws Ex DigitalResponse jurorResponse = jurorResponseRepository.findByJurorNumber(jurorNumber); validateDigitalResponseExcusal(jurorResponse, login); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); validateExcusal(jurorPool, excusalDecisionDto, login); }); } @@ -355,7 +362,8 @@ public void grantExcusalRequest_excusalCodeDeceased() throws Exception { PaperResponse jurorPaperResponse = jurorPaperResponseRepository.findByJurorNumber(jurorNumber); validatePaperResponseExcusal(jurorPaperResponse, login); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); validateExcusal(jurorPool, excusalDecisionDto, login); validateExcusalLetter(excusalDecisionDto.getExcusalReasonCode()); }); @@ -420,7 +428,8 @@ public void excusalRequest_paperResponse_alreadyProcessed() throws Exception { PaperResponse jurorPaperResponse = jurorPaperResponseRepository.findByJurorNumber(jurorNumber); validatePaperResponseExcusal(jurorPaperResponse, login); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); validateExcusal(jurorPool, excusalDecisionDto, login); validateExcusalLetter(excusalDecisionDto.getExcusalReasonCode()); }); @@ -483,7 +492,8 @@ public void excusalRequest_paperResponse_doesNotExist() throws Exception { ResponseEntity response = template.exchange(requestEntity, String.class); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); executeInTransaction(() -> { - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); validateExcusal(jurorPool, excusalDecisionDto, login); validateExcusalLetter(excusalDecisionDto.getExcusalReasonCode()); }); diff --git a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorPaperResponseControllerITest.java b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorPaperResponseControllerITest.java index 53ad0e684..d3760691f 100644 --- a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorPaperResponseControllerITest.java +++ b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorPaperResponseControllerITest.java @@ -15,7 +15,6 @@ import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.junit4.SpringRunner; import uk.gov.hmcts.juror.api.AbstractIntegrationTest; -import uk.gov.hmcts.juror.api.config.bureau.BureauJwtPayload; import uk.gov.hmcts.juror.api.juror.domain.ProcessingStatus; import uk.gov.hmcts.juror.api.juror.domain.WelshCourtLocationRepository; import uk.gov.hmcts.juror.api.moj.controller.request.CjsEmploymentDetailsDto; @@ -53,7 +52,6 @@ import java.time.LocalDateTime; import java.time.temporal.ChronoUnit; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -170,7 +168,7 @@ public void respondToSummons_courtUser_noAccess() throws Exception { HttpMethod.POST, uri); ResponseEntity response = template.exchange(requestEntity, SaveJurorPaperReplyResponseDto.class); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } @Test @@ -221,7 +219,7 @@ public void respondToSummons_courtUser_bureauOwnedJurorRecord() throws Exception HttpMethod.POST, uri); ResponseEntity response = template.exchange(requestEntity, SaveJurorPaperReplyResponseDto.class); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } @Test @@ -1764,22 +1762,10 @@ public void updateJurorPaperResponseStatus_bureauUser_noJurorRecord() throws Exc assertThat(response.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } - @Test - @Sql({"/db/mod/truncate.sql", "/db/JurorPaperResponse_updatePaperResponseStatus.sql"}) - public void updateJurorPaperResponseStatus_bureauUser_multipleJurorRecords() throws Exception { - final String bureauJwt = createJwtBureau("BUREAU_USER"); - final URI uri = URI.create("/api/v1/moj/juror-paper-response/update-status/444444444/CLOSED"); - - httpHeaders.set(HttpHeaders.AUTHORIZATION, bureauJwt); - RequestEntity requestEntity = new RequestEntity<>(httpHeaders, HttpMethod.PUT, uri); - ResponseEntity response = template.exchange(requestEntity, Void.class); - assertThat(response.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); - } - @Test @Sql({"/db/mod/truncate.sql", "/db/JurorPaperResponse_updatePaperResponseStatus.sql"}) public void updateJurorPaperResponseStatus_courtUser_thirdParty() throws Exception { - final String bureauJwt = initCourtsJwt("411", Arrays.asList("411", "774")); + final String bureauJwt = getSatelliteCourtJwt("411","411", "774"); final URI uri = URI.create("/api/v1/moj/juror-paper-response/update-status/555555555/CLOSED"); httpHeaders.set(HttpHeaders.AUTHORIZATION, bureauJwt); @@ -1798,7 +1784,7 @@ public void updateJurorPaperResponseStatus_courtUser_thirdParty() throws Excepti "555555555"); validateMergedJurorRecord(jurorPool, summonsReplyData, IJurorStatus.RESPONDED); - assertThat(jurorPool.getUserEdtq()).isEqualToIgnoringCase("COURT_USER"); + assertThat(jurorPool.getUserEdtq()).isEqualToIgnoringCase("test_court_standard"); // juror contact details are omitted from merge when completed by a third party assertThat(juror.getPhoneNumber()).isNull(); @@ -2085,16 +2071,6 @@ private void setThirdPartyDetails(JurorPaperResponseDto jurorPaperResponseDto) { jurorPaperResponseDto.setThirdParty(thirdParty); } - private String initCourtsJwt(String owner, List courts) throws Exception { - - return mintBureauJwt(BureauJwtPayload.builder() - .userLevel("99") - .login("COURT_USER") - .owner(owner) - .staff(BureauJwtPayload.Staff.builder().courts(courts).build()) - .build()); - } - private void validateMergedJurorRecord(JurorPool jurorPool, PaperResponse summonsReplyData, long statusCode) { Juror juror = jurorPool.getJuror(); diff --git a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorRecordControllerITest.java b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorRecordControllerITest.java index 38e38c7de..df37cf563 100644 --- a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorRecordControllerITest.java +++ b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/JurorRecordControllerITest.java @@ -106,7 +106,6 @@ import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorDigitalResponseRepositoryMod; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorPaperResponseRepositoryMod; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorReasonableAdjustmentRepository; -import uk.gov.hmcts.juror.api.moj.utils.JurorPoolUtils; import uk.gov.hmcts.juror.api.moj.utils.RepositoryUtils; import java.math.BigDecimal; @@ -386,7 +385,8 @@ void approvePendingJurorRecordHappyPath() throws Exception { //Check the Juror record has been created as well RepositoryUtils.retrieveFromDatabase("041600001", jurorRepository); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, "041600001"); + JurorPool jurorPool = jurorPoolRepository.findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue( + "416", "041600001"); assertThat(jurorPool.getPool().getPoolNumber()).as("Expect the Juror to be created and in pool 416220503") .isEqualTo("416220503"); assertThat(jurorPool.getStatus().getStatus()).as("Expect the Juror to be active") @@ -470,8 +470,7 @@ void editJurorDetailsHappyPathAllFieldsRequired() { .as("Expect the HTTP status to be NO CONTENT") .isEqualTo(HttpStatus.NO_CONTENT); executeInTransaction(() -> { - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); - Juror juror = jurorPool.getJuror(); + Juror juror = jurorRepository.findByJurorNumber(jurorNumber); //Check data has been changed and now matches what was in the dto. assertThat(juror.getTitle()).isEqualTo(requestDto.getTitle()); @@ -511,8 +510,7 @@ void editJurorDetailsHappyPathMandatoryFieldsOnly() { .as("Expect the HTTP status to be NO CONTENT") .isEqualTo(HttpStatus.NO_CONTENT); executeInTransaction(() -> { - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); - Juror juror = jurorPool.getJuror(); + Juror juror = jurorRepository.findByJurorNumber(jurorNumber); //Check data has been changed and now matches what was in the dto. assertThat(juror.getTitle()).isEqualTo(requestDto.getTitle()); diff --git a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/UndeliverableResponseControllerITest.java b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/UndeliverableResponseControllerITest.java index 6510608e3..aa9d4e293 100644 --- a/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/UndeliverableResponseControllerITest.java +++ b/src/integration-test/java/uk/gov/hmcts/juror/api/moj/controller/UndeliverableResponseControllerITest.java @@ -21,7 +21,6 @@ import uk.gov.hmcts.juror.api.moj.domain.JurorPool; import uk.gov.hmcts.juror.api.moj.repository.JurorHistoryRepository; import uk.gov.hmcts.juror.api.moj.repository.JurorPoolRepository; -import uk.gov.hmcts.juror.api.moj.utils.JurorPoolUtils; import java.net.URI; import java.time.LocalDate; @@ -95,8 +94,8 @@ public void markJurorAsUndeliverable_multiple_BureauUser() { private void assertUpdated(String jurorNumber) { executeInTransaction(() -> { - JurorPool jurorPool = - JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolRepository + .findByPoolCourtLocationLocCodeAndJurorJurorNumberAndIsActiveTrue("415", jurorNumber); Juror juror = jurorPool.getJuror(); assertThat(juror.isResponded()).isFalse(); @@ -132,8 +131,8 @@ public void markJurorAsUndeliverable_CourtUser_bureauOwnedRecord() throws Except restTemplate.exchange(createRequest("123456789"), String.class); assertThat(response.getStatusCode()) - .as("Expect the HTTP PUT request to be FORBIDDEN") - .isEqualTo(HttpStatus.FORBIDDEN); + .as("Expect the HTTP PUT request to be NOT_FOUND") + .isEqualTo(HttpStatus.NOT_FOUND); } @Test diff --git a/src/main/java/uk/gov/hmcts/juror/api/juror/service/JurorServiceImpl.java b/src/main/java/uk/gov/hmcts/juror/api/juror/service/JurorServiceImpl.java index 57c29787a..9f44f11cc 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/juror/service/JurorServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/juror/service/JurorServiceImpl.java @@ -24,18 +24,16 @@ import uk.gov.hmcts.juror.api.moj.domain.jurorresponse.JurorReasonableAdjustment; import uk.gov.hmcts.juror.api.moj.domain.jurorresponse.JurorResponseCjsEmployment; import uk.gov.hmcts.juror.api.moj.enumeration.ReplyMethod; -import uk.gov.hmcts.juror.api.moj.repository.JurorPoolRepository; import uk.gov.hmcts.juror.api.moj.repository.JurorRepository; import uk.gov.hmcts.juror.api.moj.repository.ReplyTypeRepository; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorDigitalResponseRepositoryMod; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorReasonableAdjustmentRepository; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorResponseCjsEmploymentRepositoryMod; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.ReasonableAdjustmentsRepository; -import uk.gov.hmcts.juror.api.moj.service.JurorPoolServiceImpl; +import uk.gov.hmcts.juror.api.moj.service.JurorPoolService; import uk.gov.hmcts.juror.api.moj.service.PoolRequestService; import uk.gov.hmcts.juror.api.moj.utils.DataUtils; import uk.gov.hmcts.juror.api.moj.utils.DateUtils; -import uk.gov.hmcts.juror.api.moj.utils.JurorPoolUtils; import uk.gov.hmcts.juror.api.moj.utils.RepositoryUtils; import java.time.LocalDateTime; @@ -56,18 +54,17 @@ public class JurorServiceImpl implements JurorService { private final JurorDigitalResponseRepositoryMod jurorResponseRepository; private final JurorResponseCjsEmploymentRepositoryMod jurorResponseCjsEmploymentRepository; private final JurorReasonableAdjustmentRepository jurorReasonableAdjustmentRepository; - private final JurorPoolRepository jurorPoolRepository; private final UrgencyService urgencyService; private final PoolRequestService poolRequestService; private final ReasonableAdjustmentsRepository reasonableAdjustmentsRepository; private final JurorRepository jurorRepository; - private final JurorPoolServiceImpl jurorPoolServiceImpl; + private final JurorPoolService jurorPoolService; @Override public JurorDetailDto getJurorByJurorNumber(final String number) { log.debug("Getting juror {} details", number); - JurorPool jurorDetails = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, number); + JurorPool jurorDetails = jurorPoolService.getJurorPoolFromUser(number); JurorDetailDto.JurorDetailDtoBuilder builder = JurorDetailDto.builder(); JurorStatus jurorStatus = new JurorStatus(); @@ -155,7 +152,7 @@ && noThirdPartyPhoneNumbers(responseDto.getThirdParty())) { } JurorPool jurorDetails = - JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, responseDto.getJurorNumber()); + jurorPoolService.getJurorPoolFromUser(responseDto.getJurorNumber()); Juror juror = jurorDetails.getJuror(); if (!ObjectUtils.isEmpty(responseDto.getThirdParty()) && !ObjectUtils.isEmpty( @@ -273,7 +270,7 @@ public DigitalResponse convertJurorResponseDtoToEntity(JurorResponseDto dto) { ); } - final JurorPool jurorDetails = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + final JurorPool jurorDetails = jurorPoolService.getJurorPoolFromUser(jurorNumber); DigitalResponse.DigitalResponseBuilder builder = DigitalResponse.builder() .jurorNumber(dto.getJurorNumber()) .dateOfBirth(dto.getDateOfBirth()) diff --git a/src/main/java/uk/gov/hmcts/juror/api/juror/service/StraightThroughProcessorImpl.java b/src/main/java/uk/gov/hmcts/juror/api/juror/service/StraightThroughProcessorImpl.java index fed7bcf07..765e62d0a 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/juror/service/StraightThroughProcessorImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/juror/service/StraightThroughProcessorImpl.java @@ -27,7 +27,6 @@ import uk.gov.hmcts.juror.api.moj.service.JurorHistoryService; import uk.gov.hmcts.juror.api.moj.service.JurorPoolService; import uk.gov.hmcts.juror.api.moj.service.PrintDataService; -import uk.gov.hmcts.juror.api.moj.utils.JurorPoolUtils; import uk.gov.hmcts.juror.api.moj.utils.RepositoryUtils; import uk.gov.hmcts.juror.api.validation.ResponseInspector; @@ -412,7 +411,7 @@ public void processAgeExcusal( final DigitalResponse savedDigitalResponse = jurorDigitalResponseRepository.findByJurorNumber(digitalResponse.getJurorNumber()); final JurorPool jurorDetails = - JurorPoolUtils.getSingleActiveJurorPool(jurorRepository, savedDigitalResponse.getJurorNumber()); + jurorPoolService.getJurorPoolFromUser(savedDigitalResponse.getJurorNumber()); // check the response for answers making it ineligible for straight through processing. //JDB-91 b. the response must not have been submitted by a third party diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/exception/JurorRecordException.java b/src/main/java/uk/gov/hmcts/juror/api/moj/exception/JurorRecordException.java index e8b5cccf5..24f3eb297 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/exception/JurorRecordException.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/exception/JurorRecordException.java @@ -48,20 +48,4 @@ public InvalidJurorNumber(String jurorNumber) { } - /** - * Exception type thrown when a single, active, juror record is expected for a single Juror Number - * but multiple juror records have been returned - sometimes active multiple juror records can be valid or expected - * for example when a juror is transferred to a different court they could have one active record per court they - * have served at. However, there are times when only a single record is expected, for example before the juror has - * attended court they are being managed by the Bureau, having their summons reply processed for a single location - */ - @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - public static class MultipleJurorRecordsFound extends JurorRecordException { - - public MultipleJurorRecordsFound(String jurorNumber) { - super(String.format("Unexpected number of Juror Records found for juror number: %s", jurorNumber)); - } - - } - } diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/exception/RestResponseEntityExceptionHandler.java b/src/main/java/uk/gov/hmcts/juror/api/moj/exception/RestResponseEntityExceptionHandler.java index 2a4a382eb..119463667 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/exception/RestResponseEntityExceptionHandler.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/exception/RestResponseEntityExceptionHandler.java @@ -150,7 +150,6 @@ public ResponseEntity handleMojExceptionBusinessRuleViolation(MojExcepti @ExceptionHandler(value = {SQLException.class, PSQLException.class, DateException.DateParseException.class, JurorPaperResponseException.UnableToFindJurorRecord.class, - JurorRecordException.MultipleJurorRecordsFound.class, PoolCreateException.UnableToCreatePool.class, JurorSequenceException.SequenceNextValNotFound.class }) diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/service/JurorPaperResponseServiceImpl.java b/src/main/java/uk/gov/hmcts/juror/api/moj/service/JurorPaperResponseServiceImpl.java index 5574de93a..d7044db6e 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/service/JurorPaperResponseServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/service/JurorPaperResponseServiceImpl.java @@ -1,7 +1,6 @@ package uk.gov.hmcts.juror.api.moj.service; import io.jsonwebtoken.lang.Collections; -import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -36,7 +35,6 @@ import uk.gov.hmcts.juror.api.moj.repository.JurorRepository; import uk.gov.hmcts.juror.api.moj.repository.SummonsSnapshotRepository; import uk.gov.hmcts.juror.api.moj.repository.UserRepository; -import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorDigitalResponseRepositoryMod; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorPaperResponseRepositoryMod; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorReasonableAdjustmentRepository; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorResponseCjsEmploymentRepositoryMod; @@ -63,28 +61,17 @@ public class JurorPaperResponseServiceImpl implements JurorPaperResponseService private static final String INVALID_CJS_EMPLOYMENT_ERROR_MESSAGE = "Invalid CJS Employment supplied for Juror %s"; private static final String INVALID_SPECIAL_NEED_ERROR_MESSAGE = "Invalid special need supplied for Juror %s"; static final String RESPONSE_UPDATED_LOG = "Paper response for Juror %s will be updated with new value for %s"; - @NonNull private final JurorPaperResponseRepositoryMod paperResponseRepository; - @NonNull private final JurorResponseCjsEmploymentRepositoryMod jurorResponseCjsEmploymentRepository; - @NonNull private final JurorReasonableAdjustmentRepository reasonableAdjustmentsRepository; - @NonNull private final UserRepository userRepository; - @NonNull - private final JurorDigitalResponseRepositoryMod jurorDigitalResponseRepositoryMod; - @NonNull private final JurorPoolRepository jurorPoolRepository; - @NonNull private final SummonsSnapshotRepository summonsSnapshotRepository; - @NonNull private final WelshCourtLocationRepository welshCourtLocationRepository; - @NonNull private final StraightThroughProcessorService straightThroughProcessorService; - - @NonNull private final JurorRepository jurorRepository; - + private final JurorPoolService jurorPoolService; + @Override @Transactional public JurorPaperResponseDetailDto getJurorPaperResponse(final String jurorNumber, BureauJwtPayload payload) { @@ -317,7 +304,7 @@ public void saveResponse(BureauJwtPayload payload, JurorPaperResponseDto paperRe log.info(String.format("Saving paper response for Juror %s, by user %s", jurorNumber, payload.getLogin())); // Check if the current user has access to the Juror record (and also that the record exists) - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolService.getJurorPoolFromUser(jurorNumber); JurorPoolUtils.checkOwnershipForCurrentUser(jurorPool, payload.getOwner()); //check if Juror Paper response already exists - then send back error diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/service/JurorPoolServiceImpl.java b/src/main/java/uk/gov/hmcts/juror/api/moj/service/JurorPoolServiceImpl.java index 60793a6e3..c97db5512 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/service/JurorPoolServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/service/JurorPoolServiceImpl.java @@ -103,7 +103,10 @@ private JurorPool getLastActiveJurorPool(String jurorNumber) { List jurorPools = jurorPoolRepository.findByJurorJurorNumberAndIsActiveOrderByPoolReturnDateDesc(jurorNumber, true); if (!jurorPools.isEmpty()) { - return jurorPools.get(0); + return jurorPools.stream() + .filter(jurorPool -> jurorPool.getOwner().equals(SecurityUtil.BUREAU_OWNER)) + .findFirst() + .orElse(jurorPools.get(0)); } throw new MojException.NotFound("Juror not found: " + jurorNumber, null); } diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/service/ReissueLetterServiceImpl.java b/src/main/java/uk/gov/hmcts/juror/api/moj/service/ReissueLetterServiceImpl.java index 8be37c36e..77a799940 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/service/ReissueLetterServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/service/ReissueLetterServiceImpl.java @@ -20,6 +20,7 @@ import uk.gov.hmcts.juror.api.moj.exception.MojException; import uk.gov.hmcts.juror.api.moj.repository.BulkPrintDataRepository; import uk.gov.hmcts.juror.api.moj.repository.JurorPoolRepository; +import uk.gov.hmcts.juror.api.moj.repository.JurorRepository; import uk.gov.hmcts.juror.api.moj.repository.JurorStatusRepository; import uk.gov.hmcts.juror.api.moj.utils.JurorPoolUtils; import uk.gov.hmcts.juror.api.moj.utils.RepositoryUtils; @@ -42,6 +43,7 @@ public class ReissueLetterServiceImpl implements ReissueLetterService { private final JurorStatusRepository jurorStatusRepository; private final JurorHistoryService jurorHistoryService; private final JurorPoolService jurorPoolService; + private final JurorRepository jurorRepository; @Transactional @@ -256,7 +258,7 @@ private List> setFormCode(List> data, List hea // determine form code based on Welsh flag String jurorNumber = datum.get(jurorNumberIndex).toString(); - Juror juror = JurorPoolUtils.getActiveJurorRecord(jurorPoolRepository, jurorNumber); + Juror juror = jurorRepository.findByJurorNumber(jurorNumber); if (juror.isWelsh()) { newData.add(formCodeIndex, FormCode.BI_SUMMONS_REMINDER.getCode()); diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/service/StraightThroughProcessorServiceImpl.java b/src/main/java/uk/gov/hmcts/juror/api/moj/service/StraightThroughProcessorServiceImpl.java index 9f4a27fe9..1b89c7c61 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/service/StraightThroughProcessorServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/service/StraightThroughProcessorServiceImpl.java @@ -53,6 +53,7 @@ public class StraightThroughProcessorServiceImpl implements StraightThroughProce private final PrintDataService printDataService; private final JurorHistoryService jurorHistoryService; private final JurorResponseAuditRepositoryMod jurorResponseAuditRepository; + private final JurorPoolService jurorPoolService; /** @@ -73,7 +74,7 @@ public boolean isValidForStraightThroughAcceptance(String jurorNumber, String ow log.trace("Enter isValidForStraightThroughAcceptance"); // Check if the current user has access to the Juror record (and also that the record exists) - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolService.getJurorPoolFromUser(jurorNumber); JurorPoolUtils.checkOwnershipForCurrentUser(jurorPool, owner); PaperResponse paperResponse = DataUtils.getJurorPaperResponse(jurorNumber, diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/service/SummonsReplyStatusUpdateServiceImpl.java b/src/main/java/uk/gov/hmcts/juror/api/moj/service/SummonsReplyStatusUpdateServiceImpl.java index d2971434c..ca4b112f7 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/service/SummonsReplyStatusUpdateServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/service/SummonsReplyStatusUpdateServiceImpl.java @@ -65,6 +65,7 @@ public class SummonsReplyStatusUpdateServiceImpl implements SummonsReplyStatusUp private final JurorRecordService jurorRecordService; private final JurorAuditChangeService jurorAuditChangeService; private final JurorThirdPartyService jurorThirdPartyService; + private final JurorPoolService jurorPoolService; private static final String TITLE = "title"; private static final String FIRST_NAME = "firstName"; @@ -91,7 +92,7 @@ public void updateJurorResponseStatus(final String jurorNumber, final Processing log.debug("Updating status for juror {} to {}", jurorNumber, status.getDescription()); final PaperResponse paperResponse = jurorPaperResponseRepository.findByJurorNumber(jurorNumber); - final JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + final JurorPool jurorPool = jurorPoolService.getJurorPoolFromUser(jurorNumber); JurorPoolUtils.checkOwnershipForCurrentUser(jurorPool, payload.getOwner()); // if there is no paper response found for the juror and status is to be updated to responded then update the @@ -166,7 +167,7 @@ public void updateDigitalJurorResponseStatus(final String jurorNumber, throw new JurorPaperResponseException.NoJurorPaperResponseRecordFound(jurorNumber); } - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolService.getJurorPoolFromUser(jurorNumber); JurorPoolUtils.checkOwnershipForCurrentUser(jurorPool, payload.getOwner()); final String auditorUsername = payload.getLogin(); @@ -260,7 +261,7 @@ private void mergeJurorResponseImplementation(AbstractJurorResponse jurorRespons return; } - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolService.getJurorPoolFromUser(jurorNumber); mergeReasonableAdjustments(jurorPool); // TODO - Processing a paper summons reply for a deceased juror is currently awaiting design/sign off @@ -349,7 +350,7 @@ private void checkSignatureIsPresent(PaperResponse paperResponse) { private void updateJurorAsResponded(String jurorNumber, String auditorUsername) { log.trace("Enter updateJurorPoolAsResponded for Juror Number: {}", jurorNumber); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolService.getJurorPoolFromUser(jurorNumber); Juror juror = jurorPool.getJuror(); juror.setResponded(true); @@ -370,7 +371,7 @@ private void updatePoolMemberAsResponded(String jurorNumber, String auditorUsern int respondedStatusCode = 2; jurorStatusRepository.findById(respondedStatusCode).ifPresent(respondedStatus -> { - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolService.getJurorPoolFromUser(jurorNumber); jurorPool.setUserEdtq(auditorUsername); jurorPool.setStatus(respondedStatus); jurorPoolRepository.save(jurorPool); diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/service/UndeliverableResponseServiceImpl.java b/src/main/java/uk/gov/hmcts/juror/api/moj/service/UndeliverableResponseServiceImpl.java index da9405286..c9ad9d63c 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/service/UndeliverableResponseServiceImpl.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/service/UndeliverableResponseServiceImpl.java @@ -8,7 +8,6 @@ import uk.gov.hmcts.juror.api.moj.domain.IJurorStatus; import uk.gov.hmcts.juror.api.moj.domain.JurorPool; import uk.gov.hmcts.juror.api.moj.domain.JurorStatus; -import uk.gov.hmcts.juror.api.moj.repository.JurorPoolRepository; import uk.gov.hmcts.juror.api.moj.utils.JurorPoolUtils; import uk.gov.hmcts.juror.api.moj.utils.SecurityUtil; @@ -18,8 +17,8 @@ @Slf4j @RequiredArgsConstructor(onConstructor_ = {@Autowired}) public class UndeliverableResponseServiceImpl implements UndeliverableResponseService { - private final JurorPoolRepository jurorPoolRepository; private final JurorHistoryService jurorHistoryService; + private final JurorPoolService jurorPoolService; @Override @Transactional @@ -31,7 +30,7 @@ public void markAsUndeliverable(List jurorNumbers) { for (String jurorNumber : jurorNumbers) { log.debug("Begin processing mark as undeliverable for juror {} by user {}", jurorNumber, username); - JurorPool jurorPool = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolRepository, jurorNumber); + JurorPool jurorPool = jurorPoolService.getJurorPoolFromUser(jurorNumber); JurorPoolUtils.checkOwnershipForCurrentUser(jurorPool, owner); JurorStatus jurorStatus = new JurorStatus(); @@ -41,7 +40,7 @@ public void markAsUndeliverable(List jurorNumbers) { jurorPool.setUserEdtq(username); jurorPool.setNextDate(null); jurorHistoryService.createUndeliveredSummonsHistory(jurorPool); - jurorPoolRepository.save(jurorPool); + jurorPoolService.save(jurorPool); } } } diff --git a/src/main/java/uk/gov/hmcts/juror/api/moj/utils/JurorPoolUtils.java b/src/main/java/uk/gov/hmcts/juror/api/moj/utils/JurorPoolUtils.java index 1b2acc77a..9032fd614 100644 --- a/src/main/java/uk/gov/hmcts/juror/api/moj/utils/JurorPoolUtils.java +++ b/src/main/java/uk/gov/hmcts/juror/api/moj/utils/JurorPoolUtils.java @@ -4,9 +4,7 @@ import uk.gov.hmcts.juror.api.JurorDigitalApplication; import uk.gov.hmcts.juror.api.bureau.domain.IPoolStatus; import uk.gov.hmcts.juror.api.juror.domain.CourtLocation; -import uk.gov.hmcts.juror.api.moj.domain.Juror; import uk.gov.hmcts.juror.api.moj.domain.JurorPool; -import uk.gov.hmcts.juror.api.moj.exception.JurorRecordException; import uk.gov.hmcts.juror.api.moj.exception.MojException; import uk.gov.hmcts.juror.api.moj.repository.JurorPoolRepository; @@ -177,53 +175,6 @@ public static JurorPool getActiveJurorPool(JurorPoolRepository jurorPoolReposito return jurorPool; } - /** - * Query the database and return a single active juror pool association for a - * given juror number. To be used when only a single active juror pool association is expecting, for example when - * the bureau are managing the summons reply - * - * @param jurorPoolRepository JPA interface to the database to generate and execute SQL queries - * @param jurorNumber 9-digit numeric string to identify jurors - * @return a juror pool record, there should be only one active record for a given juror number - */ - public static JurorPool getSingleActiveJurorPool(JurorPoolRepository jurorPoolRepository, String jurorNumber) { - log.debug("Retrieving active juror pool record for juror number {}", jurorNumber); - - List jurorPoolDetails = jurorPoolRepository - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - log.debug("{} Active Juror Record(s) found for Juror Number: {}", jurorPoolDetails.size(), jurorNumber); - switch (jurorPoolDetails.size()) { - case 0 -> throw new MojException.NotFound(String.format("Unable to find a Juror Pool association for" - + "Juror Number %s", jurorNumber), null); - case 1 -> { - log.debug("Found a single juror pool association record for juror number {}", jurorNumber); - return jurorPoolDetails.get(0); - } - default -> throw new JurorRecordException.MultipleJurorRecordsFound(jurorNumber); - } - - } - - /** - * To be used when only a single association between a Juror record and a Pool is expected to exist in a - * collection returned from a database query. - * - * @param jurorPoolRepository JPA interface to the database to generate and execute SQL queries - * @param jurorNumber 9-digit numeric string to identify jurors - * @return a single Juror object - */ - public static Juror getActiveJurorRecord(JurorPoolRepository jurorPoolRepository, String jurorNumber) { - log.debug("Retrieving active juror pool records for juror number {}", jurorNumber); - List jurorPools = getActiveJurorPoolRecords(jurorPoolRepository, jurorNumber); - - log.debug("retrieved {} active juror pool record(s) for juror number {}", jurorPools.size(), jurorNumber); - if (jurorPools.size() > 1) { - throw new JurorRecordException.MultipleJurorRecordsFound(jurorNumber); - } - - return jurorPools.get(0).getJuror(); - } - /** * To be used for retrieving a list of Jurors who are in a summoned/responded state from a specific pool and * court location. diff --git a/src/test/java/uk/gov/hmcts/juror/api/TestUtils.java b/src/test/java/uk/gov/hmcts/juror/api/TestUtils.java index 8b8f91ded..d8e36b88b 100644 --- a/src/test/java/uk/gov/hmcts/juror/api/TestUtils.java +++ b/src/test/java/uk/gov/hmcts/juror/api/TestUtils.java @@ -28,7 +28,7 @@ public final class TestUtils { public static final ObjectMapper objectMapper; - private static MockedStatic SECURITY_UTIL_MOCK; + private static MockedStatic securityUtilMock; static { objectMapper = new ObjectMapper().findAndRegisterModules(); @@ -159,17 +159,17 @@ public static void setUpMockAuthentication(String owner, String username, String @AfterAll public static void afterAll() { - if (SECURITY_UTIL_MOCK != null) { - SECURITY_UTIL_MOCK.close(); - SECURITY_UTIL_MOCK = null; + if (securityUtilMock != null) { + securityUtilMock.close(); + securityUtilMock = null; } } public static MockedStatic getSecurityUtilMock() { - if (SECURITY_UTIL_MOCK == null) { - SECURITY_UTIL_MOCK = mockStatic(SecurityUtil.class, withSettings().defaultAnswer(CALLS_REAL_METHODS)); + if (securityUtilMock == null) { + securityUtilMock = mockStatic(SecurityUtil.class, withSettings().defaultAnswer(CALLS_REAL_METHODS)); } - return SECURITY_UTIL_MOCK; + return securityUtilMock; } public static BureauJwtPayload mockSecurityUtil(BureauJwtPayload payload) { diff --git a/src/test/java/uk/gov/hmcts/juror/api/juror/service/JurorServiceImplTest.java b/src/test/java/uk/gov/hmcts/juror/api/juror/service/JurorServiceImplTest.java index 5ca5ff03f..ee5eef52b 100644 --- a/src/test/java/uk/gov/hmcts/juror/api/juror/service/JurorServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/juror/api/juror/service/JurorServiceImplTest.java @@ -24,12 +24,12 @@ import uk.gov.hmcts.juror.api.moj.domain.jurorresponse.ReplyType; import uk.gov.hmcts.juror.api.moj.enumeration.ReplyMethod; import uk.gov.hmcts.juror.api.moj.repository.AppSettingRepository; -import uk.gov.hmcts.juror.api.moj.repository.JurorPoolRepository; import uk.gov.hmcts.juror.api.moj.repository.ReplyTypeRepository; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorDigitalResponseRepositoryMod; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorReasonableAdjustmentRepository; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorResponseCjsEmploymentRepositoryMod; import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.ReasonableAdjustmentsRepository; +import uk.gov.hmcts.juror.api.moj.service.JurorPoolService; import uk.gov.hmcts.juror.api.moj.service.PoolRequestService; import uk.gov.hmcts.juror.api.moj.utils.JurorPoolUtils; import uk.gov.hmcts.juror.api.validation.ResponseInspectorImpl; @@ -74,9 +74,6 @@ public class JurorServiceImplTest { @Mock private JurorDigitalResponseRepositoryMod jurorResponseRepository; - @Mock - private JurorPoolRepository poolDetailsRepository; - @Mock private StraightThroughProcessor straightThroughProcessor; @@ -100,6 +97,8 @@ public class JurorServiceImplTest { @Mock private JurorService mockJurorService; + @Mock + private JurorPoolService jurorPoolService; @InjectMocks private JurorServiceImpl defaultService; @@ -141,9 +140,7 @@ public void setup() { @Test public void getJurorByByJurorNumber_WithJurorNumber_ReturnsJurorDetails() { - - jurorPoolUtilsMockedStatic.when(() -> JurorPoolUtils - .getSingleActiveJurorPool(poolDetailsRepository, TEST_JUROR_NUMBER)).thenReturn(jurorPoolDetails); + when(jurorPoolService.getJurorPoolFromUser(TEST_JUROR_NUMBER)).thenReturn(jurorPoolDetails); final JurorDetailDto jurorDto = defaultService.getJurorByJurorNumber(TEST_JUROR_NUMBER); assertThat(jurorDto) @@ -164,8 +161,8 @@ public void getJurorByJurorNumber_alternatePath_uniquePoolAttendTime() { doReturn(LocalDateTime.of(2024,1,1,8,0,0)) .when(mockUniquePoolService).getPoolAttendanceTime("101"); - jurorPoolUtilsMockedStatic.when(() -> JurorPoolUtils - .getSingleActiveJurorPool(poolDetailsRepository, TEST_JUROR_NUMBER)).thenReturn(jurorPoolDetails); + + when(jurorPoolService.getJurorPoolFromUser(TEST_JUROR_NUMBER)).thenReturn(jurorPoolDetails); final JurorDetailDto jurorDto = defaultService.getJurorByJurorNumber(TEST_JUROR_NUMBER); assertThat(jurorDto.getCourtAttendTime()).isEqualTo("08:00"); @@ -331,8 +328,7 @@ public void convertJurorResponseDtoToEntityTest() throws Exception { assertThat(entity.getVersion()).isEqualTo(version); - jurorPoolUtilsMockedStatic.verify(() -> JurorPoolUtils - .getSingleActiveJurorPool(poolDetailsRepository, jurorNumber), times(1)); + verify(jurorPoolService,times(1)).getJurorPoolFromUser(jurorNumber); verify(urgencyService, times(1)).setUrgencyFlags(eq(entity), Mockito.isNull()); } diff --git a/src/test/java/uk/gov/hmcts/juror/api/juror/service/StraightThroughProcessorImplTest.java b/src/test/java/uk/gov/hmcts/juror/api/juror/service/StraightThroughProcessorImplTest.java index 75b830e4a..45ebe5b5b 100644 --- a/src/test/java/uk/gov/hmcts/juror/api/juror/service/StraightThroughProcessorImplTest.java +++ b/src/test/java/uk/gov/hmcts/juror/api/juror/service/StraightThroughProcessorImplTest.java @@ -214,8 +214,7 @@ public void processDeceasedExcusal_unhappyPath_statusNotSummoned() { @Test public void processAgeExcusal_happyPath_jurorSuccessfullyExcused_exactlyTooOld() { - jurorPoolUtilsMockedStatic.when(() -> - JurorPoolUtils.getSingleActiveJurorPool(poolRepository, TEST_JUROR_NUMBER)).thenReturn(jurorPool); + when(jurorPoolService.getJurorPoolFromUser(TEST_JUROR_NUMBER)).thenReturn(jurorPool); JurorStatus disquallifiedJurorStatus = mock(JurorStatus.class); when(jurorStatusRepository.findById(IJurorStatus.DISQUALIFIED)) @@ -263,8 +262,7 @@ public void processAgeExcusal_happyPath_jurorSuccessfullyExcused_exactlyTooOld() @Test public void processAgeExcusal_happyPath_jurorSuccessfullyExcused_exactlyTooYoung() { - jurorPoolUtilsMockedStatic.when(() -> - JurorPoolUtils.getSingleActiveJurorPool(poolRepository, TEST_JUROR_NUMBER)).thenReturn(jurorPool); + when(jurorPoolService.getJurorPoolFromUser(TEST_JUROR_NUMBER)).thenReturn(jurorPool); JurorStatus disquallifiedJurorStatus = mock(JurorStatus.class); when(jurorStatusRepository.findById(IJurorStatus.DISQUALIFIED)) @@ -311,8 +309,7 @@ public void processAgeExcusal_happyPath_jurorSuccessfullyExcused_exactlyTooYoung @Test public void processAgeExcusal_unhappyPath_jurorExactlyMinimumAge() { - jurorPoolUtilsMockedStatic.when(() -> - JurorPoolUtils.getSingleActiveJurorPool(poolRepository, TEST_JUROR_NUMBER)).thenReturn(jurorPool); + when(jurorPoolService.getJurorPoolFromUser(TEST_JUROR_NUMBER)).thenReturn(jurorPool); // configure jurorResponse given(jurorResponse.getJurorNumber()).willReturn(TEST_JUROR_NUMBER); @@ -344,8 +341,7 @@ public void processAgeExcusal_unhappyPath_jurorExactlyMinimumAge() { @Test public void processAgeExcusal_unhappyPath_jurorOneDayUnderTooOld() { - jurorPoolUtilsMockedStatic.when(() -> - JurorPoolUtils.getSingleActiveJurorPool(poolRepository, TEST_JUROR_NUMBER)).thenReturn(jurorPool); + when(jurorPoolService.getJurorPoolFromUser(TEST_JUROR_NUMBER)).thenReturn(jurorPool); // configure jurorResponse given(jurorResponse.getJurorNumber()).willReturn(TEST_JUROR_NUMBER); @@ -377,8 +373,7 @@ public void processAgeExcusal_unhappyPath_jurorOneDayUnderTooOld() { @Test public void processAgeExcusal_unhappyPath_thirdParty() { - jurorPoolUtilsMockedStatic.when(() -> - JurorPoolUtils.getSingleActiveJurorPool(poolRepository, TEST_JUROR_NUMBER)).thenReturn(jurorPool); + when(jurorPoolService.getJurorPoolFromUser(TEST_JUROR_NUMBER)).thenReturn(jurorPool); // configure jurorResponse status to fail validation given(jurorResponse.getJurorNumber()).willReturn(TEST_JUROR_NUMBER); @@ -400,8 +395,7 @@ public void processAgeExcusal_unhappyPath_thirdParty() { @Test public void processAgeExcusal_unhappyPath_statusNotSummoned() { - jurorPoolUtilsMockedStatic.when(() -> - JurorPoolUtils.getSingleActiveJurorPool(poolRepository, TEST_JUROR_NUMBER)).thenReturn(jurorPool); + when(jurorPoolService.getJurorPoolFromUser(TEST_JUROR_NUMBER)).thenReturn(jurorPool); // configure jurorResponse status to fail validation given(jurorResponse.getJurorNumber()).willReturn(TEST_JUROR_NUMBER); diff --git a/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorPaperResponseServiceImplTest.java b/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorPaperResponseServiceImplTest.java index ed244668d..4c027a51f 100644 --- a/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorPaperResponseServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorPaperResponseServiceImplTest.java @@ -99,6 +99,8 @@ public class JurorPaperResponseServiceImplTest { private StraightThroughProcessorService straightThroughProcessorService; @Mock private JurorResponseAuditRepositoryMod jurorResponseAuditRepository; + @Mock + private JurorPoolService jurorPoolService; @InjectMocks private JurorPaperResponseServiceImpl jurorPaperResponseService; @@ -118,6 +120,11 @@ public void setUpMocks() { Mockito.doReturn(Collections.singletonList(courtOwnerJurorPool)).when(jurorPoolRepository) .findByJurorJurorNumberAndIsActive(VALID_JUROR_NUMBER_COURT, true); + Mockito.doReturn(bureauOwnerJurorPool).when(jurorPoolService) + .getJurorPoolFromUser(VALID_JUROR_NUMBER_BUREAU); + Mockito.doReturn(courtOwnerJurorPool).when(jurorPoolService) + .getJurorPoolFromUser(VALID_JUROR_NUMBER_COURT); + Mockito.doReturn(Collections.singletonList(bureauOwnerJurorPool)).when(jurorPoolRepository) .findByJurorJurorNumberAndIsActiveOrderByPoolReturnDateDesc("123456789", true); Mockito.doReturn(Collections.singletonList(courtOwnerJurorPool)).when(jurorPoolRepository) @@ -335,8 +342,8 @@ public void test_saveResponse_bureauUser_bureauOwnedJurorRecord() { jurorPaperResponseService.saveResponse(payload, responseDto); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive(VALID_JUROR_NUMBER_BUREAU, true); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser(VALID_JUROR_NUMBER_BUREAU); Mockito.verify(jurorPaperResponseRepository, Mockito.times(1)) .save(paperResponseArgumentCaptor.capture()); PaperResponse paperResponse = paperResponseArgumentCaptor.getValue(); @@ -364,8 +371,8 @@ public void test_saveResponse_bureauUser_courtOwnedJurorRecord() { Assertions.assertThatExceptionOfType(MojException.Forbidden.class).isThrownBy(() -> jurorPaperResponseService.saveResponse(payload, responseDto)); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive("987654321", true); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser("987654321"); Mockito.verify(jurorPaperResponseRepository, Mockito.never()).save(any()); Mockito.verify(jurorResponseCjsRepository, Mockito.never()).save(any()); Mockito.verify(jurorReasonableAdjustmentsRepository, Mockito.never()).save(any()); @@ -389,8 +396,8 @@ public void test_saveResponse_courtUser_bureauOwnedJurorRecord() { Assertions.assertThatExceptionOfType(MojException.Forbidden.class).isThrownBy(() -> jurorPaperResponseService.saveResponse(payload, responseDto)); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive("123456789", true); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser("123456789"); Mockito.verify(jurorPaperResponseRepository, Mockito.never()).save(any()); Mockito.verify(jurorResponseCjsRepository, Mockito.never()).save(any()); Mockito.verify(jurorReasonableAdjustmentsRepository, Mockito.never()).save(any()); @@ -416,8 +423,8 @@ public void test_saveResponse_courtUser_sameCourtOwnedJurorRecord() { jurorPaperResponseService.saveResponse(payload, responseDto); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive(VALID_JUROR_NUMBER_COURT, true); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser(VALID_JUROR_NUMBER_COURT); Mockito.verify(jurorPaperResponseRepository, Mockito.times(1)) .save(paperResponseArgumentCaptor.capture()); PaperResponse paperResponse = paperResponseArgumentCaptor.getValue(); @@ -446,8 +453,8 @@ public void test_saveResponse_courtUser_differentCourtOwnedJurorRecord() { Assertions.assertThatExceptionOfType(MojException.Forbidden.class).isThrownBy(() -> jurorPaperResponseService.saveResponse(payload, responseDto)); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive("987654321", true); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser("987654321"); Mockito.verify(jurorPaperResponseRepository, Mockito.never()).save(any()); Mockito.verify(jurorResponseCjsRepository, Mockito.never()).save(any()); Mockito.verify(jurorReasonableAdjustmentsRepository, Mockito.never()).save(any()); @@ -482,8 +489,8 @@ public void test_saveResponse_withCjs_noSpecialNeeds() { jurorPaperResponseService.saveResponse(payload, responseDto); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive("123456789", true); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser("123456789"); Mockito.verify(jurorPaperResponseRepository, Mockito.times(1)).save(any()); Mockito.verify(jurorResponseCjsRepository, Mockito.times(1)).saveAll(any()); Mockito.verify(jurorReasonableAdjustmentsRepository, Mockito.times(1)).saveAll(any()); @@ -505,8 +512,8 @@ public void test_saveResponse_noCjs_withSpecialNeeds() { jurorPaperResponseService.saveResponse(payload, responseDto); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive("123456789", true); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser("123456789"); Mockito.verify(jurorPaperResponseRepository, Mockito.times(1)).save(any()); Mockito.verify(jurorResponseCjsRepository, Mockito.times(1)).saveAll(any()); Mockito.verify(jurorReasonableAdjustmentsRepository, Mockito.times(1)).saveAll(any()); @@ -531,8 +538,8 @@ public void test_saveResponse_withCjs_withSpecialNeeds() { jurorPaperResponseService.saveResponse(payload, responseDto); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive("123456789", true); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser("123456789"); Mockito.verify(jurorPaperResponseRepository, Mockito.times(1)).save(any()); Mockito.verify(jurorResponseCjsRepository, Mockito.times(1)).saveAll(any()); Mockito.verify(jurorReasonableAdjustmentsRepository, Mockito.times(1)).saveAll(any()); @@ -617,8 +624,8 @@ public void test_saveResponse_welshTicked() { jurorPaperResponseService.saveResponse(payload, responseDto); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive(VALID_JUROR_NUMBER_BUREAU, true); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser(VALID_JUROR_NUMBER_BUREAU); Mockito.verify(jurorPaperResponseRepository, Mockito.times(1)) .save(paperResponseArgumentCaptor.capture()); PaperResponse paperResponse = paperResponseArgumentCaptor.getValue(); diff --git a/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorRecordServiceTest.java b/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorRecordServiceTest.java index 7b7be054f..d28840f9c 100644 --- a/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorRecordServiceTest.java +++ b/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorRecordServiceTest.java @@ -3271,6 +3271,8 @@ void positiveGetPayments() { JurorPool jurorPool = createValidJurorPool(jurorNumber, COURT_OWNER); TestUtils.mockCourtUser("415"); + doReturn(jurorPool.getJuror()).when(jurorRepository) + .findByJurorNumber(any()); doReturn(List.of(jurorPool)).when(jurorPoolRepository) .findByJurorJurorNumberAndIsActive(any(), anyBoolean()); diff --git a/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorResponseStatusUpdateServiceImplTest.java b/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorResponseStatusUpdateServiceImplTest.java index 807b2e4a4..dcc737904 100644 --- a/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorResponseStatusUpdateServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/juror/api/moj/service/JurorResponseStatusUpdateServiceImplTest.java @@ -5,7 +5,6 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.Mockito; import org.springframework.test.context.junit4.SpringRunner; import uk.gov.hmcts.juror.api.TestUtils; import uk.gov.hmcts.juror.api.config.bureau.BureauJwtPayload; @@ -29,13 +28,12 @@ import uk.gov.hmcts.juror.api.moj.repository.jurorresponse.JurorResponseAuditRepositoryMod; import uk.gov.hmcts.juror.api.moj.service.jurormanagement.JurorAuditChangeService; -import java.util.Collections; import java.util.Set; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; @@ -76,6 +74,8 @@ public class JurorResponseStatusUpdateServiceImplTest { private JurorAuditChangeService jurorAuditChangeService; @Mock private JurorRepository jurorRepository; + @Mock + private JurorPoolService jurorPoolService; @InjectMocks private SummonsReplyStatusUpdateServiceImpl summonsReplyStatusUpdateService; @@ -175,8 +175,8 @@ public void updateResponse_alsoUpdatesStaffAssignment_happy() throws Exception { given(jurorResponseRepository.findByJurorNumber(any(String.class))).willReturn(mockJurorResponse); given(mockJurorResponse.getProcessingStatus()).willReturn(currentProcessingStatus); given(mockJurorResponse.getStaff()).willReturn(null); - Mockito.doReturn(Collections.singletonList(createJurorPool(jurorNumber))).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(createJurorPool(jurorNumber)).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); // Execute logic summonsReplyStatusUpdateService.updateDigitalJurorResponseStatus(jurorNumber, ProcessingStatus.TODO, payload); @@ -278,9 +278,9 @@ private JurorPool createJurorPool(String jurorNumber) { } private void configureBureauMocks(String jurorNumber, DigitalResponse mockJurorResponse) { - Mockito.doReturn(mockJurorResponse).when(jurorResponseRepository).findByJurorNumber(any(String.class)); - Mockito.doReturn(Collections.singletonList(createJurorPool(jurorNumber))).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(mockJurorResponse).when(jurorResponseRepository).findByJurorNumber(any(String.class)); + JurorPool jurorPool = createJurorPool(jurorNumber); + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); } private void configureCourtMocks(ProcessingStatus currentProcessingStatus, String jurorNumber, @@ -290,15 +290,14 @@ private void configureCourtMocks(ProcessingStatus currentProcessingStatus, Strin courtOwnedMember.setOwner("415"); given(mockJurorResponse.getProcessingStatus()).willReturn(currentProcessingStatus); given(mockJurorResponse.getJurorNumber()).willReturn(jurorNumber); - Mockito.doReturn(Collections.singletonList(courtOwnedMember)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(courtOwnedMember).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); } private void assertNoMergeVerification() { // as we're not setting the status to CLOSED, we should not be merging data to Juror - verify(jurorPoolRepository, times(1)) - .findByJurorJurorNumberAndIsActive(any(String.class), eq(true)); + verify(jurorPoolService, times(1)) + .getJurorPoolFromUser(any(String.class)); verify(jurorPoolRepository, times(0)).save(any(JurorPool.class)); verify(jurorHistoryRepository, times(0)).save(any(JurorHistory.class)); } diff --git a/src/test/java/uk/gov/hmcts/juror/api/moj/service/StraightThroughProcessorServiceImplTest.java b/src/test/java/uk/gov/hmcts/juror/api/moj/service/StraightThroughProcessorServiceImplTest.java index e6e9b6ad5..0bb0c7389 100644 --- a/src/test/java/uk/gov/hmcts/juror/api/moj/service/StraightThroughProcessorServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/juror/api/moj/service/StraightThroughProcessorServiceImplTest.java @@ -70,6 +70,8 @@ public class StraightThroughProcessorServiceImplTest { private SummonsReplyMergeService mergeService; @Mock private JurorResponseAuditRepositoryMod jurorResponseAuditRepository; + @Mock + private JurorPoolService jurorPoolService; @InjectMocks private StraightThroughProcessorServiceImpl straightThroughProcessorService; @@ -531,8 +533,8 @@ public void test_isValidForStraightThroughAcceptance_happyPath() { paperResponse.setProcessingStatus(jurorResponseAuditRepository, ProcessingStatus.TODO); setPaperResponseDetails(paperResponse); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -556,8 +558,8 @@ public void test_isValidForStraightThroughAcceptance_titleChanged() { paperResponse.setProcessingStatus(jurorResponseAuditRepository, ProcessingStatus.TODO); setPaperResponseDetails(paperResponse); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -581,8 +583,8 @@ public void test_isValidForStraightThroughAcceptance_firstNameChanged() { setPaperResponseDetails(paperResponse); paperResponse.setFirstName(""); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -606,8 +608,8 @@ public void test_isValidForStraightThroughAcceptance_lastNameChanged() { setPaperResponseDetails(paperResponse); paperResponse.setLastName(null); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -631,8 +633,8 @@ public void test_isValidForStraightThroughAcceptance_address1Changed() { paperResponse.setProcessingStatus(jurorResponseAuditRepository, ProcessingStatus.TODO); setPaperResponseDetails(paperResponse); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -656,8 +658,8 @@ public void test_isValidForStraightThroughAcceptance_address2Changed() { paperResponse.setProcessingStatus(jurorResponseAuditRepository, ProcessingStatus.TODO); setPaperResponseDetails(paperResponse); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -681,8 +683,8 @@ public void test_isValidForStraightThroughAcceptance_address3Changed() { setPaperResponseDetails(paperResponse); paperResponse.setAddressLine3("Some Address 3"); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -706,8 +708,8 @@ public void test_isValidForStraightThroughAcceptance_address4Changed() { setPaperResponseDetails(paperResponse); paperResponse.setAddressLine4("Some Town/City"); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -731,8 +733,8 @@ public void test_isValidForStraightThroughAcceptance_address5Changed() { paperResponse.setProcessingStatus(jurorResponseAuditRepository, ProcessingStatus.TODO); setPaperResponseDetails(paperResponse); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -756,8 +758,8 @@ public void test_isValidForStraightThroughAcceptance_postcodeChanged() { setPaperResponseDetails(paperResponse); paperResponse.setPostcode(null); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -781,8 +783,8 @@ public void test_isValidForStraightThroughAcceptance_noDateOfBirth() { setPaperResponseDetails(paperResponse); paperResponse.setDateOfBirth(null); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -805,8 +807,8 @@ public void test_isValidForStraightThroughAcceptance_invalidJurorAge() { paperResponse.setProcessingStatus(jurorResponseAuditRepository, ProcessingStatus.TODO); setPaperResponseDetails(paperResponse); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -830,8 +832,8 @@ public void test_isValidForStraightThroughAcceptance_thirdParty() { setPaperResponseDetails(paperResponse); paperResponse.setRelationship("Brother"); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -858,8 +860,9 @@ public void test_isValidForStraightThroughAcceptance_invalidJurorStatus() { paperResponse.setProcessingStatus(jurorResponseAuditRepository, ProcessingStatus.TODO); setPaperResponseDetails(paperResponse); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); + Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -883,8 +886,8 @@ public void test_isValidForStraightThroughAcceptance_invalidResidency_false() { setPaperResponseDetails(paperResponse); paperResponse.setResidency(false); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -908,8 +911,8 @@ public void test_isValidForStraightThroughAcceptance_invalidResidency_null() { setPaperResponseDetails(paperResponse); paperResponse.setResidency(null); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -933,8 +936,8 @@ public void test_isValidForStraightThroughAcceptance_invalidMentalHealthAct_true setPaperResponseDetails(paperResponse); paperResponse.setMentalHealthAct(true); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -958,8 +961,8 @@ public void test_isValidForStraightThroughAcceptance_invalidMentalHealthAct_null setPaperResponseDetails(paperResponse); paperResponse.setMentalHealthAct(null); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -983,8 +986,8 @@ public void test_isValidForStraightThroughAcceptance_invalidMentalHealthCapacity setPaperResponseDetails(paperResponse); paperResponse.setMentalHealthCapacity(true); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -1008,8 +1011,8 @@ public void test_isValidForStraightThroughAcceptance_invalidMentalHealthCapacity setPaperResponseDetails(paperResponse); paperResponse.setMentalHealthCapacity(null); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -1033,8 +1036,8 @@ public void test_isValidForStraightThroughAcceptance_invalidBail_true() { setPaperResponseDetails(paperResponse); paperResponse.setBail(true); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -1058,8 +1061,8 @@ public void test_isValidForStraightThroughAcceptance_invalidBail_null() { setPaperResponseDetails(paperResponse); paperResponse.setBail(null); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -1083,8 +1086,8 @@ public void test_isValidForStraightThroughAcceptance_invalidConvictions() { setPaperResponseDetails(paperResponse); paperResponse.setConvictions(true); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -1108,8 +1111,8 @@ public void test_isValidForStraightThroughAcceptance_invalidConvictions_null() { setPaperResponseDetails(paperResponse); paperResponse.setConvictions(null); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -1133,8 +1136,8 @@ public void test_isValidForStraightThroughAcceptance_invalidSignature_false() { setPaperResponseDetails(paperResponse); paperResponse.setSigned(false); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -1158,8 +1161,8 @@ public void test_isValidForStraightThroughAcceptance_invalidSignature_null() { setPaperResponseDetails(paperResponse); paperResponse.setSigned(null); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -1183,8 +1186,8 @@ public void test_isValidForStraightThroughAcceptance_excusalRequested() { setPaperResponseDetails(paperResponse); paperResponse.setExcusal(true); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -1208,8 +1211,8 @@ public void test_isValidForStraightThroughAcceptance_deferralRequested() { setPaperResponseDetails(paperResponse); paperResponse.setDeferral(true); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -1234,8 +1237,8 @@ public void test_isValidForStraightThroughAcceptance_noReplyTypeSelected() { paperResponse.setDeferral(null); paperResponse.setExcusal(null); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Assertions.assertThat(straightThroughProcessorService @@ -1262,8 +1265,8 @@ public void test_isValidForStraightThroughAcceptance_cjsEmploymentExists() { cjsEmployment.setJurorNumber(jurorNumber); cjsEmployment.setCjsEmployer("POLICE"); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Mockito.doReturn(Collections.singletonList(cjsEmployment)) .when(jurorResponseCjsEmploymentRepository).findByJurorNumber(jurorNumber); @@ -1296,8 +1299,8 @@ public void test_isValidForStraightThroughAcceptance_reasonableAdjustmentRequest adjustment2.setJurorNumber(jurorNumber); adjustment2.setReasonableAdjustment(new ReasonableAdjustments("W", "Wheelchair Access")); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); Mockito.doReturn(paperResponse).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); Mockito.doReturn(Arrays.asList(adjustment1, adjustment2)) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); diff --git a/src/test/java/uk/gov/hmcts/juror/api/moj/service/SummonsReplyStatusUpdateServiceImplTest.java b/src/test/java/uk/gov/hmcts/juror/api/moj/service/SummonsReplyStatusUpdateServiceImplTest.java index bf81282fb..12ca26b77 100644 --- a/src/test/java/uk/gov/hmcts/juror/api/moj/service/SummonsReplyStatusUpdateServiceImplTest.java +++ b/src/test/java/uk/gov/hmcts/juror/api/moj/service/SummonsReplyStatusUpdateServiceImplTest.java @@ -24,7 +24,6 @@ import uk.gov.hmcts.juror.api.moj.domain.jurorresponse.PaperResponse; import uk.gov.hmcts.juror.api.moj.domain.jurorresponse.ReasonableAdjustments; import uk.gov.hmcts.juror.api.moj.exception.JurorPaperResponseException; -import uk.gov.hmcts.juror.api.moj.exception.JurorRecordException; import uk.gov.hmcts.juror.api.moj.exception.MojException; import uk.gov.hmcts.juror.api.moj.repository.JurorHistoryRepository; import uk.gov.hmcts.juror.api.moj.repository.JurorPoolRepository; @@ -53,6 +52,8 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoInteractions; @@ -91,6 +92,8 @@ public class SummonsReplyStatusUpdateServiceImplTest { private JurorThirdPartyService jurorThirdPartyService; @Mock private JurorResponseService jurorResponseService; + @Mock + private JurorPoolService jurorPoolService; @InjectMocks private SummonsReplyStatusUpdateServiceImpl summonsReplyStatusUpdateService; @@ -105,8 +108,13 @@ public void setUp() { //Interface method: updateJurorResponseStatus @Test public void test_updateJurorResponseStatus_noResponseFound() { + doReturn(null).when(jurorPaperResponseRepository).findByJurorNumber(any()); + JurorPool jurorPool = createJuror("123456789"); + JurorStatus jurorStatus = mock(JurorStatus.class); + jurorPool.setStatus(jurorStatus); + doReturn(IJurorStatus.RESPONDED).when(jurorStatus).getStatus(); + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(any()); BureauJwtPayload payload = buildPayload(); - Mockito.doReturn(null).when(jurorPaperResponseRepository).findByJurorNumber(any()); assertThatExceptionOfType(MojException.NotFound.class) .isThrownBy(() -> summonsReplyStatusUpdateService.updateJurorResponseStatus("123456789", ProcessingStatus.CLOSED, payload)); @@ -131,7 +139,7 @@ public void test_updateJurorResponseStatus_processingAlreadyComplete() { final BureauJwtPayload payload = buildPayload(); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); CourtLocation courtLocation = createCourtLocation("415", "CHESTER", "09:15"); JurorPool jurorPool = createJuror(jurorNumber); @@ -139,8 +147,7 @@ public void test_updateJurorResponseStatus_processingAlreadyComplete() { PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType(JurorPaperResponseException.JurorPaperResponseAlreadyExists.class) .isThrownBy(() -> summonsReplyStatusUpdateService.updateJurorResponseStatus(jurorNumber, @@ -165,15 +172,14 @@ public void test_updateJurorResponseStatus_notClosingResponse() { final BureauJwtPayload payload = buildPayload(); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); CourtLocation courtLocation = createCourtLocation("415", "CHESTER", "09:15"); JurorPool jurorPool = createJuror(jurorNumber); PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); int invocationCounter = 1; List processStatusList = Arrays.stream(ProcessingStatus.values()) @@ -207,22 +213,21 @@ public void test_updateJurorResponseStatus_closingResponse_happyPath() { final BureauJwtPayload payload = buildPayload(); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); CourtLocation courtLocation = createCourtLocation("415", "CHESTER", "09:15"); JurorPool jurorPool = createJuror(jurorNumber); PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Optional.of(createPoolStatus(respondedStatusCode))).when(jurorStatusRepository) + doReturn(Optional.of(createPoolStatus(respondedStatusCode))).when(jurorStatusRepository) .findById(respondedStatusCode); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any()); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any()); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); summonsReplyStatusUpdateService.updateJurorResponseStatus(jurorNumber, ProcessingStatus.CLOSED, payload); @@ -258,16 +263,15 @@ public void test_updateJurorResponseStatus_closingResponse_noJurorAudits() throw final BureauJwtPayload payload = buildPayload(); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Optional.of(createPoolStatus(respondedStatusCode))).when(jurorStatusRepository) + doReturn(Optional.of(createPoolStatus(respondedStatusCode))).when(jurorStatusRepository) .findById(respondedStatusCode); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any()); - Mockito.doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any()); + doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); summonsReplyStatusUpdateService.updateJurorResponseStatus(jurorNumber, ProcessingStatus.CLOSED, payload); @@ -289,7 +293,7 @@ public void test_updateJurorResponseStatus_closingResponse_alreadyProcessed() { final BureauJwtPayload payload = buildPayload(); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); CourtLocation courtLocation = createCourtLocation("415", "CHESTER", "09:15"); JurorPool jurorPool = createJuror(jurorNumber); @@ -297,8 +301,7 @@ public void test_updateJurorResponseStatus_closingResponse_alreadyProcessed() { PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType(JurorPaperResponseException.JurorPaperResponseAlreadyExists.class).isThrownBy(() -> summonsReplyStatusUpdateService.updateJurorResponseStatus(jurorNumber, @@ -320,9 +323,9 @@ public void test_updateJurorResponseStatus_closingResponse_noJurorRecord() { BureauJwtPayload payload = buildPayload(); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(new ArrayList()).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + Mockito.doThrow(MojException.NotFound.class).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType(MojException.NotFound.class).isThrownBy(() -> summonsReplyStatusUpdateService.updateJurorResponseStatus(jurorNumber, @@ -335,34 +338,6 @@ public void test_updateJurorResponseStatus_closingResponse_noJurorRecord() { .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); } - @Test - public void test_updateJurorResponseStatus_closingResponse_multipleJurorRecords() { - String jurorNumber = "123456789"; - PaperResponse response = createPaperResponse(jurorNumber); - response.setProcessingComplete(false); - response.setProcessingStatus(auditRepository, ProcessingStatus.CLOSED); - - final BureauJwtPayload payload = buildPayload(); - - List jurorPools = new ArrayList<>(); - jurorPools.add(createJuror(jurorNumber)); - jurorPools.add(createJuror(jurorNumber)); - - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - - assertThatExceptionOfType(JurorRecordException.MultipleJurorRecordsFound.class).isThrownBy(() -> - summonsReplyStatusUpdateService.updateJurorResponseStatus(jurorNumber, - ProcessingStatus.CLOSED, payload)); - - verify(jurorPaperResponseRepository, times(1)).findByJurorNumber(jurorNumber); - verify(jurorPoolRepository, Mockito.never()).save(any()); - verify(jurorPaperResponseRepository, Mockito.never()).save(any()); - verify(jurorAuditChangeService, Mockito.never()) - .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - } - @Test public void test_updateJurorResponseStatus_bureauUser_bureauOwnedJurorPool() { String jurorNumber = "123456789"; @@ -372,12 +347,11 @@ public void test_updateJurorResponseStatus_bureauUser_bureauOwnedJurorPool() { final BureauJwtPayload payload = buildPayload(); - List jurorPools = new ArrayList<>(); - jurorPools.add(createJuror(jurorNumber)); + JurorPool jurorPool = createJuror(jurorNumber); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); summonsReplyStatusUpdateService.updateJurorResponseStatus(jurorNumber, response.getProcessingStatus(), payload); @@ -401,14 +375,12 @@ public void test_updateJurorResponseStatus_bureauUser_courtOwnedJurorPool() { final BureauJwtPayload payload = buildPayload(); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("415"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType(MojException.Forbidden.class).isThrownBy(() -> summonsReplyStatusUpdateService.updateJurorResponseStatus(jurorNumber, @@ -424,14 +396,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_firs BureauJwtPayload courtPayload = buildPayload(); courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -455,14 +425,12 @@ public void test_updateJurorResponseStatus_courtUser_courtOwnedJurorPool() { BureauJwtPayload payload = buildPayload(); payload.setOwner("415"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("415"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); summonsReplyStatusUpdateService.updateJurorResponseStatus(jurorNumber, response.getProcessingStatus(), payload); @@ -489,12 +457,11 @@ public void test_updateJurorResponseStatus_courtUser_bureauOwnedJurorPool() { BureauJwtPayload payload = buildPayload(); payload.setOwner("415"); - List jurorPools = new ArrayList<>(); - jurorPools.add(createJuror(jurorNumber)); + JurorPool jurorPool = createJuror(jurorNumber); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType(MojException.Forbidden.class).isThrownBy(() -> summonsReplyStatusUpdateService.updateJurorResponseStatus(jurorNumber, @@ -510,14 +477,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_last BureauJwtPayload courtPayload = buildPayload(); courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -540,14 +505,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_dob( BureauJwtPayload courtPayload = buildPayload(); courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -570,14 +533,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_addr BureauJwtPayload courtPayload = buildPayload(); courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -600,14 +561,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_addr BureauJwtPayload courtPayload = buildPayload(); courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -630,14 +589,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_post BureauJwtPayload courtPayload = buildPayload(); courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -660,14 +617,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_bail BureauJwtPayload courtPayload = buildPayload(); courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -690,14 +645,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_conv BureauJwtPayload courtPayload = buildPayload(); courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -720,14 +673,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_ment BureauJwtPayload courtPayload = buildPayload(); courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -750,14 +701,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_ment BureauJwtPayload courtPayload = buildPayload(); courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -780,14 +729,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_resi courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -810,14 +757,12 @@ public void test_updateJurorResponseStatus_closingResponse_missingMandatory_sign BureauJwtPayload courtPayload = buildPayload(); courtPayload.setOwner("411"); - List jurorPools = new ArrayList<>(); JurorPool juror = createJuror(jurorNumber); juror.setOwner("411"); - jurorPools.add(juror); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(jurorPools).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(juror).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType( JurorPaperResponseException.JurorPaperResponseMissingMandatoryFields.class).isThrownBy(() -> @@ -873,14 +818,14 @@ public void test_paper_mergeJurorResponse_findActiveJurorPool_noRecordsFound() { PaperResponse paperResponse = createPaperResponse(jurorNumber); paperResponse.setProcessingComplete(Boolean.FALSE); - Mockito.doReturn(new ArrayList()).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doThrow(MojException.NotFound.class).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType(MojException.NotFound.class).isThrownBy(() -> summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername)); - verify(jurorPoolRepository, times(1)) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)) + .getJurorPoolFromUser(jurorNumber); verify(jurorPoolRepository, Mockito.never()).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, Mockito.never()).save(any(PaperResponse.class)); verify(welshCourtLocationRepository, Mockito.never()).findByLocCode(any()); @@ -894,64 +839,14 @@ public void test_digital_mergeJurorResponse_findActiveJurorPool_noRecordsFound() DigitalResponse digitalResponse = createDigitalResponse(jurorNumber); digitalResponse.setProcessingComplete(Boolean.FALSE); - Mockito.doReturn(new ArrayList()).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doThrow(MojException.NotFound.class).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType(MojException.NotFound.class).isThrownBy(() -> summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername)); - verify(jurorPoolRepository, times(1)) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - verify(jurorPoolRepository, Mockito.never()).save(any(JurorPool.class)); - verify(jurorDigitalResponseRepository, Mockito.never()).save(any(DigitalResponse.class)); - verify(welshCourtLocationRepository, Mockito.never()).findByLocCode(any()); - } - - @Test - public void test_paper_mergeJurorResponse_findActiveJurorPool_multipleRecordsFound() { - final String auditorUsername = "test_user"; - final String jurorNumber = "123456789"; - - PaperResponse paperResponse = createPaperResponse(jurorNumber); - paperResponse.setProcessingComplete(Boolean.FALSE); - - List multipleJurorPoolRecords = new ArrayList<>(); - multipleJurorPoolRecords.add(createJuror(jurorNumber)); - multipleJurorPoolRecords.add(createJuror(jurorNumber)); - - Mockito.doReturn(multipleJurorPoolRecords).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - - assertThatExceptionOfType(JurorRecordException.MultipleJurorRecordsFound.class).isThrownBy(() -> - summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername)); - - verify(jurorPoolRepository, times(1)) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - verify(jurorPoolRepository, Mockito.never()).save(any(JurorPool.class)); - verify(jurorPaperResponseRepository, Mockito.never()).save(any(PaperResponse.class)); - verify(welshCourtLocationRepository, Mockito.never()).findByLocCode(any()); - } - - @Test - public void test_digital_mergeJurorResponse_findActiveJurorPool_multipleRecordsFound() { - final String auditorUsername = "test_user"; - String jurorNumber = "123456789"; - - DigitalResponse digitalResponse = createDigitalResponse(jurorNumber); - digitalResponse.setProcessingComplete(Boolean.FALSE); - - List multipleJurorPoolRecords = new ArrayList<>(); - multipleJurorPoolRecords.add(createJuror(jurorNumber)); - multipleJurorPoolRecords.add(createJuror(jurorNumber)); - - Mockito.doReturn(multipleJurorPoolRecords).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - - assertThatExceptionOfType(JurorRecordException.MultipleJurorRecordsFound.class).isThrownBy(() -> - summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername)); - - verify(jurorPoolRepository, times(1)) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)) + .getJurorPoolFromUser(jurorNumber); verify(jurorPoolRepository, Mockito.never()).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, Mockito.never()).save(any(DigitalResponse.class)); verify(welshCourtLocationRepository, Mockito.never()).findByLocCode(any()); @@ -973,18 +868,17 @@ public void test_paper_mergeJurorResponse_mergeReasonableAdjustments_multipleRea PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(createmultipleReasonableAdjustmentsPaper(jurorNumber)) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(createmultipleReasonableAdjustmentsPaper(jurorNumber)) .when(jurorReasonableAdjustmentRepository) .findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -994,8 +888,8 @@ public void test_paper_mergeJurorResponse_mergeReasonableAdjustments_multipleRea assertThat(juror.getReasonableAdjustmentCode()).isEqualTo("M"); - verify(jurorPoolRepository, times(1)) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)) + .getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -1020,19 +914,18 @@ public void test_digital_mergeJurorResponse_mergeReasonableAdjustments_multipleR PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(createMultipleReasonableAdjustmentsDigital(jurorNumber)) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(createMultipleReasonableAdjustmentsDigital(jurorNumber)) .when(jurorReasonableAdjustmentRepository) .findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -1042,7 +935,7 @@ public void test_digital_mergeJurorResponse_mergeReasonableAdjustments_multipleR Juror juror = jurorCaptor.getValue(); assertThat(juror.getReasonableAdjustmentCode()).isEqualTo("M"); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -1067,17 +960,16 @@ public void test_paper_mergeJurorResponse_mergeReasonableAdjustments_singleReaso PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -1087,7 +979,7 @@ public void test_paper_mergeJurorResponse_mergeReasonableAdjustments_singleReaso Juror juror = jurorCaptor.getValue(); assertThat(juror.getReasonableAdjustmentCode()).isEqualTo("V"); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -1112,18 +1004,17 @@ public void test_digital_mergeJurorResponse_mergeReasonableAdjustments_singleRea PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -1133,7 +1024,7 @@ public void test_digital_mergeJurorResponse_mergeReasonableAdjustments_singleRea Juror juror = jurorCaptor.getValue(); assertThat(juror.getReasonableAdjustmentCode()).isEqualTo("V"); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -1156,19 +1047,18 @@ public void test_paper_mergeJurorResponse_jurorAudit_noDataChange() { PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -1191,20 +1081,19 @@ public void test_digital_mergeJurorResponse_jurorAudit_noDataChange() { PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -1232,17 +1121,16 @@ public void test_paper_mergeJurorResponse_jurorAudit_onlyDateOfBirthUpdated() { PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); - Mockito.doReturn(changedProperties).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); + doReturn(changedProperties).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -1251,7 +1139,7 @@ public void test_paper_mergeJurorResponse_jurorAudit_onlyDateOfBirthUpdated() { assertThat(jurorCaptor.getValue().getReasonableAdjustmentCode()).isEqualTo("V"); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -1278,18 +1166,17 @@ public void test_digital_mergeJurorResponse_jurorAudit_onlyDateOfBirthUpdated() PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(changedProperties).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(changedProperties).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -1298,7 +1185,7 @@ public void test_digital_mergeJurorResponse_jurorAudit_onlyDateOfBirthUpdated() assertThat(jurorCaptor.getValue().getReasonableAdjustmentCode()).isEqualTo("V"); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -1325,17 +1212,16 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_phoneN PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -1347,7 +1233,7 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_phoneN assertThat(juror.getWorkPhone()).isEqualTo("07917 020202"); assertThat(juror.getPhoneNumber()).isNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -1374,18 +1260,17 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply_phon PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -1397,7 +1282,7 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply_phon assertThat(juror.getWorkPhone()).isEqualTo("07917 020202"); assertThat(juror.getPhoneNumber()).isNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -1424,12 +1309,11 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_phoneN PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any()); + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -1441,7 +1325,7 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_phoneN assertThat(juror.getAltPhoneNumber()).isEqualTo("07917 020202"); assertThat(juror.getWorkPhone()).isNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -1467,18 +1351,17 @@ public void test_digital_mergeResponse_updateJurorPoolFromSummonsReply_phoneNumb PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any()); - Mockito.doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any()); + doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -1490,7 +1373,7 @@ public void test_digital_mergeResponse_updateJurorPoolFromSummonsReply_phoneNumb assertThat(juror.getAltPhoneNumber()).isEqualTo("07917 020202"); assertThat(juror.getWorkPhone()).isNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -1518,17 +1401,16 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_phoneN PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any()); - Mockito.doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any()); + doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -1540,7 +1422,7 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_phoneN assertThat(juror.getWorkPhone()).isEqualTo("01274 020202"); assertThat(juror.getAltPhoneNumber()).isNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -1567,18 +1449,17 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply_phon PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any()); - Mockito.doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any()); + doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -1590,7 +1471,7 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply_phon assertThat(juror.getWorkPhone()).isEqualTo("01274 020202"); assertThat(juror.getAltPhoneNumber()).isNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -1619,17 +1500,16 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_thirdP PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -1641,7 +1521,7 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_thirdP assertThat(juror.getWorkPhone()).isNull(); assertThat(juror.getAltPhoneNumber()).isNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -1670,18 +1550,17 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply_thir PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.FALSE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -1693,7 +1572,7 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply_thir assertThat(juror.getWorkPhone()).isNull(); assertThat(juror.getAltPhoneNumber()).isNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -1720,17 +1599,16 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply() thro PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -1746,7 +1624,7 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply() thro assertThat(juror.getPostcode()).isEqualTo("WA16 0PB"); assertThat(juror.getDateOfBirth()).isEqualTo(birthDate); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -1773,18 +1651,17 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply() th PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -1800,7 +1677,7 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply() th assertThat(juror.getPostcode()).isEqualTo("WA16 0PB"); assertThat(juror.getDateOfBirth()).isEqualTo(birthDate); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -1829,18 +1706,17 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_isWels final WelshCourtLocation welshCourt = new WelshCourtLocation(); welshCourt.setLocCode("457"); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(welshCourt).when(welshCourtLocationRepository).findByLocCode(anyString()); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any()); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(welshCourt).when(welshCourtLocationRepository).findByLocCode(anyString()); + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any()); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -1850,7 +1726,7 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_isWels Juror juror = jurorCaptor.getValue(); assertThat(juror.getWelsh()).isEqualTo(Boolean.TRUE); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -1879,19 +1755,18 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply_isWe final WelshCourtLocation welshCourt = new WelshCourtLocation(); welshCourt.setLocCode("457"); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(welshCourt).when(welshCourtLocationRepository).findByLocCode(anyString()); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(welshCourt).when(welshCourtLocationRepository).findByLocCode(anyString()); + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -1901,7 +1776,7 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply_isWe Juror juror = jurorCaptor.getValue(); assertThat(juror.getWelsh()).isEqualTo(Boolean.TRUE); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -1927,17 +1802,16 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_isNotW PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any()); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any()); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -1947,7 +1821,7 @@ public void test_paper_mergeJurorResponse_updateJurorPoolFromSummonsReply_isNotW Juror juror = jurorCaptor.getValue(); assertThat(juror.getWelsh()).isNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -1974,18 +1848,17 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply_isNo PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any()); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any()); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -1995,7 +1868,7 @@ public void test_digital_mergeJurorResponse_updateJurorPoolFromSummonsReply_isNo Juror juror = jurorCaptor.getValue(); assertThat(juror.getWelsh()).isNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -2022,17 +1895,16 @@ public void test_paper_mergeJurorResponse_markSummonReplyAsCompleted() { PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any()); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any()); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -2040,7 +1912,7 @@ public void test_paper_mergeJurorResponse_markSummonReplyAsCompleted() { assertThat(jurorPaperResponseCaptor.getValue().getProcessingComplete()).isEqualTo(Boolean.TRUE); assertThat(jurorPaperResponseCaptor.getValue().getCompletedAt()).isNotNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -2067,18 +1939,17 @@ public void test_digital_mergeJurorResponse_markSummonReplyAsCompleted() { PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(initChangedPropertiesMap(Boolean.TRUE)).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -2086,7 +1957,7 @@ public void test_digital_mergeJurorResponse_markSummonReplyAsCompleted() { assertThat(jurorDigitalResponseCaptor.getValue().getProcessingComplete()).isEqualTo(Boolean.TRUE); assertThat(jurorDigitalResponseCaptor.getValue().getCompletedAt()).isNotNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -2116,17 +1987,16 @@ public void test_paper_mergeJurorResponse_markSummonReplyAsCompleted_onlyTitleCh PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); - Mockito.doReturn(changedProperties).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); + doReturn(changedProperties).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); @@ -2134,7 +2004,7 @@ public void test_paper_mergeJurorResponse_markSummonReplyAsCompleted_onlyTitleCh assertThat(jurorPaperResponseCaptor.getValue().getProcessingComplete()).isEqualTo(Boolean.TRUE); assertThat(jurorPaperResponseCaptor.getValue().getCompletedAt()).isNotNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -2162,21 +2032,20 @@ public void test_digital_mergeJurorResponse_markSummonReplyAsCompleted_onlyTitle PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(null).when(jurorReasonableAdjustmentRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(changedProperties).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(null).when(jurorReasonableAdjustmentRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(changedProperties).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); - Mockito.doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), + doReturn(Boolean.FALSE).when(jurorAuditChangeService).hasNameChanged(anyString(), anyString(), anyString(), anyString()); - Mockito.doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); + doReturn(Boolean.TRUE).when(jurorAuditChangeService).hasTitleChanged(anyString(), anyString()); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); @@ -2184,7 +2053,7 @@ public void test_digital_mergeJurorResponse_markSummonReplyAsCompleted_onlyTitle assertThat(jurorDigitalResponseCaptor.getValue().getProcessingComplete()).isEqualTo(Boolean.TRUE); assertThat(jurorDigitalResponseCaptor.getValue().getCompletedAt()).isNotNull(); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -2216,16 +2085,15 @@ public void test_paper_mergeJurorResponse_auditChangeHistory_DateOfBirthChanged( PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsPaper(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorPaperResponseRepository).save(any(PaperResponse.class)); summonsReplyStatusUpdateService.mergePaperResponse(paperResponse, auditorUsername); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorPaperResponseRepository, times(1)).save(any(PaperResponse.class)); @@ -2259,20 +2127,19 @@ public void test_digital_mergeJurorResponse_auditChangeHistory_DateOfBirthChange Map changedProperties = new HashMap<>(); changedProperties.put("date Of Birth", Boolean.TRUE); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); + doReturn(digitalResponse).when(jurorDigitalResponseRepository).findByJurorNumber(jurorNumber); + doReturn(Collections.singletonList(createReasonableAdjustmentsDigital(jurorNumber))) .when(jurorReasonableAdjustmentRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(null).when(jurorPoolRepository).save(any()); - Mockito.doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); - Mockito.doReturn(changedProperties).when(jurorAuditChangeService) + doReturn(null).when(jurorPoolRepository).save(any()); + doReturn(null).when(jurorDigitalResponseRepository).save(any(DigitalResponse.class)); + doReturn(changedProperties).when(jurorAuditChangeService) .initChangedPropertyMap(any(Juror.class), any(AbstractJurorResponse.class)); summonsReplyStatusUpdateService.mergeDigitalResponse(digitalResponse, auditorUsername); - verify(jurorPoolRepository, times(1)).findByJurorJurorNumberAndIsActive(jurorNumber, true); + verify(jurorPoolService, times(1)).getJurorPoolFromUser(jurorNumber); verify(jurorRepository, times(1)).save(any(Juror.class)); verify(jurorPoolRepository, times(1)).save(any(JurorPool.class)); verify(jurorDigitalResponseRepository, times(1)).save(any(DigitalResponse.class)); @@ -2299,9 +2166,9 @@ public void test_updateJurorResponseStatus_processingAlreadyComplete_NonResponde final BureauJwtPayload payload = buildPayload(); - Mockito.doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); + doReturn(response).when(jurorPaperResponseRepository).findByJurorNumber(jurorNumber); - Mockito.doReturn(Optional.of(respondedStatus)).when(jurorStatusRepository).findById(IJurorStatus.RESPONDED); + doReturn(Optional.of(respondedStatus)).when(jurorStatusRepository).findById(IJurorStatus.RESPONDED); CourtLocation courtLocation = createCourtLocation("415", "CHESTER", "09:15"); JurorPool jurorPool = createJuror(jurorNumber); @@ -2309,8 +2176,7 @@ public void test_updateJurorResponseStatus_processingAlreadyComplete_NonResponde PoolRequest poolRequest = jurorPool.getPool(); poolRequest.setCourtLocation(courtLocation); - Mockito.doReturn(Collections.singletonList(jurorPool)).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + doReturn(jurorPool).when(jurorPoolService).getJurorPoolFromUser(jurorNumber); summonsReplyStatusUpdateService.updateJurorResponseStatus(jurorNumber, ProcessingStatus.CLOSED, payload); diff --git a/src/test/java/uk/gov/hmcts/juror/api/moj/service/UndeliverableResponseServiceTest.java b/src/test/java/uk/gov/hmcts/juror/api/moj/service/UndeliverableResponseServiceTest.java index f8002730c..ce06a9754 100644 --- a/src/test/java/uk/gov/hmcts/juror/api/moj/service/UndeliverableResponseServiceTest.java +++ b/src/test/java/uk/gov/hmcts/juror/api/moj/service/UndeliverableResponseServiceTest.java @@ -17,9 +17,7 @@ import uk.gov.hmcts.juror.api.moj.domain.JurorStatus; import uk.gov.hmcts.juror.api.moj.domain.PoolRequest; import uk.gov.hmcts.juror.api.moj.exception.MojException; -import uk.gov.hmcts.juror.api.moj.repository.JurorPoolRepository; -import java.util.ArrayList; import java.util.List; import java.util.Set; @@ -31,7 +29,7 @@ class UndeliverableResponseServiceTest { @Mock private JurorHistoryService jurorHistoryService; @Mock - private JurorPoolRepository jurorPoolRepository; + private JurorPoolService jurorPoolService; @InjectMocks private UndeliverableResponseServiceImpl undeliverableResponseService; @@ -58,16 +56,14 @@ void afterAll() { void negativeJurorRecordDoesNotExist() { String jurorNumber = "111111111"; - List members = new ArrayList<>(); - - Mockito.doReturn(members).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doThrow(MojException.NotFound.class).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType(MojException.NotFound.class).isThrownBy( () -> undeliverableResponseService.markAsUndeliverable(List.of(jurorNumber))); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.verify(jurorPoolRepository, Mockito.never()).save(Mockito.any()); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser(jurorNumber); + Mockito.verify(jurorPoolService, Mockito.never()).save(Mockito.any()); Mockito.verify(jurorHistoryService, Mockito.never()).createUndeliveredSummonsHistory(Mockito.any()); } @@ -76,18 +72,16 @@ void negativeJurorRecordDoesNotExist() { void negativeJurorRecordIsNotOwned() { String jurorNumber = "123456789"; - List members = new ArrayList<>(); - members.add(createValidJurorPool(jurorNumber, "415")); - Mockito.doReturn(members).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(createValidJurorPool(jurorNumber, "415")).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); assertThatExceptionOfType(MojException.Forbidden.class).isThrownBy( () -> undeliverableResponseService.markAsUndeliverable(List.of(jurorNumber))); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - Mockito.verify(jurorPoolRepository, Mockito.never()).save(Mockito.any()); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser(jurorNumber); + Mockito.verify(jurorPoolService, Mockito.never()).save(Mockito.any()); Mockito.verify(jurorHistoryService, Mockito.never()).createUndeliveredSummonsHistory(Mockito.any()); } @@ -97,17 +91,14 @@ void positiveMarkJurorAsUndeliverable() { String jurorNumber = "222222225"; JurorPool jurorPool = createValidJurorPool(jurorNumber, OWNER); - List members = new ArrayList<>(); - members.add(jurorPool); - - Mockito.doReturn(members).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); + Mockito.doReturn(jurorPool).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber); undeliverableResponseService.markAsUndeliverable(List.of(jurorNumber)); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive(Mockito.any(), Mockito.anyBoolean()); - Mockito.verify(jurorPoolRepository, Mockito.times(1)).save(Mockito.any()); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser(jurorNumber); + Mockito.verify(jurorPoolService, Mockito.times(1)).save(Mockito.any()); Mockito.verify(jurorHistoryService, Mockito.times(1)).createUndeliveredSummonsHistory(jurorPool); } @@ -118,25 +109,22 @@ void positiveMarkJurorAsUndeliverableMultiple() { JurorPool jurorPool1 = createValidJurorPool(jurorNumber1, OWNER); JurorPool jurorPool2 = createValidJurorPool(jurorNumber2, OWNER); - List members1 = new ArrayList<>(); - members1.add(jurorPool1); - - List members2 = new ArrayList<>(); - members2.add(jurorPool2); - Mockito.doReturn(members1).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber1, true); - Mockito.doReturn(members2).when(jurorPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber2, true); + Mockito.doReturn(jurorPool1).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber1); + Mockito.doReturn(jurorPool2).when(jurorPoolService) + .getJurorPoolFromUser(jurorNumber2); undeliverableResponseService.markAsUndeliverable(List.of(jurorNumber1, jurorNumber2)); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive(jurorNumber1, true); - Mockito.verify(jurorPoolRepository, Mockito.times(1)) - .findByJurorJurorNumberAndIsActive(jurorNumber2, true); - Mockito.verify(jurorPoolRepository, Mockito.times(1)).save(jurorPool1); - Mockito.verify(jurorPoolRepository, Mockito.times(1)).save(jurorPool2); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser(jurorNumber1); + Mockito.verify(jurorPoolService, Mockito.times(1)) + .getJurorPoolFromUser(jurorNumber2); + Mockito.verify(jurorPoolService, Mockito.times(1)).save(jurorPool1); + Mockito.verify(jurorPoolService, Mockito.times(1)).save(jurorPool2); + + Mockito.verify(jurorHistoryService, Mockito.times(1)) .createUndeliveredSummonsHistory(jurorPool1); Mockito.verify(jurorHistoryService, Mockito.times(1)) diff --git a/src/test/java/uk/gov/hmcts/juror/api/moj/utils/JurorPoolUtilsTest.java b/src/test/java/uk/gov/hmcts/juror/api/moj/utils/JurorPoolUtilsTest.java index 60e3c8d75..d3f6e421d 100644 --- a/src/test/java/uk/gov/hmcts/juror/api/moj/utils/JurorPoolUtilsTest.java +++ b/src/test/java/uk/gov/hmcts/juror/api/moj/utils/JurorPoolUtilsTest.java @@ -9,7 +9,6 @@ import uk.gov.hmcts.juror.api.moj.domain.Juror; import uk.gov.hmcts.juror.api.moj.domain.JurorPool; import uk.gov.hmcts.juror.api.moj.domain.PoolRequest; -import uk.gov.hmcts.juror.api.moj.exception.JurorRecordException; import uk.gov.hmcts.juror.api.moj.exception.MojException; import uk.gov.hmcts.juror.api.moj.repository.JurorPoolRepository; @@ -143,38 +142,6 @@ public void test_getActiveJurorPoolRecords_noRecords() { JurorPoolUtils.getActiveJurorPoolRecords(jurorPoolPoolRepository, "333333333")); } - @Test - public void test_getActiveJurorRecord_singleRecord() { - JurorPool jurorPoolOne = createJurorPool("111111111", "457"); - - Mockito.doReturn(Collections.singletonList(jurorPoolOne)).when(jurorPoolPoolRepository) - .findByJurorJurorNumberAndIsActive("111111111", true); - - Assertions.assertThat(JurorPoolUtils.getActiveJurorRecord(jurorPoolPoolRepository, "111111111")) - .isEqualTo(jurorPoolOne.getJuror()); - } - - @Test - public void test_getActiveJurorRecord_noRecords() { - Mockito.doReturn(new ArrayList()).when(jurorPoolPoolRepository) - .findByJurorJurorNumberAndIsActive("333333333", true); - - Assertions.assertThatExceptionOfType(MojException.NotFound.class).isThrownBy(() -> - JurorPoolUtils.getActiveJurorRecord(jurorPoolPoolRepository, "333333333")); - } - - @Test - public void test_getActiveJurorRecord_multipleRecords() { - JurorPool jurorPoolOne = createJurorPool("111111111", "457"); - JurorPool jurorPoolTwo = createJurorPool("111111111", "415"); - - Mockito.doReturn(Arrays.asList(jurorPoolOne, jurorPoolTwo)).when(jurorPoolPoolRepository) - .findByJurorJurorNumberAndIsActive("111111111", true); - - Assertions.assertThatExceptionOfType(JurorRecordException.MultipleJurorRecordsFound.class).isThrownBy(() -> - JurorPoolUtils.getActiveJurorRecord(jurorPoolPoolRepository, "111111111")); - } - @Test public void test_checkMultipleRecordReadAccess_bureauUser_bureauOwnedRecord() { String jurorNumber = "111111111"; @@ -362,48 +329,6 @@ public void test_getActiveJurorPoolForUser_courtUser_noJurorPool() { JurorPoolUtils.getActiveJurorPoolForUser(jurorPoolPoolRepository, jurorNumber, "415")); } - @Test - public void test_getSingleActiveJurorPool_singleJurorPool() { - String jurorNumber = "111111111"; - String owner = "400"; - JurorPool jurorPool = createJurorPool(jurorNumber, owner); - List jurorPools = Collections.singletonList(jurorPool); - Mockito.doReturn(jurorPools).when(jurorPoolPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - - JurorPool jurorForUser = JurorPoolUtils.getSingleActiveJurorPool(jurorPoolPoolRepository, jurorNumber); - Assertions.assertThat(jurorForUser) - .as("Expect the juror pool record to be returned successfully") - .isEqualTo(jurorPool); - } - - @Test - public void test_getSingleActiveJurorPool_noJurorPools() { - String jurorNumber = "111111111"; - - Mockito.doReturn(new ArrayList<>()).when(jurorPoolPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - - Assertions.assertThatExceptionOfType(MojException.NotFound.class).isThrownBy(() -> - JurorPoolUtils.getSingleActiveJurorPool(jurorPoolPoolRepository, jurorNumber)); - } - - @Test - public void test_getSingleActiveJurorPool_multipleJurorPools() { - String jurorNumber = "111111111"; - String owner = "400"; - - List jurorPools = new ArrayList<>(); - jurorPools.add(createJurorPool(jurorNumber, owner)); - jurorPools.add(createJurorPool(jurorNumber, owner)); - - Mockito.doReturn(jurorPools).when(jurorPoolPoolRepository) - .findByJurorJurorNumberAndIsActive(jurorNumber, true); - - Assertions.assertThatExceptionOfType(JurorRecordException.MultipleJurorRecordsFound.class).isThrownBy(() -> - JurorPoolUtils.getSingleActiveJurorPool(jurorPoolPoolRepository, jurorNumber)); - } - private JurorPool createJurorPool(String jurorNumber, String owner) { JurorPool jurorPool = new JurorPool(); jurorPool.setOwner(owner); diff --git a/src/test/java/uk/gov/hmcts/juror/api/utils/TestConstants.java b/src/test/java/uk/gov/hmcts/juror/api/utils/TestConstants.java index ea414e793..ab677d2c4 100644 --- a/src/test/java/uk/gov/hmcts/juror/api/utils/TestConstants.java +++ b/src/test/java/uk/gov/hmcts/juror/api/utils/TestConstants.java @@ -4,7 +4,7 @@ public class TestConstants { public static final String JWT = "GeneratedJwtFromSecret"; public static final String JWT_SECRET = "dGhpcy1pcy1hLXRlc3Qta2V5LWZvci11cy13aGVuLWNyZWF0aW5nLXNlY3JldHM="; public static final String JWT_EXPIRY_STR = "1m"; - public static final long JWT_EXPIRY = 60000; + public static final long JWT_EXPIRY = 60_000; protected TestConstants() {