[wpilib] Reduce usage of NTSendable (#5434)

This commit is contained in:
Gold856
2023-07-24 00:34:49 -04:00
committed by GitHub
parent d125711023
commit 99b88be4f3
11 changed files with 134 additions and 85 deletions

View File

@@ -11,6 +11,8 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import org.junit.jupiter.api.Test;
class CommandScheduleTest extends CommandTestBase {
@@ -116,4 +118,27 @@ class CommandScheduleTest extends CommandTestBase {
assertDoesNotThrow(() -> scheduler.cancel(mockCommand));
}
}
@Test
void smartDashboardCancelTest() {
try (CommandScheduler scheduler = new CommandScheduler();
var inst = NetworkTableInstance.create()) {
SmartDashboard.setNetworkTableInstance(inst);
SmartDashboard.putData("Scheduler", scheduler);
SmartDashboard.updateValues();
MockCommandHolder holder = new MockCommandHolder(true);
Command mockCommand = holder.getMock();
scheduler.schedule(mockCommand);
scheduler.run();
SmartDashboard.updateValues();
assertTrue(scheduler.isScheduled(mockCommand));
var table = inst.getTable("SmartDashboard");
table.getEntry("Scheduler/Cancel").setIntegerArray(new long[] {mockCommand.hashCode()});
SmartDashboard.updateValues();
scheduler.run();
assertFalse(scheduler.isScheduled(mockCommand));
}
}
}