diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/GlucoseStatus.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/GlucoseStatus.java index 94fab37d8b..191ce9e1cd 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/GlucoseStatus.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/GlucoseStatus.java @@ -59,7 +59,7 @@ public class GlucoseStatus { //long fromtime = DateUtil.now() - 60 * 1000L * 45; //List data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false); - synchronized (IobCobCalculatorPlugin.getPlugin().dataLock) { + synchronized (IobCobCalculatorPlugin.getPlugin().getDataLock()) { List data = IobCobCalculatorPlugin.getPlugin().getBgReadings(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java index 4897ff55ac..94b687b863 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobCalculatorPlugin.java @@ -65,7 +65,7 @@ public class IobCobCalculatorPlugin extends PluginBase { private volatile List bgReadings = null; // newest at index 0 private volatile List bucketed_data = null; - final Object dataLock = new Object(); + private final Object dataLock = new Object(); boolean stopCalculationTrigger = false; private Thread thread = null; @@ -108,6 +108,10 @@ public class IobCobCalculatorPlugin extends PluginBase { return bucketed_data; } + public Object getDataLock() { + return dataLock; + } + // roundup to whole minute public static long roundUpTime(long time) { if (time % 60000 == 0) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java index 492f3c0ff1..c483ffd2a6 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobOref1Thread.java @@ -96,7 +96,7 @@ public class IobCobOref1Thread extends Thread { long oldestTimeWithData = iobCobCalculatorPlugin.calculateDetectionStart(end, limitDataToOldestAvailable); - synchronized (iobCobCalculatorPlugin.dataLock) { + synchronized (iobCobCalculatorPlugin.getDataLock()) { if (bgDataReload) { iobCobCalculatorPlugin.loadBgData(end); iobCobCalculatorPlugin.createBucketedData(); diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java index 2aacb4f453..9ddf18abb0 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/iob/iobCobCalculator/IobCobThread.java @@ -95,7 +95,7 @@ public class IobCobThread extends Thread { long oldestTimeWithData = iobCobCalculatorPlugin.calculateDetectionStart(end, limitDataToOldestAvailable); - synchronized (iobCobCalculatorPlugin.dataLock) { + synchronized (iobCobCalculatorPlugin.getDataLock()) { if (bgDataReload) { iobCobCalculatorPlugin.loadBgData(end); iobCobCalculatorPlugin.createBucketedData(); diff --git a/app/src/test/java/info/AAPSMocker.java b/app/src/test/java/info/AAPSMocker.java index 850affa224..50bd20d198 100644 --- a/app/src/test/java/info/AAPSMocker.java +++ b/app/src/test/java/info/AAPSMocker.java @@ -282,10 +282,13 @@ public class AAPSMocker { PowerMockito.when(ProfileFunctions.getInstance().getProfileName()).thenReturn(TESTPROFILENAME); } - public static void mockIobCobCalculatorPlugin() { + public static IobCobCalculatorPlugin mockIobCobCalculatorPlugin() { PowerMockito.mockStatic(IobCobCalculatorPlugin.class); IobCobCalculatorPlugin iobCobCalculatorPlugin = PowerMockito.mock(IobCobCalculatorPlugin.class); PowerMockito.when(IobCobCalculatorPlugin.getPlugin()).thenReturn(iobCobCalculatorPlugin); + Object dataLock = new Object(); + PowerMockito.when(iobCobCalculatorPlugin.getDataLock()).thenReturn(dataLock); + return iobCobCalculatorPlugin; } private static MockedBus bus = new MockedBus(); diff --git a/app/src/test/java/info/nightscout/androidaps/data/GlucoseStatusTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/iob/iobCobCalculatorPlugin/GlucoseStatusTest.java similarity index 97% rename from app/src/test/java/info/nightscout/androidaps/data/GlucoseStatusTest.java rename to app/src/test/java/info/nightscout/androidaps/plugins/iob/iobCobCalculatorPlugin/GlucoseStatusTest.java index cdbd276bae..19e497b834 100644 --- a/app/src/test/java/info/nightscout/androidaps/data/GlucoseStatusTest.java +++ b/app/src/test/java/info/nightscout/androidaps/plugins/iob/iobCobCalculatorPlugin/GlucoseStatusTest.java @@ -1,4 +1,4 @@ -package info.nightscout.androidaps.data; +package info.nightscout.androidaps.plugins.iob.iobCobCalculatorPlugin; import org.json.JSONException; import org.json.JSONObject; @@ -134,10 +134,7 @@ public class GlucoseStatusTest { public void initMocking() { AAPSMocker.mockMainApp(); AAPSMocker.mockStrings(); - - PowerMockito.mockStatic(IobCobCalculatorPlugin.class); - iobCobCalculatorPlugin = mock(IobCobCalculatorPlugin.class); - when(IobCobCalculatorPlugin.getPlugin()).thenReturn(iobCobCalculatorPlugin); + iobCobCalculatorPlugin = AAPSMocker.mockIobCobCalculatorPlugin(); PowerMockito.mockStatic(DateUtil.class); when(DateUtil.now()).thenReturn(1514766900000L + T.mins(1).msecs());