[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:
Peter Johnson
2020-12-29 22:45:16 -08:00
committed by GitHub
parent e563a0b7db
commit a751fa22d2
883 changed files with 16526 additions and 17751 deletions

View File

@@ -4,13 +4,12 @@
package edu.wpi.first.wpilibj2;
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() {

View File

@@ -4,14 +4,13 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.SimHooks;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
class CommandDecoratorTest extends CommandTestBase {
@Test

View File

@@ -4,11 +4,11 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
class CommandGroupErrorTest extends CommandTestBase {
@Test
void commandInMultipleGroupsTest() {
@@ -20,8 +20,8 @@ class CommandGroupErrorTest extends CommandTestBase {
@SuppressWarnings("PMD.UnusedLocalVariable")
Command group = new ParallelCommandGroup(command1, command2);
assertThrows(IllegalArgumentException.class,
() -> new ParallelCommandGroup(command1, command2));
assertThrows(
IllegalArgumentException.class, () -> new ParallelCommandGroup(command1, command2));
}
@Test
@@ -35,8 +35,7 @@ class CommandGroupErrorTest extends CommandTestBase {
@SuppressWarnings("PMD.UnusedLocalVariable")
Command group = new ParallelCommandGroup(command1, command2);
assertThrows(IllegalArgumentException.class,
() -> scheduler.schedule(command1));
assertThrows(IllegalArgumentException.class, () -> scheduler.schedule(command1));
}
}

View File

@@ -4,13 +4,13 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
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.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
class CommandRequirementsTest extends CommandTestBase {
@Test
void requirementInterruptTest() {
@@ -63,13 +63,12 @@ class CommandRequirementsTest extends CommandTestBase {
Subsystem system = new TestSubsystem();
Command missingRequirement = new WaitUntilCommand(() -> false);
Command ends = new InstantCommand(() -> {
}, system);
Command ends = new InstantCommand(() -> {}, system);
assertThrows(IllegalArgumentException.class,
assertThrows(
IllegalArgumentException.class,
() -> scheduler.setDefaultCommand(system, missingRequirement));
assertThrows(IllegalArgumentException.class,
() -> scheduler.setDefaultCommand(system, ends));
assertThrows(IllegalArgumentException.class, () -> scheduler.setDefaultCommand(system, ends));
}
}
}

View File

@@ -4,8 +4,6 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -13,6 +11,8 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
class CommandScheduleTest extends CommandTestBase {
@Test
void instantScheduleTest() {

View File

@@ -4,19 +4,15 @@
package edu.wpi.first.wpilibj2.command;
import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Basic setup for all {@link Command tests}."
*/
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.simulation.DriverStationSim;
import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
/** Basic setup for all {@link Command tests}." */
@SuppressWarnings("PMD.AbstractClassWithoutAbstractMethod")
public abstract class CommandTestBase {
@BeforeEach
@@ -44,8 +40,7 @@ public abstract class CommandTestBase {
}
}
public class TestSubsystem extends SubsystemBase {
}
public class TestSubsystem extends SubsystemBase {}
public class MockCommandHolder {
private final Command m_mockCommand = mock(Command.class);
@@ -63,7 +58,6 @@ public abstract class CommandTestBase {
public void setFinished(boolean finished) {
when(m_mockCommand.isFinished()).thenReturn(finished);
}
}
public class Counter {

View File

@@ -4,12 +4,12 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
class ConditionalCommandTest extends CommandTestBase {
@Test
void conditionalCommandTest() {
@@ -52,8 +52,7 @@ class ConditionalCommandTest extends CommandTestBase {
new ConditionalCommand(command1, command2, () -> true);
scheduler.schedule(conditionalCommand);
scheduler.schedule(new InstantCommand(() -> {
}, system3));
scheduler.schedule(new InstantCommand(() -> {}, system3));
assertFalse(scheduler.isScheduled(conditionalCommand));

View File

@@ -4,12 +4,12 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
class DefaultCommandTest extends CommandTestBase {
@Test
void defaultCommandScheduleTest() {

View File

@@ -4,11 +4,11 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class FunctionalCommandTest extends CommandTestBase {
@Test
void functionalCommandScheduleTest() {
@@ -19,8 +19,11 @@ class FunctionalCommandTest extends CommandTestBase {
ConditionHolder cond4 = new ConditionHolder();
FunctionalCommand command =
new FunctionalCommand(() -> cond1.setCondition(true), () -> cond2.setCondition(true),
interrupted -> cond3.setCondition(true), cond4::getCondition);
new FunctionalCommand(
() -> cond1.setCondition(true),
() -> cond2.setCondition(true),
interrupted -> cond3.setCondition(true),
cond4::getCondition);
scheduler.schedule(command);
scheduler.run();

View File

@@ -4,11 +4,11 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class InstantCommandTest extends CommandTestBase {
@Test
void instantCommandScheduleTest() {

View File

@@ -4,12 +4,8 @@
package edu.wpi.first.wpilibj2.command;
import java.util.ArrayList;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.Timer;
@@ -25,9 +21,11 @@ import edu.wpi.first.wpilibj.simulation.SimHooks;
import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig;
import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator;
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
class MecanumControllerCommandTest {
@BeforeEach
@@ -49,8 +47,8 @@ class MecanumControllerCommandTest {
private double m_frontRightSpeed;
private double m_rearRightSpeed;
private final ProfiledPIDController m_rotController = new ProfiledPIDController(1, 0, 0,
new TrapezoidProfile.Constraints(3 * Math.PI, Math.PI));
private final ProfiledPIDController m_rotController =
new ProfiledPIDController(1, 0, 0, new TrapezoidProfile.Constraints(3 * Math.PI, Math.PI));
private static final double kxTolerance = 1 / 12.0;
private static final double kyTolerance = 1 / 12.0;
@@ -59,14 +57,16 @@ class MecanumControllerCommandTest {
private static final double kWheelBase = 0.5;
private static final double kTrackWidth = 0.5;
private final MecanumDriveKinematics m_kinematics = new MecanumDriveKinematics(
new Translation2d(kWheelBase / 2, kTrackWidth / 2),
new Translation2d(kWheelBase / 2, -kTrackWidth / 2),
new Translation2d(-kWheelBase / 2, kTrackWidth / 2),
new Translation2d(-kWheelBase / 2, -kTrackWidth / 2));
private final MecanumDriveKinematics m_kinematics =
new MecanumDriveKinematics(
new Translation2d(kWheelBase / 2, kTrackWidth / 2),
new Translation2d(kWheelBase / 2, -kTrackWidth / 2),
new Translation2d(-kWheelBase / 2, kTrackWidth / 2),
new Translation2d(-kWheelBase / 2, -kTrackWidth / 2));
private final MecanumDriveOdometry m_odometry = new MecanumDriveOdometry(m_kinematics,
new Rotation2d(0), new Pose2d(0, 0, new Rotation2d(0)));
private final MecanumDriveOdometry m_odometry =
new MecanumDriveOdometry(
m_kinematics, new Rotation2d(0), new Pose2d(0, 0, new Rotation2d(0)));
public void setWheelSpeeds(MecanumDriveWheelSpeeds wheelSpeeds) {
this.m_frontLeftSpeed = wheelSpeeds.frontLeftMetersPerSecond;
@@ -76,8 +76,8 @@ class MecanumControllerCommandTest {
}
public MecanumDriveWheelSpeeds getCurrentWheelSpeeds() {
return new MecanumDriveWheelSpeeds(m_frontLeftSpeed,
m_frontRightSpeed, m_rearLeftSpeed, m_rearRightSpeed);
return new MecanumDriveWheelSpeeds(
m_frontLeftSpeed, m_frontRightSpeed, m_rearLeftSpeed, m_rearRightSpeed);
}
public Pose2d getRobotPose() {
@@ -99,15 +99,17 @@ class MecanumControllerCommandTest {
final var endState = trajectory.sample(trajectory.getTotalTimeSeconds());
final var command = new MecanumControllerCommand(trajectory,
this::getRobotPose,
m_kinematics,
new PIDController(0.6, 0, 0),
new PIDController(0.6, 0, 0),
m_rotController,
8.8,
this::setWheelSpeeds,
subsystem);
final var command =
new MecanumControllerCommand(
trajectory,
this::getRobotPose,
m_kinematics,
new PIDController(0.6, 0, 0),
new PIDController(0.6, 0, 0),
m_rotController,
8.8,
this::setWheelSpeeds,
subsystem);
m_timer.reset();
m_timer.start();
@@ -122,12 +124,12 @@ class MecanumControllerCommandTest {
command.end(true);
assertAll(
() -> assertEquals(endState.poseMeters.getX(),
getRobotPose().getX(), kxTolerance),
() -> assertEquals(endState.poseMeters.getY(),
getRobotPose().getY(), kyTolerance),
() -> assertEquals(endState.poseMeters.getRotation().getRadians(),
getRobotPose().getRotation().getRadians(), kAngularTolerance)
);
() -> assertEquals(endState.poseMeters.getX(), getRobotPose().getX(), kxTolerance),
() -> assertEquals(endState.poseMeters.getY(), getRobotPose().getY(), kyTolerance),
() ->
assertEquals(
endState.poseMeters.getRotation().getRadians(),
getRobotPose().getRotation().getRadians(),
kAngularTolerance));
}
}

View File

@@ -4,16 +4,15 @@
package edu.wpi.first.wpilibj2.command;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.SimHooks;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.SimHooks;
import static org.junit.jupiter.api.Assertions.assertEquals;
class NotifierCommandTest extends CommandTestBase {
@BeforeEach
void setup() {

View File

@@ -4,8 +4,6 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -14,6 +12,8 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
class ParallelCommandGroupTest extends CommandTestBase {
@Test
void parallelGroupScheduleTest() {
@@ -123,7 +123,7 @@ class ParallelCommandGroupTest extends CommandTestBase {
MockCommandHolder command2Holder = new MockCommandHolder(true, system2, system3);
Command command2 = command2Holder.getMock();
assertThrows(IllegalArgumentException.class,
() -> new ParallelCommandGroup(command1, command2));
assertThrows(
IllegalArgumentException.class, () -> new ParallelCommandGroup(command1, command2));
}
}

View File

@@ -4,8 +4,6 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -13,6 +11,8 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.internal.verification.VerificationModeFactory.times;
import org.junit.jupiter.api.Test;
class ParallelDeadlineGroupTest extends CommandTestBase {
@Test
void parallelDeadlineScheduleTest() {
@@ -83,7 +83,6 @@ class ParallelDeadlineGroupTest extends CommandTestBase {
}
}
@Test
void parallelDeadlineRequirementTest() {
Subsystem system1 = new TestSubsystem();
@@ -120,7 +119,7 @@ class ParallelDeadlineGroupTest extends CommandTestBase {
MockCommandHolder command2Holder = new MockCommandHolder(true, system2, system3);
Command command2 = command2Holder.getMock();
assertThrows(IllegalArgumentException.class,
() -> new ParallelDeadlineGroup(command1, command2));
assertThrows(
IllegalArgumentException.class, () -> new ParallelDeadlineGroup(command1, command2));
}
}

View File

@@ -4,8 +4,6 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -16,6 +14,8 @@ import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
class ParallelRaceGroupTest extends CommandTestBase {
@Test
void parallelRaceScheduleTest() {
@@ -89,7 +89,6 @@ class ParallelRaceGroupTest extends CommandTestBase {
}
}
@Test
void parallelRaceRequirementTest() {
Subsystem system1 = new TestSubsystem();
@@ -202,5 +201,4 @@ class ParallelRaceGroupTest extends CommandTestBase {
assertFalse(scheduler.isScheduled(group));
}
}
}

View File

@@ -4,10 +4,10 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class PerpetualCommandTest extends CommandTestBase {
@Test
void perpetualCommandScheduleTest() {

View File

@@ -4,14 +4,13 @@
package edu.wpi.first.wpilibj2.command;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.jupiter.api.Test;
class PrintCommandTest extends CommandTestBase {
@Test
void printCommandScheduleTest() {

View File

@@ -4,12 +4,12 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
class ProxyScheduleCommandTest extends CommandTestBase {
@Test
void proxyScheduleCommandScheduleTest() {

View File

@@ -4,14 +4,13 @@
package edu.wpi.first.wpilibj2.command;
import java.util.Map;
import org.junit.jupiter.api.Test;
import static edu.wpi.first.wpilibj2.command.CommandGroupBase.parallel;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Map;
import org.junit.jupiter.api.Test;
class RobotDisabledCommandTest extends CommandTestBase {
@Test
void robotDisabledCommandCancelTest() {

View File

@@ -4,10 +4,10 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class RunCommandTest extends CommandTestBase {
@Test
void runCommandScheduleTest() {

View File

@@ -4,11 +4,11 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
class ScheduleCommandTest extends CommandTestBase {
@Test
void scheduleCommandScheduleTest() {

View File

@@ -4,11 +4,11 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
class SchedulerTest extends CommandTestBase {
@Test
void schedulerLambdaTestNoInterrupt() {

View File

@@ -4,15 +4,14 @@
package edu.wpi.first.wpilibj2.command;
import java.util.Map;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import java.util.Map;
import org.junit.jupiter.api.Test;
class SelectCommandTest extends CommandTestBase {
@Test
void selectCommandTest() {
@@ -26,10 +25,11 @@ class SelectCommandTest extends CommandTestBase {
Command command3 = command3Holder.getMock();
SelectCommand selectCommand =
new SelectCommand(Map.ofEntries(
Map.entry("one", command1),
Map.entry("two", command2),
Map.entry("three", command3)),
new SelectCommand(
Map.ofEntries(
Map.entry("one", command1),
Map.entry("two", command2),
Map.entry("three", command3)),
() -> "one");
scheduler.schedule(selectCommand);
@@ -61,17 +61,17 @@ class SelectCommandTest extends CommandTestBase {
Command command3 = command3Holder.getMock();
SelectCommand selectCommand =
new SelectCommand(Map.ofEntries(
Map.entry("one", command1),
Map.entry("two", command2),
Map.entry("three", command3)),
new SelectCommand(
Map.ofEntries(
Map.entry("one", command1),
Map.entry("two", command2),
Map.entry("three", command3)),
() -> "four");
assertDoesNotThrow(() -> scheduler.schedule(selectCommand));
}
}
@Test
void selectCommandRequirementTest() {
Subsystem system1 = new TestSubsystem();
@@ -87,13 +87,16 @@ class SelectCommandTest extends CommandTestBase {
MockCommandHolder command3Holder = new MockCommandHolder(true, system3, system4);
Command command3 = command3Holder.getMock();
SelectCommand selectCommand = new SelectCommand(
Map.ofEntries(Map.entry("one", command1), Map.entry("two", command2),
Map.entry("three", command3)), () -> "one");
SelectCommand selectCommand =
new SelectCommand(
Map.ofEntries(
Map.entry("one", command1),
Map.entry("two", command2),
Map.entry("three", command3)),
() -> "one");
scheduler.schedule(selectCommand);
scheduler.schedule(new InstantCommand(() -> {
}, system3));
scheduler.schedule(new InstantCommand(() -> {}, system3));
assertFalse(scheduler.isScheduled(selectCommand));

View File

@@ -4,14 +4,14 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.Test;
class SequentialCommandGroupTest extends CommandTestBase {
@Test
void sequentialGroupScheduleTest() {
@@ -97,7 +97,6 @@ class SequentialCommandGroupTest extends CommandTestBase {
}
}
@Test
void sequentialGroupRequirementTest() {
Subsystem system1 = new TestSubsystem();

View File

@@ -4,11 +4,11 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class StartEndCommandTest extends CommandTestBase {
@Test
void startEndCommandScheduleTest() {

View File

@@ -4,12 +4,8 @@
package edu.wpi.first.wpilibj2.command;
import java.util.ArrayList;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.Timer;
@@ -25,9 +21,11 @@ import edu.wpi.first.wpilibj.simulation.SimHooks;
import edu.wpi.first.wpilibj.trajectory.TrajectoryConfig;
import edu.wpi.first.wpilibj.trajectory.TrajectoryGenerator;
import edu.wpi.first.wpilibj.trajectory.TrapezoidProfile;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.ArrayList;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
class SwerveControllerCommandTest {
@BeforeEach
@@ -44,14 +42,16 @@ class SwerveControllerCommandTest {
private final Timer m_timer = new Timer();
private Rotation2d m_angle = new Rotation2d(0);
private SwerveModuleState[] m_moduleStates = new SwerveModuleState[]{
new SwerveModuleState(0, new Rotation2d(0)),
new SwerveModuleState(0, new Rotation2d(0)),
new SwerveModuleState(0, new Rotation2d(0)),
new SwerveModuleState(0, new Rotation2d(0))};
private SwerveModuleState[] m_moduleStates =
new SwerveModuleState[] {
new SwerveModuleState(0, new Rotation2d(0)),
new SwerveModuleState(0, new Rotation2d(0)),
new SwerveModuleState(0, new Rotation2d(0)),
new SwerveModuleState(0, new Rotation2d(0))
};
private final ProfiledPIDController m_rotController = new ProfiledPIDController(1, 0, 0,
new TrapezoidProfile.Constraints(3 * Math.PI, Math.PI));
private final ProfiledPIDController m_rotController =
new ProfiledPIDController(1, 0, 0, new TrapezoidProfile.Constraints(3 * Math.PI, Math.PI));
private static final double kxTolerance = 1 / 12.0;
private static final double kyTolerance = 1 / 12.0;
@@ -60,14 +60,15 @@ class SwerveControllerCommandTest {
private static final double kWheelBase = 0.5;
private static final double kTrackWidth = 0.5;
private final SwerveDriveKinematics m_kinematics = new SwerveDriveKinematics(
new Translation2d(kWheelBase / 2, kTrackWidth / 2),
new Translation2d(kWheelBase / 2, -kTrackWidth / 2),
new Translation2d(-kWheelBase / 2, kTrackWidth / 2),
new Translation2d(-kWheelBase / 2, -kTrackWidth / 2));
private final SwerveDriveKinematics m_kinematics =
new SwerveDriveKinematics(
new Translation2d(kWheelBase / 2, kTrackWidth / 2),
new Translation2d(kWheelBase / 2, -kTrackWidth / 2),
new Translation2d(-kWheelBase / 2, kTrackWidth / 2),
new Translation2d(-kWheelBase / 2, -kTrackWidth / 2));
private final SwerveDriveOdometry m_odometry = new SwerveDriveOdometry(m_kinematics,
new Rotation2d(0), new Pose2d(0, 0, new Rotation2d(0)));
private final SwerveDriveOdometry m_odometry =
new SwerveDriveOdometry(m_kinematics, new Rotation2d(0), new Pose2d(0, 0, new Rotation2d(0)));
@SuppressWarnings("PMD.ArrayIsStoredDirectly")
public void setModuleStates(SwerveModuleState[] moduleStates) {
@@ -93,14 +94,16 @@ class SwerveControllerCommandTest {
final var endState = trajectory.sample(trajectory.getTotalTimeSeconds());
final var command = new SwerveControllerCommand(trajectory,
this::getRobotPose,
m_kinematics,
new PIDController(0.6, 0, 0),
new PIDController(0.6, 0, 0),
m_rotController,
this::setModuleStates,
subsystem);
final var command =
new SwerveControllerCommand(
trajectory,
this::getRobotPose,
m_kinematics,
new PIDController(0.6, 0, 0),
new PIDController(0.6, 0, 0),
m_rotController,
this::setModuleStates,
subsystem);
m_timer.reset();
m_timer.start();
@@ -115,12 +118,12 @@ class SwerveControllerCommandTest {
command.end(true);
assertAll(
() -> assertEquals(endState.poseMeters.getX(),
getRobotPose().getX(), kxTolerance),
() -> assertEquals(endState.poseMeters.getY(),
getRobotPose().getY(), kyTolerance),
() -> assertEquals(endState.poseMeters.getRotation().getRadians(),
getRobotPose().getRotation().getRadians(), kAngularTolerance)
);
() -> assertEquals(endState.poseMeters.getX(), getRobotPose().getX(), kxTolerance),
() -> assertEquals(endState.poseMeters.getY(), getRobotPose().getY(), kyTolerance),
() ->
assertEquals(
endState.poseMeters.getRotation().getRadians(),
getRobotPose().getRotation().getRadians(),
kAngularTolerance));
}
}

View File

@@ -4,14 +4,6 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.SimHooks;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyDouble;
@@ -19,6 +11,13 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.SimHooks;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
class WaitCommandTest extends CommandTestBase {
@BeforeEach
void setup() {

View File

@@ -4,11 +4,11 @@
package edu.wpi.first.wpilibj2.command;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
class WaitUntilCommandTest extends CommandTestBase {
@Test
void waitUntilTest() {

View File

@@ -4,12 +4,6 @@
package edu.wpi.first.wpilibj2.command.button;
import org.junit.jupiter.api.Test;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.CommandTestBase;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -18,6 +12,10 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.CommandTestBase;
import org.junit.jupiter.api.Test;
class ButtonTest extends CommandTestBase {
@Test

View File

@@ -4,16 +4,15 @@
package edu.wpi.first.wpilibj2.command.button;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.CommandTestBase;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
class NetworkButtonTest extends CommandTestBase {
@BeforeEach
@@ -32,9 +31,7 @@ class NetworkButtonTest extends CommandTestBase {
var scheduler = CommandScheduler.getInstance();
var commandHolder = new MockCommandHolder(true);
var command = commandHolder.getMock();
var entry = NetworkTableInstance.getDefault()
.getTable("TestTable")
.getEntry("Test");
var entry = NetworkTableInstance.getDefault().getTable("TestTable").getEntry("Test");
var button = new NetworkButton("TestTable", "Test");
entry.setBoolean(false);