Skip to content

Commit 515d505

Browse files
remove
1 parent 12a1114 commit 515d505

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

service/src/test/java/uk/nhs/adaptors/gp2gp/common/task/TaskErrorHandlerTest.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
1414

1515
import java.util.concurrent.TimeoutException;
1616

17-
import org.junit.jupiter.api.BeforeEach;
1817
import org.junit.jupiter.api.Test;
1918
import org.junit.jupiter.api.extension.ExtendWith;
2019
import org.mockito.InjectMocks;
2120
import org.mockito.Mock;
2221
import org.mockito.junit.jupiter.MockitoExtension;
23-
import org.mockito.junit.jupiter.MockitoSettings;
24-
import org.mockito.quality.Strictness;
2522

2623
import lombok.SneakyThrows;
2724
import uk.nhs.adaptors.gp2gp.common.exception.FhirValidationException;
@@ -50,13 +47,9 @@ class TaskErrorHandlerTest {
5047
@InjectMocks
5148
private TaskErrorHandler taskErrorHandler;
5249

53-
@BeforeEach
54-
void setup() {
55-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
56-
}
57-
5850
@Test
5951
void When_HandleProcessingError_WithEhrRequestException_Expect_ProcessToBeFailedWithCorrectCode() {
52+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
6053
taskErrorHandler.handleProcessingError(new EhrRequestException(TEST_EXCEPTION_MESSAGE), taskDefinition);
6154

6255
verify(processFailureHandlingService).failProcess(
@@ -68,6 +61,7 @@ void When_HandleProcessingError_WithEhrRequestException_Expect_ProcessToBeFailed
6861

6962
@Test
7063
void When_HandleProcessingError_WithEhrValidationException_Expect_ProcessToBeFailedWithCorrectCode() {
64+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
7165
taskErrorHandler.handleProcessingError(new EhrValidationException(TEST_EXCEPTION_MESSAGE), taskDefinition);
7266

7367
verify(processFailureHandlingService).failProcess(
@@ -79,6 +73,7 @@ void When_HandleProcessingError_WithEhrValidationException_Expect_ProcessToBeFai
7973

8074
@Test
8175
void When_HandleProcessingError_WithEhrRequestException_Expect_ReturnValueOfFailService() {
76+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
8277
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
8378
.thenReturn(true, false);
8479

@@ -88,6 +83,7 @@ void When_HandleProcessingError_WithEhrRequestException_Expect_ReturnValueOfFail
8883

8984
@Test
9085
void When_HandleProcessingError_With_EhrExtractException_Expect_ProcessToBeFailedWithCorrectCode() {
86+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
9187
taskErrorHandler.handleProcessingError(new EhrExtractException("Test Exception"), taskDefinition);
9288

9389
verify(processFailureHandlingService).failProcess(
@@ -99,6 +95,7 @@ void When_HandleProcessingError_With_EhrExtractException_Expect_ProcessToBeFaile
9995

10096
@Test
10197
void When_HandleProcessingError_WithEhrExtractException_Expect_ReturnValueOfFailService() {
98+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
10299
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
103100
.thenReturn(true, false);
104101

@@ -108,6 +105,7 @@ void When_HandleProcessingError_WithEhrExtractException_Expect_ReturnValueOfFail
108105

109106
@Test
110107
void When_HandleProcessingError_WithEhrMapperException_Expect_ProcessToBeFailedWithCorrectCode() {
108+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
111109
taskErrorHandler.handleProcessingError(new EhrMapperException(TEST_EXCEPTION_MESSAGE), taskDefinition);
112110

113111
verify(processFailureHandlingService).failProcess(
@@ -119,6 +117,7 @@ void When_HandleProcessingError_WithEhrMapperException_Expect_ProcessToBeFailedW
119117

120118
@Test
121119
void When_HandleProcessingError_WithEhrMapperException_Expect_ReturnValueOfFailService() {
120+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
122121
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
123122
.thenReturn(true, false);
124123

@@ -128,6 +127,7 @@ void When_HandleProcessingError_WithEhrMapperException_Expect_ReturnValueOfFailS
128127

129128
@Test
130129
void When_HandleProcessingError_WithFhirValidationException_Expect_ProcessToBeFailedWithCorrectCode() {
130+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
131131
taskErrorHandler.handleProcessingError(new FhirValidationException(TEST_EXCEPTION_MESSAGE), taskDefinition);
132132

133133
verify(processFailureHandlingService).failProcess(
@@ -139,6 +139,7 @@ void When_HandleProcessingError_WithFhirValidationException_Expect_ProcessToBeFa
139139

140140
@Test
141141
void When_HandleProcessingError_WithFhirValidationException_Expect_ReturnValueOfFailService() {
142+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
142143
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
143144
.thenReturn(true, false);
144145

@@ -148,6 +149,7 @@ void When_HandleProcessingError_WithFhirValidationException_Expect_ReturnValueOf
148149

149150
@Test
150151
void When_HandleProcessingError_WithOtherException_Expect_ProcessToBeFailedWithCorrectCode() {
152+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
151153
taskErrorHandler.handleProcessingError(new Exception(), taskDefinition);
152154

153155
verify(processFailureHandlingService).failProcess(
@@ -159,6 +161,7 @@ void When_HandleProcessingError_WithOtherException_Expect_ProcessToBeFailedWithC
159161

160162
@Test
161163
void When_HandleProcessingError_WithOtherException_Expect_ReturnValueOfFailService() {
164+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
162165
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
163166
.thenReturn(true, false);
164167

@@ -168,6 +171,7 @@ void When_HandleProcessingError_WithOtherException_Expect_ReturnValueOfFailServi
168171

169172
@Test
170173
void When_HandleProcessingError_WithGpConnectException_Expect_ProcessToBeFailedWithCorrectCode() {
174+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
171175
taskErrorHandler.handleProcessingError(new GpConnectException(TEST_EXCEPTION_MESSAGE), taskDefinition);
172176

173177
verify(processFailureHandlingService).failProcess(
@@ -179,6 +183,7 @@ void When_HandleProcessingError_WithGpConnectException_Expect_ProcessToBeFailedW
179183

180184
@Test
181185
void When_HandleProcessingError_WithGpConnectException_Expect_ReturnValueOfFailService() {
186+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
182187
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
183188
.thenReturn(true, false);
184189

@@ -188,6 +193,7 @@ void When_HandleProcessingError_WithGpConnectException_Expect_ReturnValueOfFailS
188193

189194
@Test
190195
void When_HandleProcessingError_WithGpConnectInvalidException_Expect_ProcessToBeFailedWithCorrectCode() {
196+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
191197
taskErrorHandler.handleProcessingError(new GpConnectInvalidException(TEST_EXCEPTION_MESSAGE), taskDefinition);
192198

193199
verify(processFailureHandlingService).failProcess(
@@ -199,6 +205,7 @@ void When_HandleProcessingError_WithGpConnectInvalidException_Expect_ProcessToBe
199205

200206
@Test
201207
void When_HandleProcessingError_WithGpConnectInvalidException_Expect_ReturnValueOfFailService() {
208+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
202209
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
203210
.thenReturn(true, false);
204211

@@ -208,6 +215,7 @@ void When_HandleProcessingError_WithGpConnectInvalidException_Expect_ReturnValue
208215

209216
@Test
210217
void When_HandleProcessingError_WithGpConnectGpConnectNotFoundException_Expect_ProcessToBeFailedWithCorrectCode() {
218+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
211219
taskErrorHandler.handleProcessingError(new GpConnectNotFoundException(TEST_EXCEPTION_MESSAGE), taskDefinition);
212220

213221
verify(processFailureHandlingService).failProcess(
@@ -219,6 +227,7 @@ void When_HandleProcessingError_WithGpConnectGpConnectNotFoundException_Expect_P
219227

220228
@Test
221229
void When_HandleProcessingError_WithGpConnectNotFoundException_Expect_ReturnValueOfFailService() {
230+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
222231
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
223232
.thenReturn(true, false);
224233

@@ -228,6 +237,7 @@ void When_HandleProcessingError_WithGpConnectNotFoundException_Expect_ReturnValu
228237

229238
@Test
230239
void When_HandleProcessingError_WithMaximumExternalAttachmentsException_Expect_ProcessToBeFailedWithCorrectCode() {
240+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
231241
taskErrorHandler.handleProcessingError(new MaximumExternalAttachmentsException(TEST_EXCEPTION_MESSAGE), taskDefinition);
232242

233243
verify(processFailureHandlingService).failProcess(
@@ -239,6 +249,7 @@ void When_HandleProcessingError_WithMaximumExternalAttachmentsException_Expect_P
239249

240250
@Test
241251
void When_HandleProcessingError_WithMaximumExternalAttachmentsException_Expect_ReturnValueOfFailService() {
252+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
242253
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
243254
.thenReturn(true, false);
244255

@@ -251,7 +262,6 @@ void When_HandleProcessingError_WithMaximumExternalAttachmentsException_Expect_R
251262
}
252263

253264
@Test
254-
@MockitoSettings(strictness = Strictness.LENIENT)
255265
void When_HandleGeneralProcessingError_WithNullParameter_Expect_ProcessIsNotFailed() {
256266
taskErrorHandler.handleProcessingError(new RuntimeException(), null);
257267

@@ -260,6 +270,7 @@ void When_HandleGeneralProcessingError_WithNullParameter_Expect_ProcessIsNotFail
260270
@Test
261271
@SneakyThrows
262272
void When_FailProcessThrowsException_Expect_ExceptionToBeRethrown() {
273+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
263274
var failureHandlingException = new RuntimeException("failure handler exception");
264275
doThrow(failureHandlingException).when(processFailureHandlingService).failProcess(
265276
any(), any(), any(), any());
@@ -272,6 +283,7 @@ void When_FailProcessThrowsException_Expect_ExceptionToBeRethrown() {
272283
@Test
273284
@SneakyThrows
274285
void When_HandleProcessingError_WithGpcServerErrorExceptionAsRootCause_Expect_FailedWithCorrectCode() {
286+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
275287
Throwable testException = new RetryLimitReachedException("test", new GpcServerErrorException("exception"));
276288

277289
taskErrorHandler.handleProcessingError(testException, taskDefinition);
@@ -286,6 +298,7 @@ void When_HandleProcessingError_WithGpcServerErrorExceptionAsRootCause_Expect_Fa
286298
@Test
287299
@SneakyThrows
288300
void When_HandleProcessingError_WithTimeoutExceptionAsRootCause_Expect_FailedWithCorrectCode() {
301+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
289302
Throwable testException = new RetryLimitReachedException("test", new TimeoutException("exception"));
290303

291304
taskErrorHandler.handleProcessingError(testException, taskDefinition);

0 commit comments

Comments
 (0)