|
@@ -2,7 +2,6 @@ package eu.kanade.tachiyomi.data.library;
|
|
|
|
|
|
import android.content.Context;
|
|
|
import android.os.Build;
|
|
|
-import android.util.Pair;
|
|
|
|
|
|
import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
@@ -21,14 +20,9 @@ import eu.kanade.tachiyomi.data.database.models.Manga;
|
|
|
import eu.kanade.tachiyomi.data.source.base.Source;
|
|
|
import rx.Observable;
|
|
|
|
|
|
-import static org.mockito.Matchers.any;
|
|
|
+import static org.assertj.core.api.Assertions.assertThat;
|
|
|
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;
|
|
|
-import static org.mockito.Mockito.times;
|
|
|
-import static org.mockito.Mockito.verify;
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
|
|
@@ -62,45 +56,39 @@ public class LibraryUpdateServiceTest {
|
|
|
|
|
|
@Test
|
|
|
public void testUpdateManga() {
|
|
|
- Manga manga = Manga.create("manga1");
|
|
|
- List<Chapter> chapters = createChapters("/chapter1", "/chapter2");
|
|
|
+ Manga manga = createManga("/manga1").get(0);
|
|
|
+ manga.id = 1L;
|
|
|
+ service.db.insertManga(manga).executeAsBlocking();
|
|
|
+
|
|
|
+ List<Chapter> sourceChapters = createChapters("/chapter1", "/chapter2");
|
|
|
|
|
|
- when(source.pullChaptersFromNetwork(manga.url)).thenReturn(Observable.just(chapters));
|
|
|
- when(service.db.insertOrRemoveChapters(manga, chapters, source))
|
|
|
- .thenReturn(Observable.just(Pair.create(2, 0)));
|
|
|
+ when(source.pullChaptersFromNetwork(manga.url)).thenReturn(Observable.just(sourceChapters));
|
|
|
|
|
|
service.updateManga(manga).subscribe();
|
|
|
|
|
|
- verify(service.db).insertOrRemoveChapters(manga, chapters, source);
|
|
|
+ assertThat(service.db.getChapters(manga).executeAsBlocking()).hasSize(2);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testContinuesUpdatingWhenAMangaFails() {
|
|
|
- Manga manga1 = Manga.create("manga1");
|
|
|
- Manga manga2 = Manga.create("manga2");
|
|
|
- Manga manga3 = Manga.create("manga3");
|
|
|
-
|
|
|
- List<Manga> favManga = createManga("manga1", "manga2", "manga3");
|
|
|
+ List<Manga> favManga = createManga("/manga1", "/manga2", "/manga3");
|
|
|
+ service.db.insertMangas(favManga).executeAsBlocking();
|
|
|
+ favManga = service.db.getFavoriteMangas().executeAsBlocking();
|
|
|
|
|
|
List<Chapter> chapters = createChapters("/chapter1", "/chapter2");
|
|
|
List<Chapter> chapters3 = createChapters("/achapter1", "/achapter2");
|
|
|
|
|
|
- when(service.db.getFavoriteMangas().executeAsBlocking()).thenReturn(favManga);
|
|
|
-
|
|
|
// One of the updates will fail
|
|
|
- when(source.pullChaptersFromNetwork("manga1")).thenReturn(Observable.just(chapters));
|
|
|
- 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)));
|
|
|
- when(service.db.insertOrRemoveChapters(manga3, chapters, source)).thenReturn(Observable.just(Pair.create(2, 0)));
|
|
|
+ when(source.pullChaptersFromNetwork("/manga1")).thenReturn(Observable.just(chapters));
|
|
|
+ when(source.pullChaptersFromNetwork("/manga2")).thenReturn(Observable.<List<Chapter>>error(new Exception()));
|
|
|
+ when(source.pullChaptersFromNetwork("/manga3")).thenReturn(Observable.just(chapters3));
|
|
|
|
|
|
service.updateMangaList(service.getMangaToUpdate(null)).subscribe();
|
|
|
|
|
|
// There are 3 network attempts and 2 insertions (1 request failed)
|
|
|
- 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());
|
|
|
+ assertThat(service.db.getChapters(favManga.get(0)).executeAsBlocking()).hasSize(2);
|
|
|
+ assertThat(service.db.getChapters(favManga.get(1)).executeAsBlocking()).hasSize(0);
|
|
|
+ assertThat(service.db.getChapters(favManga.get(2)).executeAsBlocking()).hasSize(2);
|
|
|
}
|
|
|
|
|
|
private List<Chapter> createChapters(String... urls) {
|
|
@@ -108,6 +96,7 @@ public class LibraryUpdateServiceTest {
|
|
|
for (String url : urls) {
|
|
|
Chapter c = Chapter.create();
|
|
|
c.url = url;
|
|
|
+ c.name = url.substring(1);
|
|
|
list.add(c);
|
|
|
}
|
|
|
return list;
|
|
@@ -117,6 +106,8 @@ public class LibraryUpdateServiceTest {
|
|
|
List<Manga> list = new ArrayList<>();
|
|
|
for (String url : urls) {
|
|
|
Manga m = Manga.create(url);
|
|
|
+ m.title = url.substring(1);
|
|
|
+ m.favorite = true;
|
|
|
list.add(m);
|
|
|
}
|
|
|
return list;
|