From 73aa93773c2eb75617f7ad7eb2064ae127cc2543 Mon Sep 17 00:00:00 2001 From: inorichi Date: Wed, 6 Jan 2016 16:08:15 +0100 Subject: [PATCH] Replace hamcrest with assertj. ChaptersSubject now uses only one observeOn. --- app/build.gradle | 5 +--- .../ui/manga/chapter/ChaptersPresenter.java | 10 +++---- .../eu/kanade/mangafeed/CategoryTest.java | 15 ++++------ .../mangafeed/ChapterRecognitionTest.java | 30 +++++++++---------- 4 files changed, 26 insertions(+), 34 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 1ffd51528..04407f947 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -76,7 +76,6 @@ android { dependencies { final SUPPORT_LIBRARY_VERSION = '23.1.1' final DAGGER_VERSION = '2.0.2' - final HAMCREST_VERSION = '1.3' final MOCKITO_VERSION = '1.10.19' final STORIO_VERSION = '1.7.0' final ICEPICK_VERSION = '3.1.0' @@ -128,9 +127,7 @@ dependencies { } testCompile 'junit:junit:4.12' - testCompile "org.hamcrest:hamcrest-core:$HAMCREST_VERSION" - testCompile "org.hamcrest:hamcrest-library:$HAMCREST_VERSION" - testCompile "org.hamcrest:hamcrest-integration:$HAMCREST_VERSION" + testCompile 'org.assertj:assertj-core:2.3.0' testCompile "org.mockito:mockito-core:$MOCKITO_VERSION" testCompile('org.robolectric:robolectric:3.0') { exclude group: 'commons-logging', module: 'commons-logging' diff --git a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java index a97d0638f..95ce8d9f6 100644 --- a/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java +++ b/app/src/main/java/eu/kanade/mangafeed/ui/manga/chapter/ChaptersPresenter.java @@ -120,22 +120,20 @@ public class ChaptersPresenter extends BasePresenter { } private Observable getOnlineChaptersObs() { - return source - .pullChaptersFromNetwork(manga.url) + return source.pullChaptersFromNetwork(manga.url) .subscribeOn(Schedulers.io()) .flatMap(chapters -> db.insertOrRemoveChapters(manga, chapters)) .observeOn(AndroidSchedulers.mainThread()); } private Observable> getDbChaptersObs() { - return chaptersSubject - .observeOn(Schedulers.io()) - .flatMap(this::applyChapterFilters) + return chaptersSubject.flatMap(this::applyChapterFilters) .observeOn(AndroidSchedulers.mainThread()); } private Observable> applyChapterFilters(List chapters) { - Observable observable = Observable.from(chapters); + Observable observable = Observable.from(chapters) + .subscribeOn(Schedulers.io()); if (onlyUnread) { observable = observable.filter(chapter -> !chapter.read); } diff --git a/app/src/test/java/eu/kanade/mangafeed/CategoryTest.java b/app/src/test/java/eu/kanade/mangafeed/CategoryTest.java index 2afa70da3..6e5babb9a 100644 --- a/app/src/test/java/eu/kanade/mangafeed/CategoryTest.java +++ b/app/src/test/java/eu/kanade/mangafeed/CategoryTest.java @@ -17,10 +17,7 @@ import eu.kanade.mangafeed.data.database.models.Category; import eu.kanade.mangafeed.data.database.models.Manga; import eu.kanade.mangafeed.data.database.models.MangaCategory; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; +import static org.assertj.core.api.Assertions.*; @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP) @RunWith(RobolectricGradleTestRunner.class) @@ -48,13 +45,13 @@ public class CategoryTest { createCategory("Hold"); List categories = db.getCategories().executeAsBlocking(); - assertThat(categories, hasSize(2)); + assertThat(categories).hasSize(2); } @Test public void testHasLibraryMangas() { List mangas = db.getLibraryMangas().executeAsBlocking(); - assertThat(mangas, hasSize(5)); + assertThat(mangas).hasSize(5); } @Test @@ -70,7 +67,7 @@ public class CategoryTest { m.favorite = false; db.insertManga(m).executeAsBlocking(); List mangas = db.getLibraryMangas().executeAsBlocking(); - assertThat(mangas, hasSize(5)); + assertThat(mangas).hasSize(5); } @Test @@ -81,7 +78,7 @@ public class CategoryTest { // It should not have 0 as id Category c = db.getCategories().executeAsBlocking().get(0); - assertThat(c.id, not(0)); + assertThat(c.id).isNotZero(); // Add a manga to a category Manga m = db.getMangas().executeAsBlocking().get(0); @@ -92,7 +89,7 @@ public class CategoryTest { List mangas = db.getLibraryMangas().executeAsBlocking(); for (Manga manga : mangas) { if (manga.id.equals(m.id)) { - assertThat(manga.category, is(c.id)); + assertThat(manga.category).isEqualTo(c.id); } } } diff --git a/app/src/test/java/eu/kanade/mangafeed/ChapterRecognitionTest.java b/app/src/test/java/eu/kanade/mangafeed/ChapterRecognitionTest.java index 43782e2bc..1ea49ce46 100644 --- a/app/src/test/java/eu/kanade/mangafeed/ChapterRecognitionTest.java +++ b/app/src/test/java/eu/kanade/mangafeed/ChapterRecognitionTest.java @@ -7,8 +7,8 @@ import eu.kanade.mangafeed.data.database.models.Chapter; import eu.kanade.mangafeed.data.database.models.Manga; import eu.kanade.mangafeed.util.ChapterRecognition; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; + public class ChapterRecognitionTest { @@ -30,49 +30,49 @@ public class ChapterRecognitionTest { public void testWithOneDigit() { Chapter c = createChapter("Ch.3: Self-proclaimed Genius"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(3f)); + assertThat(c.chapter_number).isEqualTo(3f); } @Test public void testWithVolumeBefore() { Chapter c = createChapter("Vol.1 Ch.4: Misrepresentation"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(4f)); + assertThat(c.chapter_number).isEqualTo(4f); } @Test public void testWithVolumeAndVersionNumber() { Chapter c = createChapter("Vol.1 Ch.3 (v2) Read Online"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(3f)); + assertThat(c.chapter_number).isEqualTo(3f); } @Test public void testWithVolumeAndNumberInTitle() { Chapter c = createChapter("Vol.15 Ch.90: Here Blooms the Daylily, Part 4"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(90f)); + assertThat(c.chapter_number).isEqualTo(90f); } @Test public void testWithVolumeAndSpecialChapter() { Chapter c = createChapter("Vol.10 Ch.42.5: Homecoming (Beginning)"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(42.5f)); + assertThat(c.chapter_number).isEqualTo(42.5f); } @Test public void testWithJustANumber() { Chapter c = createChapter("Homecoming (Beginning) 42"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(42f)); + assertThat(c.chapter_number).isEqualTo(42f); } @Test public void testWithJustASpecialChapter() { Chapter c = createChapter("Homecoming (Beginning) 42.5"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(42.5f)); + assertThat(c.chapter_number).isEqualTo(42.5f); } @Test @@ -81,28 +81,28 @@ public class ChapterRecognitionTest { Manga m = new Manga(); m.title = "3x3 Eyes"; ChapterRecognition.parseChapterNumber(c, m); - assertThat(c.chapter_number, is(96f)); + assertThat(c.chapter_number).isEqualTo(96f); } @Test public void testWithColonAtTheEnd() { Chapter c = createChapter("Chapter 5: 365 days"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(5f)); + assertThat(c.chapter_number).isEqualTo(5f); } @Test public void testWithZeros() { Chapter c = createChapter("Vol.001 Ch.003: Kaguya Doesn't Know Much"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(3f)); + assertThat(c.chapter_number).isEqualTo(3f); } @Test public void testRange() { Chapter c = createChapter("Ch.191-200 Read Online"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(191f)); + assertThat(c.chapter_number).isEqualTo(191f); } @Test @@ -110,7 +110,7 @@ public class ChapterRecognitionTest { // It should be 567, not 67 (ch is a keyword to get the chapter number) Chapter c = createChapter("Bleach 567: Down With Snowwhite"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(567f)); + assertThat(c.chapter_number).isEqualTo(567f); } @Test @@ -118,7 +118,7 @@ public class ChapterRecognitionTest { // It should be 84, not 2084 Chapter c = createChapter("Onepunch-Man Punch Ver002 084 : Creeping Darkness"); ChapterRecognition.parseChapterNumber(c, randomManga); - assertThat(c.chapter_number, is(84f)); + assertThat(c.chapter_number).isEqualTo(84f); } }