Skip to content

Commit 9139019

Browse files
committed
Fix
1 parent 5426626 commit 9139019

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

src/test/java/com/thealgorithms/scheduling/SpeculativeExecutionSchedulingTest.java

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@ public void testAddAndExecuteTask() {
2323
String result = scheduler.executeTasks("Group1");
2424

2525
// 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+
}
3336
}
3437

3538
@Test
@@ -41,21 +44,27 @@ public void testMultipleTasksInGroup() {
4144
String result1 = scheduler.executeTasks("Group1");
4245

4346
// 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+
}
4955

5056
// Execute the second task
5157
String result2 = scheduler.executeTasks("Group1");
5258

5359
// 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+
}
5968
}
6069

6170
@Test

0 commit comments

Comments
 (0)