make tests compile

This commit is contained in:
Milos Kozak 2019-12-27 21:39:34 +01:00
parent 4b86961235
commit 8b88e2d270
6 changed files with 16 additions and 11 deletions

View file

@ -14,13 +14,13 @@ import java.util.Locale;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.data.ProfileStore;
import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
@ -34,7 +34,6 @@ import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -184,8 +183,10 @@ public class AAPSMocker {
}
public static ConstraintChecker mockConstraintsChecker() {
PowerMockito.mockStatic(ConstraintChecker.class);
constraintChecker = mock(ConstraintChecker.class);
when(MainApp.getConstraintChecker()).thenReturn(constraintChecker);
when(ConstraintChecker.getInstance())
.thenReturn(constraintChecker);
return constraintChecker;
}

View file

@ -287,7 +287,7 @@ public class ConstraintsCheckerTest {
//SafetyPlugin
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(pump);
constraintChecker = new ConstraintChecker();
constraintChecker = ConstraintChecker.getInstance();
safetyPlugin = SafetyPlugin.getPlugin();
objectivesPlugin = ObjectivesPlugin.INSTANCE;

View file

@ -30,7 +30,7 @@ import static org.mockito.ArgumentMatchers.anyLong;
import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, SP.class, Context.class, ProfileFunctions.class, TreatmentsPlugin.class, L.class})
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, SP.class, Context.class, ProfileFunctions.class, TreatmentsPlugin.class, L.class, ConstraintChecker.class})
public class APSResultTest {
VirtualPumpPlugin virtualPumpPlugin;
TreatmentsPlugin treatmentsPlugin;
@ -183,13 +183,13 @@ public class APSResultTest {
AAPSMocker.mockTreatmentService();
AAPSMocker.mockL();
treatmentsPlugin = AAPSMocker.mockTreatmentPlugin();
ConstraintChecker constraintChecker = AAPSMocker.mockConstraintsChecker();
AAPSMocker.mockConstraintsChecker();
when(ConstraintChecker.getInstance().isClosedLoopAllowed()).thenReturn(closedLoopEnabled);
virtualPumpPlugin = VirtualPumpPlugin.getPlugin();
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(virtualPumpPlugin);
when(constraintChecker.isClosedLoopAllowed()).thenReturn(closedLoopEnabled);
Mockito.when(SP.getDouble(anyInt(), anyDouble())).thenReturn(30d);
}

View file

@ -18,6 +18,7 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin;
import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
import info.nightscout.androidaps.plugins.source.SourceGlimpPlugin;
import info.nightscout.androidaps.utils.SP;

View file

@ -43,6 +43,7 @@ import info.nightscout.androidaps.queue.CommandQueue;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.SP;
import info.nightscout.androidaps.utils.XdripCalibrations;
import info.nightscout.androidaps.utils.resources.ResourceHelperImplementation;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
@ -889,7 +890,7 @@ public class SmsCommunicatorPluginTest {
AAPSMocker.mockConfigBuilder();
AAPSMocker.mockCommandQueue();
AAPSMocker.mockNSUpload();
AAPSMocker.mockConstraintsChecker();
ConstraintChecker constraintChecker = AAPSMocker.mockConstraintsChecker();
BgReading reading = new BgReading();
reading.value = 100;
@ -907,7 +908,8 @@ public class SmsCommunicatorPluginTest {
when(SP.getString(R.string.key_smscommunicator_allowednumbers, "")).thenReturn("1234;5678");
Lazy<InsulinOrefRapidActingPlugin> insulinOrefRapidActingPlugin = InsulinOrefRapidActingPlugin::new;
ConfigBuilderPlugin configBuilderPlugin = new ConfigBuilderPlugin(insulinOrefRapidActingPlugin);
smsCommunicatorPlugin = new SmsCommunicatorPlugin(configBuilderPlugin);
ResourceHelperImplementation resourceHelperImplementation = mock(ResourceHelperImplementation.class);
smsCommunicatorPlugin = new SmsCommunicatorPlugin(configBuilderPlugin, resourceHelperImplementation, constraintChecker);
smsCommunicatorPlugin.setPluginEnabled(PluginType.GENERAL, true);
mockStatic(LoopPlugin.class);

View file

@ -113,6 +113,7 @@ public class CommandQueueTest extends CommandQueue {
}
private void prepareMock(Double insulin, Integer carbs) throws Exception {
PowerMockito.mockStatic(ConstraintChecker.class);
ConstraintChecker constraintChecker = mock(ConstraintChecker.class);
AAPSMocker.mockMainApp();
@ -120,7 +121,7 @@ public class CommandQueueTest extends CommandQueue {
PumpInterface pump = VirtualPumpPlugin.getPlugin();
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(pump);
when(MainApp.getConstraintChecker()).thenReturn(constraintChecker);
when(ConstraintChecker.getInstance()).thenReturn(constraintChecker);
when(MainApp.isEngineeringModeOrRelease()).thenReturn(true);
Constraint<Double> bolusConstraint = new Constraint<>(0d);
when(ConstraintChecker.getInstance().applyBolusConstraints(any())).thenReturn(bolusConstraint);