@@ -70,14 +70,7 @@ void shouldDetectTasks() {
7070 final String contributedAndFinalizedChainTaskId = "0x75bc5e94ed1486b940bd6cc0013c418efad58a0a52a3d08cee89faaa21970426" ;
7171 final Task contributeAndFinalizeTask = getContributeAndFinalizeDoneTask (contributedAndFinalizedChainTaskId ).build ();
7272 when (taskService .findByCurrentStatus (TaskStatus .RUNNING )).thenReturn (List .of (contributeAndFinalizeTask ));
73-
74- final TaskDescription taskDescription = TaskDescription .builder ()
75- .chainTaskId (contributedAndFinalizedChainTaskId )
76- .isTeeTask (true )
77- .trust (BigInteger .ONE )
78- .callback ("" )
79- .build ();
80- when (iexecHubService .getTaskDescription (contributedAndFinalizedChainTaskId )).thenReturn (taskDescription );
73+ mockTaskDescriptionFromTask (contributeAndFinalizeTask );
8174
8275 detector .detect ();
8376
@@ -114,15 +107,9 @@ void shouldDetectNoFinalizedTaskAsTaskIsRevealing() {
114107 @ Test
115108 void shouldDetectContributeAndFinalizeDoneTask () {
116109 final Task task = getContributeAndFinalizeDoneTask (CHAIN_TASK_ID ).build ();
117- final TaskDescription taskDescription = TaskDescription .builder ()
118- .chainTaskId (CHAIN_TASK_ID )
119- .isTeeTask (true )
120- .trust (BigInteger .ONE )
121- .callback ("" )
122- .build ();
123110
124111 when (taskService .findByCurrentStatus (TaskStatus .RUNNING )).thenReturn (List .of (task ));
125- when ( iexecHubService . getTaskDescription ( CHAIN_TASK_ID )). thenReturn ( taskDescription );
112+ mockTaskDescriptionFromTask ( task );
126113
127114 detector .detectContributeAndFinalizeDoneTasks ();
128115
@@ -132,15 +119,9 @@ void shouldDetectContributeAndFinalizeDoneTask() {
132119 @ Test
133120 void shouldDetectNoContributeAndFinalizeDoneTaskAsTaskIsRevealing () {
134121 final Task task = getOnchainRevealingTask (CHAIN_DEAL_ID ).build ();
135- final TaskDescription taskDescription = TaskDescription .builder ()
136- .chainTaskId (task .getChainTaskId ())
137- .isTeeTask (true )
138- .trust (BigInteger .ONE )
139- .callback ("" )
140- .build ();
141122
142123 when (taskService .findByCurrentStatus (TaskStatus .RUNNING )).thenReturn (List .of (task ));
143- when ( iexecHubService . getTaskDescription ( task . getChainTaskId ())). thenReturn ( taskDescription );
124+ mockTaskDescriptionFromTask ( task );
144125
145126 detector .detectContributeAndFinalizeDoneTasks ();
146127
@@ -186,13 +167,7 @@ void shouldChainTaskNotBeCompletedAsChainTaskNotCompleted() {
186167 @ Test
187168 void shouldTaskBeContributeAndFinalizeDone () {
188169 final Task task = getContributeAndFinalizeDoneTask (CHAIN_TASK_ID ).build ();
189- final TaskDescription taskDescription = TaskDescription .builder ()
190- .chainTaskId (CHAIN_TASK_ID )
191- .isTeeTask (true )
192- .trust (BigInteger .ONE )
193- .callback ("" )
194- .build ();
195- when (iexecHubService .getTaskDescription (CHAIN_TASK_ID )).thenReturn (taskDescription );
170+ mockTaskDescriptionFromTask (task );
196171
197172 final boolean taskContributeAndFinalizeDone = detector .isTaskContributeAndFinalizeDone (task );
198173
@@ -206,13 +181,7 @@ void shouldTaskNotBeContributeAndFinalizeDoneAsNotTee() {
206181 .currentStatus (TaskStatus .FINALIZING )
207182 .tag (NO_TEE_TAG )
208183 .build ();
209- final TaskDescription taskDescription = TaskDescription .builder ()
210- .chainTaskId (CHAIN_TASK_ID )
211- .isTeeTask (false )
212- .trust (BigInteger .ONE )
213- .callback ("" )
214- .build ();
215- when (iexecHubService .getTaskDescription (CHAIN_TASK_ID )).thenReturn (taskDescription );
184+ mockTaskDescriptionFromTask (task );
216185
217186 final boolean taskContributeAndFinalizeDone = detector .isTaskContributeAndFinalizeDone (task );
218187
@@ -232,16 +201,10 @@ void shouldTaskNotBeContributeAndFinalizeDoneAsMultipleReplicates() {
232201 .chainTaskId (CHAIN_TASK_ID )
233202 .status (ChainTaskStatus .COMPLETED )
234203 .build ();
235- final TaskDescription taskDescription = TaskDescription .builder ()
236- .chainTaskId (CHAIN_TASK_ID )
237- .isTeeTask (true )
238- .trust (BigInteger .ONE )
239- .callback ("" )
240- .build ();
241204
242205 when (replicatesService .getReplicates (CHAIN_TASK_ID )).thenReturn (List .of (replicate1 , replicate2 ));
243206 when (iexecHubService .getChainTask (CHAIN_TASK_ID )).thenReturn (Optional .of (chainTask ));
244- when ( iexecHubService . getTaskDescription ( CHAIN_TASK_ID )). thenReturn ( taskDescription );
207+ mockTaskDescriptionFromTask ( task );
245208
246209 final boolean taskContributeAndFinalizeDone = detector .isTaskContributeAndFinalizeDone (task );
247210
@@ -257,15 +220,9 @@ void shouldTaskNotBeContributeAndFinalizeDoneAsReplicateNotDone() {
257220 .build ();
258221 final Replicate replicate = new Replicate (WALLET_WORKER_1 , CHAIN_TASK_ID );
259222 replicate .updateStatus (ReplicateStatus .COMPUTING , ReplicateStatusModifier .WORKER );
260- final TaskDescription taskDescription = TaskDescription .builder ()
261- .chainTaskId (CHAIN_TASK_ID )
262- .isTeeTask (true )
263- .trust (BigInteger .ONE )
264- .callback ("" )
265- .build ();
266223
267224 when (replicatesService .getReplicates (CHAIN_TASK_ID )).thenReturn (List .of (replicate ));
268- when ( iexecHubService . getTaskDescription ( CHAIN_TASK_ID )). thenReturn ( taskDescription );
225+ mockTaskDescriptionFromTask ( task );
269226
270227 final boolean taskContributeAndFinalizeDone = detector .isTaskContributeAndFinalizeDone (task );
271228
@@ -285,16 +242,10 @@ void shouldTaskNotBeContributeAndFinalizeDoneAsChainTaskNotCompleted() {
285242 .chainTaskId (CHAIN_TASK_ID )
286243 .status (ChainTaskStatus .REVEALING )
287244 .build ();
288- final TaskDescription taskDescription = TaskDescription .builder ()
289- .chainTaskId (CHAIN_TASK_ID )
290- .isTeeTask (true )
291- .trust (BigInteger .ONE )
292- .callback ("" )
293- .build ();
294245
295246 when (replicatesService .getReplicates (CHAIN_TASK_ID )).thenReturn (List .of (replicate ));
296247 when (iexecHubService .getChainTask (CHAIN_TASK_ID )).thenReturn (Optional .of (chainTask ));
297- when ( iexecHubService . getTaskDescription ( CHAIN_TASK_ID )). thenReturn ( taskDescription );
248+ mockTaskDescriptionFromTask ( task );
298249
299250 final boolean taskContributeAndFinalizeDone = detector .isTaskContributeAndFinalizeDone (task );
300251
@@ -353,5 +304,15 @@ private Task.TaskBuilder getContributeAndFinalizeDoneTask(String chainTaskId) {
353304 .tag (TEE_TAG )
354305 .trust (1 );
355306 }
307+
308+ private void mockTaskDescriptionFromTask (Task task ) {
309+ final TaskDescription taskDescription = TaskDescription .builder ()
310+ .chainTaskId (task .getChainTaskId ())
311+ .isTeeTask (task .isTeeTask ())
312+ .trust (BigInteger .valueOf (task .getTrust ()))
313+ .callback ("" )
314+ .build ();
315+ when (iexecHubService .getTaskDescription (task .getChainTaskId ())).thenReturn (taskDescription );
316+ }
356317 // endregion
357318}
0 commit comments