L.class mock

This commit is contained in:
Milos Kozak 2018-08-02 16:11:30 +02:00
parent 12883a407e
commit 5d7bebbbdc
2 changed files with 16 additions and 1 deletions

View file

@ -19,11 +19,13 @@ import info.nightscout.androidaps.data.ConstraintChecker;
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.Treatments.TreatmentService;
import info.nightscout.androidaps.queue.CommandQueue;
import info.nightscout.utils.SP;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
@ -122,6 +124,11 @@ public class AAPSMocker {
when(SP.getInt(anyInt(), anyInt())).thenReturn(0);
}
public static void mockL() {
PowerMockito.mockStatic(L.class);
when(L.isEnabled(any())).thenReturn(true);
}
public static void mockApplicationContext() {
Context context = mock(Context.class);
when(MainApp.instance().getApplicationContext()).thenReturn(context);

View file

@ -8,16 +8,18 @@ import org.powermock.modules.junit4.PowerMockRunner;
import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.utils.SP;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
/**
* Created by mike on 20.11.2017.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class})
@PrepareForTest({MainApp.class, SP.class, L.class})
public class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest {
@Test
@ -25,11 +27,17 @@ public class DanaRS_Packet_APS_Basal_Set_Temporary_BasalTest {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
// under 100% should last 30 min
DanaRS_Packet_APS_Basal_Set_Temporary_Basal packet = new DanaRS_Packet_APS_Basal_Set_Temporary_Basal();
packet.setParams(0);
assertEquals(0, packet.temporaryBasalRatio);
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
//constructor with param
packet = new DanaRS_Packet_APS_Basal_Set_Temporary_Basal(10);
assertEquals(10, packet.temporaryBasalRatio);
assertEquals(packet.PARAM30MIN, packet.temporaryBasalDuration);
// over 100% should last 15 min
packet.setParams(150);
assertEquals(150, packet.temporaryBasalRatio);