[wpilib] Deprecate getInstance() in favor of static functions (#3440)

Co-authored-by: Noam Zaks <imnoamzaks@gmail.com>
This commit is contained in:
Peter Johnson
2021-06-15 23:06:03 -07:00
committed by GitHub
parent 26ff9371d9
commit 362066a9b7
105 changed files with 1500 additions and 1539 deletions

View File

@@ -66,7 +66,7 @@ public class CounterTest extends AbstractComsSetup {
// port}.
// These data are hard-coded into the class, but they could be
// generated or loaded in any way you like.
return TestBench.getInstance().getDIOCrossConnectCollection();
return TestBench.getDIOCrossConnectCollection();
}
@BeforeClass

View File

@@ -58,7 +58,7 @@ public class DIOCrossConnectTest extends AbstractInterruptTest {
// port}.
// These data are hard-coded into the class, but they could be
// generated or loaded in any way you like.
return TestBench.getInstance().getDIOCrossConnectCollection();
return TestBench.getDIOCrossConnectCollection();
}
@AfterClass

View File

@@ -26,7 +26,7 @@ public class DriverStationTest extends AbstractComsSetup {
// Wait for data 50 times
for (int i = 0; i < 50; i++) {
DriverStation.getInstance().waitForData();
DriverStation.waitForData();
}
long endTime = RobotController.getFPGATime();
long difference = endTime - startTime;

View File

@@ -43,7 +43,7 @@ public class EncoderTest extends AbstractComsSetup {
*/
@Parameters
public static Collection<Integer[]> generateData() {
return TestBench.getInstance().getEncoderDIOCrossConnectCollection();
return TestBench.getEncoderDIOCrossConnectCollection();
}
/**

View File

@@ -30,7 +30,7 @@ public class GyroTest extends AbstractComsSetup {
@Before
public void setUp() {
logger.fine("Setup: TiltPan camera");
m_tpcam = TestBench.getInstance().getTiltPanCam();
m_tpcam = TestBench.getTiltPanCam();
m_tpcam.setup();
}

View File

@@ -58,9 +58,7 @@ public class MotorEncoderTest extends AbstractComsSetup {
// logger.fine("Loading the MotorList");
return Arrays.asList(
new MotorEncoderFixture<?>[][] {
{TestBench.getInstance().getTalonPair()},
{TestBench.getInstance().getVictorPair()},
{TestBench.getInstance().getJaguarPair()}
{TestBench.getTalonPair()}, {TestBench.getVictorPair()}, {TestBench.getJaguarPair()}
});
}

View File

@@ -46,9 +46,7 @@ public class MotorInvertingTest extends AbstractComsSetup {
// logger.fine("Loading the MotorList");
return Arrays.asList(
new MotorEncoderFixture<?>[][] {
{TestBench.getInstance().getTalonPair()},
{TestBench.getInstance().getVictorPair()},
{TestBench.getInstance().getJaguarPair()}
{TestBench.getTalonPair()}, {TestBench.getVictorPair()}, {TestBench.getJaguarPair()}
});
}

View File

@@ -60,7 +60,7 @@ public class PDPTest extends AbstractComsSetup {
@Parameters(name = "{index}: {0}, Expected Stopped Current Draw: {1}")
public static Collection<Object[]> generateData() {
// logger.fine("Loading the MotorList");
return Arrays.asList(new Object[][] {{TestBench.getInstance().getTalonPair(), 0.0}});
return Arrays.asList(new Object[][] {{TestBench.getTalonPair(), 0.0}});
}
@After

View File

@@ -72,9 +72,9 @@ public class PIDTest extends AbstractComsSetup {
data.addAll(
Arrays.asList(
new Object[][] {
{kp, ki, kd, TestBench.getInstance().getTalonPair()},
{kp, ki, kd, TestBench.getInstance().getVictorPair()},
{kp, ki, kd, TestBench.getInstance().getJaguarPair()}
{kp, ki, kd, TestBench.getTalonPair()},
{kp, ki, kd, TestBench.getVictorPair()},
{kp, ki, kd, TestBench.getJaguarPair()}
}));
}
return data;

View File

@@ -41,7 +41,7 @@ public abstract class AbstractComsSetup {
// Set some implementations so that the static methods work properly
HAL.initialize(500, 0);
HAL.observeUserProgramStarting();
DriverStation.getInstance().getAlliance();
DriverStation.getAlliance();
ds = new MockDS();
ds.start();
@@ -56,7 +56,7 @@ public abstract class AbstractComsSetup {
// Wait until the robot is enabled before starting the tests
int enableCounter = 0;
while (!DriverStation.getInstance().isEnabled()) {
while (!DriverStation.isEnabled()) {
if (enableCounter > 50) {
// Robot did not enable properly after 5 seconds.
// Force exit
@@ -164,7 +164,7 @@ public abstract class AbstractComsSetup {
TestBench.out().println();
// Wait until the robot is enabled before starting the next tests
int enableCounter = 0;
while (!DriverStation.getInstance().isEnabled()) {
while (!DriverStation.isEnabled()) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {

View File

@@ -24,11 +24,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
/**
* This class provides access to all of the elements on the test bench, for use in fixtures. This
* class is a singleton, you should use {@link #getInstance()} to obtain a reference to the {@code
* TestBench}.
*/
/** This class provides access to all of the elements on the test bench, for use in fixtures. */
public final class TestBench {
/**
* The time that it takes to have a motor go from rotating at full speed to completely stopped.
@@ -71,7 +67,7 @@ public final class TestBench {
*
* @return a freshly allocated Talon, Encoder pair
*/
public MotorEncoderFixture<Talon> getTalonPair() {
public static MotorEncoderFixture<Talon> getTalonPair() {
return new MotorEncoderFixture<Talon>() {
@Override
protected Talon giveMotorController() {
@@ -101,7 +97,7 @@ public final class TestBench {
*
* @return a freshly allocated Victor, Encoder pair
*/
public MotorEncoderFixture<Victor> getVictorPair() {
public static MotorEncoderFixture<Victor> getVictorPair() {
return new MotorEncoderFixture<Victor>() {
@Override
protected Victor giveMotorController() {
@@ -131,7 +127,7 @@ public final class TestBench {
*
* @return a freshly allocated Jaguar, Encoder pair
*/
public MotorEncoderFixture<Jaguar> getJaguarPair() {
public static MotorEncoderFixture<Jaguar> getJaguarPair() {
return new MotorEncoderFixture<Jaguar>() {
@Override
protected Jaguar giveMotorController() {
@@ -160,7 +156,7 @@ public final class TestBench {
*
* @return a freshly allocated Servo's and a freshly allocated Gyroscope
*/
public TiltPanCameraFixture getTiltPanCam() {
public static TiltPanCameraFixture getTiltPanCam() {
return new TiltPanCameraFixture() {
@Override
@@ -189,12 +185,12 @@ public final class TestBench {
};
}
public DIOCrossConnectFixture getDIOCrossConnectFixture(int inputPort, int outputPort) {
public static DIOCrossConnectFixture getDIOCrossConnectFixture(int inputPort, int outputPort) {
return new DIOCrossConnectFixture(inputPort, outputPort);
}
/** Gets two lists of possible DIO pairs for the two pairs. */
private List<List<Integer[]>> getDIOCrossConnect() {
private static List<List<Integer[]>> getDIOCrossConnect() {
List<List<Integer[]>> pairs = new ArrayList<List<Integer[]>>();
List<Integer[]> setA =
Arrays.asList(
@@ -256,7 +252,7 @@ public final class TestBench {
*
* @return pairs of DIOCrossConnectFixtures
*/
public Collection<Integer[]> getDIOCrossConnectCollection() {
public static Collection<Integer[]> getDIOCrossConnectCollection() {
Collection<Integer[]> pairs = new ArrayList<Integer[]>();
for (Collection<Integer[]> collection : getDIOCrossConnect()) {
pairs.addAll(collection);
@@ -270,7 +266,7 @@ public final class TestBench {
* @param flip whether this encoder needs to be flipped
* @return A list of different inputs to use for the tests
*/
private Collection<Integer[]> getPairArray(
private static Collection<Integer[]> getPairArray(
List<Integer[]> listA, List<Integer[]> listB, boolean flip) {
Collection<Integer[]> encoderPortPairs = new ArrayList<Integer[]>();
for (Integer[] portPairsA : listA) {
@@ -304,7 +300,7 @@ public final class TestBench {
*
* @return A collection of different input pairs to use for the encoder
*/
public Collection<Integer[]> getEncoderDIOCrossConnectCollection() {
public static Collection<Integer[]> getEncoderDIOCrossConnectCollection() {
Collection<Integer[]> encoderPortPairs = new ArrayList<Integer[]>();
assert getDIOCrossConnect().size() == 2;
encoderPortPairs.addAll(
@@ -320,7 +316,9 @@ public final class TestBench {
* new instance of it. Otherwise it returns the existing instance.
*
* @return The Singleton instance of the TestBench
* @deprecated Use the static methods instead
*/
@Deprecated
public static TestBench getInstance() {
if (instance == null) {
instance = new TestBench();