@@ -23,13 +23,16 @@ public void testAddAndExecuteTask() {
23
23
String result = scheduler .executeTasks ("Group1" );
24
24
25
25
// Check for null before splitting
26
- assertTrue (result != null , "The result should not be null after executing the task." );
27
-
28
- String [] parts = result .split (" started at " );
29
-
30
- // Validate task name and ensure start time is a valid timestamp
31
- assertEquals ("Task1" , parts [0 ]);
32
- assertTrue (Long .parseLong (parts [1 ]) > 0 , "Start time should be greater than 0" );
26
+ if (result != null ) {
27
+ String [] parts = result .split (" started at " );
28
+
29
+ // Validate task name and ensure start time is a valid timestamp
30
+ assertEquals ("Task1" , parts [0 ]);
31
+ assertTrue (Long .parseLong (parts [1 ]) > 0 , "Start time should be greater than 0" );
32
+ } else {
33
+ // Handle the case where result is null
34
+ assertTrue (false , "The result should not be null after executing the task." );
35
+ }
33
36
}
34
37
35
38
@ Test
@@ -41,21 +44,27 @@ public void testMultipleTasksInGroup() {
41
44
String result1 = scheduler .executeTasks ("Group1" );
42
45
43
46
// Check for null before splitting
44
- assertTrue (result1 != null , "The result for Task1 should not be null." );
45
-
46
- String [] parts1 = result1 .split (" started at " );
47
- assertEquals ("Task1" , parts1 [0 ]);
48
- assertTrue (Long .parseLong (parts1 [1 ]) > 0 , "Start time should be greater than 0" );
47
+ if (result1 != null ) {
48
+ String [] parts1 = result1 .split (" started at " );
49
+ assertEquals ("Task1" , parts1 [0 ]);
50
+ assertTrue (Long .parseLong (parts1 [1 ]) > 0 , "Start time should be greater than 0" );
51
+ } else {
52
+ // Handle the case where result1 is null
53
+ assertTrue (false , "The result for Task1 should not be null." );
54
+ }
49
55
50
56
// Execute the second task
51
57
String result2 = scheduler .executeTasks ("Group1" );
52
58
53
59
// Check for null before splitting
54
- assertTrue (result2 != null , "The result for Task2 should not be null." );
55
-
56
- String [] parts2 = result2 .split (" started at " );
57
- assertEquals ("Task2" , parts2 [0 ]);
58
- assertTrue (Long .parseLong (parts2 [1 ]) > 0 , "Start time should be greater than 0" );
60
+ if (result2 != null ) {
61
+ String [] parts2 = result2 .split (" started at " );
62
+ assertEquals ("Task2" , parts2 [0 ]);
63
+ assertTrue (Long .parseLong (parts2 [1 ]) > 0 , "Start time should be greater than 0" );
64
+ } else {
65
+ // Handle the case where result2 is null
66
+ assertTrue (false , "The result for Task2 should not be null." );
67
+ }
59
68
}
60
69
61
70
@ Test
0 commit comments