[commands] Remove custom test wrappers (#4296)

Use AtomicBoolean and AtomicInteger instead of
custom ConditionHolder and Counter classes.
This commit is contained in:
Starlight220
2022-06-07 03:13:11 +03:00
committed by GitHub
parent 1280a54ef3
commit abb45a68db
19 changed files with 124 additions and 138 deletions

View File

@@ -42,14 +42,14 @@ class CommandDecoratorTest extends CommandTestBase {
@Test
void untilTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
ConditionHolder condition = new ConditionHolder();
AtomicBoolean condition = new AtomicBoolean();
Command command = new WaitCommand(10).until(condition::getCondition);
Command command = new WaitCommand(10).until(condition::get);
scheduler.schedule(command);
scheduler.run();
assertTrue(scheduler.isScheduled(command));
condition.setCondition(true);
condition.set(true);
scheduler.run();
assertFalse(scheduler.isScheduled(command));
}
@@ -58,61 +58,61 @@ class CommandDecoratorTest extends CommandTestBase {
@Test
void beforeStartingTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
ConditionHolder condition = new ConditionHolder();
condition.setCondition(false);
AtomicBoolean condition = new AtomicBoolean();
condition.set(false);
Command command = new InstantCommand();
scheduler.schedule(command.beforeStarting(() -> condition.setCondition(true)));
scheduler.schedule(command.beforeStarting(() -> condition.set(true)));
assertTrue(condition.getCondition());
assertTrue(condition.get());
}
}
@Test
void andThenLambdaTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
ConditionHolder condition = new ConditionHolder();
condition.setCondition(false);
AtomicBoolean condition = new AtomicBoolean();
condition.set(false);
Command command = new InstantCommand();
scheduler.schedule(command.andThen(() -> condition.setCondition(true)));
scheduler.schedule(command.andThen(() -> condition.set(true)));
assertFalse(condition.getCondition());
assertFalse(condition.get());
scheduler.run();
assertTrue(condition.getCondition());
assertTrue(condition.get());
}
}
@Test
void andThenTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
ConditionHolder condition = new ConditionHolder();
condition.setCondition(false);
AtomicBoolean condition = new AtomicBoolean();
condition.set(false);
Command command1 = new InstantCommand();
Command command2 = new InstantCommand(() -> condition.setCondition(true));
Command command2 = new InstantCommand(() -> condition.set(true));
scheduler.schedule(command1.andThen(command2));
assertFalse(condition.getCondition());
assertFalse(condition.get());
scheduler.run();
assertTrue(condition.getCondition());
assertTrue(condition.get());
}
}
@Test
void deadlineWithTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
ConditionHolder condition = new ConditionHolder();
condition.setCondition(false);
AtomicBoolean condition = new AtomicBoolean();
condition.set(false);
Command dictator = new WaitUntilCommand(condition::getCondition);
Command dictator = new WaitUntilCommand(condition::get);
Command endsBefore = new InstantCommand();
Command endsAfter = new WaitUntilCommand(() -> false);
@@ -123,7 +123,7 @@ class CommandDecoratorTest extends CommandTestBase {
assertTrue(scheduler.isScheduled(group));
condition.setCondition(true);
condition.set(true);
scheduler.run();
assertFalse(scheduler.isScheduled(group));
@@ -133,10 +133,10 @@ class CommandDecoratorTest extends CommandTestBase {
@Test
void alongWithTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
ConditionHolder condition = new ConditionHolder();
condition.setCondition(false);
AtomicBoolean condition = new AtomicBoolean();
condition.set(false);
Command command1 = new WaitUntilCommand(condition::getCondition);
Command command1 = new WaitUntilCommand(condition::get);
Command command2 = new InstantCommand();
Command group = command1.alongWith(command2);
@@ -146,7 +146,7 @@ class CommandDecoratorTest extends CommandTestBase {
assertTrue(scheduler.isScheduled(group));
condition.setCondition(true);
condition.set(true);
scheduler.run();
assertFalse(scheduler.isScheduled(group));

View File

@@ -15,7 +15,7 @@ class CommandRequirementsTest extends CommandTestBase {
@Test
void requirementInterruptTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Subsystem requirement = new TestSubsystem();
Subsystem requirement = new SubsystemBase() {};
MockCommandHolder interruptedHolder = new MockCommandHolder(true, requirement);
Command interrupted = interruptedHolder.getMock();
@@ -42,7 +42,7 @@ class CommandRequirementsTest extends CommandTestBase {
@Test
void requirementUninterruptibleTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Subsystem requirement = new TestSubsystem();
Subsystem requirement = new SubsystemBase() {};
MockCommandHolder interruptedHolder = new MockCommandHolder(true, requirement);
Command notInterrupted = interruptedHolder.getMock();
@@ -60,7 +60,7 @@ class CommandRequirementsTest extends CommandTestBase {
@Test
void defaultCommandRequirementErrorTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Subsystem system = new TestSubsystem();
Subsystem system = new SubsystemBase() {};
Command missingRequirement = new WaitUntilCommand(() -> false);
Command ends = new InstantCommand(() -> {}, system);

View File

@@ -12,7 +12,7 @@ import edu.wpi.first.wpilibj.simulation.DriverStationSim;
import java.util.Set;
import org.junit.jupiter.api.BeforeEach;
/** Basic setup for all {@link Command tests}." */
/** Basic setup for all {@link Command tests}. */
public class CommandTestBase {
protected CommandTestBase() {}
@@ -41,8 +41,6 @@ public class CommandTestBase {
}
}
public static class TestSubsystem extends SubsystemBase {}
public static class MockCommandHolder {
private final Command m_mockCommand = mock(Command.class);
@@ -60,24 +58,4 @@ public class CommandTestBase {
when(m_mockCommand.isFinished()).thenReturn(finished);
}
}
public static class Counter {
public int m_counter;
public void increment() {
m_counter++;
}
}
public static class ConditionHolder {
private boolean m_condition;
public void setCondition(boolean condition) {
m_condition = condition;
}
public boolean getCondition() {
return m_condition;
}
}
}

View File

@@ -38,9 +38,9 @@ class ConditionalCommandTest extends CommandTestBase {
@Test
void conditionalCommandRequirementTest() {
Subsystem system1 = new TestSubsystem();
Subsystem system2 = new TestSubsystem();
Subsystem system3 = new TestSubsystem();
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);

View File

@@ -14,7 +14,7 @@ class DefaultCommandTest extends CommandTestBase {
@Test
void defaultCommandScheduleTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
TestSubsystem hasDefaultCommand = new TestSubsystem();
Subsystem hasDefaultCommand = new SubsystemBase() {};
MockCommandHolder defaultHolder = new MockCommandHolder(true, hasDefaultCommand);
Command defaultCommand = defaultHolder.getMock();
@@ -29,7 +29,7 @@ class DefaultCommandTest extends CommandTestBase {
@Test
void defaultCommandInterruptResumeTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
TestSubsystem hasDefaultCommand = new TestSubsystem();
Subsystem hasDefaultCommand = new SubsystemBase() {};
MockCommandHolder defaultHolder = new MockCommandHolder(true, hasDefaultCommand);
Command defaultCommand = defaultHolder.getMock();
@@ -54,7 +54,7 @@ class DefaultCommandTest extends CommandTestBase {
@Test
void defaultCommandDisableResumeTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
TestSubsystem hasDefaultCommand = new TestSubsystem();
Subsystem hasDefaultCommand = new SubsystemBase() {};
MockCommandHolder defaultHolder = new MockCommandHolder(false, hasDefaultCommand);
Command defaultCommand = defaultHolder.getMock();

View File

@@ -7,37 +7,38 @@ package edu.wpi.first.wpilibj2.command;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.Test;
class FunctionalCommandTest extends CommandTestBase {
@Test
void functionalCommandScheduleTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
ConditionHolder cond1 = new ConditionHolder();
ConditionHolder cond2 = new ConditionHolder();
ConditionHolder cond3 = new ConditionHolder();
ConditionHolder cond4 = new ConditionHolder();
AtomicBoolean cond1 = new AtomicBoolean();
AtomicBoolean cond2 = new AtomicBoolean();
AtomicBoolean cond3 = new AtomicBoolean();
AtomicBoolean cond4 = new AtomicBoolean();
FunctionalCommand command =
new FunctionalCommand(
() -> cond1.setCondition(true),
() -> cond2.setCondition(true),
interrupted -> cond3.setCondition(true),
cond4::getCondition);
() -> cond1.set(true),
() -> cond2.set(true),
interrupted -> cond3.set(true),
cond4::get);
scheduler.schedule(command);
scheduler.run();
assertTrue(scheduler.isScheduled(command));
cond4.setCondition(true);
cond4.set(true);
scheduler.run();
assertFalse(scheduler.isScheduled(command));
assertTrue(cond1.getCondition());
assertTrue(cond2.getCondition());
assertTrue(cond3.getCondition());
assertTrue(cond1.get());
assertTrue(cond2.get());
assertTrue(cond3.get());
}
}
}

View File

@@ -7,20 +7,21 @@ package edu.wpi.first.wpilibj2.command;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.Test;
class InstantCommandTest extends CommandTestBase {
@Test
void instantCommandScheduleTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
ConditionHolder cond = new ConditionHolder();
AtomicBoolean cond = new AtomicBoolean();
InstantCommand command = new InstantCommand(() -> cond.setCondition(true));
InstantCommand command = new InstantCommand(() -> cond.set(true));
scheduler.schedule(command);
scheduler.run();
assertTrue(cond.getCondition());
assertTrue(cond.get());
assertFalse(scheduler.isScheduled(command));
}
}

View File

@@ -8,6 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.hal.HAL;
import edu.wpi.first.wpilibj.simulation.SimHooks;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
@@ -29,9 +30,9 @@ class NotifierCommandTest extends CommandTestBase {
@ResourceLock("timing")
void notifierCommandScheduleTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Counter counter = new Counter();
AtomicInteger counter = new AtomicInteger(0);
NotifierCommand command = new NotifierCommand(counter::increment, 0.01);
NotifierCommand command = new NotifierCommand(counter::incrementAndGet, 0.01);
scheduler.schedule(command);
for (int i = 0; i < 5; ++i) {
@@ -39,7 +40,7 @@ class NotifierCommandTest extends CommandTestBase {
}
scheduler.cancel(command);
assertEquals(2, counter.m_counter);
assertEquals(2, counter.get());
}
}
}

View File

@@ -89,10 +89,10 @@ class ParallelCommandGroupTest extends CommandTestBase {
@Test
void parallelGroupRequirementTest() {
Subsystem system1 = new TestSubsystem();
Subsystem system2 = new TestSubsystem();
Subsystem system3 = new TestSubsystem();
Subsystem system4 = new TestSubsystem();
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system4 = new SubsystemBase() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
@@ -114,9 +114,9 @@ class ParallelCommandGroupTest extends CommandTestBase {
@Test
void parallelGroupRequirementErrorTest() {
Subsystem system1 = new TestSubsystem();
Subsystem system2 = new TestSubsystem();
Subsystem system3 = new TestSubsystem();
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
Command command1 = command1Holder.getMock();

View File

@@ -85,10 +85,10 @@ class ParallelDeadlineGroupTest extends CommandTestBase {
@Test
void parallelDeadlineRequirementTest() {
Subsystem system1 = new TestSubsystem();
Subsystem system2 = new TestSubsystem();
Subsystem system3 = new TestSubsystem();
Subsystem system4 = new TestSubsystem();
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system4 = new SubsystemBase() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
@@ -110,9 +110,9 @@ class ParallelDeadlineGroupTest extends CommandTestBase {
@Test
void parallelDeadlineRequirementErrorTest() {
Subsystem system1 = new TestSubsystem();
Subsystem system2 = new TestSubsystem();
Subsystem system3 = new TestSubsystem();
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
Command command1 = command1Holder.getMock();

View File

@@ -91,10 +91,10 @@ class ParallelRaceGroupTest extends CommandTestBase {
@Test
void parallelRaceRequirementTest() {
Subsystem system1 = new TestSubsystem();
Subsystem system2 = new TestSubsystem();
Subsystem system3 = new TestSubsystem();
Subsystem system4 = new TestSubsystem();
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system4 = new SubsystemBase() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
@@ -116,9 +116,9 @@ class ParallelRaceGroupTest extends CommandTestBase {
@Test
void parallelRaceRequirementErrorTest() {
Subsystem system1 = new TestSubsystem();
Subsystem system2 = new TestSubsystem();
Subsystem system3 = new TestSubsystem();
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);
Command command1 = command1Holder.getMock();
@@ -130,8 +130,8 @@ class ParallelRaceGroupTest extends CommandTestBase {
@Test
void parallelRaceOnlyCallsEndOnceTest() {
Subsystem system1 = new TestSubsystem();
Subsystem system2 = new TestSubsystem();
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
MockCommandHolder command1Holder = new MockCommandHolder(true, system1);
Command command1 = command1Holder.getMock();

View File

@@ -8,6 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.verify;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.Test;
class ProxyScheduleCommandTest extends CommandTestBase {
@@ -28,9 +29,9 @@ class ProxyScheduleCommandTest extends CommandTestBase {
@Test
void proxyScheduleCommandEndTest() {
try (CommandScheduler scheduler = CommandScheduler.getInstance()) {
ConditionHolder cond = new ConditionHolder();
AtomicBoolean cond = new AtomicBoolean();
WaitUntilCommand command = new WaitUntilCommand(cond::getCondition);
WaitUntilCommand command = new WaitUntilCommand(cond::get);
ProxyScheduleCommand scheduleCommand = new ProxyScheduleCommand(command);
@@ -39,7 +40,7 @@ class ProxyScheduleCommandTest extends CommandTestBase {
scheduler.run();
assertTrue(scheduler.isScheduled(scheduleCommand));
cond.setCondition(true);
cond.set(true);
scheduler.run();
scheduler.run();
assertFalse(scheduler.isScheduled(scheduleCommand));

View File

@@ -6,22 +6,23 @@ package edu.wpi.first.wpilibj2.command;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
class RunCommandTest extends CommandTestBase {
@Test
void runCommandScheduleTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Counter counter = new Counter();
AtomicInteger counter = new AtomicInteger(0);
RunCommand command = new RunCommand(counter::increment);
RunCommand command = new RunCommand(counter::incrementAndGet);
scheduler.schedule(command);
scheduler.run();
scheduler.run();
scheduler.run();
assertEquals(3, counter.m_counter);
assertEquals(3, counter.get());
}
}
}

View File

@@ -7,45 +7,46 @@ package edu.wpi.first.wpilibj2.command;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.concurrent.atomic.AtomicInteger;
import org.junit.jupiter.api.Test;
class SchedulerTest extends CommandTestBase {
@Test
void schedulerLambdaTestNoInterrupt() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Counter counter = new Counter();
AtomicInteger counter = new AtomicInteger();
scheduler.onCommandInitialize(command -> counter.increment());
scheduler.onCommandExecute(command -> counter.increment());
scheduler.onCommandFinish(command -> counter.increment());
scheduler.onCommandInitialize(command -> counter.incrementAndGet());
scheduler.onCommandExecute(command -> counter.incrementAndGet());
scheduler.onCommandFinish(command -> counter.incrementAndGet());
scheduler.schedule(new InstantCommand());
scheduler.run();
assertEquals(counter.m_counter, 3);
assertEquals(counter.get(), 3);
}
}
@Test
void schedulerInterruptLambdaTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Counter counter = new Counter();
AtomicInteger counter = new AtomicInteger();
scheduler.onCommandInterrupt(command -> counter.increment());
scheduler.onCommandInterrupt(command -> counter.incrementAndGet());
Command command = new WaitCommand(10);
scheduler.schedule(command);
scheduler.cancel(command);
assertEquals(counter.m_counter, 1);
assertEquals(counter.get(), 1);
}
}
@Test
void unregisterSubsystemTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Subsystem system = new TestSubsystem();
Subsystem system = new SubsystemBase() {};
scheduler.registerSubsystem(system);
assertDoesNotThrow(() -> scheduler.unregisterSubsystem(system));
@@ -55,9 +56,9 @@ class SchedulerTest extends CommandTestBase {
@Test
void schedulerCancelAllTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
Counter counter = new Counter();
AtomicInteger counter = new AtomicInteger();
scheduler.onCommandInterrupt(command -> counter.increment());
scheduler.onCommandInterrupt(command -> counter.incrementAndGet());
Command command = new WaitCommand(10);
Command command2 = new WaitCommand(10);
@@ -66,7 +67,7 @@ class SchedulerTest extends CommandTestBase {
scheduler.schedule(command2);
scheduler.cancelAll();
assertEquals(counter.m_counter, 2);
assertEquals(counter.get(), 2);
}
}
}

View File

@@ -74,10 +74,10 @@ class SelectCommandTest extends CommandTestBase {
@Test
void selectCommandRequirementTest() {
Subsystem system1 = new TestSubsystem();
Subsystem system2 = new TestSubsystem();
Subsystem system3 = new TestSubsystem();
Subsystem system4 = new TestSubsystem();
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system4 = new SubsystemBase() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);

View File

@@ -99,10 +99,10 @@ class SequentialCommandGroupTest extends CommandTestBase {
@Test
void sequentialGroupRequirementTest() {
Subsystem system1 = new TestSubsystem();
Subsystem system2 = new TestSubsystem();
Subsystem system3 = new TestSubsystem();
Subsystem system4 = new TestSubsystem();
Subsystem system1 = new SubsystemBase() {};
Subsystem system2 = new SubsystemBase() {};
Subsystem system3 = new SubsystemBase() {};
Subsystem system4 = new SubsystemBase() {};
try (CommandScheduler scheduler = new CommandScheduler()) {
MockCommandHolder command1Holder = new MockCommandHolder(true, system1, system2);

View File

@@ -7,17 +7,17 @@ package edu.wpi.first.wpilibj2.command;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.Test;
class StartEndCommandTest extends CommandTestBase {
@Test
void startEndCommandScheduleTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
ConditionHolder cond1 = new ConditionHolder();
ConditionHolder cond2 = new ConditionHolder();
AtomicBoolean cond1 = new AtomicBoolean();
AtomicBoolean cond2 = new AtomicBoolean();
StartEndCommand command =
new StartEndCommand(() -> cond1.setCondition(true), () -> cond2.setCondition(true));
StartEndCommand command = new StartEndCommand(() -> cond1.set(true), () -> cond2.set(true));
scheduler.schedule(command);
scheduler.run();
@@ -27,8 +27,8 @@ class StartEndCommandTest extends CommandTestBase {
scheduler.cancel(command);
assertFalse(scheduler.isScheduled(command));
assertTrue(cond1.getCondition());
assertTrue(cond2.getCondition());
assertTrue(cond1.get());
assertTrue(cond2.get());
}
}
}

View File

@@ -7,20 +7,21 @@ package edu.wpi.first.wpilibj2.command;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.jupiter.api.Test;
class WaitUntilCommandTest extends CommandTestBase {
@Test
void waitUntilTest() {
try (CommandScheduler scheduler = new CommandScheduler()) {
ConditionHolder condition = new ConditionHolder();
AtomicBoolean condition = new AtomicBoolean();
Command command = new WaitUntilCommand(condition::getCondition);
Command command = new WaitUntilCommand(condition::get);
scheduler.schedule(command);
scheduler.run();
assertTrue(scheduler.isScheduled(command));
condition.setCondition(true);
condition.set(true);
scheduler.run();
assertFalse(scheduler.isScheduled(command));
}

View File

@@ -16,6 +16,7 @@ import edu.wpi.first.wpilibj.simulation.SimHooks;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.CommandTestBase;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.BooleanSupplier;
import org.junit.jupiter.api.Test;
@@ -145,11 +146,11 @@ class ButtonTest extends CommandTestBase {
buttonWhileHeld.setPressed(true);
buttonWhenReleased.setPressed(true);
Counter counter = new Counter();
AtomicInteger counter = new AtomicInteger(0);
buttonWhenPressed.whenPressed(counter::increment);
buttonWhileHeld.whileHeld(counter::increment);
buttonWhenReleased.whenReleased(counter::increment);
buttonWhenPressed.whenPressed(counter::incrementAndGet);
buttonWhileHeld.whileHeld(counter::incrementAndGet);
buttonWhenReleased.whenReleased(counter::incrementAndGet);
CommandScheduler scheduler = CommandScheduler.getInstance();
@@ -158,7 +159,7 @@ class ButtonTest extends CommandTestBase {
buttonWhenReleased.setPressed(false);
scheduler.run();
assertEquals(counter.m_counter, 4);
assertEquals(counter.get(), 4);
}
@Test