From 15bb2fdd730ef9deb602a18f301bc760e31c62f3 Mon Sep 17 00:00:00 2001 From: mariopaniccia Date: Mon, 4 Dec 2023 16:30:29 +0000 Subject: [PATCH 1/4] example naming of some tests to the proposed given when then style --- .../TranscriptionControllerGetTranscriptionTest.java | 4 ++-- ...onControllerUpdateTranscriptionApprovedIntTest.java | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java index c6b60a10f53..b0187e01d1f 100644 --- a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java @@ -63,7 +63,7 @@ void setUp() { } @Test - void getTranscription() throws Exception { + void givenExistingTranscription_whenGetTranscriptionIsRequested_thenTheDetailsAreReturned() throws Exception { HearingEntity hearingEntity = dartsDatabase.getHearingRepository().findAll().get(0); TranscriptionEntity transcription = dartsDatabase.getTranscriptionStub().createTranscription(hearingEntity); transcription.setCreatedDateTime(OffsetDateTime.of(2023, 6, 20, 10, 0, 0, 0, ZoneOffset.UTC)); @@ -117,7 +117,7 @@ private void addCommentToWorkflow(TranscriptionWorkflowEntity workflowEntity, St } @Test - void getTranscriptionNotFound() throws Exception { + void givenRequestedTranscriptionDoesNotExist_whenGetTranscriptionIsRequested_thenTranscriptionNotFoundErrorIsReturned() throws Exception { MockHttpServletRequestBuilder requestBuilder = get(ENDPOINT_URL_TRANSCRIPTION, -999); MvcResult response = mockMvc.perform(requestBuilder).andExpect(status().isNotFound()).andReturn(); String actualResponse = response.getResponse().getContentAsString(); diff --git a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java index de196d09800..1888fb5e0cd 100644 --- a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java @@ -95,7 +95,7 @@ void beforeEach() { } @Test - void updateTranscriptionApprovedWithoutComment() throws Exception { + void givenAwaitingAuthorisationTranscription_whenApproveWithoutCommentIsRequested_thenNewStatusIsApprovedAndHasNoComment() throws Exception { TranscriptionEntity existingTranscription = dartsDatabase.getTranscriptionRepository().findById( transcriptionId).orElseThrow(); @@ -145,7 +145,7 @@ void updateTranscriptionApprovedWithoutComment() throws Exception { } @Test - void updateTranscriptionApprovedWithComment() throws Exception { + void givenAwaitingAuthorisationTranscription_whenApproveWithCommentIsRequested_thenNewStatusIsApprovedAndHasComment() throws Exception { UpdateTranscription updateTranscription = new UpdateTranscription(); updateTranscription.setTranscriptionStatusId(APPROVED.getId()); @@ -190,7 +190,9 @@ void updateTranscriptionApprovedWithComment() throws Exception { } @Test - void updateTranscriptionShouldReturnTranscriptionNotFoundError() throws Exception { +// alternative naming if we want to allow empty given +// void given_whenUpdateTranscriptionForNonExistingTranscriptionIsRequested_thenTranscriptionNotFoundErrorIsReturned() throws Exception { + void givenRequestedTranscriptionDoesNotExist_whenUpdateTranscriptionIsRequested_thenTranscriptionNotFoundErrorIsReturned() throws Exception { UpdateTranscription updateTranscription = new UpdateTranscription(); updateTranscription.setTranscriptionStatusId(APPROVED.getId()); updateTranscription.setWorkflowComment("APPROVED"); @@ -216,7 +218,7 @@ void updateTranscriptionShouldReturnTranscriptionNotFoundError() throws Exceptio } @Test - void updateTranscriptionShouldReturnTranscriptionWorkflowActionInvalidError() throws Exception { + void givenExistingTranscription_whenUpdateToInvalidStatusIsRequested_thenTranscriptionWorkflowActionInvalidErrorIsReturned() throws Exception { UpdateTranscription updateTranscription = new UpdateTranscription(); updateTranscription.setTranscriptionStatusId(WITH_TRANSCRIBER.getId()); updateTranscription.setWorkflowComment("APPROVED"); From 0106d9e689bfa568dc29adfd9df01d7747734bed Mon Sep 17 00:00:00 2001 From: mariopaniccia Date: Tue, 5 Dec 2023 12:50:00 +0000 Subject: [PATCH 2/4] simplified some test names by omitting the given clause when not needed simplified some test names by omitting the given clause when not needed --- .../TranscriptionControllerGetTranscriptionTest.java | 2 +- ...scriptionControllerUpdateTranscriptionApprovedIntTest.java | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java index b0187e01d1f..975a7a957d4 100644 --- a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java @@ -117,7 +117,7 @@ private void addCommentToWorkflow(TranscriptionWorkflowEntity workflowEntity, St } @Test - void givenRequestedTranscriptionDoesNotExist_whenGetTranscriptionIsRequested_thenTranscriptionNotFoundErrorIsReturned() throws Exception { + void whenGetTranscriptionForNonExistingTranscriptionIsRequested_thenTranscriptionNotFoundErrorIsReturned() throws Exception { MockHttpServletRequestBuilder requestBuilder = get(ENDPOINT_URL_TRANSCRIPTION, -999); MvcResult response = mockMvc.perform(requestBuilder).andExpect(status().isNotFound()).andReturn(); String actualResponse = response.getResponse().getContentAsString(); diff --git a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java index 1888fb5e0cd..2d61e8720d3 100644 --- a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java @@ -190,9 +190,7 @@ void givenAwaitingAuthorisationTranscription_whenApproveWithCommentIsRequested_t } @Test -// alternative naming if we want to allow empty given -// void given_whenUpdateTranscriptionForNonExistingTranscriptionIsRequested_thenTranscriptionNotFoundErrorIsReturned() throws Exception { - void givenRequestedTranscriptionDoesNotExist_whenUpdateTranscriptionIsRequested_thenTranscriptionNotFoundErrorIsReturned() throws Exception { + void whenUpdateTranscriptionForNonExistingTranscriptionIsRequested_thenTranscriptionNotFoundErrorIsReturned() throws Exception { UpdateTranscription updateTranscription = new UpdateTranscription(); updateTranscription.setTranscriptionStatusId(APPROVED.getId()); updateTranscription.setWorkflowComment("APPROVED"); From 710a922956ca47145d057eecece43eef3e9b2423 Mon Sep 17 00:00:00 2001 From: mariopaniccia Date: Tue, 5 Dec 2023 15:13:12 +0000 Subject: [PATCH 3/4] renamed some unit tests --- .../audio/component/impl/AddAudioRequestMapperImplTest.java | 2 +- .../darts/event/service/impl/EventDispatcherImplTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/uk/gov/hmcts/darts/audio/component/impl/AddAudioRequestMapperImplTest.java b/src/test/java/uk/gov/hmcts/darts/audio/component/impl/AddAudioRequestMapperImplTest.java index dc8e9faa5be..5f25b4d7892 100644 --- a/src/test/java/uk/gov/hmcts/darts/audio/component/impl/AddAudioRequestMapperImplTest.java +++ b/src/test/java/uk/gov/hmcts/darts/audio/component/impl/AddAudioRequestMapperImplTest.java @@ -31,7 +31,7 @@ void setUp() { } @Test - void testMapToMedia() { + void givenCourtroomExistsOrCreated_whenMapCourtroomAudioMetadataToMediaIsRequested_thenMetadataIsSuccessfullyMapped() { CourthouseEntity courthouse = new CourthouseEntity(); courthouse.setCourthouseName("SWANSEA"); diff --git a/src/test/java/uk/gov/hmcts/darts/event/service/impl/EventDispatcherImplTest.java b/src/test/java/uk/gov/hmcts/darts/event/service/impl/EventDispatcherImplTest.java index 252b1d126f2..7d147731ed0 100644 --- a/src/test/java/uk/gov/hmcts/darts/event/service/impl/EventDispatcherImplTest.java +++ b/src/test/java/uk/gov/hmcts/darts/event/service/impl/EventDispatcherImplTest.java @@ -28,7 +28,7 @@ class EventDispatcherImplTest { EventHandlerRepository eventHandlerRepository; @Test - void receiveWithNoHandlers() { + void givenMatchingEventHandlerOnDatabaseDoesNotExist_whenReceiveEventIsRequested_thenErrorIsReturned() { List eventHandlers = new ArrayList<>(); when(eventHandlerRepository.findByTypeAndSubType(anyString(), anyString())).thenReturn(Collections.emptyList()); EventDispatcherImpl eventDispatcher = new EventDispatcherImpl(eventHandlers, eventHandlerRepository); @@ -47,7 +47,7 @@ void receiveWithNoHandlers() { } @Test - void receiveWithOneHandlers() { + void givenMatchingEventHandlerExists_whenReceiveEventIsRequested_thenEventIsSuccessfullyReceived() { EventHandlerEntity eventHandlerEntity = new EventHandlerEntity(); when(eventHandlerRepository.findByTypeAndSubType(anyString(), anyString())).thenReturn(List.of(eventHandlerEntity)); From 64c89660410976d5cc91d9cadb5bf8af81ba89f4 Mon Sep 17 00:00:00 2001 From: mariopaniccia Date: Tue, 5 Dec 2023 15:20:00 +0000 Subject: [PATCH 4/4] made some test names less specific as per code review comments --- .../TranscriptionControllerGetTranscriptionTest.java | 4 ++-- ...scriptionControllerUpdateTranscriptionApprovedIntTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java index 975a7a957d4..189d7256194 100644 --- a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerGetTranscriptionTest.java @@ -63,7 +63,7 @@ void setUp() { } @Test - void givenExistingTranscription_whenGetTranscriptionIsRequested_thenTheDetailsAreReturned() throws Exception { + void givenExistingTranscription_whenGetTranscriptionDetailsIsRequested_thenDetailsAreReturned() throws Exception { HearingEntity hearingEntity = dartsDatabase.getHearingRepository().findAll().get(0); TranscriptionEntity transcription = dartsDatabase.getTranscriptionStub().createTranscription(hearingEntity); transcription.setCreatedDateTime(OffsetDateTime.of(2023, 6, 20, 10, 0, 0, 0, ZoneOffset.UTC)); @@ -117,7 +117,7 @@ private void addCommentToWorkflow(TranscriptionWorkflowEntity workflowEntity, St } @Test - void whenGetTranscriptionForNonExistingTranscriptionIsRequested_thenTranscriptionNotFoundErrorIsReturned() throws Exception { + void whenGetTranscriptionDetailsForNonExistingTranscriptionIsRequested_thenErrorIsReturned() throws Exception { MockHttpServletRequestBuilder requestBuilder = get(ENDPOINT_URL_TRANSCRIPTION, -999); MvcResult response = mockMvc.perform(requestBuilder).andExpect(status().isNotFound()).andReturn(); String actualResponse = response.getResponse().getContentAsString(); diff --git a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java index 2d61e8720d3..cb62d7959a9 100644 --- a/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/darts/transcriptions/controller/TranscriptionControllerUpdateTranscriptionApprovedIntTest.java @@ -190,7 +190,7 @@ void givenAwaitingAuthorisationTranscription_whenApproveWithCommentIsRequested_t } @Test - void whenUpdateTranscriptionForNonExistingTranscriptionIsRequested_thenTranscriptionNotFoundErrorIsReturned() throws Exception { + void whenUpdateTranscriptionForNonExistingTranscriptionIsRequested_thenErrorIsReturned() throws Exception { UpdateTranscription updateTranscription = new UpdateTranscription(); updateTranscription.setTranscriptionStatusId(APPROVED.getId()); updateTranscription.setWorkflowComment("APPROVED"); @@ -216,7 +216,7 @@ void whenUpdateTranscriptionForNonExistingTranscriptionIsRequested_thenTranscrip } @Test - void givenExistingTranscription_whenUpdateToInvalidStatusIsRequested_thenTranscriptionWorkflowActionInvalidErrorIsReturned() throws Exception { + void givenExistingTranscription_whenUpdateToInvalidStatusIsRequested_thenErrorIsReturned() throws Exception { UpdateTranscription updateTranscription = new UpdateTranscription(); updateTranscription.setTranscriptionStatusId(WITH_TRANSCRIBER.getId()); updateTranscription.setWorkflowComment("APPROVED");