fix some tests

This commit is contained in:
Milos Kozak 2019-11-12 17:37:44 +01:00
parent 128e8a024d
commit 3c025e97a8
6 changed files with 23 additions and 23 deletions

View file

@ -37,6 +37,7 @@ import static org.mockito.ArgumentMatchers.any;
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;
@ -183,6 +184,7 @@ public class AAPSMocker {
when(SP.getLong(anyInt(), anyLong())).thenReturn(0L);
when(SP.getBoolean(anyInt(), anyBoolean())).thenReturn(false);
when(SP.getInt(anyInt(), anyInt())).thenReturn(0);
when(SP.getString(anyInt(), anyString())).thenReturn("");
}
public static void mockL() {
@ -265,10 +267,10 @@ public class AAPSMocker {
public static void mockProfileFunctions() {
PowerMockito.mockStatic(ProfileFunctions.class);
profileFunctions = PowerMockito.mock(ProfileFunctions.class);
PowerMockito.when(ProfileFunctions.getSystemUnits()).thenReturn(Constants.MGDL);
PowerMockito.when(ProfileFunctions.getInstance()).thenReturn(profileFunctions);
profile = getValidProfile();
PowerMockito.when(ProfileFunctions.getInstance().getProfile()).thenReturn(profile);
PowerMockito.when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MGDL);
PowerMockito.when(ProfileFunctions.getInstance().getProfileName()).thenReturn(TESTPROFILENAME);
}

View file

@ -58,9 +58,9 @@ public class ProfileTest {
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);
Assert.assertEquals(100d, p.getIsf(c.getTimeInMillis()), 0.01d);
Assert.assertEquals(1800d, p.getIsfMgdl(c.getTimeInMillis()), 0.01d);
c.set(Calendar.HOUR_OF_DAY, 2);
Assert.assertEquals(110d, p.getIsf(c.getTimeInMillis()), 0.01d);
Assert.assertEquals(1980d, p.getIsfMgdl(c.getTimeInMillis()), 0.01d);
Assert.assertEquals(110d, p.getIsfTimeFromMidnight(2 * 60 * 60), 0.01d);
Assert.assertEquals("00:00 100,0 mmol/U\n" + "02:00 110,0 mmol/U", p.getIsfList().replace(".", ","));
Assert.assertEquals(30d, p.getIc(c.getTimeInMillis()), 0.01d);
@ -73,10 +73,10 @@ public class ProfileTest {
Assert.assertEquals(0.1d, p.getMaxDailyBasal());
Assert.assertEquals(2.4d, p.percentageBasalSum(), 0.01d);
Assert.assertEquals(2.4d, p.baseBasalSum(), 0.01d);
Assert.assertEquals(4.5d, p.getTarget(2 * 60 * 60), 0.01d);
Assert.assertEquals(4d, p.getTargetLow(c.getTimeInMillis()), 0.01d);
Assert.assertEquals(81d, p.getTargetMgdl(2 * 60 * 60), 0.01d);
Assert.assertEquals(72d, p.getTargetLowMgdl(c.getTimeInMillis()), 0.01d);
Assert.assertEquals(4d, p.getTargetLowTimeFromMidnight(2 * 60 * 60), 0.01d);
Assert.assertEquals(5d, p.getTargetHigh(c.getTimeInMillis()), 0.01d);
Assert.assertEquals(90d, p.getTargetHighMgdl(c.getTimeInMillis()), 0.01d);
Assert.assertEquals(5d, p.getTargetHighTimeFromMidnight(2 * 60 * 60), 0.01d);
Assert.assertEquals("00:00 4,0 - 5,0 mmol", p.getTargetList().replace(".", ","));
Assert.assertEquals(100, p.getPercentage());
@ -122,7 +122,7 @@ public class ProfileTest {
Assert.assertEquals(0.05d, p.getBasal(c.getTimeInMillis()), 0.01d);
Assert.assertEquals(1.2d, p.percentageBasalSum(), 0.01d);
Assert.assertEquals(60d, p.getIc(c.getTimeInMillis()), 0.01d);
Assert.assertEquals(220d, p.getIsf(c.getTimeInMillis()), 0.01d);
Assert.assertEquals(3960d, p.getIsfMgdl(c.getTimeInMillis()), 0.01d);
// Test timeshift functionality
p = new Profile(new JSONObject(validProfile), 100, 1);
@ -140,7 +140,7 @@ public class ProfileTest {
}
@Before
public void prepareMock() throws Exception {
public void prepareMock() {
AAPSMocker.mockMainApp();
AAPSMocker.mockConfigBuilder();
AAPSMocker.mockStrings();
@ -148,8 +148,5 @@ public class ProfileTest {
when(ConfigBuilderPlugin.getPlugin().getActivePump()).thenReturn(pump);
PowerMockito.mockStatic(FabricPrivacy.class);
// PowerMockito.doNothing().when(FabricPrivacy.log(""));
}
}

View file

@ -132,12 +132,8 @@ public class TriggerDeltaTest {
@Test
public void initializerTest(){
PowerMockito.when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MMOL);
TriggerDelta t = new TriggerDelta();
Assert.assertTrue(t.getUnits().equals(Constants.MMOL));
PowerMockito.when(ProfileFunctions.getInstance().getProfileUnits()).thenReturn(Constants.MGDL);
t = new TriggerDelta();
Assert.assertEquals(Constants.MGDL, t.getUnits());
Assert.assertTrue(t.getUnits().equals(Constants.MGDL));
}
List<BgReading> generateValidBgData() {

View file

@ -75,5 +75,8 @@ public class NewNSTreatmentDialogTest {
.thenReturn(profilePlugin);
dialog = new NewNSTreatmentDialog();
PowerMockito.spy(System.class);
when(System.currentTimeMillis()).thenReturn(1000L);
}
}

View file

@ -33,7 +33,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.profile.simple.SimpleProfilePlugin;
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin;
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback;
@ -57,7 +57,7 @@ import static org.powermock.api.mockito.PowerMockito.when;
L.class, SP.class, MainApp.class, DateUtil.class, ProfileFunctions.class,
TreatmentsPlugin.class, SmsManager.class, IobCobCalculatorPlugin.class,
CommandQueue.class, ConfigBuilderPlugin.class, NSUpload.class, ProfileInterface.class,
SimpleProfilePlugin.class, XdripCalibrations.class, VirtualPumpPlugin.class, LoopPlugin.class
LocalProfilePlugin.class, XdripCalibrations.class, VirtualPumpPlugin.class, LoopPlugin.class
})
public class SmsCommunicatorPluginTest {
@ -375,7 +375,7 @@ public class SmsCommunicatorPluginTest {
Assert.assertEquals("PROFILE LIST", smsCommunicatorPlugin.messages.get(0).text);
Assert.assertEquals("Not configured", smsCommunicatorPlugin.messages.get(1).text);
ProfileInterface profileInterface = mock(SimpleProfilePlugin.class);
ProfileInterface profileInterface = mock(LocalProfilePlugin.class);
when(ConfigBuilderPlugin.getPlugin().getActiveProfileInterface()).thenReturn(profileInterface);
//PROFILE LIST (no profile defined)

View file

@ -12,6 +12,7 @@ import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.ConstraintChecker;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
@ -28,7 +29,7 @@ import static org.mockito.Mockito.when;
* Created by kuchjir on 12/12/2017.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, GlucoseStatus.class, ConfigBuilderPlugin.class, TreatmentsPlugin.class, ConstraintChecker.class})
@PrepareForTest({MainApp.class, GlucoseStatus.class, ConfigBuilderPlugin.class, TreatmentsPlugin.class, ConstraintChecker.class, ProfileFunctions.class})
public class BolusWizardTest {
private static final double PUMP_BOLUS_STEP = 0.1;
@ -68,9 +69,9 @@ public class BolusWizardTest {
private Profile setupProfile(Double targetLow, Double targetHigh, Double insulinSensitivityFactor, Double insulinToCarbRatio) {
Profile profile = mock(Profile.class);
when(profile.getTargetLow()).thenReturn(targetLow);
when(profile.getTargetHigh()).thenReturn(targetHigh);
when(profile.getIsf()).thenReturn(insulinSensitivityFactor);
when(profile.getTargetLowMgdl()).thenReturn(targetLow);
when(profile.getTargetHighMgdl()).thenReturn(targetHigh);
when(profile.getIsfMgdl()).thenReturn(insulinSensitivityFactor);
when(profile.getIc()).thenReturn(insulinToCarbRatio);
PowerMockito.mockStatic(GlucoseStatus.class);
@ -95,6 +96,7 @@ public class BolusWizardTest {
return constraint;
}).when(AAPSMocker.constraintChecker).applyBolusConstraints(any(Constraint.class));
AAPSMocker.mockProfileFunctions();
return profile;
}
}