From 3fe90f7a0b635ee8317ced47b8713e4f9c5adcef Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 25 May 2023 13:46:15 +0200 Subject: [PATCH 1/3] Use builders in test classes --- .../iexec/core/chain/DealWatcherServiceTests.java | 8 ++++---- .../iexec/core/replicate/ReplicateServiceTests.java | 8 ++++---- .../core/task/update/TaskUpdateManagerTest.java | 12 ++++++------ 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java b/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java index a546085b..c59a7170 100644 --- a/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java +++ b/src/test/java/com/iexec/core/chain/DealWatcherServiceTests.java @@ -103,10 +103,10 @@ void shouldUpdateLastSeenBlockWhenOneDeal() { @Test void shouldUpdateLastSeenBlockWhenOneDealAndCreateTask() { - ChainApp chainApp = new ChainApp(); - chainApp.setUri("0x00"); + ChainApp chainApp = ChainApp.builder() + .uri("0x00").build(); - ChainCategory chainCategory = new ChainCategory(); + ChainCategory chainCategory = ChainCategory.builder().build(); ChainDeal chainDeal = ChainDeal.builder() .botFirst(BigInteger.valueOf(0)) @@ -146,7 +146,7 @@ void shouldUpdateLastSeenBlockWhenOneDealAndNotCreateTaskSinceDealIsExpired() { .botFirst(BigInteger.valueOf(0)) .botSize(BigInteger.valueOf(1)) .chainApp(ChainApp.builder().uri("0x00").build()) - .chainCategory(new ChainCategory()) + .chainCategory(ChainCategory.builder().build()) .params(DealParams.builder().iexecArgs("args").build()) .trust(BigInteger.valueOf(3)) .build(); diff --git a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java index 2e1e82c0..d8139c54 100644 --- a/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java +++ b/src/test/java/com/iexec/core/replicate/ReplicateServiceTests.java @@ -1410,7 +1410,7 @@ void shouldAuthorizeUpdateOnComputedWhenTaskDescriptionIsFilled() { @Test void computeUpdateReplicateStatusArgsContributed() { final int expectedWorkerWeight = 1; - final ChainContribution expectedChainContribution = new ChainContribution(); + final ChainContribution expectedChainContribution = ChainContribution.builder().build(); final String unexpectedResultLink = "resultLink"; final String unexpectedChainCallbackData = "chainCallbackData"; @@ -1426,7 +1426,7 @@ void computeUpdateReplicateStatusArgsContributed() { when(iexecHubService.getWorkerWeight(WALLET_WORKER_1)).thenReturn(expectedWorkerWeight); when(iexecHubService.getChainContribution(CHAIN_TASK_ID, WALLET_WORKER_1)) - .thenReturn(Optional.of(new ChainContribution())); + .thenReturn(Optional.of(ChainContribution.builder().build())); assertThat(replicatesService.computeUpdateReplicateStatusArgs(CHAIN_TASK_ID, WALLET_WORKER_1, statusUpdate)) .isEqualTo(UpdateReplicateStatusArgs.builder() @@ -1438,7 +1438,7 @@ void computeUpdateReplicateStatusArgsContributed() { @Test void computeUpdateReplicateStatusArgsResultUploaded() { final int unexpectedWorkerWeight = 1; - final ChainContribution unexpectedChainContribution = new ChainContribution(); + final ChainContribution unexpectedChainContribution = ChainContribution.builder().build(); final String expectedResultLink = "resultLink"; final String expectedChainCallbackData = "chainCallbackData"; final TaskDescription expectedTaskDescription = TaskDescription.builder().build(); @@ -1472,7 +1472,7 @@ void computeUpdateReplicateStatusArgsResultUploaded() { @Test void computeUpdateReplicateStatusArgsResultUploadFailed() { final int unexpectedWorkerWeight = 1; - final ChainContribution unexpectedChainContribution = new ChainContribution(); + final ChainContribution unexpectedChainContribution = ChainContribution.builder().build(); final String unexpectedResultLink = "resultLink"; final String unexpectedChainCallbackData = "chainCallbackData"; final TaskDescription expectedTaskDescription = TaskDescription.builder().build(); diff --git a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java index eb82b0c7..6df4977e 100644 --- a/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java +++ b/src/test/java/com/iexec/core/task/update/TaskUpdateManagerTest.java @@ -119,7 +119,7 @@ void shouldNotUpgrade2ReopenedSinceCurrentStatusWrong() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(true); when(iexecHubService.hasEnoughGas()).thenReturn(true); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); taskUpdateManager.consensusReached2Reopening(task); @@ -136,7 +136,7 @@ void shouldNotUpgrade2ReopenedSinceNotAfterRevealDeadline() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(true); when(iexecHubService.hasEnoughGas()).thenReturn(true); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); taskUpdateManager.consensusReached2Reopening(task); @@ -153,7 +153,7 @@ void shouldNotUpgrade2ReopenedSinceNotWeHaveSomeRevealed() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(true); when(iexecHubService.hasEnoughGas()).thenReturn(true); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); taskUpdateManager.consensusReached2Reopening(task); @@ -170,7 +170,7 @@ void shouldNotUpgrade2ReopenedSinceCantReopenOnChain() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(false); when(iexecHubService.hasEnoughGas()).thenReturn(true); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); taskUpdateManager.consensusReached2Reopening(task); @@ -187,7 +187,7 @@ void shouldNotUpgrade2ReopenedSinceNotEnoughtGas() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(true); when(iexecHubService.hasEnoughGas()).thenReturn(false); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); taskUpdateManager.consensusReached2Reopening(task); @@ -224,7 +224,7 @@ void shouldUpgrade2Reopened() { when(iexecHubService.canReopen(task.getChainTaskId())).thenReturn(true); when(iexecHubService.hasEnoughGas()).thenReturn(true); when(taskService.updateTask(task)).thenReturn(Optional.of(task)); - when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(new ChainReceipt())); + when(iexecHubService.reOpen(task.getChainTaskId())).thenReturn(Optional.of(ChainReceipt.builder().build())); when(iexecHubService.getChainTask(CHAIN_TASK_ID)).thenReturn(Optional.of(ChainTask.builder() .status(ChainTaskStatus.ACTIVE) .build())); From ec016c6eeb9708efc0cfdcdd9e06af45e3c7a848 Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 25 May 2023 13:53:12 +0200 Subject: [PATCH 2/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9375276c..a1436e77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file. - Add purge cached task descriptions ability. (#587) ### Bug Fixes - Prevent race condition on replicate update. (#568) +- Ue builders in test classes. (#589) ### Quality - Remove unused methods in `IexecHubService`. (#572) - Clean unused Replicate methods and update tests. (#573) From 9360cc5e7789520348a58be695002d6e1a0cdd2c Mon Sep 17 00:00:00 2001 From: Jeremy Bernard Date: Thu, 25 May 2023 13:55:43 +0200 Subject: [PATCH 3/3] Update CHANGELOG.md Co-authored-by: Maxence Cornaton <87655102+mcornaton@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1436e77..f9afa005 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ All notable changes to this project will be documented in this file. - Add purge cached task descriptions ability. (#587) ### Bug Fixes - Prevent race condition on replicate update. (#568) -- Ue builders in test classes. (#589) +- Use builders in test classes. (#589) ### Quality - Remove unused methods in `IexecHubService`. (#572) - Clean unused Replicate methods and update tests. (#573)