From 8b40fbcd9694f808ec9921cff27775f0d0d117e6 Mon Sep 17 00:00:00 2001 From: Bradlee Speice Date: Sun, 20 Jul 2014 21:12:00 -0400 Subject: [PATCH] First mockito test! --- app/build.gradle | 7 ++ .../manager/RefreshManagerTest.java | 102 ++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/RefreshManagerTest.java diff --git a/app/build.gradle b/app/build.gradle index 8cfdb63..0cc9f85 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -33,6 +33,10 @@ android { exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE' exclude 'LICENSE.txt' + exclude 'META-INF/INDEX.LIST' + exclude 'LICENSE' + exclude 'NOTICE' + exclude 'asm-license.txt' } productFlavors { testConfig { @@ -57,6 +61,9 @@ dependencies { provided 'de.devland.esperandro:esperandro:1.1.2' androidTestCompile 'com.jayway.awaitility:awaitility:1.6.0' + androidTestCompile 'org.mockito:mockito-core:+' + androidTestCompile 'com.google.dexmaker:dexmaker:+' + androidTestCompile 'com.google.dexmaker:dexmaker-mockito:+' // androidTestProvided 'com.squareup.dagger:dagger-compiler:1.2.0' compile 'com.jakewharton:butterknife:5.0.1' diff --git a/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/RefreshManagerTest.java b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/RefreshManagerTest.java new file mode 100644 index 0000000..9a535b3 --- /dev/null +++ b/app/src/androidTest/java/org/bspeice/minimalbible/test/activity/downloader/manager/RefreshManagerTest.java @@ -0,0 +1,102 @@ +package org.bspeice.minimalbible.test.activity.downloader.manager; + +import junit.framework.TestCase; + +import org.bspeice.minimalbible.Injector; +import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager; +import org.crosswire.jsword.book.Book; +import org.crosswire.jsword.book.install.Installer; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import dagger.Module; +import dagger.ObjectGraph; +import dagger.Provides; +import rx.functions.Action1; + +import static org.mockito.Mockito.*; + +public class RefreshManagerTest extends TestCase implements Injector { + + /** + * The object graph that should be given to classes under test. Each test is responsible + * for setting their own ObjectGraph. + */ + ObjectGraph mObjectGraph; + + @Override + public void inject(Object o) { + mObjectGraph.inject(o); + } + + @Inject RefreshManager rM; + + @Module (injects = {RefreshManagerTest.class, RefreshManager.class}) + class TGAMFModules { + Injector i; + Collection installers; + + TGAMFModules(Injector i, Collection installers) { + this.i = i; + this.installers = installers; + } + + @Provides @Singleton + Injector provideInjector() { + return i; + } + + @Provides @Singleton + Collection provideInstallers() { + return this.installers; + } + } + public void testGetAvailableModulesFlattened() throws Exception { + // Environment setup + final String mockBookName = "MockBook"; + + Book mockBook = mock(Book.class); + when(mockBook.getName()).thenReturn(mockBookName); + + Installer mockInstaller = mock(Installer.class); + List bookList = new ArrayList(); + bookList.add(mockBook); + when(mockInstaller.getBooks()).thenReturn(bookList); + + Collection mockInstallers = new ArrayList(); + mockInstallers.add(mockInstaller); + + TGAMFModules modules = new TGAMFModules(this, mockInstallers); + mObjectGraph = ObjectGraph.create(modules); + + // Now the actual test + mObjectGraph.inject(this); // Get the RefreshManager + + rM.getAvailableModulesFlattened() + .toBlocking() + .forEach(new Action1() { + @Override + public void call(Book book) { + assertEquals(mockBookName, book.getName()); + } + }); + + verify(mockInstaller).getBooks(); + verify(mockBook).getName(); + } + + /* + public void testInstallerFromBook() throws Exception { + + } + + public void testIsRefreshComplete() throws Exception { + + } + */ +} \ No newline at end of file