ConfigBuilderTest
This commit is contained in:
parent
1c6c5f85f7
commit
364364f205
7 changed files with 82 additions and 36 deletions
|
@ -106,13 +106,13 @@ public class ConfigBuilderPlugin extends PluginBase implements TreatmentsInterfa
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
MainApp.bus().unregister(this);
|
||||
}
|
||||
|
|
|
@ -76,13 +76,13 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
MainApp.bus().unregister(this);
|
||||
}
|
||||
|
|
|
@ -61,12 +61,12 @@ public class OverviewPlugin extends PluginBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
protected void onStart() {
|
||||
MainApp.bus().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
protected void onStop() {
|
||||
MainApp.bus().unregister(this);
|
||||
}
|
||||
|
||||
|
|
|
@ -79,14 +79,14 @@ public class StatuslinePlugin extends PluginBase {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
MainApp.bus().register(this);
|
||||
sendStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
MainApp.bus().unregister(this);
|
||||
sendStatus();
|
||||
|
|
|
@ -76,6 +76,8 @@ public class AAPSMocker {
|
|||
when(MainApp.gs(R.string.absolute)).thenReturn("Absolute");
|
||||
when(MainApp.gs(R.string.waitingforpumpresult)).thenReturn("Waiting for result");
|
||||
when(MainApp.gs(R.string.insulin_unit_shortname)).thenReturn("U");
|
||||
when(MainApp.gs(R.string.minimalbasalvaluereplaced)).thenReturn("Basal value replaced by minimal supported value");
|
||||
when(MainApp.gs(R.string.basalprofilenotaligned)).thenReturn("Basal values not aligned to hours: %s");
|
||||
}
|
||||
|
||||
public static MainApp mockMainApp() {
|
||||
|
@ -125,4 +127,31 @@ public class AAPSMocker {
|
|||
} catch (JSONException ignored) {}
|
||||
return profile;
|
||||
}
|
||||
|
||||
private static MockedBus bus = new MockedBus();
|
||||
|
||||
public static void prepareMockedBus() {
|
||||
when(MainApp.bus()).thenReturn(bus);
|
||||
}
|
||||
|
||||
public static class MockedBus extends Bus {
|
||||
public boolean registered = false;
|
||||
public boolean notificationSent = false;
|
||||
|
||||
@Override
|
||||
public void register(Object event) {
|
||||
registered = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregister(Object event) {
|
||||
registered = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void post(Object event) {
|
||||
notificationSent = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import com.squareup.otto.Bus;
|
|||
import junit.framework.Assert;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
|
@ -16,6 +17,7 @@ import java.util.Calendar;
|
|||
import java.util.Locale;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
@ -44,12 +46,8 @@ public class ProfileTest {
|
|||
|
||||
//String profileStore = "{\"defaultProfile\":\"Default\",\"store\":{\"Default\":" + validProfile + "}}";
|
||||
|
||||
boolean notificationSent = false;
|
||||
|
||||
@Test
|
||||
public void doTests() throws Exception {
|
||||
prepareMock();
|
||||
|
||||
Profile p = new Profile();
|
||||
|
||||
// Test valid profile
|
||||
|
@ -105,7 +103,7 @@ public class ProfileTest {
|
|||
//Test basal profile below limit
|
||||
p = new Profile(new JSONObject(belowLimitValidProfile), 100, 0);
|
||||
p.isValid("Test");
|
||||
Assert.assertEquals(true, notificationSent);
|
||||
Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent);
|
||||
|
||||
// Test profile w/o units
|
||||
p = new Profile(new JSONObject(noUnitsValidProfile), 100, 0);
|
||||
|
@ -140,37 +138,24 @@ public class ProfileTest {
|
|||
|
||||
// Test hour alignment
|
||||
MainApp.getConfigBuilder().getActivePump().getPumpDescription().is30minBasalRatesCapable = false;
|
||||
notificationSent = false;
|
||||
((AAPSMocker.MockedBus) MainApp.bus()).notificationSent = false;
|
||||
p = new Profile(new JSONObject(notAllignedBasalValidProfile), 100, 0);
|
||||
p.isValid("Test");
|
||||
Assert.assertEquals(true, notificationSent);
|
||||
Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).notificationSent);
|
||||
}
|
||||
|
||||
private void prepareMock() throws Exception {
|
||||
Locale.setDefault(new Locale("en", "US"));
|
||||
ConfigBuilderPlugin configBuilderPlugin = mock(ConfigBuilderPlugin.class);
|
||||
PowerMockito.mockStatic(ConfigBuilderPlugin.class);
|
||||
@Before
|
||||
public void prepareMock() throws Exception {
|
||||
AAPSMocker.mockMainApp();
|
||||
AAPSMocker.mockConfigBuilder();
|
||||
AAPSMocker.mockStrings();
|
||||
AAPSMocker.prepareMockedBus();
|
||||
|
||||
MainApp mainApp = mock(MainApp.class);
|
||||
PowerMockito.mockStatic(MainApp.class);
|
||||
when(MainApp.instance()).thenReturn(mainApp);
|
||||
when(MainApp.getConfigBuilder()).thenReturn(configBuilderPlugin);
|
||||
when(MainApp.getConfigBuilder().getActivePump()).thenReturn(pump);
|
||||
when(MainApp.gs(R.string.minimalbasalvaluereplaced)).thenReturn("AnyString");
|
||||
when(MainApp.gs(R.string.basalprofilenotaligned)).thenReturn("AnyString");
|
||||
|
||||
PowerMockito.mockStatic(FabricPrivacy.class);
|
||||
// PowerMockito.doNothing().when(FabricPrivacy.log(""));
|
||||
|
||||
MockedBus bus = new MockedBus();
|
||||
when(MainApp.bus()).thenReturn(bus);
|
||||
}
|
||||
|
||||
class MockedBus extends Bus {
|
||||
@Override
|
||||
public void post(Object event) {
|
||||
notificationSent = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,13 +2,21 @@ package info.nightscout.androidaps.plugins.ConfigBuilder;
|
|||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.powermock.api.mockito.PowerMockito;
|
||||
import org.powermock.core.classloader.annotations.PrepareForTest;
|
||||
import org.powermock.modules.junit4.PowerMockRunner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import info.AAPSMocker;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
|
||||
import static org.powermock.api.mockito.PowerMockito.mock;
|
||||
|
||||
@RunWith(PowerMockRunner.class)
|
||||
@PrepareForTest({MainApp.class})
|
||||
public class ConfigBuilderPluginTest {
|
||||
|
||||
@Test
|
||||
|
@ -16,4 +24,28 @@ public class ConfigBuilderPluginTest {
|
|||
ConfigBuilderPlugin configBuilderPlugin = ConfigBuilderPlugin.getPlugin();
|
||||
Assert.assertNotNull(configBuilderPlugin);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStartTest() {
|
||||
ConfigBuilderPlugin configBuilderPlugin = ConfigBuilderPlugin.getPlugin();
|
||||
configBuilderPlugin.setPluginEnabled(PluginType.GENERAL, true);
|
||||
Assert.assertEquals(true, ((AAPSMocker.MockedBus) MainApp.bus()).registered);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onStopTest() {
|
||||
ConfigBuilderPlugin configBuilderPlugin = ConfigBuilderPlugin.getPlugin();
|
||||
configBuilderPlugin.setPluginEnabled(PluginType.GENERAL, true);
|
||||
configBuilderPlugin.setPluginEnabled(PluginType.GENERAL, false);
|
||||
Assert.assertEquals(false, ((AAPSMocker.MockedBus) MainApp.bus()).registered);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void prepareMock() throws Exception {
|
||||
MainApp mainApp = mock(MainApp.class);
|
||||
PowerMockito.mockStatic(MainApp.class);
|
||||
AAPSMocker.prepareMockedBus();
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in a new issue