66import static org .mockito .ArgumentMatchers .any ;
77import static org .mockito .ArgumentMatchers .eq ;
88import static org .mockito .Mockito .doThrow ;
9- import static org .mockito .Mockito .lenient ;
109import static org .mockito .Mockito .never ;
1110import static org .mockito .Mockito .verify ;
1211import static org .mockito .Mockito .verifyNoInteractions ;
@@ -68,6 +67,7 @@ class TaskHandlerTest {
6867 @ Test
6968 @ SneakyThrows
7069 void When_TaskHandled_Expect_TaskExecuted () {
70+ when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
7171 setUpContinueMessage ();
7272
7373 var result = taskHandler .handle (message );
@@ -129,6 +129,7 @@ void When_CannotRetrieveTaskDefinition_Expect_MessageProcessingToBeAborted() {
129129 @ Test
130130 @ SneakyThrows
131131 void When_NackTaskFails_Expect_ProcessNotToBeFailed () {
132+ when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
132133 setupAckMessage (SendAcknowledgementTaskDefinition .NACK_TYPE_CODE );
133134 Exception exception = new RuntimeException (TEST_EXCEPTION_MESSAGE );
134135 doThrow (exception ).when (taskExecutor ).execute (any ());
@@ -144,6 +145,7 @@ void When_NackTaskFails_Expect_ProcessNotToBeFailed() {
144145 @ Test
145146 @ SneakyThrows
146147 void When_NonNackTaskFails_Expect_ProcessToBeFailed () {
148+ when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
147149 setUpContinueMessage ();
148150 Exception exception = new RuntimeException (TEST_EXCEPTION_MESSAGE );
149151 doThrow (exception ).when (taskExecutor ).execute (any ());
@@ -157,6 +159,7 @@ void When_NonNackTaskFails_Expect_ProcessToBeFailed() {
157159 @ Test
158160 @ SneakyThrows
159161 void When_OtherTaskFails_Expect_ResultFromErrorHandlerToBeReturned () {
162+ when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
160163 setUpContinueMessage ();
161164 Exception exception = new RuntimeException (TEST_EXCEPTION_MESSAGE );
162165 doThrow (exception ).when (taskExecutor ).execute (any ());
@@ -171,6 +174,7 @@ void When_OtherTaskFails_Expect_ResultFromErrorHandlerToBeReturned() {
171174 @ Test
172175 @ SneakyThrows
173176 void When_NonAckTaskFails_Expect_ResultFromErrorHandlerToBeReturned () {
177+ when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
174178 setupAckMessage (SendAcknowledgementTaskDefinition .ACK_TYPE_CODE );
175179 Exception exception = new RuntimeException (TEST_EXCEPTION_MESSAGE );
176180 doThrow (exception ).when (taskExecutor ).execute (any ());
@@ -186,6 +190,7 @@ void When_NonAckTaskFails_Expect_ResultFromErrorHandlerToBeReturned() {
186190 @ Test
187191 @ SneakyThrows
188192 void When_ErrorHandlerThrowsException_Expect_ExceptionToBeRethrown () {
193+ when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
189194 setUpContinueMessage ();
190195 Exception taskException = new RuntimeException ("task executor exception" );
191196 doThrow (taskException ).when (taskExecutor ).execute (any ());
@@ -214,6 +219,7 @@ void When_ProcessHasAlreadyFailed_Expect_NonNackTaskNotToBeExecuted() {
214219 @ Test
215220 @ SneakyThrows
216221 void When_ProcessHasAlreadyFailed_Expect_NackTaskToStillBeExecuted () {
222+ when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
217223 setupAckMessage (SendAcknowledgementTaskDefinition .NACK_TYPE_CODE );
218224 when (processFailureHandlingService .hasProcessFailed (any ())).thenReturn (true );
219225
@@ -227,6 +233,7 @@ void When_ProcessHasAlreadyFailed_Expect_NackTaskToStillBeExecuted() {
227233 @ Test
228234 @ SneakyThrows
229235 void When_Handle_WithExecuteThrows_MhsConnectionException_Expect_ExceptionThrown () {
236+ when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
230237 setUpContinueMessage ();
231238 doThrow (new MhsConnectionException ("test exception" )).when (taskExecutor ).execute (any ());
232239
@@ -245,6 +252,7 @@ void When_Handle_WithDataAccessResourceFailureException_Expect_ExceptionThrown()
245252 @ Test
246253 @ SneakyThrows
247254 void When_Handle_WithOtherRuntimeException_Expect_ProcessFailed () {
255+ when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
248256 setUpContinueMessage ();
249257 Exception exception = new RuntimeException (TEST_EXCEPTION_MESSAGE );
250258 doThrow (exception ).when (taskExecutor ).execute (any ());
@@ -256,7 +264,7 @@ void When_Handle_WithOtherRuntimeException_Expect_ProcessFailed() {
256264 }
257265
258266 private void setupAckMessage (String typeCode ) throws JMSException {
259- lenient (). when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
267+ when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
260268 when (message .getStringProperty (TASK_TYPE_HEADER_NAME )).thenReturn ("taskType" );
261269 when (message .getBody (String .class )).thenReturn ("body" );
262270 sendAcknowledgementTaskDefinition = SendAcknowledgementTaskDefinition .builder ()
@@ -267,7 +275,6 @@ private void setupAckMessage(String typeCode) throws JMSException {
267275 }
268276
269277 private void setUpContinueMessage () throws JMSException {
270- lenient ().when (taskExecutorFactory .getTaskExecutor (any ())).thenReturn (taskExecutor );
271278 when (message .getStringProperty (TASK_TYPE_HEADER_NAME )).thenReturn ("taskType" );
272279 when (message .getBody (String .class )).thenReturn ("body" );
273280 taskDefinition = SendDocumentTaskDefinition .builder ().conversationId (CONVERSATION_ID ).build ();
0 commit comments