|
3 | 3 | import static com.google.common.truth.Truth.assertThat; |
4 | 4 | import static com.team2813.subsystems.Intake.BUMP_VOLTAGE; |
5 | 5 | import static org.mockito.Mockito.mock; |
6 | | -import static org.mockito.Mockito.verifyNoInteractions; |
7 | 6 | import static org.mockito.Mockito.when; |
8 | 7 |
|
9 | 8 | import com.team2813.IsolatedNetworkTablesExtension; |
10 | | -import com.team2813.lib2813.testing.FakePIDMotor; |
| 9 | +import com.team2813.lib2813.testing.FakeMotor; |
11 | 10 | import com.team2813.lib2813.testing.junit.jupiter.CommandTester; |
12 | 11 | import com.team2813.lib2813.testing.junit.jupiter.WPILibExtension; |
13 | 12 | import edu.wpi.first.networktables.NetworkTableInstance; |
| 13 | +import edu.wpi.first.units.Units; |
14 | 14 | import edu.wpi.first.wpilibj.DigitalInput; |
15 | 15 | import edu.wpi.first.wpilibj2.command.Command; |
16 | 16 | import org.junit.jupiter.api.Test; |
17 | 17 | import org.junit.jupiter.api.extension.ExtendWith; |
18 | | -import org.mockito.Answers; |
19 | 18 |
|
20 | 19 | @ExtendWith({IsolatedNetworkTablesExtension.class, WPILibExtension.class}) |
21 | 20 | public final class IntakeTest { |
22 | | - final FakePIDMotor fakeMotor = mock(FakePIDMotor.class, Answers.CALLS_REAL_METHODS); |
| 21 | + final FakeMotor fakeMotor = new FakeMotor(); |
23 | 22 | final DigitalInput mockBeamBreak = mock(DigitalInput.class); |
24 | 23 |
|
25 | 24 | @Test |
26 | 25 | public void constructRealInstance(NetworkTableInstance ntInstance) { |
27 | 26 | try (Intake ignored = new Intake(ntInstance)) { |
28 | | - assertThat(fakeMotor.demand).isWithin(0.01).of(0.0); |
| 27 | + assertThat(fakeMotor.getDemand()).isWithin(0.01).of(0.0); |
29 | 28 | } |
30 | 29 | } |
31 | 30 |
|
32 | 31 | @Test |
33 | 32 | public void initialState(NetworkTableInstance ntInstance) { |
34 | 33 | try (Intake ignored = new Intake(fakeMotor, mockBeamBreak, ntInstance)) { |
35 | | - assertThat(fakeMotor.demand).isWithin(0.01).of(0.0); |
36 | | - verifyNoInteractions(fakeMotor); |
| 34 | + assertThat(fakeMotor.getDemand()).isWithin(0.01).of(0.0); |
37 | 35 | } |
38 | 36 | } |
39 | 37 |
|
40 | 38 | @Test |
41 | 39 | public void intakeCoral(NetworkTableInstance ntInstance, CommandTester commandTester) { |
42 | 40 | try (Intake intake = new Intake(fakeMotor, mockBeamBreak, ntInstance)) { |
43 | 41 | Command command = intake.intakeItemCommand(); |
44 | | - assertThat(fakeMotor.demand).isWithin(0.01).of(0.0); |
| 42 | + assertThat(fakeMotor.getDemand()).isWithin(0.01).of(0.0); |
45 | 43 |
|
46 | 44 | commandTester.runUntilComplete(command); |
47 | 45 |
|
48 | | - assertThat(fakeMotor.getVoltage()).isWithin(0.01).of(Intake.PARAMS.intakeDemand()); |
| 46 | + assertThat(fakeMotor.getMotorVoltage().in(Units.Volts)) |
| 47 | + .isWithin(0.01) |
| 48 | + .of(Intake.PARAMS.intakeDemand()); |
49 | 49 | } |
50 | 50 | } |
51 | 51 |
|
@@ -78,7 +78,9 @@ public void outtakeCoral(NetworkTableInstance ntInstance, CommandTester commandT |
78 | 78 |
|
79 | 79 | commandTester.runUntilComplete(command); |
80 | 80 | assertMotorIsRunning(); |
81 | | - assertThat(fakeMotor.getVoltage()).isWithin(0.01).of(Intake.PARAMS.outtakeDemand()); |
| 81 | + assertThat(fakeMotor.getMotorVoltage().in(Units.Volts)) |
| 82 | + .isWithin(0.01) |
| 83 | + .of(Intake.PARAMS.outtakeDemand()); |
82 | 84 | } |
83 | 85 | } |
84 | 86 |
|
@@ -114,7 +116,7 @@ public void bumpAlgae(NetworkTableInstance ntInstance, CommandTester commandTest |
114 | 116 |
|
115 | 117 | commandTester.runUntilComplete(command); |
116 | 118 |
|
117 | | - assertThat(fakeMotor.getVoltage()).isWithin(0.01).of(BUMP_VOLTAGE); |
| 119 | + assertThat(fakeMotor.getMotorVoltage().in(Units.Volts)).isWithin(0.01).of(BUMP_VOLTAGE); |
118 | 120 | } |
119 | 121 | } |
120 | 122 |
|
@@ -149,10 +151,10 @@ public void hasCoral_withoutCoral(NetworkTableInstance ntInstance) { |
149 | 151 | } |
150 | 152 |
|
151 | 153 | private void assertMotorIsStopped() { |
152 | | - assertThat(fakeMotor.demand).isWithin(0.01).of(0.0); |
| 154 | + assertThat(fakeMotor.getDemand()).isWithin(0.01).of(0.0); |
153 | 155 | } |
154 | 156 |
|
155 | 157 | private void assertMotorIsRunning() { |
156 | | - assertThat(fakeMotor.demand).isNotWithin(0.01).of(0.0); |
| 158 | + assertThat(fakeMotor.getDemand()).isNotWithin(0.01).of(0.0); |
157 | 159 | } |
158 | 160 | } |
0 commit comments