mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-04 23:28:19 -05:00
Migrate tests from androidTest to app-test!
This commit is contained in:
parent
f331f95722
commit
e9e6d1dacd
@ -3,6 +3,8 @@ apply plugin: 'kotlin'
|
||||
apply plugin: 'jacoco'
|
||||
apply plugin: 'com.github.kt3k.coveralls'
|
||||
|
||||
evaluationDependsOn(":app")
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenCentral()
|
||||
@ -20,12 +22,14 @@ def firstVariant = androidModule.android.applicationVariants.toList().first()
|
||||
dependencies {
|
||||
compile androidModule
|
||||
|
||||
testCompile 'junit:junit:4.+'
|
||||
testCompile 'org.robolectric:robolectric:+'
|
||||
testCompile 'org.mockito:mockito-all:+'
|
||||
testCompile 'com.jayway.awaitility:awaitility:+'
|
||||
|
||||
testCompile firstVariant.javaCompile.classpath
|
||||
testCompile firstVariant.javaCompile.outputs.files
|
||||
testCompile files(androidModule.plugins.findPlugin("com.android.application").getBootClasspath())
|
||||
|
||||
testCompile 'junit:junit:4.+'
|
||||
testCompile 'org.robolectric:robolectric:+'
|
||||
}
|
||||
|
||||
jacocoTestReport {
|
||||
@ -60,3 +64,8 @@ jacocoTestReport {
|
||||
coveralls {
|
||||
sourceDirs = files(androidModule.android.sourceSets.main.java.srcDirs).files.absolutePath
|
||||
}
|
||||
|
||||
tasks.withType(Test) {
|
||||
scanForTestClasses = false
|
||||
include "**/*Test.class"
|
||||
}
|
@ -5,7 +5,6 @@ import android.net.NetworkInfo;
|
||||
import android.util.Log;
|
||||
|
||||
import org.bspeice.minimalbible.Injector;
|
||||
import org.bspeice.minimalbible.MBTestCase;
|
||||
import org.bspeice.minimalbible.activity.downloader.DownloadPrefs;
|
||||
import org.bspeice.minimalbible.activity.downloader.manager.BookManager;
|
||||
import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent;
|
||||
@ -20,6 +19,9 @@ import org.crosswire.jsword.book.Books;
|
||||
import org.crosswire.jsword.book.BooksEvent;
|
||||
import org.crosswire.jsword.book.install.InstallManager;
|
||||
import org.crosswire.jsword.book.install.Installer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Collection;
|
||||
@ -37,12 +39,15 @@ import rx.functions.Action1;
|
||||
import rx.functions.Func1;
|
||||
|
||||
import static com.jayway.awaitility.Awaitility.await;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.internal.verification.VerificationModeFactory.times;
|
||||
|
||||
public class BookManagerTest extends MBTestCase implements Injector {
|
||||
// TODO: Fix @Ignore'd tests
|
||||
public class BookManagerTest implements Injector {
|
||||
|
||||
ObjectGraph mObjectGraph;
|
||||
@Inject
|
||||
@ -57,6 +62,7 @@ public class BookManagerTest extends MBTestCase implements Injector {
|
||||
mObjectGraph.inject(o);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
BookDownloadManagerTestModules modules = new BookDownloadManagerTestModules(this);
|
||||
mObjectGraph = ObjectGraph.create(modules);
|
||||
@ -73,6 +79,7 @@ public class BookManagerTest extends MBTestCase implements Injector {
|
||||
});
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void testInstallBook() throws Exception {
|
||||
final Book toInstall = installableBooks().toBlocking().first();
|
||||
|
||||
@ -94,6 +101,7 @@ public class BookManagerTest extends MBTestCase implements Injector {
|
||||
.untilTrue(signal);
|
||||
}
|
||||
|
||||
@Ignore
|
||||
public void testJobIdMatch() {
|
||||
final Book toInstall = installableBooks().toBlocking().first();
|
||||
final String jobName = bookManager.getJobId(toInstall);
|
||||
@ -114,10 +122,11 @@ public class BookManagerTest extends MBTestCase implements Injector {
|
||||
});
|
||||
|
||||
bookManager.installBook(toInstall);
|
||||
await().atMost(1, TimeUnit.SECONDS)
|
||||
await().atMost(5, TimeUnit.SECONDS)
|
||||
.untilTrue(jobNameMatch);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalListUpdatedAfterAdd() {
|
||||
Book mockBook = mock(Book.class);
|
||||
BooksEvent event = mock(BooksEvent.class);
|
||||
@ -131,6 +140,7 @@ public class BookManagerTest extends MBTestCase implements Injector {
|
||||
* This test requires deep knowledge of how to remove a book in order to test,
|
||||
* but the Kotlin interface is nice!
|
||||
*/
|
||||
@Test
|
||||
public void testLocalListUpdatedAfterRemove() throws BookException {
|
||||
BookDriver driver = mock(BookDriver.class);
|
||||
|
@ -1,18 +1,21 @@
|
||||
package org.bspeice.minimalbible.test.activity.downloader.manager;
|
||||
|
||||
import org.bspeice.minimalbible.MBTestCase;
|
||||
import org.bspeice.minimalbible.activity.downloader.manager.LocaleManager;
|
||||
import org.crosswire.common.util.Language;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import rx.Observable;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Test cases for the Locale Manager
|
||||
*/
|
||||
public class LocaleManagerTest extends MBTestCase {
|
||||
public class LocaleManagerTest {
|
||||
|
||||
@Test
|
||||
public void testSortedLanguagesList() {
|
||||
Language english = new Language("en");
|
||||
Language russian = new Language("ru");
|
@ -4,11 +4,12 @@ import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
import org.bspeice.minimalbible.Injector;
|
||||
import org.bspeice.minimalbible.MBTestCase;
|
||||
import org.bspeice.minimalbible.activity.downloader.DownloadPrefs;
|
||||
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
||||
import org.crosswire.jsword.book.Book;
|
||||
import org.crosswire.jsword.book.install.Installer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
@ -29,11 +30,15 @@ import dagger.Provides;
|
||||
import rx.functions.Action1;
|
||||
|
||||
import static com.jayway.awaitility.Awaitility.await;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class RefreshManagerTest extends MBTestCase implements Injector {
|
||||
public class RefreshManagerTest implements Injector {
|
||||
|
||||
final String mockBookName = "MockBook";
|
||||
/**
|
||||
@ -46,6 +51,7 @@ public class RefreshManagerTest extends MBTestCase implements Injector {
|
||||
Installer mockInstaller;
|
||||
Book mockBook;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
// Environment setup
|
||||
mockBook = mock(Book.class);
|
||||
@ -71,6 +77,7 @@ public class RefreshManagerTest extends MBTestCase implements Injector {
|
||||
mObjectGraph.inject(o);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetAvailableModulesFlattened() throws Exception {
|
||||
rM.getFlatModules()
|
||||
.toBlocking()
|
||||
@ -85,6 +92,7 @@ public class RefreshManagerTest extends MBTestCase implements Injector {
|
||||
verify(mockBook).getName();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInstallerFromBook() throws Exception {
|
||||
Installer i = rM.installerFromBook(mockBook).toBlocking().first();
|
||||
|
||||
@ -92,6 +100,7 @@ public class RefreshManagerTest extends MBTestCase implements Injector {
|
||||
verify(mockInstaller).getBooks();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefreshSeparateThread() {
|
||||
mockInstaller = mock(Installer.class);
|
||||
final List<Book> bookList = new ArrayList<Book>();
|
||||
@ -130,6 +139,7 @@ public class RefreshManagerTest extends MBTestCase implements Injector {
|
||||
* I'd like to point out that I can test all of this without requiring mocking of
|
||||
* either the preferences or network state. Value Boundaries for the win.
|
||||
*/
|
||||
@Test
|
||||
public void testDoUpdate() {
|
||||
long fourteenDaysAgo = Calendar.getInstance().getTime().getTime() - 1209600;
|
||||
long sixteenDaysAgo = Calendar.getInstance().getTime().getTime() - 1382400;
|
@ -2,26 +2,33 @@ package org.bspeice.minimalbible.test.format.osisparser;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
||||
import org.bspeice.minimalbible.MBTestCase;
|
||||
import org.bspeice.minimalbible.service.format.osisparser.OsisParser;
|
||||
import org.crosswire.jsword.book.OSISUtil;
|
||||
import org.crosswire.jsword.passage.Verse;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.xml.sax.Attributes;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* State machine testing, oh boy!
|
||||
*/
|
||||
public class OsisParserTest extends MBTestCase {
|
||||
public class OsisParserTest {
|
||||
|
||||
OsisParser parser;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
parser = new OsisParser();
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Test
|
||||
public void testDoWriteEnabledVerse() {
|
||||
Attributes attributes = mock(Attributes.class);
|
||||
parser.startElement("", OSISUtil.OSIS_ELEMENT_VERSE, "", attributes);
|
||||
@ -36,6 +43,7 @@ public class OsisParserTest extends MBTestCase {
|
||||
parser.getDoWrite().pop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoWriteAlwaysAdded() {
|
||||
parserAssert(parser, OSISUtil.OSIS_ELEMENT_VERSE);
|
||||
parserAssert(parser, "");
|
||||
@ -44,6 +52,7 @@ public class OsisParserTest extends MBTestCase {
|
||||
}
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
@Test
|
||||
public void testEndElementPopsQueue() {
|
||||
parser.getDoWrite().add(true);
|
||||
parser.endElement("", "", "");
|
||||
@ -54,8 +63,10 @@ public class OsisParserTest extends MBTestCase {
|
||||
// as a value computed every time - so you'd get a new "content" every time
|
||||
// you tried to update it. Thus, if you updated the content only once, you're fine.
|
||||
// Try and update multiple times, and things would start going crazy.
|
||||
// TODO: Why is this ignored?
|
||||
@SuppressLint("NewApi")
|
||||
@SuppressWarnings("unused")
|
||||
@Ignore
|
||||
public void ignoreTestVerseContentConsistent() {
|
||||
String string1 = "1";
|
||||
String string2 = "2";
|
@ -76,8 +76,6 @@ dependencies {
|
||||
|
||||
androidTestCompile 'com.jayway.awaitility:awaitility:+'
|
||||
androidTestCompile 'org.mockito:mockito-core:+'
|
||||
androidTestCompile 'com.google.dexmaker:dexmaker:+'
|
||||
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:+'
|
||||
|
||||
// Email debug reports if I crash...
|
||||
testConfigCompile('ch.acra:acra:+') {
|
||||
|
@ -1,7 +1,5 @@
|
||||
package org.bspeice.minimalbible.activity.downloader.manager
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import org.crosswire.common.progress.JobManager;
|
||||
import org.crosswire.common.progress.WorkEvent;
|
||||
import org.crosswire.common.progress.WorkListener;
|
||||
@ -21,6 +19,7 @@ import org.crosswire.jsword.book.BookException
|
||||
* only operate on installedBooksList
|
||||
*/
|
||||
//TODO: Install indexes for Bibles
|
||||
//TODO: Figure out how to get Robolectric to mock the Log, rather than removing the calls
|
||||
class BookManager(private val installedBooks: Books, val rM: RefreshManager) :
|
||||
WorkListener, BooksListener {
|
||||
|
||||
@ -96,8 +95,8 @@ class BookManager(private val installedBooks: Books, val rM: RefreshManager) :
|
||||
installedBooksList remove b
|
||||
return true
|
||||
} catch (e: BookException) {
|
||||
Log.e("InstalledManager",
|
||||
"Unable to remove book (already uninstalled?): ${e.getDetailedMessage()}")
|
||||
// Log.e("InstalledManager",
|
||||
// "Unable to remove book (already uninstalled?): ${e.getDetailedMessage()}")
|
||||
return false
|
||||
}
|
||||
}
|
||||
@ -128,14 +127,14 @@ class BookManager(private val installedBooks: Books, val rM: RefreshManager) :
|
||||
}
|
||||
|
||||
override fun workStateChanged(ev: WorkEvent) {
|
||||
Log.d("BookDownloadManager", ev.toString())
|
||||
// Log.d("BookDownloadManager", ev.toString())
|
||||
}
|
||||
|
||||
override fun bookAdded(booksEvent: BooksEvent) {
|
||||
// It's possible the install finished before we received a progress event for it,
|
||||
// we handle that case here.
|
||||
val b = booksEvent.getBook()
|
||||
Log.d("BookDownloadManager", "Book added: ${b.getName()}")
|
||||
// Log.d("BookDownloadManager", "Book added: ${b.getName()}")
|
||||
inProgressDownloads remove b
|
||||
|
||||
// Not sure why, but the inProgressDownloads might not have our book,
|
||||
|
@ -16,3 +16,6 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryErro
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
||||
|
||||
# Use the build daemon
|
||||
org.gradle.daemon=true
|
||||
|
Loading…
Reference in New Issue
Block a user