3030import io .vavr .control .Either ;
3131import org .junit .jupiter .api .BeforeEach ;
3232import org .junit .jupiter .api .Test ;
33+ import org .junit .jupiter .api .extension .ExtendWith ;
3334import org .junit .jupiter .params .ParameterizedTest ;
3435import org .junit .jupiter .params .provider .ValueSource ;
3536import org .mockito .ArgumentCaptor ;
3637import org .mockito .Mock ;
3738import org .mockito .Mockito ;
38- import org .mockito .MockitoAnnotations ;
39+ import org .mockito .junit . jupiter . MockitoExtension ;
3940import org .springframework .beans .factory .annotation .Autowired ;
4041import org .springframework .boot .test .autoconfigure .data .mongo .DataMongoTest ;
4142import org .springframework .context .ApplicationEventPublisher ;
6263
6364@ DataMongoTest
6465@ Testcontainers
66+ @ ExtendWith (MockitoExtension .class )
6567class ReplicateServiceTests {
6668
6769 private static final UpdateReplicateStatusArgs UPDATE_ARGS = UpdateReplicateStatusArgs .builder ()
@@ -72,7 +74,7 @@ class ReplicateServiceTests {
7274 private static final MongoDBContainer mongoDBContainer = new MongoDBContainer (DockerImageName .parse (System .getProperty ("mongo.image" )));
7375
7476 @ DynamicPropertySource
75- static void registerProperties (DynamicPropertyRegistry registry ) {
77+ static void registerProperties (final DynamicPropertyRegistry registry ) {
7678 registry .add ("spring.data.mongodb.host" , mongoDBContainer ::getHost );
7779 registry .add ("spring.data.mongodb.port" , () -> mongoDBContainer .getMappedPort (27017 ));
7880 }
@@ -96,7 +98,6 @@ static void registerProperties(DynamicPropertyRegistry registry) {
9698
9799 @ BeforeEach
98100 void init () {
99- MockitoAnnotations .openMocks (this );
100101 TaskLogsService taskLogsService = new TaskLogsService (taskLogsRepository );
101102 replicatesService = new ReplicatesService (mongoTemplate , replicatesRepository , iexecHubService ,
102103 applicationEventPublisher , web3jService , resultService , taskLogsService );
@@ -675,9 +676,6 @@ void shouldNotSetContributionHashSinceRevealing() {
675676
676677 when (web3jService .isBlockAvailable (anyLong ())).thenReturn (true );
677678 when (iexecHubService .repeatIsRevealedTrue (anyString (), anyString ())).thenReturn (true );
678- when (iexecHubService .getChainContribution (CHAIN_TASK_ID , WALLET_WORKER_1 )).thenReturn (Optional .of (ChainContribution .builder ()
679- .resultHash ("hash" )
680- .build ()));
681679
682680 ArgumentCaptor <ReplicateUpdatedEvent > argumentCaptor = ArgumentCaptor .forClass (ReplicateUpdatedEvent .class );
683681 ReplicateStatusDetails details = new ReplicateStatusDetails (10L );
@@ -1072,9 +1070,6 @@ void shouldAuthorizeUpdateOnResultUploaded() {
10721070 .taskDescription (TaskDescription .builder ().callback ("callback" ).build ())
10731071 .build ();
10741072
1075- when (web3jService .isBlockAvailable (anyLong ())).thenReturn (true );
1076- when (iexecHubService .repeatIsContributedTrue (anyString (), anyString ())).thenReturn (true );
1077-
10781073 assertThat (replicatesService .canUpdateReplicateStatus (replicate , statusUpdate , updateArgs ))
10791074 .isEqualTo (ReplicateStatusUpdateError .NO_ERROR );
10801075 }
@@ -1169,7 +1164,6 @@ void shouldAuthorizeUpdateOnContributeAndFinalizeDone() {
11691164 .thenReturn (true );
11701165 when (iexecHubService .getTaskDescription (CHAIN_TASK_ID )).thenReturn (task );
11711166 when (iexecHubService .isTaskInCompletedStatusOnChain (CHAIN_TASK_ID )).thenReturn (true );
1172- when (resultService .isResultUploaded (task )).thenReturn (true );
11731167
11741168 assertThat (replicatesService .canUpdateReplicateStatus (replicate , statusUpdate , null ))
11751169 .isEqualTo (ReplicateStatusUpdateError .NO_ERROR );
@@ -1187,7 +1181,6 @@ void shouldNotAuthorizeUpdateOnContributeAndFinalizeDoneWhenNotRevealed() {
11871181
11881182 when (iexecHubService .repeatIsRevealedTrue (CHAIN_TASK_ID , WALLET_WORKER_1 ))
11891183 .thenReturn (false );
1190- when (iexecHubService .isTaskInCompletedStatusOnChain (CHAIN_TASK_ID )).thenReturn (true );
11911184
11921185 assertThat (replicatesService .canUpdateReplicateStatus (replicate , statusUpdate , null ))
11931186 .isEqualTo (ReplicateStatusUpdateError .GENERIC_CANT_UPDATE );
@@ -1233,7 +1226,6 @@ void shouldNotAuthorizeUpdateOnContributeAndFinalizeDoneWhenTaskNotCompleted() {
12331226
12341227 when (iexecHubService .repeatIsRevealedTrue (CHAIN_TASK_ID , WALLET_WORKER_1 ))
12351228 .thenReturn (true );
1236- when (iexecHubService .isTaskInCompletedStatusOnChain (CHAIN_TASK_ID )).thenReturn (false );
12371229
12381230 assertThat (replicatesService .canUpdateReplicateStatus (replicate , statusUpdate , null ))
12391231 .isEqualTo (ReplicateStatusUpdateError .GENERIC_CANT_UPDATE );
@@ -1379,8 +1371,6 @@ void computeUpdateReplicateStatusArgsContributeAndFinalizeDone() {
13791371
13801372 @ Test
13811373 void computeUpdateReplicateStatusArgsResultUploadFailed () {
1382- final int unexpectedWorkerWeight = 1 ;
1383- final ChainContribution unexpectedChainContribution = ChainContribution .builder ().build ();
13841374 final String unexpectedResultLink = "resultLink" ;
13851375 final String unexpectedChainCallbackData = "chainCallbackData" ;
13861376 final TaskDescription expectedTaskDescription = TaskDescription .builder ().build ();
@@ -1395,9 +1385,6 @@ void computeUpdateReplicateStatusArgsResultUploadFailed() {
13951385 .details (details )
13961386 .build ();
13971387
1398- when (iexecHubService .getWorkerWeight (WALLET_WORKER_1 )).thenReturn (unexpectedWorkerWeight );
1399- when (iexecHubService .getChainContribution (CHAIN_TASK_ID , WALLET_WORKER_1 ))
1400- .thenReturn (Optional .of (unexpectedChainContribution ));
14011388 when (iexecHubService .getTaskDescription (CHAIN_TASK_ID ))
14021389 .thenReturn (expectedTaskDescription );
14031390
0 commit comments