Fix DanaRS tests

This commit is contained in:
Milos Kozak 2019-04-09 22:55:12 +02:00
parent e95e7922b3
commit 83e987f3c8
2 changed files with 46 additions and 28 deletions

View file

@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import android.content.Context;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
@ -20,34 +21,26 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.treatments.TreatmentService;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.assertEquals;
import static org.powermock.api.mockito.PowerMockito.when;
/**
* Created by Rumen on 31.07.2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({SP.class, MainApp.class, ConfigBuilderPlugin.class, Context.class, NSUpload.class, TreatmentsPlugin.class, TreatmentService.class, DatabaseHelper.class})
@PrepareForTest({SP.class, MainApp.class, ConfigBuilderPlugin.class, Context.class, NSUpload.class, TreatmentsPlugin.class, TreatmentService.class, DatabaseHelper.class, DateUtil.class})
public class DanaRS_Packet_APS_History_EventsTest extends DanaRS_Packet_APS_History_Events {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockBus();
SPMocker.prepareMock();
SP.putString("profile", AAPSMocker.getValidProfileStore().getData().toString());
AAPSMocker.mockConfigBuilder();
AAPSMocker.mockStrings();
PowerMockito.mockStatic(NSUpload.class);
AAPSMocker.mockDatabaseHelper();
DanaRS_Packet_APS_History_Events testPacket = new DanaRS_Packet_APS_History_Events(System.currentTimeMillis());
DanaRS_Packet_APS_History_Events testPacket = new DanaRS_Packet_APS_History_Events(DateUtil.now());
// test getRequestedParams
byte[] returnedValues = testPacket.getRequestParams();
byte[] expectedValues = getCalender(System.currentTimeMillis());
byte[] expectedValues = getCalender(DateUtil.now());
//year
assertEquals(expectedValues[0], returnedValues[0]);
//month
@ -95,4 +88,20 @@ public class DanaRS_Packet_APS_History_EventsTest extends DanaRS_Packet_APS_Hist
return ret;
}
@Before
public void prepareTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockBus();
SPMocker.prepareMock();
SP.putString("profile", AAPSMocker.getValidProfileStore().getData().toString());
AAPSMocker.mockConfigBuilder();
AAPSMocker.mockStrings();
PowerMockito.mockStatic(NSUpload.class);
AAPSMocker.mockDatabaseHelper();
PowerMockito.mockStatic(DateUtil.class);
when(DateUtil.now()).thenReturn(5456465445L);
}
}

View file

@ -1,8 +1,10 @@
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@ -10,42 +12,39 @@ import info.AAPSMocker;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.logging.L;
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.SP;
import static org.junit.Assert.assertEquals;
import static org.powermock.api.mockito.PowerMockito.when;
/**
* Created by Rumen on 31.07.2018.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, SP.class, L.class})
@PrepareForTest({MainApp.class, SP.class, L.class, DateUtil.class})
public class DanaRS_Packet_APS_Set_Event_HistoryTest {
@Test
public void runTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
// test for negative carbs
DanaRS_Packet_APS_Set_Event_History historyTest = new DanaRS_Packet_APS_Set_Event_History(DanaRPump.CARBS, System.currentTimeMillis(), -1, 0);
DanaRS_Packet_APS_Set_Event_History historyTest = new DanaRS_Packet_APS_Set_Event_History(DanaRPump.CARBS, DateUtil.now(), -1, 0);
byte[] testparams = historyTest.getRequestParams();
assertEquals((byte) 0, testparams[8]);
// 5g carbs
historyTest = new DanaRS_Packet_APS_Set_Event_History(DanaRPump.CARBS, System.currentTimeMillis(), 5, 0);
historyTest = new DanaRS_Packet_APS_Set_Event_History(DanaRPump.CARBS, DateUtil.now(), 5, 0);
testparams = historyTest.getRequestParams();
assertEquals((byte) 5, testparams[8]);
// 150g carbs
historyTest = new DanaRS_Packet_APS_Set_Event_History(DanaRPump.CARBS, System.currentTimeMillis(), 150, 0);
historyTest = new DanaRS_Packet_APS_Set_Event_History(DanaRPump.CARBS, DateUtil.now(), 150, 0);
testparams = historyTest.getRequestParams();
assertEquals((byte) 150, testparams[8]);
// test low hard limit
// test high hard limit
// test message generation
historyTest = new DanaRS_Packet_APS_Set_Event_History(DanaRPump.CARBS, System.currentTimeMillis(), 5, 0);
historyTest = new DanaRS_Packet_APS_Set_Event_History(DanaRPump.CARBS, DateUtil.now(), 5, 0);
testparams = historyTest.getRequestParams();
assertEquals((byte) 5, testparams[8]);
assertEquals(11, testparams.length);
@ -60,4 +59,14 @@ public class DanaRS_Packet_APS_Set_Event_HistoryTest {
assertEquals("APS_SET_EVENT_HISTORY", historyTest.getFriendlyName());
}
@Before
public void prepareTest() {
AAPSMocker.mockMainApp();
AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP();
AAPSMocker.mockL();
PowerMockito.mockStatic(DateUtil.class);
when(DateUtil.now()).thenReturn(5456465445L);
}
}