Fix Omnipod tests and remove one unused and one inappropriate dependency from AapsPodStateManager
This commit is contained in:
parent
90e429abb9
commit
127a369cbb
6 changed files with 33 additions and 40 deletions
|
@ -3,6 +3,10 @@ apply plugin: 'kotlin-android'
|
|||
apply plugin: 'kotlin-android-extensions'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
ext {
|
||||
powermockVersion = "1.7.3"
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion 28
|
||||
|
||||
|
@ -97,8 +101,10 @@ dependencies {
|
|||
kapt "com.google.dagger:dagger-compiler:$dagger_version"
|
||||
|
||||
testImplementation 'junit:junit:4.13'
|
||||
testImplementation "org.mockito:mockito-core:2.8.47"
|
||||
testImplementation "org.powermock:powermock-api-mockito2:$powermockVersion"
|
||||
testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}"
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ import info.nightscout.androidaps.plugins.pump.omnipod.events.EventOmnipodRefres
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodUtil
|
||||
import info.nightscout.androidaps.queue.Callback
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.WarnColors
|
||||
|
@ -64,6 +65,7 @@ class OmnipodFragment : DaggerFragment() {
|
|||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var omnipodUtil: OmnipodUtil
|
||||
@Inject lateinit var rileyLinkServiceData: RileyLinkServiceData
|
||||
@Inject lateinit var dateUtil: DateUtil
|
||||
|
||||
// TODO somehow obtain the pumpUnreachableThreshold in order to display last connection time red or white
|
||||
// @Inject lateinit var localAlertUtils: LocalAlertUtils
|
||||
|
@ -261,7 +263,8 @@ class OmnipodFragment : DaggerFragment() {
|
|||
omnipod_pod_lot.text = podStateManager.lot.toString()
|
||||
omnipod_pod_tid.text = podStateManager.tid.toString()
|
||||
omnipod_pod_firmware_version.text = resourceHelper.gs(R.string.omnipod_pod_firmware_version_value, podStateManager.pmVersion.toString(), podStateManager.piVersion.toString())
|
||||
omnipod_pod_expiry.text = podStateManager.expiryDateAsString
|
||||
val expiresAt = podStateManager.expiresAt
|
||||
omnipod_pod_expiry.text = if (expiresAt == null) "???" else dateUtil.dateAndTimeString(expiresAt.toDate())
|
||||
|
||||
val stateText: String
|
||||
when {
|
||||
|
|
|
@ -30,18 +30,15 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedule;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmniCRC;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.util.OmnipodConst;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
|
||||
public abstract class PodStateManager {
|
||||
|
||||
private final AAPSLogger aapsLogger;
|
||||
private DateUtil dateUtil;
|
||||
private final Gson gsonInstance;
|
||||
private PodState podState;
|
||||
|
||||
public PodStateManager(AAPSLogger aapsLogger, DateUtil dateUtil) {
|
||||
public PodStateManager(AAPSLogger aapsLogger) {
|
||||
this.aapsLogger = aapsLogger;
|
||||
this.dateUtil = dateUtil;
|
||||
this.gsonInstance = createGson();
|
||||
}
|
||||
|
||||
|
@ -286,12 +283,6 @@ public abstract class PodStateManager {
|
|||
return expiresAt == null ? null : expiresAt.withZone(getSafe(() -> podState.getTimeZone()));
|
||||
}
|
||||
|
||||
// TODO doesn't belong here
|
||||
public final String getExpiryDateAsString() {
|
||||
DateTime expiresAt = getExpiresAt();
|
||||
return expiresAt == null ? "???" : dateUtil.dateAndTimeString(expiresAt.toDate());
|
||||
}
|
||||
|
||||
public final PodProgressStatus getPodProgressStatus() {
|
||||
return getSafe(() -> podState.getPodProgressStatus());
|
||||
}
|
||||
|
|
|
@ -25,12 +25,11 @@ public class AapsPodStateManager extends PodStateManager {
|
|||
private final SP sp;
|
||||
private final OmnipodPumpStatus omnipodPumpStatus;
|
||||
private final RxBusWrapper rxBus;
|
||||
private final ResourceHelper resourceHelper;
|
||||
|
||||
@Inject
|
||||
public AapsPodStateManager(AAPSLogger aapsLogger, SP sp, OmnipodPumpStatus omnipodPumpStatus,
|
||||
RxBusWrapper rxBus, ResourceHelper resourceHelper, DateUtil dateUtil) {
|
||||
super(aapsLogger, dateUtil);
|
||||
RxBusWrapper rxBus) {
|
||||
super(aapsLogger);
|
||||
|
||||
if (aapsLogger == null) {
|
||||
throw new IllegalArgumentException("aapsLogger can not be null");
|
||||
|
@ -44,15 +43,11 @@ public class AapsPodStateManager extends PodStateManager {
|
|||
if (rxBus == null) {
|
||||
throw new IllegalArgumentException("rxBus can not be null");
|
||||
}
|
||||
if (resourceHelper == null) {
|
||||
throw new IllegalArgumentException("resourceHelper can not be null");
|
||||
}
|
||||
|
||||
this.aapsLogger = aapsLogger;
|
||||
this.sp = sp;
|
||||
this.omnipodPumpStatus = omnipodPumpStatus;
|
||||
this.rxBus = rxBus;
|
||||
this.resourceHelper = resourceHelper;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.FirmwareVersion;
|
|||
import info.nightscout.androidaps.plugins.pump.omnipod.defs.PodProgressStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.OmnipodPumpStatus;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.driver.comm.AapsPodStateManager;
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -27,7 +26,6 @@ public class AapsPodStateManagerTest {
|
|||
@Mock SP sp;
|
||||
@Mock OmnipodPumpStatus omnipodPumpStatus;
|
||||
RxBusWrapper rxBus = new RxBusWrapper();
|
||||
@Mock ResourceHelper resourceHelper;
|
||||
|
||||
@Test
|
||||
public void times() {
|
||||
|
@ -38,7 +36,7 @@ public class AapsPodStateManagerTest {
|
|||
|
||||
DateTimeUtils.setCurrentMillisFixed(now.getMillis());
|
||||
|
||||
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus, resourceHelper);
|
||||
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus);
|
||||
podStateManager.initState(0x0);
|
||||
podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1),
|
||||
new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS);
|
||||
|
@ -56,7 +54,7 @@ public class AapsPodStateManagerTest {
|
|||
|
||||
DateTimeUtils.setCurrentMillisFixed(now.getMillis());
|
||||
|
||||
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus, resourceHelper);
|
||||
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus);
|
||||
podStateManager.initState(0x0);
|
||||
podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1),
|
||||
new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS);
|
||||
|
@ -79,7 +77,7 @@ public class AapsPodStateManagerTest {
|
|||
|
||||
DateTimeUtils.setCurrentMillisFixed(now.getMillis());
|
||||
|
||||
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus, resourceHelper);
|
||||
AapsPodStateManager podStateManager = new AapsPodStateManager(aapsLogger, sp, omnipodPumpStatus, rxBus);
|
||||
podStateManager.initState(0x0);
|
||||
podStateManager.setInitializationParameters(0, 0, new FirmwareVersion(1, 1, 1),
|
||||
new FirmwareVersion(2, 2, 2), timeZone, PodProgressStatus.ABOVE_FIFTY_UNITS);
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.joda.time.Duration;
|
|||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -13,7 +14,6 @@ import info.nightscout.androidaps.plugins.pump.omnipod.defs.schedule.BasalSchedu
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.powermock.api.mockito.PowerMockito.when;
|
||||
|
||||
public class AapsOmnipodManagerTest {
|
||||
@Rule
|
||||
|
@ -21,17 +21,17 @@ public class AapsOmnipodManagerTest {
|
|||
|
||||
@Test
|
||||
public void validProfile() {
|
||||
Profile profile = Mockito.mock(Profile.class);
|
||||
Profile profile = mock(Profile.class);
|
||||
|
||||
Profile.ProfileValue value1 = Mockito.mock(Profile.ProfileValue.class);
|
||||
Profile.ProfileValue value1 = mock(Profile.ProfileValue.class);
|
||||
value1.timeAsSeconds = 0;
|
||||
value1.value = 0.5D;
|
||||
|
||||
Profile.ProfileValue value2 = Mockito.mock(Profile.ProfileValue.class);
|
||||
Profile.ProfileValue value2 = mock(Profile.ProfileValue.class);
|
||||
value2.timeAsSeconds = 18000;
|
||||
value2.value = 1.0D;
|
||||
|
||||
Profile.ProfileValue value3 = Mockito.mock(Profile.ProfileValue.class);
|
||||
Profile.ProfileValue value3 = mock(Profile.ProfileValue.class);
|
||||
value3.timeAsSeconds = 50400;
|
||||
value3.value = 3.05D;
|
||||
|
||||
|
@ -70,14 +70,14 @@ public class AapsOmnipodManagerTest {
|
|||
public void invalidProfileNullEntries() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Basal values can not be null");
|
||||
AapsOmnipodManager.mapProfileToBasalSchedule(Mockito.mock(Profile.class));
|
||||
AapsOmnipodManager.mapProfileToBasalSchedule(mock(Profile.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidProfileZeroEntries() {
|
||||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Entries can not be empty");
|
||||
Profile profile = Mockito.mock(Profile.class);
|
||||
Profile profile = mock(Profile.class);
|
||||
|
||||
PowerMockito.when(profile.getBasalValues()).thenReturn(new Profile.ProfileValue[0]);
|
||||
|
||||
|
@ -89,9 +89,9 @@ public class AapsOmnipodManagerTest {
|
|||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("First basal schedule entry should have 0 offset");
|
||||
|
||||
Profile profile = Mockito.mock(Profile.class);
|
||||
Profile profile = mock(Profile.class);
|
||||
|
||||
Profile.ProfileValue value = Mockito.mock(Profile.ProfileValue.class);
|
||||
Profile.ProfileValue value = mock(Profile.ProfileValue.class);
|
||||
value.timeAsSeconds = 1800;
|
||||
value.value = 0.5D;
|
||||
|
||||
|
@ -107,13 +107,13 @@ public class AapsOmnipodManagerTest {
|
|||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Invalid start time");
|
||||
|
||||
Profile profile = Mockito.mock(Profile.class);
|
||||
Profile profile = mock(Profile.class);
|
||||
|
||||
Profile.ProfileValue value1 = Mockito.mock(Profile.ProfileValue.class);
|
||||
Profile.ProfileValue value1 = mock(Profile.ProfileValue.class);
|
||||
value1.timeAsSeconds = 0;
|
||||
value1.value = 0.5D;
|
||||
|
||||
Profile.ProfileValue value2 = Mockito.mock(Profile.ProfileValue.class);
|
||||
Profile.ProfileValue value2 = mock(Profile.ProfileValue.class);
|
||||
value2.timeAsSeconds = 86400;
|
||||
value2.value = 0.5D;
|
||||
|
||||
|
@ -130,9 +130,9 @@ public class AapsOmnipodManagerTest {
|
|||
thrown.expect(IllegalArgumentException.class);
|
||||
thrown.expectMessage("Invalid start time");
|
||||
|
||||
Profile profile = Mockito.mock(Profile.class);
|
||||
Profile profile = mock(Profile.class);
|
||||
|
||||
Profile.ProfileValue value = Mockito.mock(Profile.ProfileValue.class);
|
||||
Profile.ProfileValue value = mock(Profile.ProfileValue.class);
|
||||
value.timeAsSeconds = -1;
|
||||
value.value = 0.5D;
|
||||
|
||||
|
@ -145,9 +145,9 @@ public class AapsOmnipodManagerTest {
|
|||
|
||||
@Test
|
||||
public void roundsToSupportedPrecision() {
|
||||
Profile profile = Mockito.mock(Profile.class);
|
||||
Profile profile = mock(Profile.class);
|
||||
|
||||
Profile.ProfileValue value = Mockito.mock(Profile.ProfileValue.class);
|
||||
Profile.ProfileValue value = mock(Profile.ProfileValue.class);
|
||||
value.timeAsSeconds = 0;
|
||||
value.value = 0.04D;
|
||||
|
||||
|
|
Loading…
Reference in a new issue