mirror of
https://github.com/MinimalBible/MinimalBible
synced 2024-11-24 17:08:18 -05:00
Test that the DLProgressEvent is triggered correctly
This commit is contained in:
parent
90db3e6a1a
commit
ffd4ccd08c
@ -10,6 +10,7 @@ import org.bspeice.minimalbible.activity.downloader.manager.BookManager;
|
|||||||
import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent;
|
import org.bspeice.minimalbible.activity.downloader.manager.DLProgressEvent;
|
||||||
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
import org.bspeice.minimalbible.activity.downloader.manager.RefreshManager;
|
||||||
import org.crosswire.common.progress.JobManager;
|
import org.crosswire.common.progress.JobManager;
|
||||||
|
import org.crosswire.common.progress.Progress;
|
||||||
import org.crosswire.common.progress.WorkEvent;
|
import org.crosswire.common.progress.WorkEvent;
|
||||||
import org.crosswire.common.progress.WorkListener;
|
import org.crosswire.common.progress.WorkListener;
|
||||||
import org.crosswire.jsword.book.Book;
|
import org.crosswire.jsword.book.Book;
|
||||||
@ -158,6 +159,45 @@ public class BookManagerTest implements Injector {
|
|||||||
verify(driver, times(1)).delete(secondMockBook);
|
verify(driver, times(1)).delete(secondMockBook);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure that when workProgressed is fired, the correct progress event gets triggered
|
||||||
|
* Previously, integer roundoff errors led to some strange results
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
public void testWorkProgressedCorrectProgress() {
|
||||||
|
Book mockBook = mock(Book.class);
|
||||||
|
when(mockBook.getInitials()).thenReturn("mockBook");
|
||||||
|
String bookJobName = bookManager.getJobId(mockBook);
|
||||||
|
bookManager.getBookMappings().put(bookJobName, mockBook);
|
||||||
|
|
||||||
|
// Percent to degrees
|
||||||
|
int workProgress = 1;
|
||||||
|
int totalWork = 2;
|
||||||
|
final int circularProgress = 180;
|
||||||
|
WorkEvent ev = mock(WorkEvent.class);
|
||||||
|
Progress p = mock(Progress.class);
|
||||||
|
|
||||||
|
when(p.getJobID()).thenReturn(bookJobName);
|
||||||
|
when(p.getWorkDone()).thenReturn(workProgress);
|
||||||
|
when(p.getTotalWork()).thenReturn(totalWork);
|
||||||
|
|
||||||
|
when(ev.getJob()).thenReturn(p);
|
||||||
|
|
||||||
|
final AtomicBoolean progressCorrect = new AtomicBoolean(false);
|
||||||
|
bookManager.getDownloadEvents()
|
||||||
|
.subscribe(new Action1<DLProgressEvent>() {
|
||||||
|
@Override
|
||||||
|
public void call(DLProgressEvent dlProgressEvent) {
|
||||||
|
progressCorrect.set(circularProgress == dlProgressEvent.toCircular());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
bookManager.workProgressed(ev);
|
||||||
|
|
||||||
|
await().atMost(10, TimeUnit.SECONDS)
|
||||||
|
.untilTrue(progressCorrect);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modules needed for this test case
|
* Modules needed for this test case
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user