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 index b0ed9b9..73c30f4 100644 --- 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 @@ -1,15 +1,21 @@ package org.bspeice.minimalbible.test.activity.downloader.manager; +import com.jayway.awaitility.Awaitility; + 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 org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; import javax.inject.Inject; import javax.inject.Singleton; @@ -19,6 +25,7 @@ import dagger.ObjectGraph; import dagger.Provides; import rx.functions.Action1; +import static com.jayway.awaitility.Awaitility.await; import static org.mockito.Mockito.*; public class RefreshManagerTest extends TestCase implements Injector { @@ -113,9 +120,36 @@ public class RefreshManagerTest extends TestCase implements Injector { verify(mockInstaller).getBooks(); } - /* - public void testIsRefreshComplete() throws Exception { + public void testRefreshSeparateThread() { + Installer mockInstaller = mock(Installer.class); + final List bookList = new ArrayList(); + when(mockInstaller.getBooks()).thenAnswer(new Answer>() { + @Override + public List answer(InvocationOnMock invocationOnMock) throws Throwable { + Thread.sleep(1000); // Just long enough to give us a gap between + // refresh start and complete + return bookList; + } + }); + Collection mockInstallers = new ArrayList(); + mockInstallers.add(mockInstaller); + + RMTModules modules = new RMTModules(this, mockInstallers); + mObjectGraph = ObjectGraph.create(modules); + + // And the actual test + mObjectGraph.inject(this); + + // So the refresh should be kicked off at the constructor, meaning that it's not "complete" + assertFalse(rM.isRefreshComplete()); + + // But, if it's on another thread, it should finish up eventually, right? + await().atMost(5, TimeUnit.SECONDS).until(new Callable() { + @Override + public Boolean call() throws Exception { + return rM.isRefreshComplete(); + } + }); } - */ } \ No newline at end of file diff --git a/app/src/testConfig/java/org/bspeice/minimalbible/Modules.java b/app/src/testConfig/java/org/bspeice/minimalbible/Modules.java index 28462ad..652e2bb 100644 --- a/app/src/testConfig/java/org/bspeice/minimalbible/Modules.java +++ b/app/src/testConfig/java/org/bspeice/minimalbible/Modules.java @@ -5,22 +5,13 @@ package org.bspeice.minimalbible; * Also the entry point for setting whether or not we are using testing mode */ public class Modules { - private static TestModules testModules = new TestModules(); private Modules() {} - public static void enableTestingMode() { - testModules.setTestMode(true); - } - - public static void disableTestingMode() { - testModules.setTestMode(false); - } - public static Object[] list(MinimalBible app) { return new Object[] { new MinimalBibleModules(app), - testModules + new TestModules() }; } } diff --git a/app/src/testConfig/java/org/bspeice/minimalbible/TestModules.java b/app/src/testConfig/java/org/bspeice/minimalbible/TestModules.java index 560b4b5..f6560a2 100644 --- a/app/src/testConfig/java/org/bspeice/minimalbible/TestModules.java +++ b/app/src/testConfig/java/org/bspeice/minimalbible/TestModules.java @@ -26,19 +26,6 @@ public class TestModules { return testActivityTitle; } - /** - * Provide an application-wide hub to enable/disable a "testing" mode - * Each application is free to interpret what this means, but allows for programming - * different behavior to respond to different testing needs in code that can't be mocked - * *cough cough* `Activities`. - * @return - */ - @Provides - @Named("Testing") - boolean isTest() { - return isTest; - } - @Provides @Singleton @Named("ValidCategories") List provideValidCategories() { @@ -49,14 +36,4 @@ public class TestModules { add(BookCategory.MAPS); }}; } - - private boolean isTest; - - public void setTestMode(boolean isTest) { - this.isTest = isTest; - } - - public boolean getTestMode() { - return isTest; - } }