RefreshManager going functional!

This commit is contained in:
Bradlee Speice
2014-10-22 22:21:42 -04:00
parent 6d15167100
commit 22fd32b26d
13 changed files with 205 additions and 281 deletions

View File

@ -35,37 +35,6 @@ import static com.jayway.awaitility.Awaitility.await;
public class BookDownloadManagerTest extends TestCase implements Injector {
ObjectGraph mObjectGraph;
/**
* Modules needed for this test case
*/
@Module(injects = {BookDownloadManager.class,
RefreshManager.class,
BookDownloadManagerTest.class})
public static class BookDownloadManagerTestModules {
Injector i;
BookDownloadManagerTestModules(Injector i) {
this.i = i;
}
@Provides
@Singleton
Injector provideInjector() {
return i;
}
@Provides @Singleton
Books provideBooks() {
return Books.installed();
}
@Provides @Singleton
Collection<Installer> provideInstallers() {
return new InstallManager().getInstallers().values();
}
}
@Inject BookDownloadManager bookDownloadManager;
@Inject RefreshManager refreshManager;
@Inject Books installedBooks;
@ -82,7 +51,7 @@ public class BookDownloadManagerTest extends TestCase implements Injector {
}
Observable<Book> installableBooks() {
return refreshManager.getAvailableModulesFlattened()
return refreshManager.getAvailableModulesFlat()
.filter(new Func1<Book, Boolean>() {
@Override
public Boolean call(Book book) {
@ -135,4 +104,43 @@ public class BookDownloadManagerTest extends TestCase implements Injector {
await().atMost(1, TimeUnit.SECONDS)
.untilTrue(jobNameMatch);
}
/**
* Modules needed for this test case
*/
@Module(injects = {BookDownloadManager.class,
RefreshManager.class,
BookDownloadManagerTest.class})
@SuppressWarnings("unused")
public static class BookDownloadManagerTestModules {
Injector i;
BookDownloadManagerTestModules(Injector i) {
this.i = i;
}
@Provides
@Singleton
Injector provideInjector() {
return i;
}
@Provides
@Singleton
Books provideBooks() {
return Books.installed();
}
@Provides
@Singleton
Collection<Installer> provideInstallers() {
return new InstallManager().getInstallers().values();
}
@Provides
@Singleton
RefreshManager refreshManager(Collection<Installer> installers) {
return new RefreshManager(installers);
}
}
}

View File

@ -36,40 +36,10 @@ import rx.functions.Func1;
*/
public class InstalledManagerTest extends TestCase implements Injector {
ObjectGraph mObjectGraph;
@Module(injects = {InstalledManager.class,
InstalledManagerTest.class,
RefreshManager.class,
BookDownloadManager.class})
static class IMTestModules {
Injector i;
public IMTestModules(Injector i) {
this.i = i;
}
@Provides @Singleton
Injector provideInjector() {
return this.i;
}
@Provides @Singleton
Books provideInstalledBooks() {
return Books.installed();
}
@Provides
List<Book> provideInstalledBooksList(Books b) {
return b.getBooks();
}
@Provides @Singleton
Collection<Installer> provideInstallers() {
return new InstallManager().getInstallers().values();
}
}
@Inject InstalledManager iM;
@Inject Books installedBooks;
@Inject
InstalledManager iM;
@Inject
Books installedBooks;
@Override
public void inject(Object o) {
@ -121,4 +91,46 @@ public class InstalledManagerTest extends TestCase implements Injector {
});
assertFalse(foundMismatch.get());
}
@Module(injects = {InstalledManager.class,
InstalledManagerTest.class,
RefreshManager.class,
BookDownloadManager.class})
@SuppressWarnings("unused")
static class IMTestModules {
Injector i;
public IMTestModules(Injector i) {
this.i = i;
}
@Provides
@Singleton
Injector provideInjector() {
return this.i;
}
@Provides
@Singleton
Books provideInstalledBooks() {
return Books.installed();
}
@Provides
List<Book> provideInstalledBooksList(Books b) {
return b.getBooks();
}
@Provides
@Singleton
Collection<Installer> provideInstallers() {
return new InstallManager().getInstallers().values();
}
@Provides
@Singleton
RefreshManager refreshManager(Collection<Installer> installers) {
return new RefreshManager(installers);
}
}
}

View File

@ -1,7 +1,5 @@
package org.bspeice.minimalbible.test.activity.downloader.manager;
import com.jayway.awaitility.Awaitility;
import junit.framework.TestCase;
import org.bspeice.minimalbible.Injector;
@ -26,7 +24,9 @@ import dagger.Provides;
import rx.functions.Action1;
import static com.jayway.awaitility.Awaitility.await;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class RefreshManagerTest extends TestCase implements Injector {
@ -35,34 +35,14 @@ public class RefreshManagerTest extends TestCase implements Injector {
* for setting their own ObjectGraph.
*/
ObjectGraph mObjectGraph;
@Inject
RefreshManager rM;
@Override
public void inject(Object o) {
mObjectGraph.inject(o);
}
@Inject RefreshManager rM;
@Module (injects = {RefreshManagerTest.class, RefreshManager.class})
class RMTModules {
Injector i;
Collection<Installer> installers;
RMTModules(Injector i, Collection<Installer> installers) {
this.i = i;
this.installers = installers;
}
@Provides @Singleton
Injector provideInjector() {
return i;
}
@Provides @Singleton
Collection<Installer> provideInstallers() {
return this.installers;
}
}
public void testGetAvailableModulesFlattened() throws Exception {
// Environment setup
final String mockBookName = "MockBook";
@ -78,13 +58,13 @@ public class RefreshManagerTest extends TestCase implements Injector {
Collection<Installer> mockInstallers = new ArrayList<Installer>();
mockInstallers.add(mockInstaller);
RMTModules modules = new RMTModules(this, mockInstallers);
RMTModules modules = new RMTModules(mockInstallers);
mObjectGraph = ObjectGraph.create(modules);
// Now the actual test
mObjectGraph.inject(this); // Get the RefreshManager
rM.getAvailableModulesFlattened()
rM.getAvailableModulesFlat()
.toBlocking()
.forEach(new Action1<Book>() {
@Override
@ -109,12 +89,12 @@ public class RefreshManagerTest extends TestCase implements Injector {
Collection<Installer> mockInstallers = new ArrayList<Installer>();
mockInstallers.add(mockInstaller);
RMTModules modules = new RMTModules(this, mockInstallers);
RMTModules modules = new RMTModules(mockInstallers);
mObjectGraph = ObjectGraph.create(modules);
// And the actual test
mObjectGraph.inject(this);
Installer i = rM.installerFromBook(mockBook);
Installer i = rM.installerFromBook(mockBook).toBlocking().first();
assertSame(mockInstaller, i);
verify(mockInstaller).getBooks();
@ -127,7 +107,7 @@ public class RefreshManagerTest extends TestCase implements Injector {
@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
// refresh start and complete
return bookList;
}
});
@ -135,21 +115,43 @@ public class RefreshManagerTest extends TestCase implements Injector {
Collection<Installer> mockInstallers = new ArrayList<Installer>();
mockInstallers.add(mockInstaller);
RMTModules modules = new RMTModules(this, mockInstallers);
RMTModules modules = new RMTModules(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());
assertFalse(rM.getRefreshComplete().get());
// 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();
return rM.getRefreshComplete().get();
}
});
}
@Module(injects = {RefreshManagerTest.class, RefreshManager.class})
@SuppressWarnings("unused")
class RMTModules {
Collection<Installer> installers;
RMTModules(Collection<Installer> installers) {
this.installers = installers;
}
@Provides
@Singleton
Collection<Installer> provideInstallers() {
return this.installers;
}
@Provides
@Singleton
RefreshManager refreshManager(Collection<Installer> installers) {
return new RefreshManager(installers);
}
}
}