mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Clean up Java style (#5990)
Also make equivalent changes in C++ where applicable. Co-authored-by: Sriman Achanta <68172138+srimanachanta@users.noreply.github.com>
This commit is contained in:
@@ -4,11 +4,11 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.both;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
@@ -7,8 +7,8 @@ package edu.wpi.first.wpilibj;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
@@ -38,7 +38,7 @@ public class BuiltInAccelerometerTest extends AbstractComsSetup {
|
||||
/** Test with all valid ranges to make sure unpacking is always done correctly. */
|
||||
@Parameters
|
||||
public static Collection<BuiltInAccelerometer.Range[]> generateData() {
|
||||
return Arrays.asList(
|
||||
return List.of(
|
||||
new BuiltInAccelerometer.Range[][] {
|
||||
{BuiltInAccelerometer.Range.k2G},
|
||||
{BuiltInAccelerometer.Range.k4G},
|
||||
|
||||
@@ -14,8 +14,8 @@ import edu.wpi.first.math.filter.LinearFilter;
|
||||
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
@@ -56,7 +56,7 @@ public class MotorEncoderTest extends AbstractComsSetup {
|
||||
@Parameters(name = "{index}: {0}")
|
||||
public static Collection<MotorEncoderFixture<?>[]> generateData() {
|
||||
// logger.fine("Loading the MotorList");
|
||||
return Arrays.asList(
|
||||
return List.of(
|
||||
new MotorEncoderFixture<?>[][] {
|
||||
{TestBench.getTalonPair()}, {TestBench.getVictorPair()}, {TestBench.getJaguarPair()}
|
||||
});
|
||||
|
||||
@@ -10,8 +10,8 @@ import static org.junit.Assert.assertTrue;
|
||||
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
@@ -44,7 +44,7 @@ public class MotorInvertingTest extends AbstractComsSetup {
|
||||
@Parameters(name = "{index}: {0}")
|
||||
public static Collection<MotorEncoderFixture<?>[]> generateData() {
|
||||
// logger.fine("Loading the MotorList");
|
||||
return Arrays.asList(
|
||||
return List.of(
|
||||
new MotorEncoderFixture<?>[][] {
|
||||
{TestBench.getTalonPair()}, {TestBench.getVictorPair()}, {TestBench.getJaguarPair()}
|
||||
});
|
||||
|
||||
@@ -4,17 +4,17 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import edu.wpi.first.hal.can.CANMessageNotFoundException;
|
||||
import edu.wpi.first.wpilibj.fixtures.MotorEncoderFixture;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
@@ -65,7 +65,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.getTalonPair(), 0.0}});
|
||||
return List.of(new Object[][] {{TestBench.getTalonPair(), 0.0}});
|
||||
}
|
||||
|
||||
@After
|
||||
|
||||
@@ -16,8 +16,8 @@ import edu.wpi.first.wpilibj.smartdashboard.SendableBuilderImpl;
|
||||
import edu.wpi.first.wpilibj.test.AbstractComsSetup;
|
||||
import edu.wpi.first.wpilibj.test.TestBench;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
@@ -72,13 +72,13 @@ public class PIDTest extends AbstractComsSetup {
|
||||
@Parameters
|
||||
public static Collection<Object[]> generateData() {
|
||||
// logger.fine("Loading the MotorList");
|
||||
Collection<Object[]> data = new ArrayList<Object[]>();
|
||||
Collection<Object[]> data = new ArrayList<>();
|
||||
double kp = 0.001;
|
||||
double ki = 0.0005;
|
||||
double kd = 0.0;
|
||||
for (int i = 0; i < 1; i++) {
|
||||
data.addAll(
|
||||
Arrays.asList(
|
||||
List.of(
|
||||
new Object[][] {
|
||||
{kp, ki, kd, TestBench.getTalonPair()},
|
||||
{kp, ki, kd, TestBench.getVictorPair()},
|
||||
|
||||
@@ -31,7 +31,7 @@ public abstract class AbstractComsSetup {
|
||||
// We have no way to stop the MockDS, so its thread is daemon.
|
||||
private static MockDS ds;
|
||||
|
||||
/**
|
||||
/*
|
||||
* This sets up the network communications library to enable the driver station. After starting
|
||||
* network coms, it will loop until the driver station returns that the robot is enabled, to
|
||||
* ensure that tests will be able to run on the hardware.
|
||||
|
||||
@@ -34,15 +34,11 @@ public abstract class AbstractTestSuite {
|
||||
*/
|
||||
protected List<Class<?>> getAnnotatedTestClasses() {
|
||||
SuiteClasses annotation = getClass().getAnnotation(SuiteClasses.class);
|
||||
List<Class<?>> classes = new ArrayList<>();
|
||||
if (annotation == null) {
|
||||
throw new RuntimeException(
|
||||
String.format("class '%s' must have a SuiteClasses annotation", getClass().getName()));
|
||||
}
|
||||
for (Class<?> c : annotation.value()) {
|
||||
classes.add(c);
|
||||
}
|
||||
return classes;
|
||||
return List.of(annotation.value());
|
||||
}
|
||||
|
||||
private boolean areAnySuperClassesOfTypeAbstractTestSuite(Class<?> check) {
|
||||
|
||||
@@ -24,9 +24,8 @@ public class AntJunitLauncher {
|
||||
*/
|
||||
public static void main(String... args) {
|
||||
if (args.length == 0) {
|
||||
String path =
|
||||
String pathToReports =
|
||||
String.format("%s/%s", System.getProperty("user.dir"), "/testResults/AntReports");
|
||||
String pathToReports = path;
|
||||
Project project = new Project();
|
||||
|
||||
try {
|
||||
|
||||
@@ -20,7 +20,6 @@ import edu.wpi.first.wpilibj.motorcontrol.Talon;
|
||||
import edu.wpi.first.wpilibj.motorcontrol.Victor;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -59,7 +58,7 @@ public final class TestBench {
|
||||
* The single constructor for the TestBench. This method is private in order to prevent multiple
|
||||
* TestBench objects from being allocated.
|
||||
*/
|
||||
protected TestBench() {}
|
||||
private TestBench() {}
|
||||
|
||||
/**
|
||||
* Constructs a new set of objects representing a connected set of Talon controlled Motors and an
|
||||
@@ -68,7 +67,7 @@ public final class TestBench {
|
||||
* @return a freshly allocated Talon, Encoder pair
|
||||
*/
|
||||
public static MotorEncoderFixture<Talon> getTalonPair() {
|
||||
return new MotorEncoderFixture<Talon>() {
|
||||
return new MotorEncoderFixture<>() {
|
||||
@Override
|
||||
protected Talon giveMotorController() {
|
||||
return new Talon(kTalonChannel);
|
||||
@@ -98,7 +97,7 @@ public final class TestBench {
|
||||
* @return a freshly allocated Victor, Encoder pair
|
||||
*/
|
||||
public static MotorEncoderFixture<Victor> getVictorPair() {
|
||||
return new MotorEncoderFixture<Victor>() {
|
||||
return new MotorEncoderFixture<>() {
|
||||
@Override
|
||||
protected Victor giveMotorController() {
|
||||
return new Victor(kVictorChannel);
|
||||
@@ -128,7 +127,7 @@ public final class TestBench {
|
||||
* @return a freshly allocated Jaguar, Encoder pair
|
||||
*/
|
||||
public static MotorEncoderFixture<Jaguar> getJaguarPair() {
|
||||
return new MotorEncoderFixture<Jaguar>() {
|
||||
return new MotorEncoderFixture<>() {
|
||||
@Override
|
||||
protected Jaguar giveMotorController() {
|
||||
return new Jaguar(kJaguarChannel);
|
||||
@@ -190,9 +189,9 @@ public final class TestBench {
|
||||
|
||||
/** Gets two lists of possible DIO pairs for the two pairs. */
|
||||
private static List<List<Integer[]>> getDIOCrossConnect() {
|
||||
List<List<Integer[]>> pairs = new ArrayList<List<Integer[]>>();
|
||||
List<List<Integer[]>> pairs = new ArrayList<>();
|
||||
List<Integer[]> setA =
|
||||
Arrays.asList(
|
||||
List.of(
|
||||
new Integer[][] {
|
||||
{DIOCrossConnectA1, DIOCrossConnectA2},
|
||||
{DIOCrossConnectA2, DIOCrossConnectA1}
|
||||
@@ -200,7 +199,7 @@ public final class TestBench {
|
||||
pairs.add(setA);
|
||||
|
||||
List<Integer[]> setB =
|
||||
Arrays.asList(
|
||||
List.of(
|
||||
new Integer[][] {
|
||||
{DIOCrossConnectB1, DIOCrossConnectB2},
|
||||
{DIOCrossConnectB2, DIOCrossConnectB1}
|
||||
@@ -252,7 +251,7 @@ public final class TestBench {
|
||||
* @return pairs of DIOCrossConnectFixtures
|
||||
*/
|
||||
public static Collection<Integer[]> getDIOCrossConnectCollection() {
|
||||
Collection<Integer[]> pairs = new ArrayList<Integer[]>();
|
||||
Collection<Integer[]> pairs = new ArrayList<>();
|
||||
for (Collection<Integer[]> collection : getDIOCrossConnect()) {
|
||||
pairs.addAll(collection);
|
||||
}
|
||||
@@ -267,7 +266,7 @@ public final class TestBench {
|
||||
*/
|
||||
private static Collection<Integer[]> getPairArray(
|
||||
List<Integer[]> listA, List<Integer[]> listB, boolean flip) {
|
||||
Collection<Integer[]> encoderPortPairs = new ArrayList<Integer[]>();
|
||||
Collection<Integer[]> encoderPortPairs = new ArrayList<>();
|
||||
for (Integer[] portPairsA : listA) {
|
||||
Integer[] inputs = new Integer[5];
|
||||
inputs[0] = portPairsA[0]; // InputA
|
||||
@@ -279,7 +278,7 @@ public final class TestBench {
|
||||
inputs[4] = flip ? 0 : 1; // The flip bit
|
||||
}
|
||||
|
||||
ArrayList<Integer[]> construtorInput = new ArrayList<Integer[]>();
|
||||
ArrayList<Integer[]> construtorInput = new ArrayList<>();
|
||||
construtorInput.add(inputs);
|
||||
|
||||
inputs = inputs.clone();
|
||||
@@ -300,7 +299,7 @@ public final class TestBench {
|
||||
* @return A collection of different input pairs to use for the encoder
|
||||
*/
|
||||
public static Collection<Integer[]> getEncoderDIOCrossConnectCollection() {
|
||||
Collection<Integer[]> encoderPortPairs = new ArrayList<Integer[]>();
|
||||
Collection<Integer[]> encoderPortPairs = new ArrayList<>();
|
||||
assert getDIOCrossConnect().size() == 2;
|
||||
encoderPortPairs.addAll(
|
||||
getPairArray(getDIOCrossConnect().get(0), getDIOCrossConnect().get(1), false));
|
||||
|
||||
@@ -8,7 +8,6 @@ import edu.wpi.first.wpilibj.WpiLibJTestSuite;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.logging.LogManager;
|
||||
@@ -77,40 +76,36 @@ public class TestSuite extends AbstractTestSuite {
|
||||
|
||||
/** Displays a help message for the user when they use the --help flag at runtime. */
|
||||
protected static void displayHelp() {
|
||||
StringBuilder helpMessage = new StringBuilder("Test Parameters help: \n");
|
||||
helpMessage.append(
|
||||
"\t"
|
||||
String helpMessage =
|
||||
"Test Parameters help: \n"
|
||||
+ "\t"
|
||||
+ QUICK_TEST_FLAG
|
||||
+ " will cause the quick test to be run. Ignores other flags except for "
|
||||
+ METHOD_REPEAT_FILTER
|
||||
+ "\n");
|
||||
helpMessage.append(
|
||||
"\t"
|
||||
+ "\n"
|
||||
+ "\t"
|
||||
+ CLASS_NAME_FILTER
|
||||
+ " will use the supplied regex text to search for suite/test class names "
|
||||
+ "matching the regex and run them.\n");
|
||||
helpMessage.append(
|
||||
"\t"
|
||||
+ "matching the regex and run them.\n"
|
||||
+ "\t"
|
||||
+ METHOD_NAME_FILTER
|
||||
+ " will use the supplied regex text to search for test methods (excluding methods "
|
||||
+ "with the @Ignore annotation) and run only those methods. Can be paired with "
|
||||
+ METHOD_REPEAT_FILTER
|
||||
+ " to "
|
||||
+ "repeat the selected tests multiple times.\n");
|
||||
helpMessage.append(
|
||||
"\t"
|
||||
+ "repeat the selected tests multiple times.\n"
|
||||
+ "\t"
|
||||
+ METHOD_REPEAT_FILTER
|
||||
+ " will repeat the tests selected with either "
|
||||
+ QUICK_TEST_FLAG
|
||||
+ " or "
|
||||
+ CLASS_NAME_FILTER
|
||||
+ " and run them the given number of times.\n");
|
||||
helpMessage.append(
|
||||
"[NOTE] All regex uses the syntax defined by java.util.regex.Pattern. This "
|
||||
+ " and run them the given number of times.\n"
|
||||
+ "[NOTE] All regex uses the syntax defined by java.util.regex.Pattern. This "
|
||||
+ "documentation can be found at "
|
||||
+ "http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html\n");
|
||||
helpMessage.append("\n");
|
||||
helpMessage.append("\n");
|
||||
+ "http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html\n"
|
||||
+ "\n"
|
||||
+ "\n";
|
||||
|
||||
TestBench.out().println(helpMessage);
|
||||
}
|
||||
@@ -123,7 +118,7 @@ public class TestSuite extends AbstractTestSuite {
|
||||
StringBuilder invalidMessage = new StringBuilder("Invalid Usage: " + message + "\n");
|
||||
invalidMessage.append("Params received: ");
|
||||
for (String a : args) {
|
||||
invalidMessage.append(a + " ");
|
||||
invalidMessage.append(a).append(" ");
|
||||
}
|
||||
invalidMessage.append("\n");
|
||||
invalidMessage.append(
|
||||
@@ -145,9 +140,9 @@ public class TestSuite extends AbstractTestSuite {
|
||||
for (Class<?> c : classes) {
|
||||
if (c.getPackage().equals(packagE)) {
|
||||
packagE = c.getPackage();
|
||||
loadedTestsMessage.append(packagE.getName() + "\n");
|
||||
loadedTestsMessage.append(packagE.getName()).append("\n");
|
||||
}
|
||||
loadedTestsMessage.append("\t" + c.getSimpleName() + "\n");
|
||||
loadedTestsMessage.append("\t").append(c.getSimpleName()).append("\n");
|
||||
}
|
||||
TestBench.out().println(loadedTestsMessage);
|
||||
}
|
||||
@@ -193,7 +188,7 @@ public class TestSuite extends AbstractTestSuite {
|
||||
}
|
||||
}
|
||||
|
||||
ArrayList<String> argsParsed = new ArrayList<String>(Arrays.asList(args));
|
||||
ArrayList<String> argsParsed = new ArrayList<>(List.of(args));
|
||||
if (argsParsed.contains(HELP_FLAG)) {
|
||||
// If the user inputs the help flag then return the help message and exit
|
||||
// without running any tests
|
||||
@@ -257,7 +252,7 @@ public class TestSuite extends AbstractTestSuite {
|
||||
// If a specific method has been requested
|
||||
if (methodFilter) {
|
||||
List<ClassMethodPair> pairs = (new TestSuite()).getMethodMatching(methodRegex);
|
||||
if (pairs.size() == 0) {
|
||||
if (pairs.isEmpty()) {
|
||||
displayInvalidUsage(
|
||||
"None of the arguments passed to the method name filter matched.", args);
|
||||
return null;
|
||||
@@ -292,7 +287,7 @@ public class TestSuite extends AbstractTestSuite {
|
||||
// If a specific class has been requested
|
||||
if (classFilter) {
|
||||
List<Class<?>> testClasses = (new TestSuite()).getSuiteOrTestMatchingRegex(classRegex);
|
||||
if (testClasses.size() == 0) {
|
||||
if (testClasses.isEmpty()) {
|
||||
displayInvalidUsage("None of the arguments passed to the filter matched.", args);
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user