mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-07-03 03:01:44 +00:00
[build] Apply spotless for java formatting (#1768)
Update checkstyle config to be compatible with spotless. Co-authored-by: Austin Shalit <austinshalit@gmail.com>
This commit is contained in:
@@ -4,13 +4,12 @@
|
||||
|
||||
package edu.wpi.first.wpilibj;
|
||||
|
||||
import edu.wpi.first.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
|
||||
import org.junit.jupiter.api.extension.BeforeAllCallback;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext.Namespace;
|
||||
|
||||
import edu.wpi.first.hal.HAL;
|
||||
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
|
||||
|
||||
public final class MockHardwareExtension implements BeforeAllCallback {
|
||||
private static ExtensionContext getRoot(ExtensionContext context) {
|
||||
return context.getParent().map(MockHardwareExtension::getRoot).orElse(context);
|
||||
@@ -18,10 +17,15 @@ public final class MockHardwareExtension implements BeforeAllCallback {
|
||||
|
||||
@Override
|
||||
public void beforeAll(ExtensionContext context) {
|
||||
getRoot(context).getStore(Namespace.GLOBAL).getOrComputeIfAbsent("HAL Initialized", key -> {
|
||||
initializeHardware();
|
||||
return true;
|
||||
}, Boolean.class);
|
||||
getRoot(context)
|
||||
.getStore(Namespace.GLOBAL)
|
||||
.getOrComputeIfAbsent(
|
||||
"HAL Initialized",
|
||||
key -> {
|
||||
initializeHardware();
|
||||
return true;
|
||||
},
|
||||
Boolean.class);
|
||||
}
|
||||
|
||||
private void initializeHardware() {
|
||||
@@ -31,7 +35,5 @@ public final class MockHardwareExtension implements BeforeAllCallback {
|
||||
dsSim.setAutonomous(false);
|
||||
dsSim.setEnabled(true);
|
||||
dsSim.setTest(true);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,13 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
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.
|
||||
*/
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
/** The basic test for all {@link Command} tests. */
|
||||
public abstract class AbstractCommandTest {
|
||||
@BeforeEach
|
||||
void commandSetup() {
|
||||
@@ -35,16 +33,14 @@ public abstract class AbstractCommandTest {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void assertCommandState(MockCommand command, int initialize, int execute,
|
||||
int isFinished, int end, int interrupted) {
|
||||
protected void assertCommandState(
|
||||
MockCommand command, int initialize, int execute, int isFinished, int end, int interrupted) {
|
||||
assertAll(
|
||||
() -> assertEquals(initialize, command.getInitializeCount()),
|
||||
() -> assertEquals(execute, command.getExecuteCount()),
|
||||
() -> assertEquals(isFinished, command.getIsFinishedCount()),
|
||||
() -> assertEquals(end, command.getEndCount()),
|
||||
() -> assertEquals(interrupted, command.getInterruptedCount())
|
||||
);
|
||||
() -> assertEquals(interrupted, command.getInterruptedCount()));
|
||||
}
|
||||
|
||||
protected void sleep(int time) {
|
||||
|
||||
@@ -4,12 +4,10 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import edu.wpi.first.wpilibj.buttons.InternalButton;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import edu.wpi.first.wpilibj.buttons.InternalButton;
|
||||
|
||||
|
||||
/**
|
||||
* Test that covers the {@link edu.wpi.first.wpilibj.buttons.Button} with the {@link Command}
|
||||
* library.
|
||||
@@ -24,9 +22,7 @@ class ButtonTest extends AbstractCommandTest {
|
||||
m_button2 = new InternalButton();
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple Button Test.
|
||||
*/
|
||||
/** Simple Button Test. */
|
||||
@Test
|
||||
void buttonTest() {
|
||||
final MockCommand command1 = new MockCommand();
|
||||
@@ -109,5 +105,4 @@ class ButtonTest extends AbstractCommandTest {
|
||||
assertCommandState(command3, 1, 4, 4, 0, 1);
|
||||
assertCommandState(command4, 1, 3, 3, 0, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,13 +6,9 @@ package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
/** Ported from the old CrioTest Classes. */
|
||||
class CommandParallelGroupTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Simple Parallel Command Group With 2 commands one command terminates first.
|
||||
*/
|
||||
/** Simple Parallel Command Group With 2 commands one command terminates first. */
|
||||
@Test
|
||||
void parallelCommandGroupWithTwoCommandsTest() {
|
||||
final MockCommand command1 = new MockCommand();
|
||||
@@ -49,5 +45,4 @@ class CommandParallelGroupTest extends AbstractCommandTest {
|
||||
assertCommandState(command2, 1, 5, 5, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,9 +6,7 @@ package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
/** Ported from the old CrioTest Classes. */
|
||||
class CommandScheduleTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Simple scheduling of a command and making sure the command is run and successfully terminates.
|
||||
@@ -32,9 +30,7 @@ class CommandScheduleTest extends AbstractCommandTest {
|
||||
assertCommandState(command, 1, 3, 3, 1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Simple scheduling of a command and making sure the command is run and cancels correctly.
|
||||
*/
|
||||
/** Simple scheduling of a command and making sure the command is run and cancels correctly. */
|
||||
@Test
|
||||
void runAndCancelTest() {
|
||||
final MockCommand command = new MockCommand();
|
||||
|
||||
@@ -5,12 +5,9 @@
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
/** Ported from the old CrioTest Classes. */
|
||||
class CommandSequentialGroupTest extends AbstractCommandTest {
|
||||
private static final Logger logger = Logger.getLogger(CommandSequentialGroupTest.class.getName());
|
||||
|
||||
@@ -36,7 +33,6 @@ class CommandSequentialGroupTest extends AbstractCommandTest {
|
||||
commandGroup.addSequential(command2, 2.0);
|
||||
commandGroup.addSequential(command3);
|
||||
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
@@ -87,5 +83,4 @@ class CommandSequentialGroupTest extends AbstractCommandTest {
|
||||
assertCommandState(command3, 1, 3, 3, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,13 +6,9 @@ package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Ported from the old CrioTest Classes.
|
||||
*/
|
||||
/** Ported from the old CrioTest Classes. */
|
||||
class CommandSupersedeTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Testing one command superseding another because of dependencies.
|
||||
*/
|
||||
/** Testing one command superseding another because of dependencies. */
|
||||
@Test
|
||||
void oneCommandSupersedingAnotherBecauseOfDependenciesTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
@@ -64,11 +60,12 @@ class CommandSupersedeTest extends AbstractCommandTest {
|
||||
void commandFailingSupersedingBecauseFirstCanNotBeInterruptedTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
final MockCommand command1 = new MockCommand(subsystem) {
|
||||
{
|
||||
setInterruptible(false);
|
||||
}
|
||||
};
|
||||
final MockCommand command1 =
|
||||
new MockCommand(subsystem) {
|
||||
{
|
||||
setInterruptible(false);
|
||||
}
|
||||
};
|
||||
|
||||
final MockCommand command2 = new MockCommand(subsystem);
|
||||
|
||||
|
||||
@@ -6,24 +6,20 @@ package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test a {@link Command} that times out.
|
||||
*/
|
||||
/** Test a {@link Command} that times out. */
|
||||
class CommandTimeoutTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Command 2 second Timeout Test.
|
||||
*/
|
||||
/** Command 2 second Timeout Test. */
|
||||
@Test
|
||||
void twoSecondTimeoutTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
final MockCommand command = new MockCommand(subsystem, 2) {
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return super.isFinished() || isTimedOut();
|
||||
}
|
||||
};
|
||||
final MockCommand command =
|
||||
new MockCommand(subsystem, 2) {
|
||||
@Override
|
||||
public boolean isFinished() {
|
||||
return super.isFinished() || isTimedOut();
|
||||
}
|
||||
};
|
||||
|
||||
command.start();
|
||||
assertCommandState(command, 0, 0, 0, 0, 0);
|
||||
|
||||
@@ -4,13 +4,13 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ConditionalCommandTest extends AbstractCommandTest {
|
||||
MockConditionalCommand m_command;
|
||||
MockConditionalCommand m_commandNull;
|
||||
@@ -28,9 +28,13 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
m_commandNull = new MockConditionalCommand(m_onTrue, null);
|
||||
}
|
||||
|
||||
protected void assertConditionalCommandState(MockConditionalCommand command, int initialize,
|
||||
int execute, int isFinished, int end,
|
||||
int interrupted) {
|
||||
protected void assertConditionalCommandState(
|
||||
MockConditionalCommand command,
|
||||
int initialize,
|
||||
int execute,
|
||||
int isFinished,
|
||||
int end,
|
||||
int interrupted) {
|
||||
assertEquals(initialize, command.getInitializeCount());
|
||||
assertEquals(execute, command.getExecuteCount());
|
||||
assertEquals(isFinished, command.getIsFinishedCount());
|
||||
@@ -46,11 +50,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -84,11 +88,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onFalse
|
||||
Scheduler.getInstance().run(); // init command and select m_onFalse
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onFalse
|
||||
Scheduler.getInstance().run(); // init m_onFalse
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -122,11 +126,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -161,11 +165,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -196,11 +200,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -231,11 +235,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -264,11 +268,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -300,11 +304,11 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
Scheduler.getInstance().run(); // init command and select m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
Scheduler.getInstance().run(); // init m_onTrue
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertCommandState(m_onFalse, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_command, 1, 1, 1, 0, 0);
|
||||
@@ -329,10 +333,10 @@ class ConditionalCommandTest extends AbstractCommandTest {
|
||||
Scheduler.getInstance().add(m_commandNull);
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_commandNull, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init command and select m_onFalse
|
||||
Scheduler.getInstance().run(); // init command and select m_onFalse
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_commandNull, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run(); // init m_onFalse
|
||||
Scheduler.getInstance().run(); // init m_onFalse
|
||||
assertCommandState(m_onTrue, 0, 0, 0, 0, 0);
|
||||
assertConditionalCommandState(m_commandNull, 1, 1, 1, 1, 0);
|
||||
Scheduler.getInstance().run();
|
||||
|
||||
@@ -6,18 +6,13 @@ package edu.wpi.first.wpilibj.command;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Tests the {@link Command} library.
|
||||
*/
|
||||
/** Tests the {@link Command} library. */
|
||||
public class DefaultCommandTest extends AbstractCommandTest {
|
||||
/**
|
||||
* Testing of default commands where the interrupting command ends itself.
|
||||
*/
|
||||
/** Testing of default commands where the interrupting command ends itself. */
|
||||
@Test
|
||||
void defaultCommandWhereTheInteruptingCommandEndsItselfTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
|
||||
|
||||
final MockCommand defaultCommand = new MockCommand(subsystem);
|
||||
|
||||
final MockCommand anotherCommand = new MockCommand(subsystem);
|
||||
@@ -58,10 +53,7 @@ public class DefaultCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(anotherCommand, 1, 3, 3, 1, 0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Testing of default commands where the interrupting command is canceled.
|
||||
*/
|
||||
/** Testing of default commands where the interrupting command is canceled. */
|
||||
@Test
|
||||
void defaultCommandsInterruptingCommandCanceledTest() {
|
||||
final ASubsystem subsystem = new ASubsystem();
|
||||
@@ -104,5 +96,4 @@ public class DefaultCommandTest extends AbstractCommandTest {
|
||||
assertCommandState(defaultCommand, 2, 5, 5, 0, 1);
|
||||
assertCommandState(anotherCommand, 1, 2, 2, 0, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,31 +56,22 @@ public class MockCommand extends Command {
|
||||
++m_interruptedCount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* How many times the initialize method has been called.
|
||||
*/
|
||||
/** How many times the initialize method has been called. */
|
||||
public int getInitializeCount() {
|
||||
return m_initializeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the initialize method has been called at least once.
|
||||
*/
|
||||
/** If the initialize method has been called at least once. */
|
||||
public boolean hasInitialized() {
|
||||
return getInitializeCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many time the execute method has been called.
|
||||
*/
|
||||
/** How many time the execute method has been called. */
|
||||
public int getExecuteCount() {
|
||||
return m_executeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the isFinished method has been called.
|
||||
*/
|
||||
/** How many times the isFinished method has been called. */
|
||||
public int getIsFinishedCount() {
|
||||
return m_isFinishedCount;
|
||||
}
|
||||
@@ -103,37 +94,27 @@ public class MockCommand extends Command {
|
||||
m_hasFinished = hasFinished;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the end method has been called.
|
||||
*/
|
||||
/** How many times the end method has been called. */
|
||||
public int getEndCount() {
|
||||
return m_endCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the end method has been called at least once.
|
||||
*/
|
||||
/** If the end method has been called at least once. */
|
||||
public boolean hasEnd() {
|
||||
return getEndCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the interrupted method has been called.
|
||||
*/
|
||||
/** How many times the interrupted method has been called. */
|
||||
public int getInterruptedCount() {
|
||||
return m_interruptedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the interrupted method has been called at least once.
|
||||
*/
|
||||
/** If the interrupted method has been called at least once. */
|
||||
public boolean hasInterrupted() {
|
||||
return getInterruptedCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset internal counters.
|
||||
*/
|
||||
/** Reset internal counters. */
|
||||
public void resetCounters() {
|
||||
m_initializeCount = 0;
|
||||
m_executeCount = 0;
|
||||
@@ -142,5 +123,4 @@ public class MockCommand extends Command {
|
||||
m_endCount = 0;
|
||||
m_interruptedCount = 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,66 +51,47 @@ public class MockConditionalCommand extends ConditionalCommand {
|
||||
++m_interruptedCount;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* How many times the initialize method has been called.
|
||||
*/
|
||||
/** How many times the initialize method has been called. */
|
||||
public int getInitializeCount() {
|
||||
return m_initializeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the initialize method has been called at least once.
|
||||
*/
|
||||
/** If the initialize method has been called at least once. */
|
||||
public boolean hasInitialized() {
|
||||
return getInitializeCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many time the execute method has been called.
|
||||
*/
|
||||
/** How many time the execute method has been called. */
|
||||
public int getExecuteCount() {
|
||||
return m_executeCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the isFinished method has been called.
|
||||
*/
|
||||
/** How many times the isFinished method has been called. */
|
||||
public int getIsFinishedCount() {
|
||||
return m_isFinishedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the end method has been called.
|
||||
*/
|
||||
/** How many times the end method has been called. */
|
||||
public int getEndCount() {
|
||||
return m_endCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the end method has been called at least once.
|
||||
*/
|
||||
/** If the end method has been called at least once. */
|
||||
public boolean hasEnd() {
|
||||
return getEndCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* How many times the interrupted method has been called.
|
||||
*/
|
||||
/** How many times the interrupted method has been called. */
|
||||
public int getInterruptedCount() {
|
||||
return m_interruptedCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the interrupted method has been called at least once.
|
||||
*/
|
||||
/** If the interrupted method has been called at least once. */
|
||||
public boolean hasInterrupted() {
|
||||
return getInterruptedCount() > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset internal counters.
|
||||
*/
|
||||
/** Reset internal counters. */
|
||||
public void resetCounters() {
|
||||
m_condition = false;
|
||||
m_initializeCount = 0;
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.command;
|
||||
|
||||
/**
|
||||
* A class to simulate a simple subsystem.
|
||||
*/
|
||||
/** A class to simulate a simple subsystem. */
|
||||
public class MockSubsystem extends Subsystem {
|
||||
@Override
|
||||
protected void initDefaultCommand() {}
|
||||
|
||||
@@ -4,24 +4,22 @@
|
||||
|
||||
package edu.wpi.first.wpilibj.shuffleboard;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
import edu.wpi.first.wpilibj.command.InstantCommand;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
||||
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 edu.wpi.first.networktables.NetworkTableEntry;
|
||||
import edu.wpi.first.networktables.NetworkTableInstance;
|
||||
import edu.wpi.first.wpilibj.Sendable;
|
||||
import edu.wpi.first.wpilibj.command.InstantCommand;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ShuffleboardTabTest {
|
||||
private NetworkTableInstance m_ntInstance;
|
||||
private ShuffleboardTab m_tab;
|
||||
@@ -63,7 +61,6 @@ public class ShuffleboardTabTest {
|
||||
() -> assertEquals(1.0, entry.getValue().getDouble()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testAddBoolean() {
|
||||
NetworkTableEntry entry = m_tab.add("Bool", false).getEntry();
|
||||
@@ -84,47 +81,51 @@ public class ShuffleboardTabTest {
|
||||
void testAddNamedSendableWithProperties() {
|
||||
Sendable sendable = new InstantCommand("Command");
|
||||
String widgetType = "Command Widget";
|
||||
m_tab.add(sendable)
|
||||
.withWidget(widgetType)
|
||||
.withProperties(mapOf("foo", 1234, "bar", "baz"));
|
||||
m_tab.add(sendable).withWidget(widgetType).withProperties(mapOf("foo", 1234, "bar", "baz"));
|
||||
|
||||
m_instance.update();
|
||||
String meta = "/Shuffleboard/.metadata/Tab/Command";
|
||||
|
||||
assertAll(
|
||||
() -> assertEquals(1234,
|
||||
m_ntInstance.getEntry(meta + "/Properties/foo").getDouble(-1),
|
||||
"Property 'foo' not set correctly"),
|
||||
() -> assertEquals("baz",
|
||||
m_ntInstance.getEntry(meta + "/Properties/bar").getString(null),
|
||||
"Property 'bar' not set correctly"),
|
||||
() -> assertEquals(widgetType,
|
||||
m_ntInstance.getEntry(meta + "/PreferredComponent").getString(null),
|
||||
"Preferred component not set correctly"));
|
||||
() ->
|
||||
assertEquals(
|
||||
1234,
|
||||
m_ntInstance.getEntry(meta + "/Properties/foo").getDouble(-1),
|
||||
"Property 'foo' not set correctly"),
|
||||
() ->
|
||||
assertEquals(
|
||||
"baz",
|
||||
m_ntInstance.getEntry(meta + "/Properties/bar").getString(null),
|
||||
"Property 'bar' not set correctly"),
|
||||
() ->
|
||||
assertEquals(
|
||||
widgetType,
|
||||
m_ntInstance.getEntry(meta + "/PreferredComponent").getString(null),
|
||||
"Preferred component not set correctly"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddNumberArray() {
|
||||
NetworkTableEntry entry = m_tab.add("DoubleArray", new double[]{1, 2, 3}).getEntry();
|
||||
NetworkTableEntry entry = m_tab.add("DoubleArray", new double[] {1, 2, 3}).getEntry();
|
||||
assertAll(
|
||||
() -> assertEquals("/Shuffleboard/Tab/DoubleArray", entry.getName()),
|
||||
() -> assertArrayEquals(new double[]{1, 2, 3}, entry.getValue().getDoubleArray()));
|
||||
() -> assertArrayEquals(new double[] {1, 2, 3}, entry.getValue().getDoubleArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddBooleanArray() {
|
||||
NetworkTableEntry entry = m_tab.add("BoolArray", new boolean[]{true, false}).getEntry();
|
||||
NetworkTableEntry entry = m_tab.add("BoolArray", new boolean[] {true, false}).getEntry();
|
||||
assertAll(
|
||||
() -> assertEquals("/Shuffleboard/Tab/BoolArray", entry.getName()),
|
||||
() -> assertArrayEquals(new boolean[]{true, false}, entry.getValue().getBooleanArray()));
|
||||
() -> assertArrayEquals(new boolean[] {true, false}, entry.getValue().getBooleanArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAddStringArray() {
|
||||
NetworkTableEntry entry = m_tab.add("StringArray", new String[]{"foo", "bar"}).getEntry();
|
||||
NetworkTableEntry entry = m_tab.add("StringArray", new String[] {"foo", "bar"}).getEntry();
|
||||
assertAll(
|
||||
() -> assertEquals("/Shuffleboard/Tab/StringArray", entry.getName()),
|
||||
() -> assertArrayEquals(new String[]{"foo", "bar"}, entry.getValue().getStringArray()));
|
||||
() -> assertArrayEquals(new String[] {"foo", "bar"}, entry.getValue().getStringArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,9 +134,7 @@ public class ShuffleboardTabTest {
|
||||
assertThrows(IllegalArgumentException.class, () -> m_tab.add("foo", "baz"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Stub for Java 9 {@code Map.of()}.
|
||||
*/
|
||||
/** Stub for Java 9 {@code Map.of()}. */
|
||||
@SuppressWarnings({"unchecked", "PMD"})
|
||||
private static <K, V> Map<K, V> mapOf(Object... entries) {
|
||||
Map<K, V> map = new HashMap<>();
|
||||
@@ -144,5 +143,4 @@ public class ShuffleboardTabTest {
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user