Fix DanaRS tests
This commit is contained in:
parent
e95e7922b3
commit
83e987f3c8
2 changed files with 46 additions and 28 deletions
|
@ -3,6 +3,7 @@ package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.powermock.api.mockito.PowerMockito;
|
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.general.nsclient.NSUpload;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentService;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentService;
|
||||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.powermock.api.mockito.PowerMockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Rumen on 31.07.2018.
|
* Created by Rumen on 31.07.2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@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 {
|
public class DanaRS_Packet_APS_History_EventsTest extends DanaRS_Packet_APS_History_Events {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
AAPSMocker.mockMainApp();
|
DanaRS_Packet_APS_History_Events testPacket = new DanaRS_Packet_APS_History_Events(DateUtil.now());
|
||||||
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());
|
|
||||||
// test getRequestedParams
|
// test getRequestedParams
|
||||||
byte[] returnedValues = testPacket.getRequestParams();
|
byte[] returnedValues = testPacket.getRequestParams();
|
||||||
byte[] expectedValues = getCalender(System.currentTimeMillis());
|
byte[] expectedValues = getCalender(DateUtil.now());
|
||||||
//year
|
//year
|
||||||
assertEquals(expectedValues[0], returnedValues[0]);
|
assertEquals(expectedValues[0], returnedValues[0]);
|
||||||
//month
|
//month
|
||||||
|
@ -95,4 +88,20 @@ public class DanaRS_Packet_APS_History_EventsTest extends DanaRS_Packet_APS_Hist
|
||||||
return ret;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
package info.nightscout.androidaps.plugins.pump.danaRS.comm;
|
||||||
|
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.powermock.api.mockito.PowerMockito;
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
import org.powermock.modules.junit4.PowerMockRunner;
|
||||||
|
|
||||||
|
@ -10,42 +12,39 @@ import info.AAPSMocker;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.logging.L;
|
import info.nightscout.androidaps.logging.L;
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
||||||
|
import info.nightscout.androidaps.utils.DateUtil;
|
||||||
import info.nightscout.androidaps.utils.SP;
|
import info.nightscout.androidaps.utils.SP;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.powermock.api.mockito.PowerMockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by Rumen on 31.07.2018.
|
* Created by Rumen on 31.07.2018.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
@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 {
|
public class DanaRS_Packet_APS_Set_Event_HistoryTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void runTest() {
|
public void runTest() {
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockApplicationContext();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
AAPSMocker.mockL();
|
|
||||||
|
|
||||||
// test for negative carbs
|
// 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();
|
byte[] testparams = historyTest.getRequestParams();
|
||||||
assertEquals((byte) 0, testparams[8]);
|
assertEquals((byte) 0, testparams[8]);
|
||||||
// 5g carbs
|
// 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();
|
testparams = historyTest.getRequestParams();
|
||||||
assertEquals((byte) 5, testparams[8]);
|
assertEquals((byte) 5, testparams[8]);
|
||||||
// 150g carbs
|
// 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();
|
testparams = historyTest.getRequestParams();
|
||||||
assertEquals((byte) 150, testparams[8]);
|
assertEquals((byte) 150, testparams[8]);
|
||||||
// test low hard limit
|
// test low hard limit
|
||||||
// test high hard limit
|
// test high hard limit
|
||||||
|
|
||||||
// test message generation
|
// 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();
|
testparams = historyTest.getRequestParams();
|
||||||
assertEquals((byte) 5, testparams[8]);
|
assertEquals((byte) 5, testparams[8]);
|
||||||
assertEquals(11, testparams.length);
|
assertEquals(11, testparams.length);
|
||||||
|
@ -60,4 +59,14 @@ public class DanaRS_Packet_APS_Set_Event_HistoryTest {
|
||||||
assertEquals("APS_SET_EVENT_HISTORY", historyTest.getFriendlyName());
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue