mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-25 01:41:43 +00:00
[wpilib] SendableChooser: Add onChange listener (#5458)
This commit is contained in:
@@ -8,6 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -64,6 +65,23 @@ class SendableChooserTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testChangeListener() {
|
||||
try (var chooser = new SendableChooser<Integer>()) {
|
||||
for (int i = 1; i <= 3; i++) {
|
||||
chooser.addOption(String.valueOf(i), i);
|
||||
}
|
||||
AtomicInteger currentVal = new AtomicInteger();
|
||||
chooser.onChange(val -> currentVal.set(val));
|
||||
|
||||
SmartDashboard.putData("chooser", chooser);
|
||||
SmartDashboard.updateValues();
|
||||
SmartDashboard.putString("chooser/selected", "3");
|
||||
SmartDashboard.updateValues();
|
||||
assertEquals(3, currentVal.get());
|
||||
}
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
m_inst.close();
|
||||
|
||||
Reference in New Issue
Block a user