11package dev .enola .be .task ;
22
3+ import static ch .vorburger .test .Assert .assertTrue ;
4+
35import dev .enola .be .task .test .FailingTask ;
46import dev .enola .be .task .test .ImmediateTask ;
57import dev .enola .be .task .test .SlowTask ;
@@ -30,15 +32,15 @@ private static void testCompletedTask() throws Exception {
3032 var task = new ImmediateTask ("test" );
3133 var result = executor .await (task );
3234 var output = task .output ().get ();
33- assert result == output : "The result and output objects must be the same" ;
34- assert "Result: test" .equals (result ) : "Result should match expected output" ;
35+ assertTrue ( result == output , "The result and output objects must be the same" ) ;
36+ assertTrue ( "Result: test" .equals (result ), "Result should match expected output" ) ;
3537
3638 var toString = task .toString ();
37- assert toString .contains ("ImmediateTask" ) : "toString should contain class name" ;
38- assert toString .contains ("id: " + task .id ().toString ()) : "toString should contain ID" ;
39- assert toString .contains ("input: test" ) : "toString should contain input" ;
40- assert toString .contains ("output: Result: test" ) : "toString should contain output" ;
41- assert toString .contains ("status: COMPLETED" ) : "toString should contain COMPLETED" ;
39+ assertTrue ( toString .contains ("ImmediateTask" ), "toString should contain class name" ) ;
40+ assertTrue ( toString .contains ("id: " + task .id ().toString ()), "toString !contains ID" ) ;
41+ assertTrue ( toString .contains ("input: test" ), "toString should contain input" ) ;
42+ assertTrue ( toString .contains ("output: Result: test" ), "toString should contain output" ) ;
43+ assertTrue ( toString .contains ("status: COMPLETED" ), "toString should contain COMPLETED" ) ;
4244 }
4345 }
4446
@@ -54,18 +56,17 @@ private static void testFailingTask(FailingTask.FailureMode failureMode) throws
5456
5557 try {
5658 executor .await (task );
57- assert false : "Should have thrown an exception" ;
59+ assertTrue ( false , "Should have thrown an exception" ) ;
5860 } catch (Throwable e ) {
5961 // Expected
6062 }
61-
62- assert task .status () == Status .FAILED : "Status should be FAILED after exception" ;
63+ assertTrue (task .status () == Status .FAILED , "Status should be FAILED after exception" );
6364
6465 var toString = task .toString ();
65- assert !toString .contains ("output" ) : "toString should not contain output" ;
66- assert toString .contains ("status: FAILED" ) : "toString should contain FAILED" ;
67- assert toString .contains ("failure:" ) : "toString should contain failure:" ;
68- assert toString .contains ("exception" ) : "toString should contain exception" ;
66+ assertTrue ( !toString .contains ("output" ), "toString should not contain output" ) ;
67+ assertTrue ( toString .contains ("status: FAILED" ), "toString should contain FAILED" ) ;
68+ assertTrue ( toString .contains ("failure:" ), "toString should contain failure:" ) ;
69+ assertTrue ( toString .contains ("exception" ), "toString should contain exception" ) ;
6970 }
7071 }
7172
@@ -74,19 +75,21 @@ private static void testTimingOutTask() throws Exception {
7475 var task = new SlowTask ("test" , 1000 , Duration .ofMillis (1 ));
7576 try {
7677 executor .await (task );
77- assert false : "Should have thrown an exception due to timeout" ;
78+ assertTrue ( false , "Should have thrown an exception due to timeout" ) ;
7879
7980 } catch (UncheckedTaskAwaitException e ) {
80- assert e .getCause () instanceof CancellationException
81- : "Cause should be CancellationException" ;
81+ assertTrue (
82+ e .getCause () instanceof CancellationException ,
83+ "Cause should be CancellationException" );
8284 // Expected
8385 }
84- assert task .status () == Status .CANCELLED
85- : "Status should now be CANCELLED, but is " + task .status ();
86+ assertTrue (
87+ task .status () == Status .CANCELLED ,
88+ "Status should now be CANCELLED, but is " + task .status ());
8689
8790 var toString = task .toString ();
88- assert !toString .contains ("output" ) : "toString should not contain output" ;
89- assert toString .contains ("status: CANCELLED" ) : "toString should contain CANCELLED" ;
91+ assertTrue ( !toString .contains ("output" ), "toString should not contain output" ) ;
92+ assertTrue ( toString .contains ("status: CANCELLED" ), "toString should contain CANCELLED" ) ;
9093 }
9194 }
9295
@@ -99,13 +102,14 @@ private static void testCancelTask() throws Exception {
99102
100103 try {
101104 task .await ();
102- assert false : "Should have thrown CancellationException" ;
105+ assertTrue ( false , "Should have thrown CancellationException" ) ;
103106 } catch (UncheckedTaskAwaitException e ) {
104107 // Expected
105108 }
106109
107- assert task .status () == Status .CANCELLED
108- : "Status should be CANCELLED after cancel(), but is " + task .status ();
110+ assertTrue (
111+ task .status () == Status .CANCELLED ,
112+ "Status should be CANCELLED after cancel(), but is " + task .status ());
109113 }
110114 }
111115
@@ -116,7 +120,7 @@ private static void testGetTask() throws Exception {
116120 executor .async (task );
117121
118122 var retrieved = executor .get (taskId );
119- assert retrieved .id ().equals (taskId ) : "Retrieved task ID should match" ;
123+ assertTrue ( retrieved .id ().equals (taskId ), "Retrieved task ID should match" ) ;
120124 }
121125 }
122126
@@ -125,10 +129,11 @@ private static void testGetNonExistentTask() throws Exception {
125129 var randomId = UUID .randomUUID ();
126130 try {
127131 executor .get (randomId );
128- assert false : "Should have thrown IllegalArgumentException" ;
132+ assertTrue ( false , "Should have thrown IllegalArgumentException" ) ;
129133 } catch (IllegalArgumentException e ) {
130- assert e .getMessage ().contains ("No such task" )
131- : "Error message should mention 'No such task'" ;
134+ assertTrue (
135+ e .getMessage ().contains ("No such task" ),
136+ "Error message should mention 'No such task'" );
132137 }
133138 }
134139 }
@@ -142,29 +147,30 @@ private static void testListTasks() throws Exception {
142147 executor .async (task2 );
143148
144149 var taskIds = executor .list ();
145- assert taskIds .size () == 2 : "Should have 2 tasks, got " + taskIds .size ();
146- assert taskIds .contains (task1 .id ()) : "Should contain task1 ID" ;
147- assert taskIds .contains (task2 .id ()) : "Should contain task2 ID" ;
150+ assertTrue ( taskIds .size () == 2 , "Should have 2 tasks, got " + taskIds .size () );
151+ assertTrue ( taskIds .contains (task1 .id ()), "Should contain task1 ID" ) ;
152+ assertTrue ( taskIds .contains (task2 .id ()), "Should contain task2 ID" ) ;
148153 }
149154 }
150155
151156 private static void testTaskStatusProgression () throws Exception {
152157 try (var executor = new TaskExecutor ()) {
153158 var task = new SlowTask ("test" , 1000 );
154159
155- assert task .status () == Status .PENDING : "Status should be PENDING: " + task .status ();
156- assert task .toString ().contains ("status: PENDING" ) : "toString !PENDING" ;
160+ assertTrue (
161+ task .status () == Status .PENDING , "Status should be PENDING: " + task .status ());
162+ assertTrue (task .toString ().contains ("status: PENDING" ), "toString !PENDING" );
157163
158164 executor .async (task );
159165
160166 var status = task .status ();
161- assert status == Status .IN_PROGRESS : "Status should be IN_PROGRESS, got " + status ;
162- assert task .toString ().contains ("status: IN_PROGRESS" ) : "toString !IN_PROGRESS" ;
167+ assertTrue ( status == Status .IN_PROGRESS , "Status should be IN_PROGRESS, got " + status ) ;
168+ assertTrue ( task .toString ().contains ("status: IN_PROGRESS" ), "toString !IN_PROGRESS" ) ;
163169
164170 task .await ();
165171
166- assert task .status () == Status .COMPLETED : "Final status should be COMPLETED" ;
167- assert task .toString ().contains ("status: COMPLETED" ) : "toString !COMPLETED" ;
172+ assertTrue ( task .status () == Status .COMPLETED , "Final status should be COMPLETED" ) ;
173+ assertTrue ( task .toString ().contains ("status: COMPLETED" ), "toString !COMPLETED" ) ;
168174 }
169175 }
170176
@@ -175,10 +181,11 @@ private static void testResubmitTaskFailure() throws Exception {
175181
176182 try {
177183 executor .async (task );
178- assert false : "Should have thrown IllegalStateException on resubmit" ;
184+ assertTrue ( false , "Should have thrown IllegalStateException on resubmit" ) ;
179185 } catch (IllegalStateException e ) {
180- assert e .getMessage ().contains ("already submitted" )
181- : "Error message should mention 'already submitted'" ;
186+ assertTrue (
187+ e .getMessage ().contains ("already submitted" ),
188+ "Error message should mention 'already submitted'" );
182189 }
183190 }
184191 }
@@ -191,10 +198,11 @@ private static void testSubmitTaskToAnotherExecutorFailure() throws Exception {
191198 try (var executor2 = new TaskExecutor ()) {
192199 try {
193200 executor2 .async (task );
194- assert false : "Should have thrown IllegalStateException on resubmit" ;
201+ assertTrue ( false , "Should have thrown IllegalStateException on resubmit" ) ;
195202 } catch (IllegalStateException e ) {
196- assert e .getMessage ().contains ("not PENDING" )
197- : "Error message should mention 'not PENDING'" ;
203+ assertTrue (
204+ e .getMessage ().contains ("not PENDING" ),
205+ "Error message should mention 'not PENDING'" );
198206 }
199207 }
200208 }
@@ -216,7 +224,7 @@ protected String execute() {
216224 }
217225 };
218226 var threadName = executor .await (task );
219- assert threadName .equals (task .id ().toString ());
227+ assertTrue ( threadName .equals (task .id ().toString () ));
220228 }
221229 }
222230}
0 commit comments