This commit is contained in:
Johannes Mockenhaupt 2018-06-23 00:50:53 +02:00
parent 53b9d5cae3
commit 940d58fc79
No known key found for this signature in database
GPG key ID: 9E1EA6AF7BBBB0D1
7 changed files with 59 additions and 47 deletions

View file

@ -111,16 +111,6 @@ public class ConstraintsCheckerTest {
Assert.assertEquals(Boolean.FALSE, c.value()); Assert.assertEquals(Boolean.FALSE, c.value());
} }
// @Test
// public void isAdvancedFilteringEnabledTest() throws Exception {
// when(MainApp.getConfigBuilder().getActiveBgSource()).thenReturn(SourceGlimpPlugin.getPlugin());
//
// Constraint<Boolean> c = constraintChecker.isAdvancedFilteringEnabled();
// Assert.assertEquals(true, c.getReasonList().size() == 1); // Safety
// Assert.assertEquals(true, c.getMostLimitedReasonList().size() == 1); // Safety
// Assert.assertEquals(Boolean.FALSE, c.value());
// }
@Test @Test
public void isSMBModeEnabledTest() throws Exception { public void isSMBModeEnabledTest() throws Exception {
objectivesPlugin.objectives.get(7).setStartedOn(null); objectivesPlugin.objectives.get(7).setStartedOn(null);

View file

@ -89,17 +89,6 @@ public class SafetyPluginTest {
Assert.assertEquals(Boolean.FALSE, c.value()); Assert.assertEquals(Boolean.FALSE, c.value());
} }
// TODO
// @Test
// public void bgsourceShouldPreventSMBAlways() throws Exception {
// when(MainApp.getConfigBuilder().getActiveBgSource()).thenReturn(SourceGlimpPlugin.getPlugin());
//
// Constraint<Boolean> c = new Constraint<>(true);
// c = safetyPlugin.isAdvancedFilteringEnabled(c);
// Assert.assertEquals("Safety: SMB always and after carbs disabled because active BG source doesn\\'t support advanced filtering", c.getReasons());
// Assert.assertEquals(Boolean.FALSE, c.value());
// }
@Test @Test
public void basalRateShouldBeLimited() throws Exception { public void basalRateShouldBeLimited() throws Exception {
when(SP.getDouble(R.string.key_openapsma_max_basal, 1d)).thenReturn(1d); when(SP.getDouble(R.string.key_openapsma_max_basal, 1d)).thenReturn(1d);

View file

@ -14,9 +14,4 @@ public class SourceDexcomG5PluginTest {
public void getPlugin() { public void getPlugin() {
Assert.assertNotEquals(null, SourceDexcomG5Plugin.getPlugin()); Assert.assertNotEquals(null, SourceDexcomG5Plugin.getPlugin());
} }
// @Test
// public void advancedFilteringSupported() {
// Assert.assertEquals(true, SourceDexcomG5Plugin.getPlugin().advancedFilteringSupported());
// }
} }

View file

@ -14,9 +14,4 @@ public class SourceGlimpPluginTest {
public void getPlugin() { public void getPlugin() {
Assert.assertNotEquals(null, SourceGlimpPlugin.getPlugin()); Assert.assertNotEquals(null, SourceGlimpPlugin.getPlugin());
} }
// @Test
// public void advancedFilteringSupported() {
// Assert.assertEquals(false, SourceGlimpPlugin.getPlugin().advancedFilteringSupported());
// }
} }

View file

@ -14,9 +14,4 @@ public class SourceMM640gPluginTest {
public void getPlugin() { public void getPlugin() {
Assert.assertNotEquals(null, SourceMM640gPlugin.getPlugin()); Assert.assertNotEquals(null, SourceMM640gPlugin.getPlugin());
} }
// @Test
// public void advancedFilteringSupported() {
// Assert.assertEquals(false, SourceMM640gPlugin.getPlugin().advancedFilteringSupported());
// }
} }

View file

@ -12,9 +12,4 @@ public class SourceNSClientPluginTest {
public void getPlugin() { public void getPlugin() {
Assert.assertNotEquals(null, SourceNSClientPlugin.getPlugin()); Assert.assertNotEquals(null, SourceNSClientPlugin.getPlugin());
} }
// @Test
// public void advancedFilteringSupported() {
// Assert.assertEquals(false, SourceNSClientPlugin.getPlugin().advancedFilteringSupported());
// }
} }

View file

@ -1,22 +1,75 @@
package info.nightscout.androidaps.plugins.Source; package info.nightscout.androidaps.plugins.Source;
import android.os.Bundle;
import android.support.annotation.NonNull;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; 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 org.powermock.modules.junit4.PowerMockRunner;
import info.nightscout.androidaps.plugins.Source.SourceXdripPlugin; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.DatabaseHelper;
import static junit.framework.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
@PrepareForTest({MainApp.class, DatabaseHelper.class})
public class SourceXdripPluginTest { public class SourceXdripPluginTest {
private SourceXdripPlugin plugin = SourceXdripPlugin.getPlugin();
@Before
public void prepareTest() {
PowerMockito.mockStatic(MainApp.class);
when(MainApp.gs(0)).thenReturn("");
DatabaseHelper databaseHelper = mock(DatabaseHelper.class);
when(MainApp.getDbHelper()).thenReturn(databaseHelper);
when(databaseHelper.createIfNotExists(any(), any())).thenReturn(true);
}
@Test @Test
public void getPlugin() { public void pluginInitializes() {
Assert.assertNotEquals(null, SourceXdripPlugin.getPlugin()); Assert.assertNotEquals(null, SourceXdripPlugin.getPlugin());
} }
// @Test // TODO
// public void advancedFilteringSupported() { @Ignore("Bundle needs to be properly mocked")
// Assert.assertEquals(false, SourceXdripPlugin.getPlugin().advancedFilteringSupported()); @Test
// } public void bgWithUnknownSourceIsMarkedUnfiltered() {
Bundle bundle = createBroadcastBundle();
BgReading bgReadings = plugin.processNewData(bundle).get(0);
assertFalse(bgReadings.filtered);
}
// TODO
@Ignore("Bundle needs to be properly mocked")
@Test
public void bgWithSourceG5NativeIsMarkedFiltered() {
Bundle bundle = createBroadcastBundle();
bundle.putString(Intents.XDRIP_DATA_SOURCE_DESCRIPTION, "G5 Native");
BgReading bgReadings = plugin.processNewData(bundle).get(0);
assertTrue(bgReadings.filtered);
}
@NonNull
private Bundle createBroadcastBundle() {
Bundle bundle = new Bundle();
bundle.putDouble(Intents.EXTRA_BG_ESTIMATE, 100.0);
bundle.putString(Intents.EXTRA_BG_SLOPE_NAME, "DoubleDown");
bundle.putLong(Intents.EXTRA_TIMESTAMP, 0L);
bundle.putDouble(Intents.EXTRA_RAW, 430.0);
return bundle;
}
} }