fix tests

This commit is contained in:
Milos Kozak 2019-04-16 21:28:21 +02:00
parent 952a6fe509
commit a6bd81a1b9
6 changed files with 14 additions and 10 deletions

View file

@ -59,7 +59,7 @@ public class GlucoseStatus {
//long fromtime = DateUtil.now() - 60 * 1000L * 45;
//List<BgReading> data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false);
synchronized (IobCobCalculatorPlugin.getPlugin().dataLock) {
synchronized (IobCobCalculatorPlugin.getPlugin().getDataLock()) {
List<BgReading> data = IobCobCalculatorPlugin.getPlugin().getBgReadings();

View file

@ -65,7 +65,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
private volatile List<BgReading> bgReadings = null; // newest at index 0
private volatile List<BgReading> 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)

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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());