fix tests
This commit is contained in:
parent
952a6fe509
commit
a6bd81a1b9
6 changed files with 14 additions and 10 deletions
|
@ -59,7 +59,7 @@ public class GlucoseStatus {
|
||||||
//long fromtime = DateUtil.now() - 60 * 1000L * 45;
|
//long fromtime = DateUtil.now() - 60 * 1000L * 45;
|
||||||
//List<BgReading> data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false);
|
//List<BgReading> data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false);
|
||||||
|
|
||||||
synchronized (IobCobCalculatorPlugin.getPlugin().dataLock) {
|
synchronized (IobCobCalculatorPlugin.getPlugin().getDataLock()) {
|
||||||
|
|
||||||
List<BgReading> data = IobCobCalculatorPlugin.getPlugin().getBgReadings();
|
List<BgReading> data = IobCobCalculatorPlugin.getPlugin().getBgReadings();
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
private volatile List<BgReading> bgReadings = null; // newest at index 0
|
private volatile List<BgReading> bgReadings = null; // newest at index 0
|
||||||
private volatile List<BgReading> bucketed_data = null;
|
private volatile List<BgReading> bucketed_data = null;
|
||||||
|
|
||||||
final Object dataLock = new Object();
|
private final Object dataLock = new Object();
|
||||||
|
|
||||||
boolean stopCalculationTrigger = false;
|
boolean stopCalculationTrigger = false;
|
||||||
private Thread thread = null;
|
private Thread thread = null;
|
||||||
|
@ -108,6 +108,10 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
||||||
return bucketed_data;
|
return bucketed_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Object getDataLock() {
|
||||||
|
return dataLock;
|
||||||
|
}
|
||||||
|
|
||||||
// roundup to whole minute
|
// roundup to whole minute
|
||||||
public static long roundUpTime(long time) {
|
public static long roundUpTime(long time) {
|
||||||
if (time % 60000 == 0)
|
if (time % 60000 == 0)
|
||||||
|
|
|
@ -96,7 +96,7 @@ public class IobCobOref1Thread extends Thread {
|
||||||
|
|
||||||
long oldestTimeWithData = iobCobCalculatorPlugin.calculateDetectionStart(end, limitDataToOldestAvailable);
|
long oldestTimeWithData = iobCobCalculatorPlugin.calculateDetectionStart(end, limitDataToOldestAvailable);
|
||||||
|
|
||||||
synchronized (iobCobCalculatorPlugin.dataLock) {
|
synchronized (iobCobCalculatorPlugin.getDataLock()) {
|
||||||
if (bgDataReload) {
|
if (bgDataReload) {
|
||||||
iobCobCalculatorPlugin.loadBgData(end);
|
iobCobCalculatorPlugin.loadBgData(end);
|
||||||
iobCobCalculatorPlugin.createBucketedData();
|
iobCobCalculatorPlugin.createBucketedData();
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class IobCobThread extends Thread {
|
||||||
|
|
||||||
long oldestTimeWithData = iobCobCalculatorPlugin.calculateDetectionStart(end, limitDataToOldestAvailable);
|
long oldestTimeWithData = iobCobCalculatorPlugin.calculateDetectionStart(end, limitDataToOldestAvailable);
|
||||||
|
|
||||||
synchronized (iobCobCalculatorPlugin.dataLock) {
|
synchronized (iobCobCalculatorPlugin.getDataLock()) {
|
||||||
if (bgDataReload) {
|
if (bgDataReload) {
|
||||||
iobCobCalculatorPlugin.loadBgData(end);
|
iobCobCalculatorPlugin.loadBgData(end);
|
||||||
iobCobCalculatorPlugin.createBucketedData();
|
iobCobCalculatorPlugin.createBucketedData();
|
||||||
|
|
|
@ -282,10 +282,13 @@ public class AAPSMocker {
|
||||||
PowerMockito.when(ProfileFunctions.getInstance().getProfileName()).thenReturn(TESTPROFILENAME);
|
PowerMockito.when(ProfileFunctions.getInstance().getProfileName()).thenReturn(TESTPROFILENAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void mockIobCobCalculatorPlugin() {
|
public static IobCobCalculatorPlugin mockIobCobCalculatorPlugin() {
|
||||||
PowerMockito.mockStatic(IobCobCalculatorPlugin.class);
|
PowerMockito.mockStatic(IobCobCalculatorPlugin.class);
|
||||||
IobCobCalculatorPlugin iobCobCalculatorPlugin = PowerMockito.mock(IobCobCalculatorPlugin.class);
|
IobCobCalculatorPlugin iobCobCalculatorPlugin = PowerMockito.mock(IobCobCalculatorPlugin.class);
|
||||||
PowerMockito.when(IobCobCalculatorPlugin.getPlugin()).thenReturn(iobCobCalculatorPlugin);
|
PowerMockito.when(IobCobCalculatorPlugin.getPlugin()).thenReturn(iobCobCalculatorPlugin);
|
||||||
|
Object dataLock = new Object();
|
||||||
|
PowerMockito.when(iobCobCalculatorPlugin.getDataLock()).thenReturn(dataLock);
|
||||||
|
return iobCobCalculatorPlugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MockedBus bus = new MockedBus();
|
private static MockedBus bus = new MockedBus();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.data;
|
package info.nightscout.androidaps.plugins.iob.iobCobCalculatorPlugin;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -134,10 +134,7 @@ public class GlucoseStatusTest {
|
||||||
public void initMocking() {
|
public void initMocking() {
|
||||||
AAPSMocker.mockMainApp();
|
AAPSMocker.mockMainApp();
|
||||||
AAPSMocker.mockStrings();
|
AAPSMocker.mockStrings();
|
||||||
|
iobCobCalculatorPlugin = AAPSMocker.mockIobCobCalculatorPlugin();
|
||||||
PowerMockito.mockStatic(IobCobCalculatorPlugin.class);
|
|
||||||
iobCobCalculatorPlugin = mock(IobCobCalculatorPlugin.class);
|
|
||||||
when(IobCobCalculatorPlugin.getPlugin()).thenReturn(iobCobCalculatorPlugin);
|
|
||||||
|
|
||||||
PowerMockito.mockStatic(DateUtil.class);
|
PowerMockito.mockStatic(DateUtil.class);
|
||||||
when(DateUtil.now()).thenReturn(1514766900000L + T.mins(1).msecs());
|
when(DateUtil.now()).thenReturn(1514766900000L + T.mins(1).msecs());
|
Loading…
Reference in a new issue