mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-22 07:58:20 -05:00
First mockito test!
This commit is contained in:
parent
021cf1359d
commit
8b40fbcd96
@ -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'
|
||||
|
@ -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<Installer> installers;
|
||||
|
||||
TGAMFModules(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";
|
||||
|
||||
Book mockBook = mock(Book.class);
|
||||
when(mockBook.getName()).thenReturn(mockBookName);
|
||||
|
||||
Installer mockInstaller = mock(Installer.class);
|
||||
List<Book> bookList = new ArrayList<Book>();
|
||||
bookList.add(mockBook);
|
||||
when(mockInstaller.getBooks()).thenReturn(bookList);
|
||||
|
||||
Collection<Installer> mockInstallers = new ArrayList<Installer>();
|
||||
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<Book>() {
|
||||
@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 {
|
||||
|
||||
}
|
||||
*/
|
||||
}
|
Loading…
Reference in New Issue
Block a user