mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-10 12:47:26 +01:00
Replace hamcrest with assertj. ChaptersSubject now uses only one observeOn.
This commit is contained in:
parent
dd833852ad
commit
73aa93773c
@ -76,7 +76,6 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
final SUPPORT_LIBRARY_VERSION = '23.1.1'
|
final SUPPORT_LIBRARY_VERSION = '23.1.1'
|
||||||
final DAGGER_VERSION = '2.0.2'
|
final DAGGER_VERSION = '2.0.2'
|
||||||
final HAMCREST_VERSION = '1.3'
|
|
||||||
final MOCKITO_VERSION = '1.10.19'
|
final MOCKITO_VERSION = '1.10.19'
|
||||||
final STORIO_VERSION = '1.7.0'
|
final STORIO_VERSION = '1.7.0'
|
||||||
final ICEPICK_VERSION = '3.1.0'
|
final ICEPICK_VERSION = '3.1.0'
|
||||||
@ -128,9 +127,7 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
testCompile "org.hamcrest:hamcrest-core:$HAMCREST_VERSION"
|
testCompile 'org.assertj:assertj-core:2.3.0'
|
||||||
testCompile "org.hamcrest:hamcrest-library:$HAMCREST_VERSION"
|
|
||||||
testCompile "org.hamcrest:hamcrest-integration:$HAMCREST_VERSION"
|
|
||||||
testCompile "org.mockito:mockito-core:$MOCKITO_VERSION"
|
testCompile "org.mockito:mockito-core:$MOCKITO_VERSION"
|
||||||
testCompile('org.robolectric:robolectric:3.0') {
|
testCompile('org.robolectric:robolectric:3.0') {
|
||||||
exclude group: 'commons-logging', module: 'commons-logging'
|
exclude group: 'commons-logging', module: 'commons-logging'
|
||||||
|
@ -120,22 +120,20 @@ public class ChaptersPresenter extends BasePresenter<ChaptersFragment> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Observable<PostResult> getOnlineChaptersObs() {
|
private Observable<PostResult> getOnlineChaptersObs() {
|
||||||
return source
|
return source.pullChaptersFromNetwork(manga.url)
|
||||||
.pullChaptersFromNetwork(manga.url)
|
|
||||||
.subscribeOn(Schedulers.io())
|
.subscribeOn(Schedulers.io())
|
||||||
.flatMap(chapters -> db.insertOrRemoveChapters(manga, chapters))
|
.flatMap(chapters -> db.insertOrRemoveChapters(manga, chapters))
|
||||||
.observeOn(AndroidSchedulers.mainThread());
|
.observeOn(AndroidSchedulers.mainThread());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Observable<List<Chapter>> getDbChaptersObs() {
|
private Observable<List<Chapter>> getDbChaptersObs() {
|
||||||
return chaptersSubject
|
return chaptersSubject.flatMap(this::applyChapterFilters)
|
||||||
.observeOn(Schedulers.io())
|
|
||||||
.flatMap(this::applyChapterFilters)
|
|
||||||
.observeOn(AndroidSchedulers.mainThread());
|
.observeOn(AndroidSchedulers.mainThread());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Observable<List<Chapter>> applyChapterFilters(List<Chapter> chapters) {
|
private Observable<List<Chapter>> applyChapterFilters(List<Chapter> chapters) {
|
||||||
Observable<Chapter> observable = Observable.from(chapters);
|
Observable<Chapter> observable = Observable.from(chapters)
|
||||||
|
.subscribeOn(Schedulers.io());
|
||||||
if (onlyUnread) {
|
if (onlyUnread) {
|
||||||
observable = observable.filter(chapter -> !chapter.read);
|
observable = observable.filter(chapter -> !chapter.read);
|
||||||
}
|
}
|
||||||
|
@ -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.Manga;
|
||||||
import eu.kanade.mangafeed.data.database.models.MangaCategory;
|
import eu.kanade.mangafeed.data.database.models.MangaCategory;
|
||||||
|
|
||||||
import static org.hamcrest.MatcherAssert.assertThat;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
import static org.hamcrest.Matchers.hasSize;
|
|
||||||
import static org.hamcrest.Matchers.is;
|
|
||||||
import static org.hamcrest.Matchers.not;
|
|
||||||
|
|
||||||
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
|
@Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
|
||||||
@RunWith(RobolectricGradleTestRunner.class)
|
@RunWith(RobolectricGradleTestRunner.class)
|
||||||
@ -48,13 +45,13 @@ public class CategoryTest {
|
|||||||
createCategory("Hold");
|
createCategory("Hold");
|
||||||
|
|
||||||
List<Category> categories = db.getCategories().executeAsBlocking();
|
List<Category> categories = db.getCategories().executeAsBlocking();
|
||||||
assertThat(categories, hasSize(2));
|
assertThat(categories).hasSize(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHasLibraryMangas() {
|
public void testHasLibraryMangas() {
|
||||||
List<Manga> mangas = db.getLibraryMangas().executeAsBlocking();
|
List<Manga> mangas = db.getLibraryMangas().executeAsBlocking();
|
||||||
assertThat(mangas, hasSize(5));
|
assertThat(mangas).hasSize(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -70,7 +67,7 @@ public class CategoryTest {
|
|||||||
m.favorite = false;
|
m.favorite = false;
|
||||||
db.insertManga(m).executeAsBlocking();
|
db.insertManga(m).executeAsBlocking();
|
||||||
List<Manga> mangas = db.getLibraryMangas().executeAsBlocking();
|
List<Manga> mangas = db.getLibraryMangas().executeAsBlocking();
|
||||||
assertThat(mangas, hasSize(5));
|
assertThat(mangas).hasSize(5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -81,7 +78,7 @@ public class CategoryTest {
|
|||||||
|
|
||||||
// It should not have 0 as id
|
// It should not have 0 as id
|
||||||
Category c = db.getCategories().executeAsBlocking().get(0);
|
Category c = db.getCategories().executeAsBlocking().get(0);
|
||||||
assertThat(c.id, not(0));
|
assertThat(c.id).isNotZero();
|
||||||
|
|
||||||
// Add a manga to a category
|
// Add a manga to a category
|
||||||
Manga m = db.getMangas().executeAsBlocking().get(0);
|
Manga m = db.getMangas().executeAsBlocking().get(0);
|
||||||
@ -92,7 +89,7 @@ public class CategoryTest {
|
|||||||
List<Manga> mangas = db.getLibraryMangas().executeAsBlocking();
|
List<Manga> mangas = db.getLibraryMangas().executeAsBlocking();
|
||||||
for (Manga manga : mangas) {
|
for (Manga manga : mangas) {
|
||||||
if (manga.id.equals(m.id)) {
|
if (manga.id.equals(m.id)) {
|
||||||
assertThat(manga.category, is(c.id));
|
assertThat(manga.category).isEqualTo(c.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,8 @@ import eu.kanade.mangafeed.data.database.models.Chapter;
|
|||||||
import eu.kanade.mangafeed.data.database.models.Manga;
|
import eu.kanade.mangafeed.data.database.models.Manga;
|
||||||
import eu.kanade.mangafeed.util.ChapterRecognition;
|
import eu.kanade.mangafeed.util.ChapterRecognition;
|
||||||
|
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
public class ChapterRecognitionTest {
|
public class ChapterRecognitionTest {
|
||||||
|
|
||||||
@ -30,49 +30,49 @@ public class ChapterRecognitionTest {
|
|||||||
public void testWithOneDigit() {
|
public void testWithOneDigit() {
|
||||||
Chapter c = createChapter("Ch.3: Self-proclaimed Genius");
|
Chapter c = createChapter("Ch.3: Self-proclaimed Genius");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(3f));
|
assertThat(c.chapter_number).isEqualTo(3f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithVolumeBefore() {
|
public void testWithVolumeBefore() {
|
||||||
Chapter c = createChapter("Vol.1 Ch.4: Misrepresentation");
|
Chapter c = createChapter("Vol.1 Ch.4: Misrepresentation");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(4f));
|
assertThat(c.chapter_number).isEqualTo(4f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithVolumeAndVersionNumber() {
|
public void testWithVolumeAndVersionNumber() {
|
||||||
Chapter c = createChapter("Vol.1 Ch.3 (v2) Read Online");
|
Chapter c = createChapter("Vol.1 Ch.3 (v2) Read Online");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(3f));
|
assertThat(c.chapter_number).isEqualTo(3f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithVolumeAndNumberInTitle() {
|
public void testWithVolumeAndNumberInTitle() {
|
||||||
Chapter c = createChapter("Vol.15 Ch.90: Here Blooms the Daylily, Part 4");
|
Chapter c = createChapter("Vol.15 Ch.90: Here Blooms the Daylily, Part 4");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(90f));
|
assertThat(c.chapter_number).isEqualTo(90f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithVolumeAndSpecialChapter() {
|
public void testWithVolumeAndSpecialChapter() {
|
||||||
Chapter c = createChapter("Vol.10 Ch.42.5: Homecoming (Beginning)");
|
Chapter c = createChapter("Vol.10 Ch.42.5: Homecoming (Beginning)");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(42.5f));
|
assertThat(c.chapter_number).isEqualTo(42.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithJustANumber() {
|
public void testWithJustANumber() {
|
||||||
Chapter c = createChapter("Homecoming (Beginning) 42");
|
Chapter c = createChapter("Homecoming (Beginning) 42");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(42f));
|
assertThat(c.chapter_number).isEqualTo(42f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithJustASpecialChapter() {
|
public void testWithJustASpecialChapter() {
|
||||||
Chapter c = createChapter("Homecoming (Beginning) 42.5");
|
Chapter c = createChapter("Homecoming (Beginning) 42.5");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(42.5f));
|
assertThat(c.chapter_number).isEqualTo(42.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -81,28 +81,28 @@ public class ChapterRecognitionTest {
|
|||||||
Manga m = new Manga();
|
Manga m = new Manga();
|
||||||
m.title = "3x3 Eyes";
|
m.title = "3x3 Eyes";
|
||||||
ChapterRecognition.parseChapterNumber(c, m);
|
ChapterRecognition.parseChapterNumber(c, m);
|
||||||
assertThat(c.chapter_number, is(96f));
|
assertThat(c.chapter_number).isEqualTo(96f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithColonAtTheEnd() {
|
public void testWithColonAtTheEnd() {
|
||||||
Chapter c = createChapter("Chapter 5: 365 days");
|
Chapter c = createChapter("Chapter 5: 365 days");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(5f));
|
assertThat(c.chapter_number).isEqualTo(5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWithZeros() {
|
public void testWithZeros() {
|
||||||
Chapter c = createChapter("Vol.001 Ch.003: Kaguya Doesn't Know Much");
|
Chapter c = createChapter("Vol.001 Ch.003: Kaguya Doesn't Know Much");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(3f));
|
assertThat(c.chapter_number).isEqualTo(3f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRange() {
|
public void testRange() {
|
||||||
Chapter c = createChapter("Ch.191-200 Read Online");
|
Chapter c = createChapter("Ch.191-200 Read Online");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(191f));
|
assertThat(c.chapter_number).isEqualTo(191f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -110,7 +110,7 @@ public class ChapterRecognitionTest {
|
|||||||
// It should be 567, not 67 (ch is a keyword to get the chapter number)
|
// It should be 567, not 67 (ch is a keyword to get the chapter number)
|
||||||
Chapter c = createChapter("Bleach 567: Down With Snowwhite");
|
Chapter c = createChapter("Bleach 567: Down With Snowwhite");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(567f));
|
assertThat(c.chapter_number).isEqualTo(567f);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -118,7 +118,7 @@ public class ChapterRecognitionTest {
|
|||||||
// It should be 84, not 2084
|
// It should be 84, not 2084
|
||||||
Chapter c = createChapter("Onepunch-Man Punch Ver002 084 : Creeping Darkness");
|
Chapter c = createChapter("Onepunch-Man Punch Ver002 084 : Creeping Darkness");
|
||||||
ChapterRecognition.parseChapterNumber(c, randomManga);
|
ChapterRecognition.parseChapterNumber(c, randomManga);
|
||||||
assertThat(c.chapter_number, is(84f));
|
assertThat(c.chapter_number).isEqualTo(84f);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user