MainAppTest
This commit is contained in:
parent
6e69b25d8a
commit
c57d14aa05
4 changed files with 121 additions and 24 deletions
|
@ -66,6 +66,7 @@ android {
|
|||
version "1.60c-dev"
|
||||
buildConfigField "String", "VERSION", '"' + version + '"'
|
||||
buildConfigField "String", "BUILDVERSION", generateGitBuild()
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
|
||||
ndk {
|
||||
moduleName "BleCommandUtil"
|
||||
|
@ -153,8 +154,9 @@ android {
|
|||
|
||||
testOptions {
|
||||
unitTests.returnDefaultValues = true
|
||||
unitTests.includeAndroidResources = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
|
@ -228,6 +230,7 @@ dependencies {
|
|||
testCompile "joda-time:joda-time:2.9.4.2"
|
||||
testCompile "com.google.truth:truth:0.39"
|
||||
testCompile "org.skyscreamer:jsonassert:1.5.0"
|
||||
testCompile 'org.robolectric:robolectric:3.8'
|
||||
|
||||
androidTestCompile "org.mockito:mockito-core:2.7.22"
|
||||
androidTestCompile "com.google.dexmaker:dexmaker:${dexmakerVersion}"
|
||||
|
|
|
@ -282,9 +282,6 @@ public class MainApp extends Application {
|
|||
}
|
||||
|
||||
public static DatabaseHelper getDbHelper() {
|
||||
if (sDatabaseHelper == null) {
|
||||
sDatabaseHelper = OpenHelperManager.getHelper(sInstance, DatabaseHelper.class);
|
||||
}
|
||||
return sDatabaseHelper;
|
||||
}
|
||||
|
||||
|
@ -321,21 +318,6 @@ public class MainApp extends Application {
|
|||
return newList;
|
||||
}
|
||||
|
||||
/*
|
||||
@Nullable
|
||||
public static InsulinInterface getInsulinIterfaceById(int id) {
|
||||
if (pluginsList != null) {
|
||||
for (PluginBase p : pluginsList) {
|
||||
if (p.getType() == PluginType.INSULIN && ((InsulinInterface) p).getId() == id)
|
||||
return (InsulinInterface) p;
|
||||
}
|
||||
} else {
|
||||
log.error("InsulinInterface not found");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
|
||||
public static ArrayList<PluginBase> getSpecificPluginsVisibleInList(PluginType type) {
|
||||
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||
|
||||
|
@ -399,7 +381,7 @@ public class MainApp extends Application {
|
|||
return engineeringMode || !devBranch;
|
||||
}
|
||||
|
||||
private String getLogDirectory() {
|
||||
public String getLogDirectory() {
|
||||
LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
|
||||
return lc.getProperty("EXT_FILES_DIR");
|
||||
}
|
||||
|
@ -407,6 +389,9 @@ public class MainApp extends Application {
|
|||
@Override
|
||||
public void onTerminate() {
|
||||
super.onTerminate();
|
||||
sDatabaseHelper.close();
|
||||
if (sDatabaseHelper != null) {
|
||||
sDatabaseHelper.close();
|
||||
sDatabaseHelper = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
111
app/src/test/java/info/nightscout/MainAppTest.java
Normal file
111
app/src/test/java/info/nightscout/MainAppTest.java
Normal file
|
@ -0,0 +1,111 @@
|
|||
package info.nightscout;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.Overview.OverviewPlugin;
|
||||
|
||||
|
||||
/**
|
||||
* Created by mike on 28.03.2018.
|
||||
*/
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MainAppTest {
|
||||
MainApp mainApp = new MainApp();
|
||||
|
||||
@Test
|
||||
public void busTest() {
|
||||
Assert.assertNotNull(mainApp.bus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gsTest() {
|
||||
Assert.assertEquals("AndroidAPS", mainApp.gs(R.string.app_name));
|
||||
Assert.assertEquals("AndroidAPS", mainApp.gs(R.string.app_name, ""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gcTest() {
|
||||
Assert.assertEquals(-16711681, mainApp.gc(R.color.basal));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instanceTest() {
|
||||
Assert.assertNotNull(mainApp.instance());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDbHelperTest() {
|
||||
Assert.assertNotNull(mainApp.getDbHelper());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void closeDbHelperTest() {
|
||||
mainApp.closeDbHelper();
|
||||
Assert.assertNull(mainApp.getDbHelper());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getConfigBuilderTest() {
|
||||
Assert.assertNotNull(mainApp.getConfigBuilder());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getConstraintCheckerTest() {
|
||||
Assert.assertNotNull(mainApp.getConstraintChecker());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getPluginsListTest() {
|
||||
Assert.assertNotNull(mainApp.getPluginsList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSpecificPluginsListTest() {
|
||||
// currently MDI, VP, R, Rv2, KoreanR, RS
|
||||
Assert.assertEquals(6, mainApp.getSpecificPluginsList(PluginType.PUMP).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSpecificPluginsVisibleInListTest() {
|
||||
// currently MDI, VP, R, Rv2, KoreanR, RS
|
||||
Assert.assertEquals(6, mainApp.getSpecificPluginsVisibleInList(PluginType.PUMP).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSpecificPluginsListByInterfaceTest() {
|
||||
// currently MDI, VP, R, Rv2, KoreanR, RS
|
||||
Assert.assertEquals(6, mainApp.getSpecificPluginsListByInterface(PumpInterface.class).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSpecificPluginsVisibleInListByInterfaceTest() {
|
||||
// currently MDI, VP, R, Rv2, KoreanR, RS
|
||||
Assert.assertEquals(6, mainApp.getSpecificPluginsVisibleInListByInterface(PumpInterface.class, PluginType.PUMP).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSpecificPluginTest() {
|
||||
// currently MDI, VP, R, Rv2, KoreanR, RS
|
||||
Assert.assertEquals("Overview", mainApp.getSpecificPlugin(OverviewPlugin.class).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEngineeringModeOrReleaseTest() {
|
||||
Assert.assertEquals(false, mainApp.isEngineeringModeOrRelease());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLogDirectoryTest() {
|
||||
// logger not initialized in Roboelectric
|
||||
Assert.assertNull(mainApp.getLogDirectory());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.PumpDanaR;
|
||||
package info.nightscout.androidaps.plugins.PumpDanaR;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
|
@ -17,8 +17,6 @@ import info.nightscout.androidaps.R;
|
|||
import info.nightscout.androidaps.interfaces.Constraint;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPlugin;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||
import info.nightscout.utils.SP;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
Loading…
Reference in a new issue