Skip to content

Commit

Permalink
Migrate tests from androidTest to app-test!
Browse files Browse the repository at this point in the history
  • Loading branch information
Bradlee Speice committed Nov 20, 2014
1 parent f331f95 commit e9e6d1d
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 21 deletions.
15 changes: 12 additions & 3 deletions app-test/build.gradle
Expand Up @@ -3,6 +3,8 @@ apply plugin: 'kotlin'
apply plugin: 'jacoco'
apply plugin: 'com.github.kt3k.coveralls'

evaluationDependsOn(":app")

buildscript {
repositories {
mavenCentral()
Expand All @@ -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 {
Expand Down Expand Up @@ -60,3 +64,8 @@ jacocoTestReport {
coveralls {
sourceDirs = files(androidModule.android.sourceSets.main.java.srcDirs).files.absolutePath
}

tasks.withType(Test) {
scanForTestClasses = false
include "**/*Test.class"
}
Expand Up @@ -5,7 +5,6 @@
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;
Expand All @@ -20,6 +19,9 @@
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;
Expand All @@ -37,12 +39,15 @@
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
Expand All @@ -57,6 +62,7 @@ public void inject(Object o) {
mObjectGraph.inject(o);
}

@Before
public void setUp() {
BookDownloadManagerTestModules modules = new BookDownloadManagerTestModules(this);
mObjectGraph = ObjectGraph.create(modules);
Expand All @@ -73,6 +79,7 @@ public Boolean call(Book book) {
});
}

@Ignore
public void testInstallBook() throws Exception {
final Book toInstall = installableBooks().toBlocking().first();

Expand All @@ -94,6 +101,7 @@ public void call(DLProgressEvent dlProgressEvent) {
.untilTrue(signal);
}

@Ignore
public void testJobIdMatch() {
final Book toInstall = installableBooks().toBlocking().first();
final String jobName = bookManager.getJobId(toInstall);
Expand All @@ -114,10 +122,11 @@ public void workStateChanged(WorkEvent ev) {
});

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);
Expand All @@ -131,6 +140,7 @@ public void testLocalListUpdatedAfterAdd() {
* 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);

Expand Down
@@ -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");
Expand Down
Expand Up @@ -4,11 +4,12 @@
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;
Expand All @@ -29,11 +30,15 @@
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";
/**
Expand All @@ -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);
Expand All @@ -71,6 +77,7 @@ public void inject(Object o) {
mObjectGraph.inject(o);
}

@Test
public void testGetAvailableModulesFlattened() throws Exception {
rM.getFlatModules()
.toBlocking()
Expand All @@ -85,13 +92,15 @@ public void call(Book book) {
verify(mockBook).getName();
}

@Test
public void testInstallerFromBook() throws Exception {
Installer i = rM.installerFromBook(mockBook).toBlocking().first();

assertSame(mockInstaller, i);
verify(mockInstaller).getBooks();
}

@Test
public void testRefreshSeparateThread() {
mockInstaller = mock(Installer.class);
final List<Book> bookList = new ArrayList<Book>();
Expand Down Expand Up @@ -130,6 +139,7 @@ public Boolean call() throws Exception {
* 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;
Expand Down
Expand Up @@ -2,26 +2,33 @@

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);
Expand All @@ -36,6 +43,7 @@ private void parserAssert(OsisParser parser, String element) {
parser.getDoWrite().pop();
}

@Test
public void testDoWriteAlwaysAdded() {
parserAssert(parser, OSISUtil.OSIS_ELEMENT_VERSE);
parserAssert(parser, "");
Expand All @@ -44,6 +52,7 @@ public void testDoWriteAlwaysAdded() {
}

@SuppressLint("NewApi")
@Test
public void testEndElementPopsQueue() {
parser.getDoWrite().add(true);
parser.endElement("", "", "");
Expand All @@ -54,8 +63,10 @@ public void testEndElementPopsQueue() {
// 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";
Expand Down
2 changes: 0 additions & 2 deletions app/build.gradle
Expand Up @@ -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:+') {
Expand Down
@@ -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;
Expand All @@ -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 {

Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion gradle.properties
Expand Up @@ -15,4 +15,7 @@ org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryErro
# When configured, Gradle will run in incubating parallel mode.
# 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
# org.gradle.parallel=true

# Use the build daemon
org.gradle.daemon=true

0 comments on commit e9e6d1d

Please sign in to comment.