fix tests

This commit is contained in:
Milos Kozak 2019-03-30 17:10:21 +01:00
parent f1f1be160b
commit 6357dd40d7
2 changed files with 11 additions and 9 deletions

View file

@ -53,7 +53,7 @@ public class ActionStartTempTarget extends Action {
int unitResId = value.getUnits().equals(Constants.MGDL) ? R.string.mgdl : R.string.mmol; int unitResId = value.getUnits().equals(Constants.MGDL) ? R.string.mgdl : R.string.mmol;
new LayoutBuilder() new LayoutBuilder()
.add(new Label(MainApp.gs(R.string.careportal_newnstreatment_percentage_label), MainApp.gs(unitResId), value)) .add(new Label(MainApp.gs(R.string.careportal_temporarytarget), MainApp.gs(unitResId), value))
.add(new Label(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "min", duration)) .add(new Label(MainApp.gs(R.string.careportal_newnstreatment_duration_min_label), "min", duration))
.build(root); .build(root);
} }

View file

@ -18,9 +18,11 @@ import java.util.List;
import info.AAPSMocker; import info.AAPSMocker;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.db.BgReading; import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.data.NSSgv; import info.nightscout.androidaps.plugins.general.nsclient.data.NSSgv;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.utils.DateUtil; import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.T; import info.nightscout.androidaps.utils.T;
@ -29,12 +31,12 @@ import static org.mockito.ArgumentMatchers.anyLong;
import static org.powermock.api.mockito.PowerMockito.when; import static org.powermock.api.mockito.PowerMockito.when;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, Bus.class, ProfileFunctions.class, DateUtil.class}) @PrepareForTest({MainApp.class, Bus.class, ProfileFunctions.class, DateUtil.class, IobCobCalculatorPlugin.class})
public class TriggerBgTest { public class TriggerBgTest {
@Test @Test
public void shouldRunTest() { public void shouldRunTest() {
when(MainApp.getDbHelper().getBgreadingsDataFromTime(anyLong(), anyBoolean())).thenReturn(generateOneCurrentRecordBgData()); when(IobCobCalculatorPlugin.getPlugin().getBgReadings()).thenReturn(generateOneCurrentRecordBgData());
TriggerBg t = new TriggerBg().units(Constants.MMOL).threshold(4.1d).comparator(Trigger.Comparator.IS_EQUAL); TriggerBg t = new TriggerBg().units(Constants.MMOL).threshold(4.1d).comparator(Trigger.Comparator.IS_EQUAL);
Assert.assertFalse(t.shouldRun()); Assert.assertFalse(t.shouldRun());
@ -42,21 +44,21 @@ public class TriggerBgTest {
Assert.assertTrue(t.shouldRun()); Assert.assertTrue(t.shouldRun());
t = new TriggerBg().units(Constants.MGDL).threshold(214).comparator(Trigger.Comparator.IS_EQUAL_OR_GREATER); t = new TriggerBg().units(Constants.MGDL).threshold(214).comparator(Trigger.Comparator.IS_EQUAL_OR_GREATER);
Assert.assertTrue(t.shouldRun()); Assert.assertTrue(t.shouldRun());
t = new TriggerBg().units(Constants.MGDL).threshold(214).comparator(Trigger.Comparator.IS_EQUAL_OR_LOWER); t = new TriggerBg().units(Constants.MGDL).threshold(214).comparator(Trigger.Comparator.IS_EQUAL_OR_LESSER);
Assert.assertTrue(t.shouldRun()); Assert.assertTrue(t.shouldRun());
t = new TriggerBg().units(Constants.MGDL).threshold(215).comparator(Trigger.Comparator.IS_EQUAL); t = new TriggerBg().units(Constants.MGDL).threshold(215).comparator(Trigger.Comparator.IS_EQUAL);
Assert.assertFalse(t.shouldRun()); Assert.assertFalse(t.shouldRun());
t = new TriggerBg().units(Constants.MGDL).threshold(215).comparator(Trigger.Comparator.IS_EQUAL_OR_LOWER); t = new TriggerBg().units(Constants.MGDL).threshold(215).comparator(Trigger.Comparator.IS_EQUAL_OR_LESSER);
Assert.assertTrue(t.shouldRun()); Assert.assertTrue(t.shouldRun());
t = new TriggerBg().units(Constants.MGDL).threshold(215).comparator(Trigger.Comparator.IS_EQUAL_OR_GREATER); t = new TriggerBg().units(Constants.MGDL).threshold(215).comparator(Trigger.Comparator.IS_EQUAL_OR_GREATER);
Assert.assertFalse(t.shouldRun()); Assert.assertFalse(t.shouldRun());
t = new TriggerBg().units(Constants.MGDL).threshold(213).comparator(Trigger.Comparator.IS_EQUAL_OR_GREATER); t = new TriggerBg().units(Constants.MGDL).threshold(213).comparator(Trigger.Comparator.IS_EQUAL_OR_GREATER);
Assert.assertTrue(t.shouldRun()); Assert.assertTrue(t.shouldRun());
t = new TriggerBg().units(Constants.MGDL).threshold(213).comparator(Trigger.Comparator.IS_EQUAL_OR_LOWER); t = new TriggerBg().units(Constants.MGDL).threshold(213).comparator(Trigger.Comparator.IS_EQUAL_OR_LESSER);
Assert.assertFalse(t.shouldRun()); Assert.assertFalse(t.shouldRun());
when(MainApp.getDbHelper().getBgreadingsDataFromTime(anyLong(), anyBoolean())).thenReturn(new ArrayList<>()); when(IobCobCalculatorPlugin.getPlugin().getBgReadings()).thenReturn(new ArrayList<>());
t = new TriggerBg().units(Constants.MGDL).threshold(213).comparator(Trigger.Comparator.IS_EQUAL_OR_LOWER); t = new TriggerBg().units(Constants.MGDL).threshold(213).comparator(Trigger.Comparator.IS_EQUAL_OR_LESSER);
Assert.assertFalse(t.shouldRun()); Assert.assertFalse(t.shouldRun());
t = new TriggerBg().comparator(Trigger.Comparator.IS_NOT_AVAILABLE); t = new TriggerBg().comparator(Trigger.Comparator.IS_NOT_AVAILABLE);
Assert.assertTrue(t.shouldRun()); Assert.assertTrue(t.shouldRun());
@ -84,7 +86,7 @@ public class TriggerBgTest {
public void mock() { public void mock() {
AAPSMocker.mockMainApp(); AAPSMocker.mockMainApp();
AAPSMocker.mockBus(); AAPSMocker.mockBus();
AAPSMocker.mockDatabaseHelper(); AAPSMocker.mockIobCobCalculatorPlugin();
AAPSMocker.mockProfileFunctions(); AAPSMocker.mockProfileFunctions();
PowerMockito.mockStatic(DateUtil.class); PowerMockito.mockStatic(DateUtil.class);