11package frc .robot .lib ;
22
3+ import com .revrobotics .CANSparkMax ;
34import com .revrobotics .RelativeEncoder ;
45import com .revrobotics .SparkMaxAnalogSensor ;
56import com .revrobotics .SparkMaxLimitSwitch ;
@@ -15,26 +16,32 @@ public class DummySparkMaxAnswer extends REVLibErrorAnswer {
1516
1617 private static final long serialVersionUID = 2284848703213263465L ;
1718
19+ public static final DummySparkMaxAnswer ANSWER = new DummySparkMaxAnswer ();
20+
21+ public static final CANSparkMax DUMMY_SPARK_MAX = Mockito .mock (CANSparkMax .class , ANSWER );
22+
23+ public static final RelativeEncoder DUMMY_ENCODER = Mockito .mock (RelativeEncoder .class , REVLibErrorAnswer .ANSWER );
24+ public static final SparkMaxAnalogSensor DUMMY_ANALOG_SENSOR = Mockito .mock (SparkMaxAnalogSensor .class , REVLibErrorAnswer .ANSWER );
25+ public static final SparkMaxLimitSwitch DUMMY_LIMIT_SWITCH = Mockito .mock (SparkMaxLimitSwitch .class , REVLibErrorAnswer .ANSWER );
26+ public static final SparkMaxPIDController DUMMY_PID_CONTROLLER = Mockito .mock (SparkMaxPIDController .class , REVLibErrorAnswer .ANSWER );
27+
1828 @ Override
1929 public Object answer (InvocationOnMock invocation ) throws Throwable {
2030 Class <?> returnType = invocation .getMethod ().getReturnType ();
21- if (returnType == RelativeEncoder .class || returnType == SparkMaxAnalogSensor .class || returnType == SparkMaxAnalogSensor .class || returnType == SparkMaxLimitSwitch .class ) {
22- return Mockito .mock (returnType , new REVLibErrorAnswer ());
31+ if (returnType == RelativeEncoder .class ) {
32+ return DUMMY_ENCODER ;
33+ } else if (returnType == SparkMaxAnalogSensor .class ) {
34+ return DUMMY_ANALOG_SENSOR ;
35+ } else if (returnType == SparkMaxLimitSwitch .class ) {
36+ return DUMMY_LIMIT_SWITCH ;
2337 } else if (returnType == SparkMaxPIDController .class ) {
24- return Mockito .mock (SparkMaxPIDController .class , new REVLibErrorAnswer () {
25- private static final long serialVersionUID = 558452215206948125L ;
26- @ Override
27- public Object answer (InvocationOnMock invocation ) throws Throwable {
28- if (invocation .getMethod ().getReturnType () == AccelStrategy .class ) {
29- return AccelStrategy .kTrapezoidal ;
30- }
31- return super .answer (invocation );
32- }
33- });
38+ return DUMMY_PID_CONTROLLER ;
3439 } else if (returnType == MotorType .class ) {
3540 return MotorType .kBrushless ;
3641 } else if (returnType == IdleMode .class ) {
3742 return IdleMode .kBrake ;
43+ } else if (returnType == AccelStrategy .class ) {
44+ return AccelStrategy .kTrapezoidal ;
3845 }
3946 return super .answer (invocation );
4047 }
0 commit comments