Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit feb67e0

Browse files
authored
Merge pull request #40 from brettle/master
Add mocking necessary for VelocityPIDControllerTest to run off-robot
2 parents e24676a + cdf299b commit feb67e0

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

Robot2018/test/org/usfirst/frc/team199/Robot2018/VelocityPIDControllerTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,33 @@
55
import static org.mockito.Mockito.verify;
66
import static org.mockito.Mockito.when;
77

8+
import org.junit.jupiter.api.BeforeEach;
89
import org.junit.jupiter.api.Test;
910
import org.usfirst.frc.team199.Robot2018.autonomous.VelocityPIDController;
1011

12+
import edu.wpi.first.wpilibj.HLUsageReporting;
1113
import edu.wpi.first.wpilibj.PIDSource;
1214
import edu.wpi.first.wpilibj.SpeedController;
1315
import edu.wpi.first.wpilibj.Timer;
1416
import edu.wpi.first.wpilibj.internal.HardwareTimer;
1517

1618
class VelocityPIDControllerTest {
1719

20+
@BeforeEach
21+
void setUp() {
22+
// Since VelocityPIDController extends PIDController and PIDController calls
23+
// static methods in wpilib that only work on robot,
24+
// we setup these mocks to allow the tests to run off robot.
25+
HardwareTimer tim = mock(HardwareTimer.class);
26+
Timer.Interface timerInstance = mock(Timer.Interface.class);
27+
when(tim.newTimer()).thenReturn(timerInstance);
28+
Timer.SetImplementation(tim);
29+
HLUsageReporting.Interface usageReporter = mock(HLUsageReporting.Interface.class);
30+
HLUsageReporting.SetImplementation(usageReporter);
31+
}
32+
1833
@Test
1934
void test1() {
20-
HardwareTimer tim = new HardwareTimer();
21-
Timer.SetImplementation(tim);
2235
PIDSource source = mock(PIDSource.class);
2336
SpeedController out = mock(SpeedController.class);
2437
double p = 1;

0 commit comments

Comments
 (0)