mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-11-04 08:08:55 +01:00 
			
		
		
		
	Fix tests
This commit is contained in:
		@@ -6,7 +6,6 @@ import android.content.Intent;
 | 
			
		||||
import android.os.Build;
 | 
			
		||||
import android.os.SystemClock;
 | 
			
		||||
 | 
			
		||||
import org.assertj.core.data.Offset;
 | 
			
		||||
import org.junit.Before;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.junit.runner.RunWith;
 | 
			
		||||
@@ -132,9 +131,9 @@ public class LibraryUpdateAlarmTest {
 | 
			
		||||
        long shouldRunAt = SystemClock.elapsedRealtime() + (hours * 60 * 60 * 1000);
 | 
			
		||||
 | 
			
		||||
        // Margin error of 3 seconds
 | 
			
		||||
        Offset<Long> offset = Offset.offset(3 * 1000L);
 | 
			
		||||
 | 
			
		||||
        assertThat(alarmManager.getNextScheduledAlarm().triggerAtTime).isCloseTo(shouldRunAt, offset);
 | 
			
		||||
        assertThat(alarmManager.getNextScheduledAlarm().triggerAtTime)
 | 
			
		||||
                .isGreaterThan(shouldRunAt - 3000)
 | 
			
		||||
                .isLessThan(shouldRunAt + 3000);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -23,6 +23,7 @@ import rx.Observable;
 | 
			
		||||
 | 
			
		||||
import static org.mockito.Matchers.any;
 | 
			
		||||
import static org.mockito.Matchers.anyInt;
 | 
			
		||||
import static org.mockito.Matchers.anyListOf;
 | 
			
		||||
import static org.mockito.Matchers.eq;
 | 
			
		||||
import static org.mockito.Mockito.mock;
 | 
			
		||||
import static org.mockito.Mockito.never;
 | 
			
		||||
@@ -88,7 +89,7 @@ public class LibraryUpdateServiceTest {
 | 
			
		||||
 | 
			
		||||
        // One of the updates will fail
 | 
			
		||||
        when(source.pullChaptersFromNetwork("manga1")).thenReturn(Observable.just(chapters));
 | 
			
		||||
        when(source.pullChaptersFromNetwork("manga2")).thenReturn(Observable.error(new Exception()));
 | 
			
		||||
        when(source.pullChaptersFromNetwork("manga2")).thenReturn(Observable.<List<Chapter>>error(new Exception()));
 | 
			
		||||
        when(source.pullChaptersFromNetwork("manga3")).thenReturn(Observable.just(chapters3));
 | 
			
		||||
 | 
			
		||||
        when(service.db.insertOrRemoveChapters(manga1, chapters, source)).thenReturn(Observable.just(Pair.create(2, 0)));
 | 
			
		||||
@@ -97,9 +98,9 @@ public class LibraryUpdateServiceTest {
 | 
			
		||||
        service.updateLibrary().subscribe();
 | 
			
		||||
 | 
			
		||||
        // There are 3 network attempts and 2 insertions (1 request failed)
 | 
			
		||||
        verify(source, times(3)).pullChaptersFromNetwork(any());
 | 
			
		||||
        verify(service.db, times(2)).insertOrRemoveChapters(any(), any(), any());
 | 
			
		||||
        verify(service.db, never()).insertOrRemoveChapters(eq(manga2), any(), any());
 | 
			
		||||
        verify(source, times(3)).pullChaptersFromNetwork((String)any());
 | 
			
		||||
        verify(service.db, times(2)).insertOrRemoveChapters((Manga)any(), anyListOf(Chapter.class), (Source)any());
 | 
			
		||||
        verify(service.db, never()).insertOrRemoveChapters(eq(manga2), anyListOf(Chapter.class), (Source)any());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private List<Chapter> createChapters(String... urls) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user