fix NPE in Simulator

This commit is contained in:
Milos Kozak 2018-04-07 16:33:37 +02:00
parent ca01fcc270
commit 2fee7f3186
6 changed files with 15 additions and 2 deletions

View file

@ -17,6 +17,7 @@ import info.nightscout.androidaps.data.ConstraintChecker;
import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.DatabaseHelper; import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.queue.CommandQueue;
import info.nightscout.utils.SP; import info.nightscout.utils.SP;
import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyBoolean;
@ -122,11 +123,17 @@ public class AAPSMocker {
when(MainApp.getDbHelper()).thenReturn(databaseHelper); when(MainApp.getDbHelper()).thenReturn(databaseHelper);
} }
public static void mockCommandQueue() {
CommandQueue queue = mock(CommandQueue.class);
when(ConfigBuilderPlugin.getCommandQueue()).thenReturn(queue);
}
public static Profile getValidProfile() { public static Profile getValidProfile() {
try { try {
if (profile == null) if (profile == null)
profile = new Profile(new JSONObject(validProfile), Constants.MGDL); profile = new Profile(new JSONObject(validProfile), Constants.MGDL);
} catch (JSONException ignored) {} } catch (JSONException ignored) {
}
return profile; return profile;
} }

View file

@ -257,6 +257,7 @@ public class ConstraintsCheckerTest {
AAPSMocker.mockBus(); AAPSMocker.mockBus();
AAPSMocker.mockStrings(); AAPSMocker.mockStrings();
AAPSMocker.mockSP(); AAPSMocker.mockSP();
AAPSMocker.mockCommandQueue();
// RS constructor // RS constructor
when(SP.getString(R.string.key_danars_address, "")).thenReturn(""); when(SP.getString(R.string.key_danars_address, "")).thenReturn("");

View file

@ -15,12 +15,13 @@ import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType; import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus; import info.nightscout.androidaps.plugins.PumpCombo.ruffyscripter.history.Bolus;
import info.nightscout.androidaps.queue.CommandQueue;
import info.nightscout.utils.ToastUtils; import info.nightscout.utils.ToastUtils;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, ToastUtils.class, Context.class}) @PrepareForTest({MainApp.class, ConfigBuilderPlugin.class, ToastUtils.class, Context.class, CommandQueue.class})
public class ComboPluginTest { public class ComboPluginTest {
ComboPlugin comboPlugin; ComboPlugin comboPlugin;
@ -63,6 +64,7 @@ public class ComboPluginTest {
AAPSMocker.mockConfigBuilder(); AAPSMocker.mockConfigBuilder();
AAPSMocker.mockBus(); AAPSMocker.mockBus();
AAPSMocker.mockStrings(); AAPSMocker.mockStrings();
AAPSMocker.mockCommandQueue();
comboPlugin = ComboPlugin.getPlugin(); comboPlugin = ComboPlugin.getPlugin();
} }

View file

@ -66,6 +66,7 @@ public class DanaRPluginTest {
AAPSMocker.mockStrings(); AAPSMocker.mockStrings();
AAPSMocker.mockApplicationContext(); AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP(); AAPSMocker.mockSP();
AAPSMocker.mockCommandQueue();
when(SP.getString(R.string.key_danars_address, "")).thenReturn(""); when(SP.getString(R.string.key_danars_address, "")).thenReturn("");

View file

@ -66,6 +66,7 @@ public class DanaRSPluginTest {
AAPSMocker.mockStrings(); AAPSMocker.mockStrings();
AAPSMocker.mockApplicationContext(); AAPSMocker.mockApplicationContext();
AAPSMocker.mockSP(); AAPSMocker.mockSP();
AAPSMocker.mockCommandQueue();
when(SP.getString(R.string.key_danars_address, "")).thenReturn(""); when(SP.getString(R.string.key_danars_address, "")).thenReturn("");

View file

@ -49,6 +49,7 @@ public class InsightPluginTest {
AAPSMocker.mockConfigBuilder(); AAPSMocker.mockConfigBuilder();
AAPSMocker.mockBus(); AAPSMocker.mockBus();
AAPSMocker.mockStrings(); AAPSMocker.mockStrings();
AAPSMocker.mockCommandQueue();
insightPlugin = InsightPlugin.getPlugin(); insightPlugin = InsightPlugin.getPlugin();
} }