mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Java cleanups (#1776)
* Remove extra ';'s * Remove unnecessary conversions to String * Use StandardCharsets object * Replace infinite while with check for interrupted thread * Remove redundant local vars * Remove redundant throws clause * Remove redundant primitive wrapping * Fix malformed Nested class test * Remove unnecessary unboxing * Remove unnecessary explicit type argument * Replace lambdas with method references * Replace statement lambdas with expression lambdas * Replace null check with method call * Replace number comparison with method call * Fix broken javadoc comments * Replace Arrays.asList with singletonLists * Remove excessive lambda usage * Remove redundant string operation * Remove redundant type casts * Remove unnecessary returns * Remove redundant suppressions * Fix unresolved file reference * static analysis fixes
This commit is contained in:
committed by
Peter Johnson
parent
39561751fc
commit
df12fc2a86
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -161,7 +161,7 @@ public abstract class AbstractInterruptTest extends AbstractComsSetup {
|
||||
}
|
||||
|
||||
@Test(timeout = 2000)
|
||||
public void testMultipleInterruptsTriggering() throws Exception {
|
||||
public void testMultipleInterruptsTriggering() {
|
||||
// Given
|
||||
final InterruptCounter counter = new InterruptCounter();
|
||||
TestInterruptHandlerFunction function = new TestInterruptHandlerFunction(counter);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -39,18 +39,18 @@ public class AnalogCrossConnectTest extends AbstractInterruptTest {
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
public static void setUpBeforeClass() {
|
||||
analogIO = TestBench.getAnalogCrossConnectFixture();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
public static void tearDownAfterClass() {
|
||||
analogIO.teardown();
|
||||
analogIO = null;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
analogIO.setup();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@ public class AnalogPotentiometerTest extends AbstractComsSetup {
|
||||
private static final double DOUBLE_COMPARISON_DELTA = 2.0;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
m_analogIO = TestBench.getAnalogCrossConnectFixture();
|
||||
m_potSource = new FakePotentiometerSource(m_analogIO.getOutput(), 360);
|
||||
m_pot = new AnalogPotentiometer(m_analogIO.getInput(), 360.0, 0);
|
||||
@@ -40,7 +40,7 @@ public class AnalogPotentiometerTest extends AbstractComsSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
m_potSource.reset();
|
||||
m_pot.close();
|
||||
m_analogIO.teardown();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -78,17 +78,17 @@ public class CounterTest extends AbstractComsSetup {
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
public static void setUpBeforeClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
public static void tearDownAfterClass() {
|
||||
counter.teardown();
|
||||
counter = null;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
counter.setup();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -70,13 +70,13 @@ public class DIOCrossConnectTest extends AbstractInterruptTest {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
public static void tearDownAfterClass() {
|
||||
dio.teardown();
|
||||
dio = null;
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
dio.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -79,7 +79,7 @@ public class EncoderTest extends AbstractComsSetup {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
public static void tearDownAfterClass() {
|
||||
encoder.teardown();
|
||||
encoder = null;
|
||||
}
|
||||
@@ -88,13 +88,13 @@ public class EncoderTest extends AbstractComsSetup {
|
||||
* Sets up the test and verifies that the test was reset to the default state.
|
||||
*/
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
encoder.setup();
|
||||
testDefaultState();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
encoder.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -35,14 +35,14 @@ public class GyroTest extends AbstractComsSetup {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
logger.fine("Setup: TiltPan camera");
|
||||
m_tpcam = TestBench.getInstance().getTiltPanCam();
|
||||
m_tpcam.setup();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
m_tpcam.teardown();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public class MotorEncoderTest extends AbstractComsSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
me.reset();
|
||||
encodersResetCheck(me);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2014-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2014-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -51,7 +51,7 @@ public class PCMTest extends AbstractComsSetup {
|
||||
private static DigitalInput fakeSolenoid2;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
public static void setUpBeforeClass() {
|
||||
compressor = new Compressor();
|
||||
|
||||
fakePressureSwitch = new DigitalOutput(11);
|
||||
@@ -62,7 +62,7 @@ public class PCMTest extends AbstractComsSetup {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
public static void tearDownAfterClass() {
|
||||
compressor.close();
|
||||
|
||||
fakePressureSwitch.close();
|
||||
@@ -73,7 +73,7 @@ public class PCMTest extends AbstractComsSetup {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void reset() throws Exception {
|
||||
public void reset() {
|
||||
compressor.stop();
|
||||
fakePressureSwitch.set(false);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2016-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2016-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -41,12 +41,12 @@ public class PDPTest extends AbstractComsSetup {
|
||||
private final double m_expectedStoppedCurrentDraw;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
public static void setUpBeforeClass() {
|
||||
pdp = new PowerDistributionPanel();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
public static void tearDownAfterClass() {
|
||||
pdp.close();
|
||||
pdp = null;
|
||||
me.teardown();
|
||||
@@ -74,7 +74,7 @@ public class PDPTest extends AbstractComsSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
me.reset();
|
||||
}
|
||||
|
||||
|
||||
@@ -94,18 +94,18 @@ public class PIDTest extends AbstractComsSetup {
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
public static void setUpBeforeClass() {
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
public static void tearDownAfterClass() {
|
||||
logger.fine("TearDownAfterClass: " + me.getType());
|
||||
me.teardown();
|
||||
me = null;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
logger.fine("Setup: " + me.getType());
|
||||
me.setup();
|
||||
m_table = NetworkTableInstance.getDefault().getTable("TEST_PID");
|
||||
@@ -118,7 +118,7 @@ public class PIDTest extends AbstractComsSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
logger.fine("Teardown: " + me.getType());
|
||||
m_runner.disable();
|
||||
m_controller.close();
|
||||
@@ -174,12 +174,12 @@ public class PIDTest extends AbstractComsSetup {
|
||||
public void testSetSetpoint() {
|
||||
setupAbsoluteTolerance();
|
||||
setupOutputRange();
|
||||
Double reference = 2500.0;
|
||||
double reference = 2500.0;
|
||||
m_runner.disable();
|
||||
m_controller.setSetpoint(reference);
|
||||
m_runner.enable();
|
||||
assertEquals("Did not correctly set reference", reference, new Double(m_controller
|
||||
.getSetpoint()));
|
||||
assertEquals("Did not correctly set reference", reference, m_controller
|
||||
.getSetpoint(), 1e-3);
|
||||
}
|
||||
|
||||
@Test(timeout = 10000)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -39,7 +39,7 @@ public class RelayCrossConnectTest extends AbstractComsSetup {
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
m_relayFixture = TestBench.getRelayCrossConnectFixture();
|
||||
m_relayFixture.setup();
|
||||
m_builder = new SendableBuilderImpl();
|
||||
@@ -48,7 +48,7 @@ public class RelayCrossConnectTest extends AbstractComsSetup {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
public void tearDown() {
|
||||
m_relayFixture.reset();
|
||||
m_relayFixture.teardown();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2018 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -15,7 +15,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Suite;
|
||||
import org.junit.runners.Suite.SuiteClasses;
|
||||
import org.junit.runners.model.InitializationError;
|
||||
|
||||
import edu.wpi.first.wpilibj.test.AbstractTestSuite.ClassMethodPair;
|
||||
|
||||
@@ -40,12 +39,12 @@ public class AbstractTestSuiteTest {
|
||||
TestForAbstractTestSuite m_testSuite;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
public void setUp() {
|
||||
m_testSuite = new TestForAbstractTestSuite();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTestsMatchingAll() throws InitializationError {
|
||||
public void testGetTestsMatchingAll() {
|
||||
// when
|
||||
List<Class<?>> collectedTests = m_testSuite.getAllClassMatching(".*");
|
||||
// then
|
||||
@@ -53,7 +52,7 @@ public class AbstractTestSuiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTestsMatchingSample() throws InitializationError {
|
||||
public void testGetTestsMatchingSample() {
|
||||
// when
|
||||
List<Class<?>> collectedTests = m_testSuite.getAllClassMatching(".*Sample.*");
|
||||
// then
|
||||
@@ -61,7 +60,7 @@ public class AbstractTestSuiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTestsMatchingUnusual() throws InitializationError {
|
||||
public void testGetTestsMatchingUnusual() {
|
||||
// when
|
||||
List<Class<?>> collectedTests = m_testSuite.getAllClassMatching(".*Unusual.*");
|
||||
// then
|
||||
@@ -70,7 +69,7 @@ public class AbstractTestSuiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTestsFromSuiteMatchingAll() throws InitializationError {
|
||||
public void testGetTestsFromSuiteMatchingAll() {
|
||||
// when
|
||||
List<Class<?>> collectedTests = m_testSuite.getSuiteOrTestMatchingRegex(".*");
|
||||
// then
|
||||
@@ -78,7 +77,7 @@ public class AbstractTestSuiteTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetTestsFromSuiteMatchingTest() throws InitializationError {
|
||||
public void testGetTestsFromSuiteMatchingTest() {
|
||||
// when
|
||||
List<Class<?>> collectedTests = m_testSuite.getSuiteOrTestMatchingRegex(".*Test.*");
|
||||
// then
|
||||
|
||||
@@ -80,7 +80,7 @@ public final class TestBench {
|
||||
* @return a freshly allocated Talon, Encoder pair
|
||||
*/
|
||||
public MotorEncoderFixture<Talon> getTalonPair() {
|
||||
MotorEncoderFixture<Talon> talonPair = new MotorEncoderFixture<Talon>() {
|
||||
return new MotorEncoderFixture<Talon>() {
|
||||
@Override
|
||||
protected Talon giveSpeedController() {
|
||||
return new Talon(kTalonChannel);
|
||||
@@ -101,7 +101,6 @@ public final class TestBench {
|
||||
return kTalonPDPChannel;
|
||||
}
|
||||
};
|
||||
return talonPair;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -111,7 +110,7 @@ public final class TestBench {
|
||||
* @return a freshly allocated Victor, Encoder pair
|
||||
*/
|
||||
public MotorEncoderFixture<Victor> getVictorPair() {
|
||||
MotorEncoderFixture<Victor> vicPair = new MotorEncoderFixture<Victor>() {
|
||||
return new MotorEncoderFixture<Victor>() {
|
||||
@Override
|
||||
protected Victor giveSpeedController() {
|
||||
return new Victor(kVictorChannel);
|
||||
@@ -132,7 +131,6 @@ public final class TestBench {
|
||||
return kVictorPDPChannel;
|
||||
}
|
||||
};
|
||||
return vicPair;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -142,7 +140,7 @@ public final class TestBench {
|
||||
* @return a freshly allocated Jaguar, Encoder pair
|
||||
*/
|
||||
public MotorEncoderFixture<Jaguar> getJaguarPair() {
|
||||
MotorEncoderFixture<Jaguar> jagPair = new MotorEncoderFixture<Jaguar>() {
|
||||
return new MotorEncoderFixture<Jaguar>() {
|
||||
@Override
|
||||
protected Jaguar giveSpeedController() {
|
||||
return new Jaguar(kJaguarChannel);
|
||||
@@ -163,7 +161,6 @@ public final class TestBench {
|
||||
return kJaguarPDPChannel;
|
||||
}
|
||||
};
|
||||
return jagPair;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -172,7 +169,8 @@ public final class TestBench {
|
||||
* @return a freshly allocated Servo's and a freshly allocated Gyroscope
|
||||
*/
|
||||
public TiltPanCameraFixture getTiltPanCam() {
|
||||
TiltPanCameraFixture tpcam = new TiltPanCameraFixture() {
|
||||
|
||||
return new TiltPanCameraFixture() {
|
||||
@Override
|
||||
protected AnalogGyro giveGyro() {
|
||||
AnalogGyro gyro = new AnalogGyro(kGyroChannel);
|
||||
@@ -197,13 +195,10 @@ public final class TestBench {
|
||||
return new Servo(kPanServoChannel);
|
||||
}
|
||||
};
|
||||
|
||||
return tpcam;
|
||||
}
|
||||
|
||||
public DIOCrossConnectFixture getDIOCrossConnectFixture(int inputPort, int outputPort) {
|
||||
DIOCrossConnectFixture dio = new DIOCrossConnectFixture(inputPort, outputPort);
|
||||
return dio;
|
||||
return new DIOCrossConnectFixture(inputPort, outputPort);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -228,7 +223,7 @@ public final class TestBench {
|
||||
|
||||
@SuppressWarnings("JavadocMethod")
|
||||
public static AnalogCrossConnectFixture getAnalogCrossConnectFixture() {
|
||||
AnalogCrossConnectFixture analogIO = new AnalogCrossConnectFixture() {
|
||||
return new AnalogCrossConnectFixture() {
|
||||
@Override
|
||||
protected AnalogOutput giveAnalogOutput() {
|
||||
return new AnalogOutput(0);
|
||||
@@ -239,12 +234,11 @@ public final class TestBench {
|
||||
return new AnalogInput(2);
|
||||
}
|
||||
};
|
||||
return analogIO;
|
||||
}
|
||||
|
||||
@SuppressWarnings("JavadocMethod")
|
||||
public static RelayCrossConnectFixture getRelayCrossConnectFixture() {
|
||||
RelayCrossConnectFixture relay = new RelayCrossConnectFixture() {
|
||||
return new RelayCrossConnectFixture() {
|
||||
@Override
|
||||
protected Relay giveRelay() {
|
||||
return new Relay(0);
|
||||
@@ -260,7 +254,6 @@ public final class TestBench {
|
||||
return new DigitalInput(19);
|
||||
}
|
||||
};
|
||||
return relay;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user