mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
Switch non-integration tests to JUnit 5 (#1120)
This commit is contained in:
committed by
Peter Johnson
parent
c7e97f45f5
commit
9108a93598
@@ -7,12 +7,12 @@
|
||||
|
||||
package edu.wpi.cscore;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JNITest {
|
||||
class JNITest {
|
||||
@Test
|
||||
public void jniLinkTest() {
|
||||
void jniLinkTest() {
|
||||
// Test to verify that the JNI test link works correctly.
|
||||
edu.wpi.cscore.CameraServerJNI.getHostname();
|
||||
CameraServerJNI.getHostname();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,25 +7,24 @@
|
||||
|
||||
package edu.wpi.first.hal.sim;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.AccelerometerJNI;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.sim.AccelerometerSim;
|
||||
import edu.wpi.first.wpilibj.sim.CallbackStore;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class AccelerometerSimTest {
|
||||
class AccelerometerSimTest {
|
||||
static class TriggeredStore {
|
||||
public boolean wasTriggered = false;
|
||||
public boolean wasTriggered;
|
||||
public boolean setValue = true;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCallbacks() {
|
||||
void testCallbacks() {
|
||||
HAL.initialize(500, 0);
|
||||
AccelerometerSim sim = new AccelerometerSim();
|
||||
sim.resetData();
|
||||
|
||||
@@ -44,6 +44,7 @@ class ConnectionListenerTest {
|
||||
/**
|
||||
* Connect to the server.
|
||||
*/
|
||||
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
|
||||
private void connect() {
|
||||
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
|
||||
m_clientInst.startClient("127.0.0.1", 10000);
|
||||
@@ -112,6 +113,7 @@ class ConnectionListenerTest {
|
||||
|
||||
@Test
|
||||
@DisabledOnOs(OS.WINDOWS)
|
||||
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
|
||||
void testThreaded() {
|
||||
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
|
||||
List<ConnectionNotification> events = new ArrayList<>();
|
||||
|
||||
@@ -10,14 +10,21 @@ package edu.wpi.first.networktables;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class EntryListenerTest extends TestCase {
|
||||
NetworkTableInstance m_serverInst;
|
||||
NetworkTableInstance m_clientInst;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
class EntryListenerTest {
|
||||
private NetworkTableInstance m_serverInst;
|
||||
private NetworkTableInstance m_clientInst;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
m_serverInst = NetworkTableInstance.create();
|
||||
m_serverInst.setNetworkIdentity("server");
|
||||
|
||||
@@ -25,12 +32,13 @@ public class EntryListenerTest extends TestCase {
|
||||
m_clientInst.setNetworkIdentity("client");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
m_clientInst.close();
|
||||
m_serverInst.close();
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
|
||||
private void connect() {
|
||||
m_serverInst.startServer("connectionlistenertest.ini", "127.0.0.1", 10000);
|
||||
m_clientInst.startClient("127.0.0.1", 10000);
|
||||
@@ -51,7 +59,8 @@ public class EntryListenerTest extends TestCase {
|
||||
/**
|
||||
* Test prefix with a new remote.
|
||||
*/
|
||||
public void testPrefixNewRemote() {
|
||||
@Test
|
||||
void testPrefixNewRemote() {
|
||||
connect();
|
||||
List<EntryNotification> events = new ArrayList<>();
|
||||
final int handle = m_serverInst.addEntryListener("/foo", events::add,
|
||||
@@ -70,11 +79,13 @@ public class EntryListenerTest extends TestCase {
|
||||
assertTrue(m_serverInst.waitForEntryListenerQueue(1.0));
|
||||
|
||||
// Check the event
|
||||
assertEquals(events.size(), 1);
|
||||
assertEquals(events.get(0).listener, handle);
|
||||
assertEquals(events.get(0).getEntry(), m_serverInst.getEntry("/foo/bar"));
|
||||
assertEquals(events.get(0).name, "/foo/bar");
|
||||
assertEquals(events.get(0).value, NetworkTableValue.makeDouble(1.0));
|
||||
assertEquals(events.get(0).flags, EntryListenerFlags.kNew);
|
||||
assertAll("Event",
|
||||
() -> assertEquals(1, events.size()),
|
||||
() -> assertEquals(handle, events.get(0).listener),
|
||||
() -> assertEquals(m_serverInst.getEntry("/foo/bar"), events.get(0).getEntry()),
|
||||
() -> assertEquals("/foo/bar", events.get(0).name),
|
||||
() -> assertEquals(NetworkTableValue.makeDouble(1.0), events.get(0).value),
|
||||
() -> assertEquals(EntryListenerFlags.kNew, events.get(0).flags)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,11 @@
|
||||
|
||||
package edu.wpi.first.networktables;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class JNITest {
|
||||
class JNITest {
|
||||
@Test
|
||||
public void jniLinkTest() {
|
||||
void jniLinkTest() {
|
||||
// Test to verify that the JNI test link works correctly.
|
||||
int inst = NetworkTablesJNI.getDefaultInstance();
|
||||
NetworkTablesJNI.flush(inst);
|
||||
|
||||
@@ -10,25 +10,29 @@ package edu.wpi.first.networktables;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class LoggerTest extends TestCase {
|
||||
NetworkTableInstance m_clientInst;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
class LoggerTest {
|
||||
private NetworkTableInstance m_clientInst;
|
||||
|
||||
@BeforeEach
|
||||
protected void setUp() {
|
||||
m_clientInst = NetworkTableInstance.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
@AfterEach
|
||||
protected void tearDown() {
|
||||
m_clientInst.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the logger.
|
||||
*/
|
||||
public void testLogger() {
|
||||
@Test
|
||||
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
|
||||
void addMessageTest() {
|
||||
List<LogMessage> msgs = new ArrayList<>();
|
||||
m_clientInst.addLogger(msgs::add, LogMessage.kInfo, 100);
|
||||
|
||||
|
||||
@@ -7,68 +7,74 @@
|
||||
|
||||
package edu.wpi.first.networktables;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
public class NetworkTableTest extends TestCase {
|
||||
public void testBasenameKey() {
|
||||
assertEquals("simple", NetworkTable.basenameKey("simple"));
|
||||
assertEquals("simple", NetworkTable.basenameKey("one/two/many/simple"));
|
||||
assertEquals("simple",
|
||||
NetworkTable.basenameKey("//////an/////awful/key////simple"));
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
class NetworkTableTest {
|
||||
private static Stream<Arguments> basenameKeyArguments() {
|
||||
return Stream.of(
|
||||
Arguments.of("simple", "simple"),
|
||||
Arguments.of("simple", "one/two/many/simple"),
|
||||
Arguments.of("simple", "//////an/////awful/key////simple")
|
||||
);
|
||||
}
|
||||
|
||||
public void testNormalizeKeySlash() {
|
||||
assertEquals("/", NetworkTable.normalizeKey("///"));
|
||||
assertEquals("/no/normal/req", NetworkTable.normalizeKey("/no/normal/req"));
|
||||
assertEquals("/no/leading/slash",
|
||||
NetworkTable.normalizeKey("no/leading/slash"));
|
||||
assertEquals(
|
||||
"/what/an/awful/key/",
|
||||
NetworkTable.normalizeKey("//////what////an/awful/////key///"));
|
||||
@ParameterizedTest
|
||||
@MethodSource("basenameKeyArguments")
|
||||
void basenameKeyTest(final String expected, final String testString) {
|
||||
assertEquals(expected, NetworkTable.basenameKey(testString));
|
||||
}
|
||||
|
||||
public void testNormalizeKeyNoSlash() {
|
||||
assertEquals("a", NetworkTable.normalizeKey("a", false));
|
||||
assertEquals("a", NetworkTable.normalizeKey("///a", false));
|
||||
assertEquals("leading/slash",
|
||||
NetworkTable.normalizeKey("/leading/slash", false));
|
||||
assertEquals("no/leading/slash",
|
||||
NetworkTable.normalizeKey("no/leading/slash", false));
|
||||
assertEquals(
|
||||
"what/an/awful/key/",
|
||||
NetworkTable.normalizeKey("//////what////an/awful/////key///", false));
|
||||
private static Stream<Arguments> normalizeKeySlashArguments() {
|
||||
return Stream.of(
|
||||
Arguments.of("/", "///"),
|
||||
Arguments.of("/no/normal/req", "/no/normal/req"),
|
||||
Arguments.of("/no/leading/slash", "no/leading/slash"),
|
||||
Arguments.of("/what/an/awful/key/", "//////what////an/awful/////key///")
|
||||
);
|
||||
}
|
||||
|
||||
public void testGetHierarchyEmpty() {
|
||||
List<String> expected = new ArrayList<>();
|
||||
expected.add("/");
|
||||
assertEquals(expected, NetworkTable.getHierarchy(""));
|
||||
@ParameterizedTest
|
||||
@MethodSource("normalizeKeySlashArguments")
|
||||
void normalizeKeySlashTest(final String expected, final String testString) {
|
||||
assertEquals(expected, NetworkTable.normalizeKey(testString));
|
||||
}
|
||||
|
||||
public void testGetHierarchyRoot() {
|
||||
List<String> expected = new ArrayList<>();
|
||||
expected.add("/");
|
||||
assertEquals(expected, NetworkTable.getHierarchy("/"));
|
||||
private static Stream<Arguments> normalizeKeyNoSlashArguments() {
|
||||
return Stream.of(
|
||||
Arguments.of("a", "a"),
|
||||
Arguments.of("a", "///a"),
|
||||
Arguments.of("leading/slash", "/leading/slash"),
|
||||
Arguments.of("no/leading/slash", "no/leading/slash"),
|
||||
Arguments.of("what/an/awful/key/", "//////what////an/awful/////key///")
|
||||
);
|
||||
}
|
||||
|
||||
public void testGetHierarchyNormal() {
|
||||
List<String> expected = new ArrayList<>();
|
||||
expected.add("/");
|
||||
expected.add("/foo");
|
||||
expected.add("/foo/bar");
|
||||
expected.add("/foo/bar/baz");
|
||||
assertEquals(expected, NetworkTable.getHierarchy("/foo/bar/baz"));
|
||||
@ParameterizedTest
|
||||
@MethodSource("normalizeKeyNoSlashArguments")
|
||||
void normalizeKeyNoSlashTest(final String expected, final String testString) {
|
||||
assertEquals(expected, NetworkTable.normalizeKey(testString, false));
|
||||
}
|
||||
|
||||
public void testGetHierarchyTrailingSlash() {
|
||||
List<String> expected = new ArrayList<>();
|
||||
expected.add("/");
|
||||
expected.add("/foo");
|
||||
expected.add("/foo/bar");
|
||||
expected.add("/foo/bar/");
|
||||
assertEquals(expected, NetworkTable.getHierarchy("/foo/bar/"));
|
||||
private static Stream<Arguments> getHierarchyArguments() {
|
||||
return Stream.of(
|
||||
Arguments.of(Arrays.asList("/"), ""),
|
||||
Arguments.of(Arrays.asList("/"), "/"),
|
||||
Arguments.of(Arrays.asList("/", "/foo", "/foo/bar", "/foo/bar/baz"), "/foo/bar/baz"),
|
||||
Arguments.of(Arrays.asList("/", "/foo", "/foo/bar", "/foo/bar/"), "/foo/bar/")
|
||||
);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource("getHierarchyArguments")
|
||||
void getHierarchyTest(final List<String> expected, final String testString) {
|
||||
assertEquals(expected, NetworkTable.getHierarchy(testString));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,10 +115,9 @@ compileJava {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompileOnly 'junit:junit:4.12'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.2.0'
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.2.0'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.2.0'
|
||||
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.2.0'
|
||||
|
||||
devCompile sourceSets.main.output
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<description>PMD Ruleset for WPILib</description>
|
||||
|
||||
<exclude-pattern>.*/*JNI.*</exclude-pattern>
|
||||
<exclude-pattern>.*/*Test.*</exclude-pattern>
|
||||
<exclude-pattern>.*/*IntegrationTests.*</exclude-pattern>
|
||||
|
||||
<rule ref="category/java/bestpractices.xml">
|
||||
<exclude name="AccessorClassGeneration" />
|
||||
@@ -16,6 +16,8 @@
|
||||
<exclude name="AvoidReassigningParameters" />
|
||||
<exclude name="JUnitAssertionsShouldIncludeMessage" />
|
||||
<exclude name="JUnitTestContainsTooManyAsserts" />
|
||||
<exclude name="JUnit4TestShouldUseAfterAnnotation" />
|
||||
<exclude name="JUnit4TestShouldUseBeforeAnnotation" />
|
||||
<exclude name="JUnit4TestShouldUseTestAnnotation" />
|
||||
<exclude name="ReplaceHashtableWithMap" />
|
||||
<exclude name="ReplaceVectorWithList" />
|
||||
@@ -23,6 +25,12 @@
|
||||
<exclude name="SystemPrintln" />
|
||||
<exclude name="UseVarargs" />
|
||||
</rule>
|
||||
<rule ref="category/java/bestpractices.xml/UnusedPrivateMethod">
|
||||
<properties>
|
||||
<property name="violationSuppressRegex"
|
||||
value=".*'.*Arguments\(\)'.*" />
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<rule ref="category/java/design.xml">
|
||||
<exclude name="DataClass" />
|
||||
@@ -61,33 +69,6 @@
|
||||
class="net.sourceforge.pmd.lang.java.rule.migrating.UnnecessaryCastRule"
|
||||
externalInfoUrl="https://github.com/pmd/pmd/blob/master/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/migrating/UnnecessaryCastRule.java" />
|
||||
|
||||
<!--
|
||||
<rule ref="rulesets/java/basic.xml" />
|
||||
<rule ref="rulesets/java/braces.xml" />
|
||||
<rule ref="rulesets/java/empty.xml" />
|
||||
<rule ref="rulesets/java/empty.xml/EmptyCatchBlock">
|
||||
<properties>
|
||||
<property name="allowCommentedBlocks"
|
||||
value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="rulesets/java/imports.xml" />
|
||||
<rule ref="rulesets/java/junit.xml">
|
||||
<exclude name="JUnitTestContainsTooManyAsserts" />
|
||||
</rule>
|
||||
<rule ref="rulesets/java/strings.xml">
|
||||
<exclude name="AvoidDuplicateLiterals" />
|
||||
</rule>
|
||||
<rule ref="rulesets/java/unnecessary.xml" />
|
||||
<rule ref="rulesets/java/unusedcode.xml" />
|
||||
<rule ref="rulesets/java/unusedcode.xml/UnusedFormalParameter">
|
||||
<properties>
|
||||
<property name="checkAll"
|
||||
value="true" />
|
||||
</properties>
|
||||
</rule>
|
||||
-->
|
||||
|
||||
<!-- Custom Rules -->
|
||||
<rule name="UseRequireNonNull"
|
||||
message="Use Objects.requireNonNull() instead of throwing a NullPointerException yourself."
|
||||
@@ -98,9 +79,9 @@
|
||||
<properties>
|
||||
<property name="xpath">
|
||||
<value>
|
||||
<![CDATA[
|
||||
//IfStatement[child::Expression//NullLiteral]/Statement//ThrowStatement/Expression/PrimaryExpression/PrimaryPrefix/AllocationExpression/ClassOrInterfaceType[@Image='NullPointerException']
|
||||
]]>
|
||||
<![CDATA[
|
||||
//IfStatement[child::Expression//NullLiteral]/Statement//ThrowStatement/Expression/PrimaryExpression/PrimaryPrefix/AllocationExpression/ClassOrInterfaceType[@Image='NullPointerException']
|
||||
]]>
|
||||
</value>
|
||||
</property>
|
||||
</properties>
|
||||
|
||||
@@ -60,8 +60,6 @@ dependencies {
|
||||
compile project(':ntcore')
|
||||
compile project(':cscore')
|
||||
compile project(':cameraserver')
|
||||
testCompile 'org.hamcrest:hamcrest-all:1.3'
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'com.google.guava:guava:19.0'
|
||||
devCompile project(':hal')
|
||||
devCompile project(':wpiutil')
|
||||
|
||||
@@ -7,26 +7,26 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class CircularBufferTest {
|
||||
private double[] m_values = {751.848, 766.366, 342.657, 234.252, 716.126,
|
||||
class CircularBufferTest {
|
||||
private final double[] m_values = {751.848, 766.366, 342.657, 234.252, 716.126,
|
||||
132.344, 445.697, 22.727, 421.125, 799.913};
|
||||
private double[] m_addFirstOut = {799.913, 421.125, 22.727, 445.697, 132.344,
|
||||
private final double[] m_addFirstOut = {799.913, 421.125, 22.727, 445.697, 132.344,
|
||||
716.126, 234.252, 342.657};
|
||||
private double[] m_addLastOut = {342.657, 234.252, 716.126, 132.344, 445.697,
|
||||
private final double[] m_addLastOut = {342.657, 234.252, 716.126, 132.344, 445.697,
|
||||
22.727, 421.125, 799.913};
|
||||
|
||||
@BeforeClass
|
||||
public static void before() {
|
||||
@BeforeAll
|
||||
static void before() {
|
||||
UnitTestUtility.setupMockBase();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addFirstTest() {
|
||||
void addFirstTest() {
|
||||
CircularBuffer queue = new CircularBuffer(8);
|
||||
|
||||
for (double value : m_values) {
|
||||
@@ -39,7 +39,7 @@ public class CircularBufferTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void addLastTest() {
|
||||
void addLastTest() {
|
||||
CircularBuffer queue = new CircularBuffer(8);
|
||||
|
||||
for (double value : m_values) {
|
||||
@@ -52,7 +52,7 @@ public class CircularBufferTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pushPopTest() {
|
||||
void pushPopTest() {
|
||||
CircularBuffer queue = new CircularBuffer(3);
|
||||
|
||||
// Insert three elements into the buffer
|
||||
@@ -96,7 +96,7 @@ public class CircularBufferTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resetTest() {
|
||||
void resetTest() {
|
||||
CircularBuffer queue = new CircularBuffer(5);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
@@ -111,7 +111,8 @@ public class CircularBufferTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resizeTest() {
|
||||
@SuppressWarnings("PMD.ExcessiveMethodLength")
|
||||
void resizeTest() {
|
||||
CircularBuffer queue = new CircularBuffer(5);
|
||||
|
||||
/* Buffer contains {1, 2, 3, _, _}
|
||||
|
||||
@@ -7,22 +7,22 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class PIDToleranceTest {
|
||||
class PIDToleranceTest {
|
||||
private PIDController m_pid;
|
||||
private final double m_setPoint = 50.0;
|
||||
private final double m_tolerance = 10.0;
|
||||
private final double m_range = 200;
|
||||
private static final double m_setPoint = 50.0;
|
||||
private static final double m_tolerance = 10.0;
|
||||
private static final double m_range = 200;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupClass() {
|
||||
@BeforeAll
|
||||
static void setupClass() {
|
||||
UnitTestUtility.setupMockBase();
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class PIDToleranceTest {
|
||||
}
|
||||
|
||||
private FakeInput m_inp;
|
||||
private PIDOutput m_out = new PIDOutput() {
|
||||
private final PIDOutput m_out = new PIDOutput() {
|
||||
@Override
|
||||
public void pidWrite(double out) {
|
||||
}
|
||||
@@ -57,53 +57,53 @@ public class PIDToleranceTest {
|
||||
};
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
m_inp = new FakeInput();
|
||||
m_pid = new PIDController(0.05, 0.0, 0.0, m_inp, m_out);
|
||||
m_pid.setInputRange(-m_range / 2, m_range / 2);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
@AfterEach
|
||||
void tearDown() {
|
||||
m_pid.close();
|
||||
m_pid = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbsoluteTolerance() {
|
||||
void absoluteToleranceTest() {
|
||||
m_pid.setAbsoluteTolerance(m_tolerance);
|
||||
m_pid.setSetpoint(m_setPoint);
|
||||
m_pid.enable();
|
||||
Timer.delay(1);
|
||||
assertFalse("Error was in tolerance when it should not have been. Error was "
|
||||
+ m_pid.getError(), m_pid.onTarget());
|
||||
assertFalse(m_pid.onTarget(), "Error was in tolerance when it should not have been. Error was "
|
||||
+ m_pid.getError());
|
||||
m_inp.m_val = m_setPoint + m_tolerance / 2;
|
||||
Timer.delay(1.0);
|
||||
assertTrue("Error was not in tolerance when it should have been. Error was "
|
||||
+ m_pid.getError(), m_pid.onTarget());
|
||||
assertTrue(m_pid.onTarget(), "Error was not in tolerance when it should have been. Error was "
|
||||
+ m_pid.getError());
|
||||
m_inp.m_val = m_setPoint + 10 * m_tolerance;
|
||||
Timer.delay(1.0);
|
||||
assertFalse("Error was in tolerance when it should not have been. Error was "
|
||||
+ m_pid.getError(), m_pid.onTarget());
|
||||
assertFalse(m_pid.onTarget(), "Error was in tolerance when it should not have been. Error was "
|
||||
+ m_pid.getError());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPercentTolerance() {
|
||||
void percentToleranceTest() {
|
||||
m_pid.setPercentTolerance(m_tolerance);
|
||||
m_pid.setSetpoint(m_setPoint);
|
||||
m_pid.enable();
|
||||
assertFalse("Error was in tolerance when it should not have been. Error was "
|
||||
+ m_pid.getError(), m_pid.onTarget());
|
||||
assertFalse(m_pid.onTarget(), "Error was in tolerance when it should not have been. Error was "
|
||||
+ m_pid.getError());
|
||||
//half of percent tolerance away from setPoint
|
||||
m_inp.m_val = m_setPoint + m_tolerance / 200 * m_range;
|
||||
Timer.delay(1.0);
|
||||
assertTrue("Error was not in tolerance when it should have been. Error was "
|
||||
+ m_pid.getError(), m_pid.onTarget());
|
||||
assertTrue(m_pid.onTarget(), "Error was not in tolerance when it should have been. Error was "
|
||||
+ m_pid.getError());
|
||||
//double percent tolerance away from setPoint
|
||||
m_inp.m_val = m_setPoint + m_tolerance / 50 * m_range;
|
||||
Timer.delay(1.0);
|
||||
assertFalse("Error was in tolerance when it should not have been. Error was "
|
||||
+ m_pid.getError(), m_pid.onTarget());
|
||||
assertFalse(m_pid.onTarget(), "Error was in tolerance when it should not have been. Error was "
|
||||
+ m_pid.getError());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
public class RobotControllerTest extends UtilityClassTest {
|
||||
public RobotControllerTest() {
|
||||
class RobotControllerTest extends UtilityClassTest {
|
||||
RobotControllerTest() {
|
||||
super(RobotController.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,107 +8,102 @@
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.DoubleStream;
|
||||
import java.util.stream.IntStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class SpeedControllerGroupTest {
|
||||
private final SpeedController[] m_speedControllers;
|
||||
private final SpeedControllerGroup m_group;
|
||||
|
||||
/**
|
||||
* Returns a Collection of ArrayLists with various MockSpeedController configurations.
|
||||
*/
|
||||
@Parameterized.Parameters
|
||||
public static Collection<Object[][]> data() {
|
||||
return Arrays.asList((Object[][][]) new SpeedController[][][] {
|
||||
{{new MockSpeedController()}},
|
||||
{{new MockSpeedController(),
|
||||
new MockSpeedController()}},
|
||||
{{new MockSpeedController(),
|
||||
new MockSpeedController(),
|
||||
new MockSpeedController()}}
|
||||
class SpeedControllerGroupTest {
|
||||
private static Stream<Arguments> speedControllerArguments() {
|
||||
return IntStream.of(1, 2, 3).mapToObj(number -> {
|
||||
SpeedController[] speedControllers = Stream.generate(MockSpeedController::new)
|
||||
.limit(number)
|
||||
.toArray(SpeedController[]::new);
|
||||
SpeedControllerGroup group = new SpeedControllerGroup(speedControllers[0],
|
||||
Arrays.copyOfRange(speedControllers, 1, speedControllers.length));
|
||||
return Arguments.of(group, speedControllers);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct SpeedControllerGroupTest.
|
||||
*/
|
||||
public SpeedControllerGroupTest(SpeedController[] speedControllers) {
|
||||
m_group = new SpeedControllerGroup(speedControllers[0],
|
||||
Arrays.copyOfRange(speedControllers, 1, speedControllers.length));
|
||||
m_speedControllers = speedControllers;
|
||||
@ParameterizedTest
|
||||
@MethodSource("speedControllerArguments")
|
||||
void setTest(final SpeedControllerGroup group, final SpeedController[] speedControllers) {
|
||||
group.set(1.0);
|
||||
|
||||
assertArrayEquals(DoubleStream.generate(() -> 1.0).limit(speedControllers.length).toArray(),
|
||||
Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(),
|
||||
0.00005);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSet() {
|
||||
m_group.set(1.0);
|
||||
@ParameterizedTest
|
||||
@MethodSource("speedControllerArguments")
|
||||
void getInvertedTest(final SpeedControllerGroup group,
|
||||
final SpeedController[] speedControllers) {
|
||||
group.setInverted(true);
|
||||
|
||||
assertArrayEquals(Arrays.stream(m_speedControllers).mapToDouble(__ -> 1.0).toArray(),
|
||||
Arrays.stream(m_speedControllers).mapToDouble(SpeedController::get).toArray(),
|
||||
0.0);
|
||||
assertTrue(group.getInverted());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetInverted() {
|
||||
m_group.setInverted(true);
|
||||
@ParameterizedTest
|
||||
@MethodSource("speedControllerArguments")
|
||||
void setInvertedDoesNotModifySpeedControllersTest(final SpeedControllerGroup group,
|
||||
final SpeedController[] speedControllers) {
|
||||
group.setInverted(true);
|
||||
|
||||
assertTrue(m_group.getInverted());
|
||||
assertArrayEquals(Stream.generate(() -> false).limit(speedControllers.length).toArray(),
|
||||
Arrays.stream(speedControllers).map(SpeedController::getInverted).toArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInvertedDoesNotModifySpeedControllers() {
|
||||
for (SpeedController speedController : m_speedControllers) {
|
||||
speedController.setInverted(false);
|
||||
}
|
||||
m_group.setInverted(true);
|
||||
@ParameterizedTest
|
||||
@MethodSource("speedControllerArguments")
|
||||
void setInvertedDoesInvertTest(final SpeedControllerGroup group,
|
||||
final SpeedController[] speedControllers) {
|
||||
group.setInverted(true);
|
||||
group.set(1.0);
|
||||
|
||||
assertArrayEquals(Arrays.stream(m_speedControllers).map(__ -> false).toArray(),
|
||||
Arrays.stream(m_speedControllers).map(SpeedController::getInverted).toArray());
|
||||
assertArrayEquals(DoubleStream.generate(() -> -1.0).limit(speedControllers.length).toArray(),
|
||||
Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(),
|
||||
0.00005);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetInvertedDoesInvert() {
|
||||
m_group.setInverted(true);
|
||||
m_group.set(1.0);
|
||||
@ParameterizedTest
|
||||
@MethodSource("speedControllerArguments")
|
||||
void disableTest(final SpeedControllerGroup group,
|
||||
final SpeedController[] speedControllers) {
|
||||
group.set(1.0);
|
||||
group.disable();
|
||||
|
||||
assertArrayEquals(Arrays.stream(m_speedControllers).mapToDouble(__ -> -1.0).toArray(),
|
||||
Arrays.stream(m_speedControllers).mapToDouble(SpeedController::get).toArray(),
|
||||
0.0);
|
||||
assertArrayEquals(DoubleStream.generate(() -> 0.0).limit(speedControllers.length).toArray(),
|
||||
Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(),
|
||||
0.00005);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDisable() {
|
||||
m_group.set(1.0);
|
||||
m_group.disable();
|
||||
@ParameterizedTest
|
||||
@MethodSource("speedControllerArguments")
|
||||
void stopMotorTest(final SpeedControllerGroup group,
|
||||
final SpeedController[] speedControllers) {
|
||||
group.set(1.0);
|
||||
group.stopMotor();
|
||||
|
||||
assertArrayEquals(Arrays.stream(m_speedControllers).mapToDouble(__ -> 0.0).toArray(),
|
||||
Arrays.stream(m_speedControllers).mapToDouble(SpeedController::get).toArray(),
|
||||
0.0);
|
||||
assertArrayEquals(DoubleStream.generate(() -> 0.0).limit(speedControllers.length).toArray(),
|
||||
Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(),
|
||||
0.00005);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStopMotor() {
|
||||
m_group.set(1.0);
|
||||
m_group.stopMotor();
|
||||
@ParameterizedTest
|
||||
@MethodSource("speedControllerArguments")
|
||||
void pidWriteTest(final SpeedControllerGroup group,
|
||||
final SpeedController[] speedControllers) {
|
||||
group.pidWrite(1.0);
|
||||
|
||||
assertArrayEquals(Arrays.stream(m_speedControllers).mapToDouble(__ -> 0.0).toArray(),
|
||||
Arrays.stream(m_speedControllers).mapToDouble(SpeedController::get).toArray(),
|
||||
0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPidWrite() {
|
||||
m_group.pidWrite(1.0);
|
||||
|
||||
assertArrayEquals(Arrays.stream(m_speedControllers).mapToDouble(__ -> 1.0).toArray(),
|
||||
Arrays.stream(m_speedControllers).mapToDouble(SpeedController::get).toArray(),
|
||||
0.0);
|
||||
assertArrayEquals(DoubleStream.generate(() -> 1.0).limit(speedControllers.length).toArray(),
|
||||
Arrays.stream(speedControllers).mapToDouble(SpeedController::get).toArray(),
|
||||
0.00005);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ public final class UnitTestUtility {
|
||||
Thread.sleep((long) (seconds * 1e3));
|
||||
} catch (InterruptedException ex) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new RuntimeException("Thread was interrupted", ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,23 +9,25 @@ package edu.wpi.first.wpilibj;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.DynamicTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestFactory;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
|
||||
|
||||
@SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod")
|
||||
public abstract class UtilityClassTest {
|
||||
@Before
|
||||
public void setup() {
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
UnitTestUtility.setupMockBase();
|
||||
}
|
||||
|
||||
@@ -36,38 +38,30 @@ public abstract class UtilityClassTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingleConstructor() {
|
||||
assertEquals("More than one constructor defined", 1,
|
||||
m_clazz.getDeclaredConstructors().length);
|
||||
public void singleConstructorTest() {
|
||||
assertEquals(1, m_clazz.getDeclaredConstructors().length,
|
||||
"More than one constructor defined");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConstructorPrivate() {
|
||||
public void constructorPrivateTest() {
|
||||
Constructor constructor = m_clazz.getDeclaredConstructors()[0];
|
||||
|
||||
assertFalse("Constructor is not private", constructor.isAccessible());
|
||||
assertFalse(constructor.isAccessible(), "Constructor is not private");
|
||||
}
|
||||
|
||||
@Test(expected = InvocationTargetException.class)
|
||||
public void testConstructorReflection() throws Throwable {
|
||||
@Test
|
||||
public void constructorReflectionTest() {
|
||||
Constructor constructor = m_clazz.getDeclaredConstructors()[0];
|
||||
constructor.setAccessible(true);
|
||||
constructor.newInstance();
|
||||
assertThrows(InvocationTargetException.class, () -> constructor.newInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublicMethodsStatic() {
|
||||
List<String> failures = new ArrayList<>();
|
||||
for (Method method : m_clazz.getDeclaredMethods()) {
|
||||
int modifiers = method.getModifiers();
|
||||
if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) {
|
||||
failures.add(method.toString());
|
||||
}
|
||||
}
|
||||
|
||||
if (!failures.isEmpty()) {
|
||||
fail("Found public methods that are not static: "
|
||||
+ Arrays.toString(failures.toArray()));
|
||||
}
|
||||
@TestFactory
|
||||
Stream<DynamicTest> publicMethodsStaticTestFactory() {
|
||||
return Arrays.stream(m_clazz.getDeclaredMethods())
|
||||
.filter(method -> Modifier.isPublic(method.getModifiers()))
|
||||
.map(method -> dynamicTest(method.getName(),
|
||||
() -> assertTrue(Modifier.isStatic(method.getModifiers()))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,16 +7,17 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.can;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
|
||||
public class CANStatusTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
class CANStatusTest {
|
||||
@Test
|
||||
public void canStatusGetDoesntThrow() {
|
||||
void canStatusGetDoesntThrow() {
|
||||
HAL.initialize(500, 0);
|
||||
CANStatus status = new CANStatus();
|
||||
CANJNI.GetCANStatus(status);
|
||||
// Nothing we can assert, so just make sure it didn't throw.
|
||||
assertDoesNotThrow(() -> CANJNI.GetCANStatus(status));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,19 +7,20 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
import edu.wpi.first.wpilibj.UnitTestUtility;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
* The basic test for all {@link Command} tests.
|
||||
*/
|
||||
public abstract class AbstractCommandTest {
|
||||
@Before
|
||||
public void commandSetup() {
|
||||
@BeforeEach
|
||||
void commandSetup() {
|
||||
UnitTestUtility.setupMockBase();
|
||||
Scheduler.getInstance().removeAll();
|
||||
Scheduler.getInstance().enable();
|
||||
@@ -43,18 +44,16 @@ public abstract class AbstractCommandTest {
|
||||
|
||||
protected void assertCommandState(MockCommand command, int initialize, int execute,
|
||||
int isFinished, int end, int interrupted) {
|
||||
assertEquals(initialize, command.getInitializeCount());
|
||||
assertEquals(execute, command.getExecuteCount());
|
||||
assertEquals(isFinished, command.getIsFinishedCount());
|
||||
assertEquals(end, command.getEndCount());
|
||||
assertEquals(interrupted, command.getInterruptedCount());
|
||||
assertAll(
|
||||
() -> assertEquals(initialize, command.getInitializeCount()),
|
||||
() -> assertEquals(execute, command.getExecuteCount()),
|
||||
() -> assertEquals(isFinished, command.getIsFinishedCount()),
|
||||
() -> assertEquals(end, command.getEndCount()),
|
||||
() -> assertEquals(interrupted, command.getInterruptedCount())
|
||||
);
|
||||
}
|
||||
|
||||
protected void sleep(int time) {
|
||||
try {
|
||||
Thread.sleep(time);
|
||||
} catch (InterruptedException ex) {
|
||||
fail("Sleep Interrupted!?!?!?!?");
|
||||
}
|
||||
assertDoesNotThrow(() -> Thread.sleep(time));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.buttons.InternalButton;
|
||||
|
||||
@@ -17,12 +17,12 @@ import edu.wpi.first.wpilibj.buttons.InternalButton;
|
||||
* Test that covers the {@link edu.wpi.first.wpilibj.buttons.Button} with the {@link Command}
|
||||
* library.
|
||||
*/
|
||||
public class ButtonTest extends AbstractCommandTest {
|
||||
class ButtonTest extends AbstractCommandTest {
|
||||
private InternalButton m_button1;
|
||||
private InternalButton m_button2;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
m_button1 = new InternalButton();
|
||||
m_button2 = new InternalButton();
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class ButtonTest extends AbstractCommandTest {
|
||||
* Simple Button Test.
|
||||
*/
|
||||
@Test
|
||||
public void test() {
|
||||
void buttonTest() {
|
||||
final MockCommand command1 = new MockCommand();
|
||||
final MockCommand command2 = new MockCommand();
|
||||
final MockCommand command3 = new MockCommand();
|
||||
|
||||
@@ -7,17 +7,17 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
public class CommandParallelGroupTest extends AbstractCommandTest {
|
||||
class CommandParallelGroupTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Simple Parallel Command Group With 2 commands one command terminates first.
|
||||
*/
|
||||
@Test
|
||||
public void testParallelCommandGroupWithTwoCommands() {
|
||||
void parallelCommandGroupWithTwoCommandsTest() {
|
||||
final MockCommand command1 = new MockCommand();
|
||||
final MockCommand command2 = new MockCommand();
|
||||
|
||||
|
||||
@@ -7,17 +7,17 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
public class CommandScheduleTest extends AbstractCommandTest {
|
||||
class CommandScheduleTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Simple scheduling of a command and making sure the command is run and successfully terminates.
|
||||
*/
|
||||
@Test
|
||||
public void testRunAndTerminate() {
|
||||
void runAndTerminateTest() {
|
||||
final MockCommand command = new MockCommand();
|
||||
command.start();
|
||||
assertCommandState(command, 0, 0, 0, 0, 0);
|
||||
@@ -39,7 +39,7 @@ public class CommandScheduleTest extends AbstractCommandTest {
|
||||
* Simple scheduling of a command and making sure the command is run and cancels correctly.
|
||||
*/
|
||||
@Test
|
||||
public void testRunAndCancel() {
|
||||
void runAndCancelTest() {
|
||||
final MockCommand command = new MockCommand();
|
||||
command.start();
|
||||
assertCommandState(command, 0, 0, 0, 0, 0);
|
||||
|
||||
@@ -9,41 +9,29 @@ package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
public class CommandSequentialGroupTest extends AbstractCommandTest {
|
||||
private static Logger logger = Logger.getLogger(CommandSequentialGroupTest.class.getName());
|
||||
class CommandSequentialGroupTest extends AbstractCommandTest {
|
||||
private static final Logger logger = Logger.getLogger(CommandSequentialGroupTest.class.getName());
|
||||
|
||||
/**
|
||||
* Simple Command Group With 3 commands that all depend on a subsystem. Some commands have a
|
||||
* timeout.
|
||||
*/
|
||||
@Test(timeout = 20000)
|
||||
@Test
|
||||
public void testThreeCommandOnSubSystem() {
|
||||
logger.fine("Begining Test");
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
logger.finest("Creating Mock Command1");
|
||||
final MockCommand command1 = new MockCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
final MockCommand command1 = new MockCommand(subsystem);
|
||||
logger.finest("Creating Mock Command2");
|
||||
final MockCommand command2 = new MockCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
final MockCommand command2 = new MockCommand(subsystem);
|
||||
logger.finest("Creating Mock Command3");
|
||||
final MockCommand command3 = new MockCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
final MockCommand command3 = new MockCommand(subsystem);
|
||||
|
||||
logger.finest("Creating Command Group");
|
||||
final CommandGroup commandGroup = new CommandGroup();
|
||||
|
||||
@@ -7,35 +7,22 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
public class CommandSupersedeTest extends AbstractCommandTest {
|
||||
private static final Logger logger = Logger.getLogger(CommandSupersedeTest.class.getName());
|
||||
|
||||
|
||||
class CommandSupersedeTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Testing one command superseding another because of dependencies.
|
||||
*/
|
||||
@Test
|
||||
public void testOneCommandSupersedingAnotherBecauseOfDependencies() {
|
||||
void oneCommandSupersedingAnotherBecauseOfDependenciesTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
final MockCommand command1 = new MockCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
final MockCommand command1 = new MockCommand(subsystem);
|
||||
|
||||
final MockCommand command2 = new MockCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
final MockCommand command2 = new MockCommand(subsystem);
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
@@ -76,21 +63,17 @@ public class CommandSupersedeTest extends AbstractCommandTest {
|
||||
* command cannot be interrupted.
|
||||
*/
|
||||
@Test
|
||||
public void testCommandFailingSupersedingBecauseFirstCanNotBeInterrupted() {
|
||||
@SuppressWarnings("PMD.NonStaticInitializer")
|
||||
void commandFailingSupersedingBecauseFirstCanNotBeInterruptedTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
final MockCommand command1 = new MockCommand() {
|
||||
final MockCommand command1 = new MockCommand(subsystem) {
|
||||
{
|
||||
requires(subsystem);
|
||||
setInterruptible(false);
|
||||
}
|
||||
};
|
||||
|
||||
final MockCommand command2 = new MockCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
final MockCommand command2 = new MockCommand(subsystem);
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
@@ -116,5 +99,4 @@ public class CommandSupersedeTest extends AbstractCommandTest {
|
||||
assertCommandState(command1, 1, 4, 4, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,26 +7,21 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test a {@link Command} that times out.
|
||||
*/
|
||||
public class CommandTimeoutTest extends AbstractCommandTest {
|
||||
class CommandTimeoutTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Command 2 second Timeout Test.
|
||||
*/
|
||||
@Test
|
||||
public void testTwoSecondTimeout() {
|
||||
void twoSecondTimeoutTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
final MockCommand command = new MockCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
setTimeout(2);
|
||||
}
|
||||
|
||||
final MockCommand command = new MockCommand(subsystem, 2) {
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return super.isFinished() || isTimedOut();
|
||||
@@ -49,5 +44,4 @@ public class CommandTimeoutTest extends AbstractCommandTest {
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command, 1, 4, 4, 1, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,15 +7,13 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
//import org.junit.Ignore;
|
||||
|
||||
public class ConditionalCommandTest extends AbstractCommandTest {
|
||||
class ConditionalCommandTest extends AbstractCommandTest {
|
||||
MockConditionalCommand m_command;
|
||||
MockConditionalCommand m_commandNull;
|
||||
MockCommand m_onTrue;
|
||||
@@ -23,8 +21,8 @@ public class ConditionalCommandTest extends AbstractCommandTest {
|
||||
MockSubsystem m_subsys;
|
||||
Boolean m_condition;
|
||||
|
||||
@Before
|
||||
public void initCommands() {
|
||||
@BeforeEach
|
||||
void initCommands() {
|
||||
m_subsys = new MockSubsystem();
|
||||
m_onTrue = new MockCommand(m_subsys);
|
||||
m_onFalse = new MockCommand(m_subsys);
|
||||
@@ -43,7 +41,7 @@ public class ConditionalCommandTest extends AbstractCommandTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnTrue() {
|
||||
void onTrueTest() {
|
||||
m_command.setCondition(true);
|
||||
|
||||
Scheduler.getInstance().add(m_command);
|
||||
@@ -76,12 +74,12 @@ public class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 5, 5, 1, 0);
|
||||
|
||||
assertTrue("Did not initialize the true command", m_onTrue.getInitializeCount() > 0);
|
||||
assertTrue("Initialized the false command", m_onFalse.getInitializeCount() == 0);
|
||||
assertTrue(m_onTrue.getInitializeCount() > 0, "Did not initialize the true command");
|
||||
assertTrue(m_onFalse.getInitializeCount() == 0, "Initialized the false command");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnFalse() {
|
||||
void onFalseTest() {
|
||||
m_command.setCondition(false);
|
||||
|
||||
Scheduler.getInstance().add(m_command);
|
||||
@@ -114,12 +112,12 @@ public class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 5, 5, 1, 0);
|
||||
|
||||
assertTrue("Did not initialize the false command", m_onFalse.getInitializeCount() > 0);
|
||||
assertTrue("Initialized the true command", m_onTrue.getInitializeCount() == 0);
|
||||
assertTrue(m_onFalse.getInitializeCount() > 0, "Did not initialize the false command");
|
||||
assertTrue(m_onTrue.getInitializeCount() == 0, "Initialized the true command");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCancelSubCommand() {
|
||||
void cancelSubCommandTest() {
|
||||
m_command.setCondition(true);
|
||||
|
||||
Scheduler.getInstance().add(m_command);
|
||||
@@ -158,7 +156,7 @@ public class ConditionalCommandTest extends AbstractCommandTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCancelRequires() {
|
||||
void cancelRequiresTest() {
|
||||
m_command.setCondition(true);
|
||||
|
||||
Scheduler.getInstance().add(m_command);
|
||||
@@ -193,7 +191,7 @@ public class ConditionalCommandTest extends AbstractCommandTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCancelCondCommand() {
|
||||
void cancelCondCommandTest() {
|
||||
m_command.setCondition(true);
|
||||
|
||||
Scheduler.getInstance().add(m_command);
|
||||
@@ -228,7 +226,7 @@ public class ConditionalCommandTest extends AbstractCommandTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnTrueTwice() {
|
||||
void onTrueTwiceTest() {
|
||||
m_command.setCondition(true);
|
||||
|
||||
Scheduler.getInstance().add(m_command);
|
||||
@@ -296,7 +294,7 @@ public class ConditionalCommandTest extends AbstractCommandTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnTrueInstant() {
|
||||
void onTrueInstantTest() {
|
||||
m_command.setCondition(true);
|
||||
m_onTrue.setHasFinished(true);
|
||||
|
||||
@@ -327,7 +325,7 @@ public class ConditionalCommandTest extends AbstractCommandTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOnFalseNull() {
|
||||
void onFalseNullTest() {
|
||||
m_commandNull.setCondition(false);
|
||||
|
||||
Scheduler.getInstance().add(m_commandNull);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests the {@link Command} library.
|
||||
@@ -17,21 +17,13 @@ public class DefaultCommandTest extends AbstractCommandTest {
|
||||
* Testing of default commands where the interrupting command ends itself.
|
||||
*/
|
||||
@Test
|
||||
public void testDefaultCommandWhereTheInteruptingCommandEndsItself() {
|
||||
void defaultCommandWhereTheInteruptingCommandEndsItselfTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
final MockCommand defaultCommand = new MockCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
final MockCommand defaultCommand = new MockCommand(subsystem);
|
||||
|
||||
final MockCommand anotherCommand = new MockCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
final MockCommand anotherCommand = new MockCommand(subsystem);
|
||||
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
|
||||
subsystem.init(defaultCommand);
|
||||
|
||||
@@ -74,21 +66,11 @@ public class DefaultCommandTest extends AbstractCommandTest {
|
||||
* Testing of default commands where the interrupting command is canceled.
|
||||
*/
|
||||
@Test
|
||||
public void testDefaultCommandsInterruptingCommandCanceled() {
|
||||
void defaultCommandsInterruptingCommandCanceledTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
final MockCommand defaultCommand = new MockCommand(subsystem);
|
||||
final MockCommand anotherCommand = new MockCommand(subsystem);
|
||||
|
||||
|
||||
final MockCommand defaultCommand = new MockCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
|
||||
final MockCommand anotherCommand = new MockCommand() {
|
||||
{
|
||||
requires(subsystem);
|
||||
}
|
||||
};
|
||||
assertCommandState(defaultCommand, 0, 0, 0, 0, 0);
|
||||
subsystem.init(defaultCommand);
|
||||
subsystem.initDefaultCommand();
|
||||
|
||||
@@ -24,6 +24,11 @@ public class MockCommand extends Command {
|
||||
requires(subsys);
|
||||
}
|
||||
|
||||
public MockCommand(Subsystem subsys, double timeout) {
|
||||
this(subsys);
|
||||
setTimeout(timeout);
|
||||
}
|
||||
|
||||
public MockCommand() {
|
||||
super();
|
||||
}
|
||||
|
||||
@@ -7,19 +7,19 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTablesJNI;
|
||||
|
||||
public class JNITest {
|
||||
class JNITest {
|
||||
@Test
|
||||
public void jniNtcoreLinkTest() {
|
||||
void jniNtcoreLinkTest() {
|
||||
// Test to verify that the JNI test link works correctly.
|
||||
NetworkTablesJNI.flush(NetworkTablesJNI.getDefaultInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jniHalLinkTest() {
|
||||
void jniHalLinkTest() {
|
||||
HAL.initialize(500, 0);
|
||||
// Test to verify that the JNI test link works correctly.
|
||||
HALUtil.getHALRuntimeType();
|
||||
|
||||
@@ -7,11 +7,12 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.hal;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class MatchInfoDataTest {
|
||||
class MatchInfoDataTest {
|
||||
@Test
|
||||
public void matchInfoDataDoesNotThrow() {
|
||||
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
|
||||
void matchInfoDataDoesNotThrow() {
|
||||
HAL.initialize(500, 0);
|
||||
MatchInfoData data = new MatchInfoData();
|
||||
HAL.getMatchInfo(data);
|
||||
|
||||
@@ -9,8 +9,8 @@ package edu.wpi.first.wpilibj.livewindow;
|
||||
|
||||
import edu.wpi.first.wpilibj.UtilityClassTest;
|
||||
|
||||
public class LiveWindowTest extends UtilityClassTest {
|
||||
public LiveWindowTest() {
|
||||
class LiveWindowTest extends UtilityClassTest {
|
||||
LiveWindowTest() {
|
||||
super(LiveWindow.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,27 +7,25 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.sim;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogInput;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class AnalogInputSimTest {
|
||||
class AnalogInputSimTest {
|
||||
static class DoubleStore {
|
||||
public boolean m_wasTriggered = false;
|
||||
public boolean m_wasCorrectType = false;
|
||||
public double m_setValue = 0;
|
||||
public boolean m_wasTriggered;
|
||||
public boolean m_wasCorrectType;
|
||||
public double m_setValue0;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCallback() {
|
||||
void setCallbackTest() {
|
||||
HAL.initialize(500, 0);
|
||||
|
||||
|
||||
AnalogInput input = new AnalogInput(5);
|
||||
|
||||
AnalogInSim inputSim = input.getSimObject();
|
||||
|
||||
for (double i = 0; i < 5.0; i += 0.1) {
|
||||
|
||||
@@ -7,19 +7,19 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.sim;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.AnalogOutput;
|
||||
import edu.wpi.first.wpilibj.hal.HAL;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class AnalogOutputSimTest {
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class AnalogOutputSimTest {
|
||||
static class DoubleStore {
|
||||
public boolean m_wasTriggered = false;
|
||||
public boolean m_wasCorrectType = false;
|
||||
public boolean m_wasTriggered;
|
||||
public boolean m_wasCorrectType;
|
||||
public double m_setValue = -1;
|
||||
|
||||
public void reset() {
|
||||
@@ -30,7 +30,7 @@ public class AnalogOutputSimTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetCallback() {
|
||||
void setCallbackTest() {
|
||||
HAL.initialize(500, 0);
|
||||
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@ package edu.wpi.first.wpilibj.smartdashboard;
|
||||
|
||||
import edu.wpi.first.wpilibj.UtilityClassTest;
|
||||
|
||||
public class SmartDashboardTest extends UtilityClassTest {
|
||||
public SmartDashboardTest() {
|
||||
class SmartDashboardTest extends UtilityClassTest {
|
||||
SmartDashboardTest() {
|
||||
super(SmartDashboard.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ dependencies {
|
||||
compile project(':cscore')
|
||||
compile project(':cameraserver')
|
||||
compile 'junit:junit:4.11'
|
||||
testCompile 'org.hamcrest:hamcrest-all:1.3'
|
||||
compile 'com.googlecode.junit-toolbox:junit-toolbox:2.0'
|
||||
compile 'org.apache.ant:ant:1.9.4'
|
||||
compile 'org.apache.ant:ant-junit:1.9.4'
|
||||
|
||||
Reference in New Issue
Block a user