mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-27 02:01:42 +00:00
[wpilibj] Use try with resources for Java tests (#2612)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -21,35 +21,36 @@ class CommandParallelGroupTest extends AbstractCommandTest {
|
||||
final MockCommand command1 = new MockCommand();
|
||||
final MockCommand command2 = new MockCommand();
|
||||
|
||||
final CommandGroup commandGroup = new CommandGroup();
|
||||
commandGroup.addParallel(command1);
|
||||
commandGroup.addParallel(command2);
|
||||
try (CommandGroup commandGroup = new CommandGroup()) {
|
||||
commandGroup.addParallel(command1);
|
||||
commandGroup.addParallel(command2);
|
||||
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
commandGroup.start();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 0);
|
||||
command1.setHasFinished(true);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 1, 0);
|
||||
assertCommandState(command2, 1, 3, 3, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 1, 0);
|
||||
assertCommandState(command2, 1, 4, 4, 0, 0);
|
||||
command2.setHasFinished(true);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 1, 0);
|
||||
assertCommandState(command2, 1, 5, 5, 1, 0);
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
commandGroup.start();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 0);
|
||||
command1.setHasFinished(true);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 1, 0);
|
||||
assertCommandState(command2, 1, 3, 3, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 1, 0);
|
||||
assertCommandState(command2, 1, 4, 4, 0, 0);
|
||||
command2.setHasFinished(true);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 3, 3, 1, 0);
|
||||
assertCommandState(command2, 1, 5, 5, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Copyright (c) 2008-2019 FIRST. All Rights Reserved. */
|
||||
/* Copyright (c) 2008-2020 FIRST. All Rights Reserved. */
|
||||
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
||||
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
||||
/* the project. */
|
||||
@@ -34,60 +34,61 @@ class CommandSequentialGroupTest extends AbstractCommandTest {
|
||||
final MockCommand command3 = new MockCommand(subsystem);
|
||||
|
||||
logger.finest("Creating Command Group");
|
||||
final CommandGroup commandGroup = new CommandGroup();
|
||||
commandGroup.addSequential(command1, 1.0);
|
||||
commandGroup.addSequential(command2, 2.0);
|
||||
commandGroup.addSequential(command3);
|
||||
try (CommandGroup commandGroup = new CommandGroup()) {
|
||||
commandGroup.addSequential(command1, 1.0);
|
||||
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);
|
||||
logger.finest("Starting Command group");
|
||||
commandGroup.start();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
sleep(1250); // command 1 timeout
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
logger.finest("Starting Command group");
|
||||
commandGroup.start();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command2, 0, 0, 0, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
sleep(1250); // command 1 timeout
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 1, 1, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
sleep(2500); // command 2 timeout
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 1, 1, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 0);
|
||||
assertCommandState(command3, 0, 0, 0, 0, 0);
|
||||
sleep(2500); // command 2 timeout
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 1, 1, 0, 0);
|
||||
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 2, 2, 0, 0);
|
||||
command3.setHasFinished(true);
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 2, 2, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 3, 3, 1, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 3, 3, 1, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 2, 2, 0, 0);
|
||||
command3.setHasFinished(true);
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 2, 2, 0, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 3, 3, 1, 0);
|
||||
Scheduler.getInstance().run();
|
||||
assertCommandState(command1, 1, 1, 1, 0, 1);
|
||||
assertCommandState(command2, 1, 2, 2, 0, 1);
|
||||
assertCommandState(command3, 1, 3, 3, 1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user