mirror of
				https://github.com/MinimalBible/MinimalBible-Legacy
				synced 2025-11-04 02:10:30 -05:00 
			
		
		
		
	Unit test fixes, works locally.
We'll see if it finally runs on Travis...
This commit is contained in:
		@ -1,26 +1,27 @@
 | 
			
		||||
package org.bspeice.minimalbible.test;
 | 
			
		||||
 | 
			
		||||
import android.test.InstrumentationTestCase;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import android.view.LayoutInflater;
 | 
			
		||||
import android.view.View;
 | 
			
		||||
 | 
			
		||||
import org.bspeice.minimalbible.MinimalBible;
 | 
			
		||||
import org.bspeice.minimalbible.MinimalBibleModules;
 | 
			
		||||
import org.bspeice.minimalbible.R;
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.BookItemHolder;
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.manager.BookDownloadThread;
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.manager.DLProgressEvent;
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.manager.DownloadManager;
 | 
			
		||||
import org.bspeice.minimalbible.activities.downloader.manager.RefreshManager;
 | 
			
		||||
import org.crosswire.jsword.book.Book;
 | 
			
		||||
import org.crosswire.jsword.book.install.Installer;
 | 
			
		||||
 | 
			
		||||
import java.util.concurrent.Callable;
 | 
			
		||||
import java.util.concurrent.CountDownLatch;
 | 
			
		||||
import java.util.concurrent.TimeUnit;
 | 
			
		||||
 | 
			
		||||
import javax.inject.Inject;
 | 
			
		||||
import javax.inject.Provider;
 | 
			
		||||
 | 
			
		||||
import dagger.Module;
 | 
			
		||||
 | 
			
		||||
import static com.jayway.awaitility.Awaitility.*;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Tests for the Download activity
 | 
			
		||||
 */
 | 
			
		||||
@ -30,8 +31,9 @@ public class DownloadActivityTest extends InstrumentationTestCase {
 | 
			
		||||
            injects = DownloadActivityTest.class)
 | 
			
		||||
    public static class DownloadActivityTestModule {}
 | 
			
		||||
 | 
			
		||||
    @Inject
 | 
			
		||||
    DownloadManager dm;
 | 
			
		||||
    @Inject DownloadManager dm;
 | 
			
		||||
    @Inject Provider<BookDownloadThread> bookDownloadThreadProvider;
 | 
			
		||||
    @Inject RefreshManager rm;
 | 
			
		||||
 | 
			
		||||
    public void setUp() {
 | 
			
		||||
        MinimalBible.getApplication().getObjGraph()
 | 
			
		||||
@ -47,21 +49,28 @@ public class DownloadActivityTest extends InstrumentationTestCase {
 | 
			
		||||
     */
 | 
			
		||||
    public void testInitialProgressEventOnDownload() throws InterruptedException {
 | 
			
		||||
        final CountDownLatch signal = new CountDownLatch(1);
 | 
			
		||||
        Installer i = (Installer) dm.getInstallers().values().toArray()[0];
 | 
			
		||||
        Book testBook = i.getBooks().get(0);
 | 
			
		||||
        View dummyView = LayoutInflater.from(MinimalBible.getApplication())
 | 
			
		||||
                .inflate(R.layout.list_download_items, null);
 | 
			
		||||
        BookItemHolder holder = new BookItemHolder(dummyView, testBook);
 | 
			
		||||
 | 
			
		||||
        // Need to make sure we've refreshed the refreshmanager first
 | 
			
		||||
        Installer i = (Installer) dm.getInstallers().values().toArray()[0];
 | 
			
		||||
        final Book testBook = i.getBooks().get(0);
 | 
			
		||||
        await().until(new Callable<Boolean>() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public Boolean call() throws Exception {
 | 
			
		||||
                return rm.installerFromBook(testBook) != null;
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        // And wait for the actual download
 | 
			
		||||
        dm.getDownloadBus().register(new Object() {
 | 
			
		||||
            public void onEvent(DLProgressEvent event) {
 | 
			
		||||
                Log.d("testInitial", Integer.toString(event.getProgress()));
 | 
			
		||||
                if (event.getProgress() == 0) {
 | 
			
		||||
                    signal.countDown();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
        holder.onDownloadItem(dummyView);
 | 
			
		||||
 | 
			
		||||
        BookDownloadThread thread = bookDownloadThreadProvider.get();
 | 
			
		||||
        thread.downloadBook(testBook);
 | 
			
		||||
 | 
			
		||||
        signal.await(10, TimeUnit.SECONDS);
 | 
			
		||||
        if (signal.getCount() != 0) {
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user