Switch non-integration tests to JUnit 5 (#1120)

This commit is contained in:
Austin Shalit
2018-06-11 18:01:49 -04:00
committed by Peter Johnson
parent c7e97f45f5
commit 9108a93598
34 changed files with 383 additions and 445 deletions

View File

@@ -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, _, _}

View File

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

View File

@@ -7,8 +7,8 @@
package edu.wpi.first.wpilibj;
public class RobotControllerTest extends UtilityClassTest {
public RobotControllerTest() {
class RobotControllerTest extends UtilityClassTest {
RobotControllerTest() {
super(RobotController.class);
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -24,6 +24,11 @@ public class MockCommand extends Command {
requires(subsys);
}
public MockCommand(Subsystem subsys, double timeout) {
this(subsys);
setTimeout(timeout);
}
public MockCommand() {
super();
}

View File

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

View File

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

View File

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

View File

@@ -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) {

View File

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

View File

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