Remove the "testing" mode

This commit is contained in:
Bradlee Speice 2014-09-03 21:44:17 -04:00
parent abbcbb3947
commit 5ebd66b6c7
3 changed files with 38 additions and 36 deletions

View File

@ -1,15 +1,21 @@
package org.bspeice.minimalbible.test.activity.downloader.manager; package org.bspeice.minimalbible.test.activity.downloader.manager;
import com.jayway.awaitility.Awaitility;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.bspeice.minimalbible.Injector; import org.bspeice.minimalbible.Injector;
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager; import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
import org.crosswire.jsword.book.Book; import org.crosswire.jsword.book.Book;
import org.crosswire.jsword.book.install.Installer; import org.crosswire.jsword.book.install.Installer;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.TimeUnit;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Singleton; import javax.inject.Singleton;
@ -19,6 +25,7 @@ import dagger.ObjectGraph;
import dagger.Provides; import dagger.Provides;
import rx.functions.Action1; import rx.functions.Action1;
import static com.jayway.awaitility.Awaitility.await;
import static org.mockito.Mockito.*; import static org.mockito.Mockito.*;
public class RefreshManagerTest extends TestCase implements Injector { public class RefreshManagerTest extends TestCase implements Injector {
@ -113,9 +120,36 @@ public class RefreshManagerTest extends TestCase implements Injector {
verify(mockInstaller).getBooks(); verify(mockInstaller).getBooks();
} }
/* public void testRefreshSeparateThread() {
public void testIsRefreshComplete() throws Exception { Installer mockInstaller = mock(Installer.class);
final List<Book> bookList = new ArrayList<Book>();
when(mockInstaller.getBooks()).thenAnswer(new Answer<List<Book>>() {
@Override
public List<Book> answer(InvocationOnMock invocationOnMock) throws Throwable {
Thread.sleep(1000); // Just long enough to give us a gap between
// refresh start and complete
return bookList;
}
});
Collection<Installer> mockInstallers = new ArrayList<Installer>();
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<Boolean>() {
@Override
public Boolean call() throws Exception {
return rM.isRefreshComplete();
}
});
} }
*/
} }

View File

@ -5,22 +5,13 @@ package org.bspeice.minimalbible;
* Also the entry point for setting whether or not we are using testing mode * Also the entry point for setting whether or not we are using testing mode
*/ */
public class Modules { public class Modules {
private static TestModules testModules = new TestModules();
private Modules() {} private Modules() {}
public static void enableTestingMode() {
testModules.setTestMode(true);
}
public static void disableTestingMode() {
testModules.setTestMode(false);
}
public static Object[] list(MinimalBible app) { public static Object[] list(MinimalBible app) {
return new Object[] { return new Object[] {
new MinimalBibleModules(app), new MinimalBibleModules(app),
testModules new TestModules()
}; };
} }
} }

View File

@ -26,19 +26,6 @@ public class TestModules {
return testActivityTitle; 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 @Provides @Singleton
@Named("ValidCategories") @Named("ValidCategories")
List<BookCategory> provideValidCategories() { List<BookCategory> provideValidCategories() {
@ -49,14 +36,4 @@ public class TestModules {
add(BookCategory.MAPS); add(BookCategory.MAPS);
}}; }};
} }
private boolean isTest;
public void setTestMode(boolean isTest) {
this.isTest = isTest;
}
public boolean getTestMode() {
return isTest;
}
} }