DanaRv2.comm
This commit is contained in:
parent
248ab8bc76
commit
6bc2d9eef5
|
@ -1,61 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.pump.danaRv2.comm;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
||||||
import org.powermock.modules.junit4.PowerMockRunner;
|
|
||||||
|
|
||||||
import info.AAPSMocker;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.logging.L;
|
|
||||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump;
|
|
||||||
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin;
|
|
||||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
|
||||||
import info.nightscout.androidaps.queue.CommandQueue;
|
|
||||||
import info.nightscout.androidaps.utils.SP;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
import static org.powermock.api.mockito.PowerMockito.when;
|
|
||||||
|
|
||||||
@RunWith(PowerMockRunner.class)
|
|
||||||
@PrepareForTest({MainApp.class, SP.class, L.class, ConfigBuilderPlugin.class, CommandQueue.class})
|
|
||||||
public class MsgCheckValue_v2Test {
|
|
||||||
@Test
|
|
||||||
public void runTest() {
|
|
||||||
Treatment t = new Treatment();
|
|
||||||
MsgCheckValue_v2 packet = new MsgCheckValue_v2();
|
|
||||||
// test message decoding
|
|
||||||
packet.handleMessage(createArray(34, (byte) 3));
|
|
||||||
DanaRPump pump = DanaRPump.getInstance();
|
|
||||||
assertEquals(DanaRPump.EXPORT_MODEL, pump.model);
|
|
||||||
}
|
|
||||||
|
|
||||||
byte[] createArray(int length, byte fillWith){
|
|
||||||
byte[] ret = new byte[length];
|
|
||||||
for(int i = 0; i<length; i++){
|
|
||||||
ret[i] = fillWith;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
double[] createArray(int length, double fillWith){
|
|
||||||
double[] ret = new double[length];
|
|
||||||
for(int i = 0; i<length; i++){
|
|
||||||
ret[i] = fillWith;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void mock() {
|
|
||||||
AAPSMocker.mockMainApp();
|
|
||||||
AAPSMocker.mockApplicationContext();
|
|
||||||
AAPSMocker.mockSP();
|
|
||||||
AAPSMocker.mockL();
|
|
||||||
AAPSMocker.mockConfigBuilder();
|
|
||||||
AAPSMocker.mockCommandQueue();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
package info.nightscout.androidaps.plugins.pump.danaRv2.comm
|
||||||
|
|
||||||
|
import info.AAPSMocker
|
||||||
|
import info.nightscout.androidaps.MainApp
|
||||||
|
import info.nightscout.androidaps.logging.L
|
||||||
|
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaR.DanaRPump
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin
|
||||||
|
import info.nightscout.androidaps.plugins.pump.danaRv2.DanaRv2Plugin
|
||||||
|
import info.nightscout.androidaps.queue.CommandQueue
|
||||||
|
import info.nightscout.androidaps.utils.SP
|
||||||
|
import org.junit.Assert
|
||||||
|
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
|
||||||
|
|
||||||
|
@RunWith(PowerMockRunner::class)
|
||||||
|
@PrepareForTest(MainApp::class, SP::class, L::class, ConfigBuilderPlugin::class, CommandQueue::class, DanaRKoreanPlugin::class, DanaRPlugin::class, DanaRv2Plugin::class)
|
||||||
|
class MsgCheckValue_v2Test {
|
||||||
|
|
||||||
|
@Test fun runTest() {
|
||||||
|
val packet = MsgCheckValue_v2()
|
||||||
|
// test message decoding
|
||||||
|
packet.handleMessage(createArray(34, 3.toByte()))
|
||||||
|
val pump = DanaRPump.getInstance()
|
||||||
|
Assert.assertEquals(DanaRPump.EXPORT_MODEL.toLong(), pump.model.toLong())
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createArray(length: Int, fillWith: Byte): ByteArray {
|
||||||
|
val ret = ByteArray(length)
|
||||||
|
for (i in 0 until length) {
|
||||||
|
ret[i] = fillWith
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
fun createArray(length: Int, fillWith: Double): DoubleArray {
|
||||||
|
val ret = DoubleArray(length)
|
||||||
|
for (i in 0 until length) {
|
||||||
|
ret[i] = fillWith
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun mock() {
|
||||||
|
AAPSMocker.mockMainApp()
|
||||||
|
AAPSMocker.mockApplicationContext()
|
||||||
|
AAPSMocker.mockSP()
|
||||||
|
AAPSMocker.mockL()
|
||||||
|
AAPSMocker.mockConfigBuilder()
|
||||||
|
AAPSMocker.mockCommandQueue()
|
||||||
|
|
||||||
|
PowerMockito.mockStatic(DanaRKoreanPlugin::class.java)
|
||||||
|
val drk = PowerMockito.mock(DanaRKoreanPlugin::class.java)
|
||||||
|
PowerMockito.`when`(DanaRKoreanPlugin.getPlugin()).thenReturn(drk)
|
||||||
|
|
||||||
|
PowerMockito.mockStatic(DanaRPlugin::class.java)
|
||||||
|
val dr = PowerMockito.mock(DanaRPlugin::class.java)
|
||||||
|
PowerMockito.`when`(DanaRPlugin.getPlugin()).thenReturn(dr)
|
||||||
|
|
||||||
|
PowerMockito.mockStatic(DanaRv2Plugin::class.java)
|
||||||
|
val drv2 = PowerMockito.mock(DanaRv2Plugin::class.java)
|
||||||
|
PowerMockito.`when`(DanaRv2Plugin.getPlugin()).thenReturn(drv2)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue