[wpilib] SendableChooser: Add onChange listener (#5458)

This commit is contained in:
Gold856
2023-07-18 19:33:45 -04:00
committed by GitHub
parent 6f7cdd460e
commit 0b91ca6d5a
6 changed files with 98 additions and 6 deletions

View File

@@ -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();