2323import org .mockito .Mock ;
2424import org .mockito .MockitoAnnotations ;
2525
26+ import java .time .Duration ;
2627import java .util .Optional ;
2728import java .util .concurrent .CancellationException ;
2829import java .util .concurrent .ExecutorService ;
@@ -39,7 +40,7 @@ class BlockchainAdapterServiceTests {
3940 static final String CHAIN_TASK_ID = "CHAIN_TASK_ID" ;
4041 static final String LINK = "link" ;
4142 static final String CALLBACK = "callback" ;
42- static final int PERIOD = 10 ;
43+ static final Duration PERIOD = Duration . ofMillis ( 10 ) ;
4344 static final int MAX_ATTEMPTS = 3 ;
4445
4546 @ Mock
@@ -134,7 +135,7 @@ void isCommandCompletedTrueWhenSuccess() {
134135 .thenReturn (CommandStatus .SUCCESS );
135136
136137 Optional <Boolean > commandCompleted = blockchainAdapterService .isCommandCompleted (
137- blockchainAdapterClient ::getStatusForInitializeTaskRequest , CHAIN_TASK_ID , PERIOD , MAX_ATTEMPTS );
138+ blockchainAdapterClient ::getStatusForInitializeTaskRequest , CHAIN_TASK_ID , MAX_ATTEMPTS );
138139 assertEquals (Optional .of (true ), commandCompleted );
139140 }
140141
@@ -146,7 +147,7 @@ void isCommandCompletedFalseWhenFailure() {
146147 .thenReturn (CommandStatus .FAILURE );
147148
148149 Optional <Boolean > commandCompleted = blockchainAdapterService .isCommandCompleted (
149- blockchainAdapterClient ::getStatusForInitializeTaskRequest , CHAIN_TASK_ID , PERIOD , MAX_ATTEMPTS );
150+ blockchainAdapterClient ::getStatusForInitializeTaskRequest , CHAIN_TASK_ID , MAX_ATTEMPTS );
150151 assertEquals (Optional .of (false ), commandCompleted );
151152 }
152153
@@ -155,7 +156,7 @@ void isCommandCompletedFalseWhenMaxAttempts() {
155156 when (blockchainAdapterClient .getStatusForInitializeTaskRequest (CHAIN_TASK_ID ))
156157 .thenReturn (CommandStatus .PROCESSING );
157158 Optional <Boolean > commandCompleted = blockchainAdapterService .isCommandCompleted (
158- blockchainAdapterClient ::getStatusForInitializeTaskRequest , CHAIN_TASK_ID , PERIOD , MAX_ATTEMPTS );
159+ blockchainAdapterClient ::getStatusForInitializeTaskRequest , CHAIN_TASK_ID , MAX_ATTEMPTS );
159160 assertEquals (Optional .empty (), commandCompleted );
160161 }
161162
@@ -164,18 +165,20 @@ void isCommandCompletedFalseWhenFeignException() {
164165 when (blockchainAdapterClient .getStatusForFinalizeTaskRequest (CHAIN_TASK_ID ))
165166 .thenThrow (FeignException .class );
166167 Optional <Boolean > commandCompleted = blockchainAdapterService .isCommandCompleted (
167- blockchainAdapterClient ::getStatusForFinalizeTaskRequest , CHAIN_TASK_ID , PERIOD , MAX_ATTEMPTS );
168+ blockchainAdapterClient ::getStatusForFinalizeTaskRequest , CHAIN_TASK_ID , MAX_ATTEMPTS );
168169 assertEquals (Optional .empty (), commandCompleted );
169170 }
170171
171172 @ Test
172173 void isCommandCompletedFalseWhenInterrupted () throws InterruptedException {
174+ blockchainAdapterService = new BlockchainAdapterService (blockchainAdapterClient , Duration .ofSeconds (5 ), MAX_ATTEMPTS );
175+
173176 when (blockchainAdapterClient .getStatusForFinalizeTaskRequest (CHAIN_TASK_ID ))
174177 .thenReturn (CommandStatus .PROCESSING );
175178 ExecutorService service = Executors .newSingleThreadExecutor ();
176179 Future <?> future = service .submit (() ->
177180 blockchainAdapterService .isCommandCompleted (blockchainAdapterClient ::getStatusForFinalizeTaskRequest ,
178- CHAIN_TASK_ID , 5000L , MAX_ATTEMPTS ));
181+ CHAIN_TASK_ID , MAX_ATTEMPTS ));
179182 Thread .sleep (1000L );
180183 future .cancel (true );
181184 assertThrows (CancellationException .class , future ::get );
0 commit comments