Skip to content

Commit 5426626

Browse files
committed
Fix
1 parent f24ca6c commit 5426626

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ public void testAddAndExecuteTask() {
2121
scheduler.addTask("Group1", "Task1");
2222

2323
String result = scheduler.executeTasks("Group1");
24+
25+
// Check for null before splitting
26+
assertTrue(result != null, "The result should not be null after executing the task.");
27+
2428
String[] parts = result.split(" started at ");
2529

2630
// Validate task name and ensure start time is a valid timestamp
@@ -35,12 +39,20 @@ public void testMultipleTasksInGroup() {
3539

3640
// Execute the first task
3741
String result1 = scheduler.executeTasks("Group1");
42+
43+
// Check for null before splitting
44+
assertTrue(result1 != null, "The result for Task1 should not be null.");
45+
3846
String[] parts1 = result1.split(" started at ");
3947
assertEquals("Task1", parts1[0]);
4048
assertTrue(Long.parseLong(parts1[1]) > 0, "Start time should be greater than 0");
4149

4250
// Execute the second task
4351
String result2 = scheduler.executeTasks("Group1");
52+
53+
// Check for null before splitting
54+
assertTrue(result2 != null, "The result for Task2 should not be null.");
55+
4456
String[] parts2 = result2.split(" started at ");
4557
assertEquals("Task2", parts2[0]);
4658
assertTrue(Long.parseLong(parts2[1]) > 0, "Start time should be greater than 0");
@@ -54,6 +66,7 @@ public void testExecuteAllTasks() {
5466
scheduler.executeTasks("Group1");
5567
scheduler.executeTasks("Group1");
5668

69+
// Confirm executing tasks again returns null
5770
assertNull(scheduler.executeTasks("Group1"));
5871
}
5972

0 commit comments

Comments
 (0)