Skip to content

Commit ada4d34

Browse files
Added lenient
1 parent 63e5256 commit ada4d34

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

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

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
import static org.junit.jupiter.api.Assertions.assertTrue;
66
import static org.mockito.ArgumentMatchers.any;
77
import static org.mockito.ArgumentMatchers.eq;
8-
import static org.mockito.Mockito.doThrow;
9-
import static org.mockito.Mockito.verify;
10-
import static org.mockito.Mockito.verifyNoInteractions;
11-
import static org.mockito.Mockito.when;
128

9+
import static org.mockito.Mockito.*;
1310
import static uk.nhs.adaptors.gp2gp.common.task.TaskType.GET_GPC_STRUCTURED;
1411

1512
import java.util.concurrent.TimeoutException;
1613

14+
import org.junit.jupiter.api.BeforeEach;
1715
import org.junit.jupiter.api.Test;
1816
import org.junit.jupiter.api.extension.ExtendWith;
1917
import org.mockito.InjectMocks;
@@ -47,9 +45,17 @@ class TaskErrorHandlerTest {
4745
@InjectMocks
4846
private TaskErrorHandler taskErrorHandler;
4947

48+
private boolean skipSetup;
49+
50+
@BeforeEach
51+
void setUp() {
52+
if (!skipSetup) {
53+
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
54+
}
55+
}
56+
5057
@Test
5158
void When_HandleProcessingError_WithEhrRequestException_Expect_ProcessToBeFailedWithCorrectCode() {
52-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
5359
taskErrorHandler.handleProcessingError(new EhrRequestException(TEST_EXCEPTION_MESSAGE), taskDefinition);
5460

5561
verify(processFailureHandlingService).failProcess(
@@ -61,7 +67,6 @@ void When_HandleProcessingError_WithEhrRequestException_Expect_ProcessToBeFailed
6167

6268
@Test
6369
void When_HandleProcessingError_WithEhrValidationException_Expect_ProcessToBeFailedWithCorrectCode() {
64-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
6570
taskErrorHandler.handleProcessingError(new EhrValidationException(TEST_EXCEPTION_MESSAGE), taskDefinition);
6671

6772
verify(processFailureHandlingService).failProcess(
@@ -73,7 +78,6 @@ void When_HandleProcessingError_WithEhrValidationException_Expect_ProcessToBeFai
7378

7479
@Test
7580
void When_HandleProcessingError_WithEhrRequestException_Expect_ReturnValueOfFailService() {
76-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
7781
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
7882
.thenReturn(true, false);
7983

@@ -83,7 +87,6 @@ void When_HandleProcessingError_WithEhrRequestException_Expect_ReturnValueOfFail
8387

8488
@Test
8589
void When_HandleProcessingError_With_EhrExtractException_Expect_ProcessToBeFailedWithCorrectCode() {
86-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
8790
taskErrorHandler.handleProcessingError(new EhrExtractException("Test Exception"), taskDefinition);
8891

8992
verify(processFailureHandlingService).failProcess(
@@ -95,7 +98,6 @@ void When_HandleProcessingError_With_EhrExtractException_Expect_ProcessToBeFaile
9598

9699
@Test
97100
void When_HandleProcessingError_WithEhrExtractException_Expect_ReturnValueOfFailService() {
98-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
99101
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
100102
.thenReturn(true, false);
101103

@@ -105,7 +107,6 @@ void When_HandleProcessingError_WithEhrExtractException_Expect_ReturnValueOfFail
105107

106108
@Test
107109
void When_HandleProcessingError_WithEhrMapperException_Expect_ProcessToBeFailedWithCorrectCode() {
108-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
109110
taskErrorHandler.handleProcessingError(new EhrMapperException(TEST_EXCEPTION_MESSAGE), taskDefinition);
110111

111112
verify(processFailureHandlingService).failProcess(
@@ -117,7 +118,6 @@ void When_HandleProcessingError_WithEhrMapperException_Expect_ProcessToBeFailedW
117118

118119
@Test
119120
void When_HandleProcessingError_WithEhrMapperException_Expect_ReturnValueOfFailService() {
120-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
121121
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
122122
.thenReturn(true, false);
123123

@@ -127,7 +127,6 @@ void When_HandleProcessingError_WithEhrMapperException_Expect_ReturnValueOfFailS
127127

128128
@Test
129129
void When_HandleProcessingError_WithFhirValidationException_Expect_ProcessToBeFailedWithCorrectCode() {
130-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
131130
taskErrorHandler.handleProcessingError(new FhirValidationException(TEST_EXCEPTION_MESSAGE), taskDefinition);
132131

133132
verify(processFailureHandlingService).failProcess(
@@ -139,7 +138,6 @@ void When_HandleProcessingError_WithFhirValidationException_Expect_ProcessToBeFa
139138

140139
@Test
141140
void When_HandleProcessingError_WithFhirValidationException_Expect_ReturnValueOfFailService() {
142-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
143141
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
144142
.thenReturn(true, false);
145143

@@ -149,7 +147,6 @@ void When_HandleProcessingError_WithFhirValidationException_Expect_ReturnValueOf
149147

150148
@Test
151149
void When_HandleProcessingError_WithOtherException_Expect_ProcessToBeFailedWithCorrectCode() {
152-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
153150
taskErrorHandler.handleProcessingError(new Exception(), taskDefinition);
154151

155152
verify(processFailureHandlingService).failProcess(
@@ -161,7 +158,6 @@ void When_HandleProcessingError_WithOtherException_Expect_ProcessToBeFailedWithC
161158

162159
@Test
163160
void When_HandleProcessingError_WithOtherException_Expect_ReturnValueOfFailService() {
164-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
165161
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
166162
.thenReturn(true, false);
167163

@@ -171,7 +167,6 @@ void When_HandleProcessingError_WithOtherException_Expect_ReturnValueOfFailServi
171167

172168
@Test
173169
void When_HandleProcessingError_WithGpConnectException_Expect_ProcessToBeFailedWithCorrectCode() {
174-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
175170
taskErrorHandler.handleProcessingError(new GpConnectException(TEST_EXCEPTION_MESSAGE), taskDefinition);
176171

177172
verify(processFailureHandlingService).failProcess(
@@ -183,7 +178,6 @@ void When_HandleProcessingError_WithGpConnectException_Expect_ProcessToBeFailedW
183178

184179
@Test
185180
void When_HandleProcessingError_WithGpConnectException_Expect_ReturnValueOfFailService() {
186-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
187181
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
188182
.thenReturn(true, false);
189183

@@ -193,7 +187,6 @@ void When_HandleProcessingError_WithGpConnectException_Expect_ReturnValueOfFailS
193187

194188
@Test
195189
void When_HandleProcessingError_WithGpConnectInvalidException_Expect_ProcessToBeFailedWithCorrectCode() {
196-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
197190
taskErrorHandler.handleProcessingError(new GpConnectInvalidException(TEST_EXCEPTION_MESSAGE), taskDefinition);
198191

199192
verify(processFailureHandlingService).failProcess(
@@ -205,7 +198,6 @@ void When_HandleProcessingError_WithGpConnectInvalidException_Expect_ProcessToBe
205198

206199
@Test
207200
void When_HandleProcessingError_WithGpConnectInvalidException_Expect_ReturnValueOfFailService() {
208-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
209201
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
210202
.thenReturn(true, false);
211203

@@ -215,7 +207,6 @@ void When_HandleProcessingError_WithGpConnectInvalidException_Expect_ReturnValue
215207

216208
@Test
217209
void When_HandleProcessingError_WithGpConnectGpConnectNotFoundException_Expect_ProcessToBeFailedWithCorrectCode() {
218-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
219210
taskErrorHandler.handleProcessingError(new GpConnectNotFoundException(TEST_EXCEPTION_MESSAGE), taskDefinition);
220211

221212
verify(processFailureHandlingService).failProcess(
@@ -227,7 +218,6 @@ void When_HandleProcessingError_WithGpConnectGpConnectNotFoundException_Expect_P
227218

228219
@Test
229220
void When_HandleProcessingError_WithGpConnectNotFoundException_Expect_ReturnValueOfFailService() {
230-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
231221
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
232222
.thenReturn(true, false);
233223

@@ -237,7 +227,6 @@ void When_HandleProcessingError_WithGpConnectNotFoundException_Expect_ReturnValu
237227

238228
@Test
239229
void When_HandleProcessingError_WithMaximumExternalAttachmentsException_Expect_ProcessToBeFailedWithCorrectCode() {
240-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
241230
taskErrorHandler.handleProcessingError(new MaximumExternalAttachmentsException(TEST_EXCEPTION_MESSAGE), taskDefinition);
242231

243232
verify(processFailureHandlingService).failProcess(
@@ -249,7 +238,6 @@ void When_HandleProcessingError_WithMaximumExternalAttachmentsException_Expect_P
249238

250239
@Test
251240
void When_HandleProcessingError_WithMaximumExternalAttachmentsException_Expect_ReturnValueOfFailService() {
252-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
253241
when(processFailureHandlingService.failProcess(any(), any(), any(), any()))
254242
.thenReturn(true, false);
255243

@@ -263,14 +251,14 @@ void When_HandleProcessingError_WithMaximumExternalAttachmentsException_Expect_R
263251

264252
@Test
265253
void When_HandleGeneralProcessingError_WithNullParameter_Expect_ProcessIsNotFailed() {
254+
lenient().when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
266255
taskErrorHandler.handleProcessingError(new RuntimeException(), null);
267256

268257
verifyNoInteractions(processFailureHandlingService);
269258
}
270259
@Test
271260
@SneakyThrows
272261
void When_FailProcessThrowsException_Expect_ExceptionToBeRethrown() {
273-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
274262
var failureHandlingException = new RuntimeException("failure handler exception");
275263
doThrow(failureHandlingException).when(processFailureHandlingService).failProcess(
276264
any(), any(), any(), any());
@@ -283,7 +271,6 @@ void When_FailProcessThrowsException_Expect_ExceptionToBeRethrown() {
283271
@Test
284272
@SneakyThrows
285273
void When_HandleProcessingError_WithGpcServerErrorExceptionAsRootCause_Expect_FailedWithCorrectCode() {
286-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
287274
Throwable testException = new RetryLimitReachedException("test", new GpcServerErrorException("exception"));
288275

289276
taskErrorHandler.handleProcessingError(testException, taskDefinition);
@@ -298,7 +285,6 @@ void When_HandleProcessingError_WithGpcServerErrorExceptionAsRootCause_Expect_Fa
298285
@Test
299286
@SneakyThrows
300287
void When_HandleProcessingError_WithTimeoutExceptionAsRootCause_Expect_FailedWithCorrectCode() {
301-
when(taskDefinition.getTaskType()).thenReturn(GET_GPC_STRUCTURED);
302288
Throwable testException = new RetryLimitReachedException("test", new TimeoutException("exception"));
303289

304290
taskErrorHandler.handleProcessingError(testException, taskDefinition);

0 commit comments

Comments
 (0)