From 79aac82e7f04d3c3abfcb09458722e24585d6b25 Mon Sep 17 00:00:00 2001 From: AbuSalam22 <136581242+AbuSalam22@users.noreply.github.com> Date: Tue, 23 Jul 2024 12:45:55 +0100 Subject: [PATCH] DTSCCI-414 Remove Spring context --- .../UpdateCaseProgressHandlerTest.java | 23 ++++------- .../UpdateHmcPartiesNotifiedHandlerTest.java | 38 ++++++++--------- ...tchBusinessProcessCallbackHandlerTest.java | 4 +- .../service/AirlineEpimsDataLoaderTest.java | 7 ++-- .../service/AirlineEpimsServiceTest.java | 41 ++++--------------- .../CivilDocumentStitchingServiceTest.java | 28 ++++++------- ...rviceOfDateValidationMessageUtilsTest.java | 26 +++++------- .../validation/DateOfBirthValidatorTest.java | 32 +++++++++++---- .../DeadlineExtensionValidatorTest.java | 35 ++++------------ .../validation/PaymentDateValidatorTest.java | 28 +++++++++---- 10 files changed, 113 insertions(+), 149 deletions(-) diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/automatedhearingnotice/UpdateCaseProgressHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/automatedhearingnotice/UpdateCaseProgressHandlerTest.java index ec933180d94..c78bdface73 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/automatedhearingnotice/UpdateCaseProgressHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/automatedhearingnotice/UpdateCaseProgressHandlerTest.java @@ -1,17 +1,15 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.automatedhearingnotice; -import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackType; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.service.hearingnotice.HearingNoticeCamundaService; @@ -23,18 +21,13 @@ import static uk.gov.hmcts.reform.civil.enums.CaseState.HEARING_READINESS; import static uk.gov.hmcts.reform.civil.enums.CaseState.PREPARE_FOR_HEARING_CONDUCT_HEARING; -@SpringBootTest(classes = { - UpdateCaseProgressHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class -}) +@ExtendWith(MockitoExtension.class) class UpdateCaseProgressHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private UpdateCaseProgressHandler handler; - @Autowired - private ObjectMapper objectMapper; - @MockBean + + @Mock private HearingNoticeCamundaService camundaService; @Test diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/automatedhearingnotice/UpdateHmcPartiesNotifiedHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/automatedhearingnotice/UpdateHmcPartiesNotifiedHandlerTest.java index d45c2d51068..78f8426a288 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/automatedhearingnotice/UpdateHmcPartiesNotifiedHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/automatedhearingnotice/UpdateHmcPartiesNotifiedHandlerTest.java @@ -1,17 +1,15 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.automatedhearingnotice; -import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import uk.gov.hmcts.reform.civil.callback.CallbackParams; import uk.gov.hmcts.reform.civil.handler.callback.BaseCallbackHandlerTest; -import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.BusinessProcess; import uk.gov.hmcts.reform.civil.model.CaseData; import uk.gov.hmcts.reform.civil.sampledata.CaseDataBuilder; @@ -32,20 +30,16 @@ import static org.mockito.Mockito.when; import static uk.gov.hmcts.reform.civil.callback.CallbackType.ABOUT_TO_SUBMIT; -@SpringBootTest(classes = { - UpdateHmcPartiesNotifiedHandler.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class -}) +@ExtendWith(MockitoExtension.class) class UpdateHmcPartiesNotifiedHandlerTest extends BaseCallbackHandlerTest { - @Autowired + @InjectMocks private UpdateHmcPartiesNotifiedHandler handler; - @Autowired - private ObjectMapper objectMapper; - @MockBean + + @Mock private HearingNoticeCamundaService hearingNoticeCamundaService; - @MockBean + + @Mock private HearingsService hearingsService; @BeforeEach @@ -55,15 +49,15 @@ void setUp() { .hearingId("HER1234") .hearingLocationEpims("12345") .days(List.of(HearingDay.builder() - .hearingStartDateTime(LocalDateTime.of(2023, 01, 01, 0, 0, 0)) - .hearingEndDateTime(LocalDateTime.of(2023, 01, 01, 12, 0, 0)) + .hearingStartDateTime(LocalDateTime.of(2023, 1, 1, 0, 0, 0)) + .hearingEndDateTime(LocalDateTime.of(2023, 1, 1, 12, 0, 0)) .build())) .hearingStartDateTime(LocalDateTime.of(2022, 11, 7, 15, 15)) .requestVersion(10L) .responseDateTime(LocalDateTime.of(2022, 10, 10, 15, 15)) .build()); when(hearingsService.updatePartiesNotifiedResponse(anyString(), anyString(), anyInt(), any(), any())) - .thenReturn(new ResponseEntity("Ok", HttpStatus.ACCEPTED)); + .thenReturn(new ResponseEntity<>("Ok", HttpStatus.ACCEPTED)); } @Test @@ -75,8 +69,8 @@ void shouldReturnExpectedCallbackResponseOnAboutToSubmit() { LocalDateTime receivedDate = LocalDateTime.of(2022, 10, 10, 15, 15); List hearingDays = List.of(HearingDay.builder() - .hearingStartDateTime(LocalDateTime.of(2023, 01, 01, 0, 0, 0)) - .hearingEndDateTime(LocalDateTime.of(2023, 01, 01, 12, 0, 0)) + .hearingStartDateTime(LocalDateTime.of(2023, 1, 1, 0, 0, 0)) + .hearingEndDateTime(LocalDateTime.of(2023, 1, 1, 12, 0, 0)) .build()); PartiesNotified partiesNotified = PartiesNotified.builder() .serviceData(PartiesNotifiedServiceData.builder() @@ -86,7 +80,7 @@ void shouldReturnExpectedCallbackResponseOnAboutToSubmit() { .build()) .build(); - var result = handler.handle(params); + handler.handle(params); verify(hearingsService).updatePartiesNotifiedResponse("BEARER_TOKEN", "HER1234", 10, receivedDate, partiesNotified); } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/DispatchBusinessProcessCallbackHandlerTest.java b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/DispatchBusinessProcessCallbackHandlerTest.java index b82f755b1db..b7b1c591255 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/DispatchBusinessProcessCallbackHandlerTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/handler/callback/camunda/businessprocess/DispatchBusinessProcessCallbackHandlerTest.java @@ -1,12 +1,12 @@ package uk.gov.hmcts.reform.civil.handler.callback.camunda.businessprocess; import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.api.BeforeEach; import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.ccd.client.model.AboutToStartOrSubmitCallbackResponse; import uk.gov.hmcts.reform.civil.callback.CallbackParams; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/AirlineEpimsDataLoaderTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/AirlineEpimsDataLoaderTest.java index 7b8b2e07427..f1a4f6ede58 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/AirlineEpimsDataLoaderTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/AirlineEpimsDataLoaderTest.java @@ -1,12 +1,13 @@ package uk.gov.hmcts.reform.civil.service; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; -import org.springframework.boot.test.context.SpringBootTest; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import static org.junit.jupiter.api.Assertions.assertEquals; -@SpringBootTest(classes = {AirlineEpimsDataLoader.class}) +@ExtendWith(MockitoExtension.class) class AirlineEpimsDataLoaderTest { private AirlineEpimsDataLoader airlineEpimsDataLoader; diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/AirlineEpimsServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/AirlineEpimsServiceTest.java index e75b6a1be96..490637f9c7e 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/AirlineEpimsServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/AirlineEpimsServiceTest.java @@ -2,9 +2,11 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.civil.model.AirlineEpimsId; + import java.util.ArrayList; import java.util.List; @@ -12,10 +14,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.BDDMockito.given; -@SpringBootTest(classes = {AirlineEpimsService.class}) +@ExtendWith(MockitoExtension.class) class AirlineEpimsServiceTest { - @MockBean + @Mock private AirlineEpimsDataLoader airlineEpimsDataLoader; private AirlineEpimsService airlineEpimsService; @@ -28,73 +30,48 @@ void setup() { given(airlineEpimsDataLoader.getAirlineEpimsIDList()) .willReturn(airlineEpimsIDList); + + airlineEpimsService = new AirlineEpimsService(airlineEpimsDataLoader); + } @Test void getEpimsIdForAirline_shouldReturnCorrespondingEpimsIdForAirline() { - // Given - airlineEpimsService = new AirlineEpimsService(airlineEpimsDataLoader); - - // When String result = airlineEpimsService.getEpimsIdForAirline("Gulf Air"); - // Then assertThat(result).isEqualTo("36791"); } @Test void getEpimsIdForAirline_givenInvalidAirline_shouldThrowException() { - // Given - airlineEpimsService = new AirlineEpimsService(airlineEpimsDataLoader); - - // Then assertThatExceptionOfType(IllegalStateException.class) .isThrownBy(() -> airlineEpimsService.getEpimsIdForAirline("INVALID_AIRLINE")); } @Test void getEpimsIdForAirline_givenNoLocationAirline_shouldThrowException() { - // Given - airlineEpimsService = new AirlineEpimsService(airlineEpimsDataLoader); - - // Then assertThatExceptionOfType(IllegalStateException.class) .isThrownBy(() -> airlineEpimsService.getEpimsIdForAirline("NoLocationAirline")); } @Test void getEpimsIdForAirlineIgnoreCase_shouldReturnCorrespondingEpimsIdForAirline() { - // Given - airlineEpimsService = new AirlineEpimsService(airlineEpimsDataLoader); - - // When String result = airlineEpimsService.getEpimsIdForAirlineIgnoreCase("gulf air"); - // Then assertThat(result).isEqualTo("36791"); } @Test void getEpimsIdForAirlineIgnoreCase_givenInvalidAirline_shouldThrowException() { - // Given - airlineEpimsService = new AirlineEpimsService(airlineEpimsDataLoader); - - // When String result = airlineEpimsService.getEpimsIdForAirlineIgnoreCase("INVALID_AIRLINE"); - // Then assertThat(result).isNull(); } @Test void getEpimsIdForAirlineIgnoreCase_givenNoLocationAirline_shouldThrowException() { - // Given - airlineEpimsService = new AirlineEpimsService(airlineEpimsDataLoader); - - // When String result = airlineEpimsService.getEpimsIdForAirlineIgnoreCase("NoLocationAirline"); - // Then assertThat(result).isNull(); } } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/service/stitching/CivilDocumentStitchingServiceTest.java b/src/test/java/uk/gov/hmcts/reform/civil/service/stitching/CivilDocumentStitchingServiceTest.java index 8493d5d8bb3..f02524e432d 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/service/stitching/CivilDocumentStitchingServiceTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/service/stitching/CivilDocumentStitchingServiceTest.java @@ -1,19 +1,17 @@ package uk.gov.hmcts.reform.civil.service.stitching; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.civil.config.StitchingConfiguration; import uk.gov.hmcts.reform.civil.documentmanagement.model.CaseDocument; import uk.gov.hmcts.reform.civil.documentmanagement.model.Document; import uk.gov.hmcts.reform.civil.exceptions.StitchingFailedException; -import uk.gov.hmcts.reform.civil.helpers.CaseDetailsConverter; import uk.gov.hmcts.reform.civil.model.Bundle; import uk.gov.hmcts.reform.civil.model.BundleRequest; import uk.gov.hmcts.reform.civil.model.CaseData; @@ -36,21 +34,21 @@ import static uk.gov.hmcts.reform.civil.documentmanagement.model.DocumentType.SEALED_CLAIM; import static uk.gov.hmcts.reform.civil.service.docmosis.DocmosisTemplates.N1; -@ExtendWith(SpringExtension.class) -@SpringBootTest(classes = { - CivilDocumentStitchingService.class, - JacksonAutoConfiguration.class, - CaseDetailsConverter.class -}) +@ExtendWith(MockitoExtension.class) class CivilDocumentStitchingServiceTest { - @Autowired + @InjectMocks private CivilDocumentStitchingService civilDocumentStitchingService; - @MockBean + + @Mock private BundleRequestExecutor bundleRequestExecutor; - @MockBean + + @Mock private StitchingConfiguration stitchingConfiguration; + @Mock + private ObjectMapper objectMapper; + CaseData caseData; private static final CaseDocument CLAIM_FORM = diff --git a/src/test/java/uk/gov/hmcts/reform/civil/utils/ServiceOfDateValidationMessageUtilsTest.java b/src/test/java/uk/gov/hmcts/reform/civil/utils/ServiceOfDateValidationMessageUtilsTest.java index 539b54774c7..0d9b20fb087 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/utils/ServiceOfDateValidationMessageUtilsTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/utils/ServiceOfDateValidationMessageUtilsTest.java @@ -1,10 +1,10 @@ package uk.gov.hmcts.reform.civil.utils; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInstance; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.civil.bankholidays.WorkingDayIndicator; import uk.gov.hmcts.reform.civil.model.CertificateOfService; import uk.gov.hmcts.reform.civil.service.DeadlinesCalculator; @@ -18,23 +18,19 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -@SpringBootTest(classes = { - ServiceOfDateValidationMessageUtils.class, - -}) -@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@ExtendWith(MockitoExtension.class) class ServiceOfDateValidationMessageUtilsTest { - @MockBean + @Mock private DeadlinesCalculator deadlinesCalculator; - @MockBean + @Mock private WorkingDayIndicator workingDayIndicator; - @MockBean + @Mock private Time time; - @Autowired + @InjectMocks private ServiceOfDateValidationMessageUtils serviceUtils; @Test @@ -49,7 +45,6 @@ void shouldThrowError_whenDeemedServedDateIsOlderThan14Days() { LocalDateTime currentDateTime = LocalDateTime.now(); when(time.now()).thenReturn(currentDateTime); when(deadlinesCalculator.plusWorkingDays(currentDate, 2)).thenReturn(currentDate); - when(workingDayIndicator.isWorkingDay(any(LocalDate.class))).thenReturn(true); List errorMessages = serviceUtils.getServiceOfDateValidationMessages(certificateOfService); @@ -101,10 +96,9 @@ void shouldThrowError_whenCosDefendantNotifyDateIsOlderThan14Days() { @Test void shouldThrowError_whenDeemedServedDateIsNotWorkingDay() { LocalDate currentDate = LocalDate.now(); - LocalDate deemedServedDate = currentDate; CertificateOfService certificateOfService = CertificateOfService.builder() .cosDateOfServiceForDefendant(currentDate) - .cosDateDeemedServedForDefendant(deemedServedDate) + .cosDateDeemedServedForDefendant(currentDate) .build(); LocalDateTime currentDateTime = LocalDateTime.now(); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/validation/DateOfBirthValidatorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/validation/DateOfBirthValidatorTest.java index 38c6ea5f214..3b8c6d456d6 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/validation/DateOfBirthValidatorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/validation/DateOfBirthValidatorTest.java @@ -1,26 +1,40 @@ package uk.gov.hmcts.reform.civil.validation; +import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.civil.model.Party; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; import java.time.LocalDate; import static org.assertj.core.api.Assertions.assertThat; -@SpringBootTest(classes = {DateOfBirthValidator.class, ValidationAutoConfiguration.class}) +@ExtendWith(MockitoExtension.class) class DateOfBirthValidatorTest { - @Autowired - DateOfBirthValidator validator; + private DateOfBirthValidator dateOfBirthValidator; + + @BeforeEach + void setUp() { + ValidatorFactory validatorFactory = Validation.byDefaultProvider() + .configure() + .messageInterpolator(new ParameterMessageInterpolator()) + .buildValidatorFactory(); + + Validator validator = validatorFactory.getValidator(); + dateOfBirthValidator = new DateOfBirthValidator(validator); + } @Test void shouldReturnError_whenDateOfBirthIsInTheFuture() { Party party = Party.builder().individualDateOfBirth(LocalDate.now().plusDays(1)).build(); - var errors = validator.validate(party); + var errors = dateOfBirthValidator.validate(party); assertThat(errors).containsExactly("The date entered cannot be in the future"); } @@ -29,7 +43,7 @@ void shouldReturnError_whenDateOfBirthIsInTheFuture() { void shouldReturnNoError_whenDateOfBirthIsInThePast() { Party party = Party.builder().individualDateOfBirth(LocalDate.now().minusYears(19)).build(); - var errors = validator.validate(party); + var errors = dateOfBirthValidator.validate(party); assertThat(errors).isEmpty(); } @@ -38,7 +52,7 @@ void shouldReturnNoError_whenDateOfBirthIsInThePast() { void shouldReturnNoError_whenDateOfBirthIsNotProvided() { Party party = Party.builder().build(); - var errors = validator.validate(party); + var errors = dateOfBirthValidator.validate(party); assertThat(errors).isEmpty(); } diff --git a/src/test/java/uk/gov/hmcts/reform/civil/validation/DeadlineExtensionValidatorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/validation/DeadlineExtensionValidatorTest.java index ef5212314df..112aab12623 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/validation/DeadlineExtensionValidatorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/validation/DeadlineExtensionValidatorTest.java @@ -3,10 +3,10 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.civil.bankholidays.WorkingDayIndicator; import java.time.DayOfWeek; @@ -19,18 +19,15 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; -@SpringBootTest(classes = { - DeadlineExtensionValidator.class, - JacksonAutoConfiguration.class -}) +@ExtendWith(MockitoExtension.class) class DeadlineExtensionValidatorTest { private static final LocalDate NOW = now(); - @MockBean + @Mock private WorkingDayIndicator workingDayIndicator; - @Autowired + @InjectMocks private DeadlineExtensionValidator validator; @Nested @@ -105,7 +102,6 @@ void shouldReturnNoErrors_whenValidExtensionForSpec() { @Test void shouldReturnErrors_whenExtensionDateisPastDateForSpec() { - when(workingDayIndicator.isWorkingDay(any())).thenReturn(true); LocalDate agreedExtension = NOW.minusDays(10); LocalDateTime currentResponseDeadline = NOW.plusDays(7).atTime(16, 0); @@ -120,7 +116,6 @@ void shouldReturnErrors_whenExtensionDateisPastDateForSpec() { @Test void shouldReturnErrors_whenExtensionDateisAfterResponseDeadlineDateForSpec() { - when(workingDayIndicator.isWorkingDay(any())).thenReturn(true); LocalDate agreedExtension = NOW.plusDays(5); LocalDateTime currentResponseDeadline = NOW.plusDays(7).atTime(16, 0); @@ -133,22 +128,6 @@ void shouldReturnErrors_whenExtensionDateisAfterResponseDeadlineDateForSpec() { assertThat(errors).contains("The agreed extension date must be after the current deadline"); } - /*@Test - void shouldReturnErrors_whenAgreedExtensionDateIsBeyond29And56DaysForSpec() { - when(workingDayIndicator.isWorkingDay(any())).thenReturn(false); - - LocalDate agreedExtension = NOW.with(DayOfWeek.SUNDAY).plusDays(7); - LocalDateTime currentResponseDeadline = NOW.plusDays(7).atTime(16, 0); - when(workingDayIndicator.getNextWorkingDay(any())).thenReturn(currentResponseDeadline.toLocalDate()); - - List errors = validator.specValidateProposedDeadline( - agreedExtension, - currentResponseDeadline, - true - ); - assertThat(errors).contains("Date must be from claim issue date plus a maximum of between 29 and 56 days."); - } -*/ @Test void shouldReturnErrors_whenAgreedExtensionDateIsWeekendForSpec() { when(workingDayIndicator.isWorkingDay(any())).thenReturn(false); diff --git a/src/test/java/uk/gov/hmcts/reform/civil/validation/PaymentDateValidatorTest.java b/src/test/java/uk/gov/hmcts/reform/civil/validation/PaymentDateValidatorTest.java index 91a81a6b95e..729dac7f976 100644 --- a/src/test/java/uk/gov/hmcts/reform/civil/validation/PaymentDateValidatorTest.java +++ b/src/test/java/uk/gov/hmcts/reform/civil/validation/PaymentDateValidatorTest.java @@ -1,21 +1,35 @@ package uk.gov.hmcts.reform.civil.validation; +import org.hibernate.validator.messageinterpolation.ParameterMessageInterpolator; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; import uk.gov.hmcts.reform.civil.model.RespondToClaim; +import javax.validation.Validation; +import javax.validation.Validator; +import javax.validation.ValidatorFactory; import java.time.LocalDate; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -@SpringBootTest(classes = {PaymentDateValidator.class, ValidationAutoConfiguration.class}) +@ExtendWith(MockitoExtension.class) class PaymentDateValidatorTest { - @Autowired - PaymentDateValidator paymentDateValidator; + private PaymentDateValidator paymentDateValidator; + + @BeforeEach + void setUp() { + ValidatorFactory validatorFactory = Validation.byDefaultProvider() + .configure() + .messageInterpolator(new ParameterMessageInterpolator()) + .buildValidatorFactory(); + + Validator validator = validatorFactory.getValidator(); + paymentDateValidator = new PaymentDateValidator(validator); + } @Test void shouldBeValidDate_whenToday() { @@ -36,7 +50,7 @@ void shouldBeValidDate_whenPastDate() { } @Test - void shouldBeValidDate_whenFutureDate() throws NoSuchFieldException { + void shouldBeValidDate_whenFutureDate() { RespondToClaim respondToClaim = RespondToClaim.builder() .whenWasThisAmountPaid(LocalDate.now().plusDays(1)) .build();