MintManga parser
This commit is contained in:
@@ -7,4 +7,6 @@ interface MangaParserTest {
|
||||
fun testMangaDetails()
|
||||
|
||||
fun testMangaPages()
|
||||
|
||||
fun testTags()
|
||||
}
|
||||
@@ -1,32 +1,41 @@
|
||||
package org.koitharu.kotatsu.parsers
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okhttp3.OkHttpClient
|
||||
import org.junit.BeforeClass
|
||||
import org.koin.core.context.startKoin
|
||||
import org.koin.dsl.module
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.domain.MangaLoaderContext
|
||||
import org.koitharu.kotatsu.domain.MangaRepository
|
||||
import org.koitharu.kotatsu.core.parser.MangaRepository
|
||||
import org.koitharu.kotatsu.parsers.repository.ReadmangaRuTest
|
||||
|
||||
abstract class RepositoryTestEnvironment {
|
||||
|
||||
lateinit var repository: MangaRepository
|
||||
lateinit var repository: MangaRepository
|
||||
|
||||
@BeforeClass
|
||||
fun initialize(cls: Class<out MangaRepository>) {
|
||||
startKoin {
|
||||
modules(listOf(
|
||||
module {
|
||||
factory {
|
||||
OkHttpClient()
|
||||
}
|
||||
}, module {
|
||||
single {
|
||||
MangaLoaderContext()
|
||||
}
|
||||
}
|
||||
))
|
||||
}
|
||||
val constructor = cls.getConstructor(MangaLoaderContext::class.java)
|
||||
repository = constructor.newInstance(MangaLoaderContext())
|
||||
}
|
||||
@BeforeClass
|
||||
fun initialize(source: MangaSource) {
|
||||
startKoin {
|
||||
modules(listOf(
|
||||
module {
|
||||
factory {
|
||||
OkHttpClient()
|
||||
}
|
||||
}, module {
|
||||
single {
|
||||
MangaLoaderContext()
|
||||
}
|
||||
}
|
||||
))
|
||||
}
|
||||
val constructor = source.cls.getConstructor(MangaLoaderContext::class.java)
|
||||
repository = constructor.newInstance(MangaLoaderContext())
|
||||
}
|
||||
|
||||
fun getMangaList() = runBlocking { repository.getList(2) }
|
||||
|
||||
fun getMangaItem() = runBlocking { repository.getDetails(repository.getList(4).last()) }
|
||||
|
||||
fun getTags() = runBlocking { repository.getTags() }
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.koitharu.kotatsu.parsers.repository
|
||||
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import org.junit.Assert
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.MangaParserTest
|
||||
import org.koitharu.kotatsu.parsers.RepositoryTestEnvironment
|
||||
import org.koitharu.kotatsu.utils.TestUtil
|
||||
import org.mockito.junit.MockitoJUnitRunner
|
||||
|
||||
@RunWith(MockitoJUnitRunner::class)
|
||||
class MintMangaTest : MangaParserTest {
|
||||
|
||||
@Test
|
||||
override fun testMangaList() {
|
||||
val list = getMangaList()
|
||||
Assert.assertTrue(list.size == 70)
|
||||
val item = list[40]
|
||||
Assert.assertTrue(item.title.isNotEmpty())
|
||||
Assert.assertTrue(item.rating in 0f..1f)
|
||||
TestUtil.assertValidUrl(item.url)
|
||||
TestUtil.assertValidUrl(item.coverUrl)
|
||||
Assert.assertEquals(item.source, MangaSource.MINTMANGA)
|
||||
}
|
||||
|
||||
@Test
|
||||
override fun testMangaDetails() {
|
||||
val manga = getMangaItem()
|
||||
Assert.assertNotNull(manga.largeCoverUrl)
|
||||
TestUtil.assertValidUrl(manga.largeCoverUrl!!)
|
||||
Assert.assertNotNull(manga.chapters)
|
||||
val chapter = manga.chapters!!.last()
|
||||
Assert.assertEquals(chapter.source, MangaSource.MINTMANGA)
|
||||
TestUtil.assertValidUrl(chapter.url)
|
||||
}
|
||||
|
||||
@Test
|
||||
override fun testMangaPages() {
|
||||
val chapter = getMangaItem().chapters!!.first()
|
||||
val pages = runBlocking { repository.getPages(chapter) }
|
||||
Assert.assertFalse(pages.isEmpty())
|
||||
Assert.assertEquals(pages.first().source, MangaSource.MINTMANGA)
|
||||
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
|
||||
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
|
||||
}
|
||||
|
||||
@Test
|
||||
override fun testTags() {
|
||||
val tags = getTags()
|
||||
Assert.assertFalse(tags.isEmpty())
|
||||
val tag = tags.first()
|
||||
Assert.assertFalse(tag.title.isBlank())
|
||||
Assert.assertEquals(tag.source, MangaSource.MINTMANGA)
|
||||
TestUtil.assertValidUrl("https://mintmanga.live/list/genre/${tag.key}")
|
||||
}
|
||||
|
||||
companion object : RepositoryTestEnvironment() {
|
||||
|
||||
@JvmStatic
|
||||
@BeforeClass
|
||||
fun setUp() = initialize(MangaSource.MINTMANGA)
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import org.junit.Assert
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.koitharu.kotatsu.domain.repository.ReadmangaRepository
|
||||
import org.koitharu.kotatsu.core.model.MangaSource
|
||||
import org.koitharu.kotatsu.parsers.MangaParserTest
|
||||
import org.koitharu.kotatsu.parsers.RepositoryTestEnvironment
|
||||
import org.koitharu.kotatsu.utils.TestUtil
|
||||
@@ -16,38 +16,51 @@ class ReadmangaRuTest : MangaParserTest {
|
||||
|
||||
@Test
|
||||
override fun testMangaList() {
|
||||
val list = runBlocking { repository.getList(1) }
|
||||
val list = getMangaList()
|
||||
Assert.assertTrue(list.size == 70)
|
||||
val item = list[40]
|
||||
Assert.assertTrue(item.title.isNotEmpty())
|
||||
Assert.assertTrue(item.rating in 0f..1f)
|
||||
TestUtil.assertValidUrl(item.url)
|
||||
TestUtil.assertValidUrl(item.coverUrl)
|
||||
Assert.assertEquals(item.source, MangaSource.READMANGA_RU)
|
||||
}
|
||||
|
||||
@Test
|
||||
override fun testMangaDetails() {
|
||||
val manga = runBlocking { repository.getDetails(repository.getList(1).last()) }
|
||||
val manga = getMangaItem()
|
||||
Assert.assertNotNull(manga.largeCoverUrl)
|
||||
TestUtil.assertValidUrl(manga.largeCoverUrl!!)
|
||||
Assert.assertNotNull(manga.chapters)
|
||||
val chapter = manga.chapters!!.last()
|
||||
Assert.assertEquals(chapter.source, MangaSource.READMANGA_RU)
|
||||
TestUtil.assertValidUrl(chapter.url)
|
||||
}
|
||||
|
||||
@Test
|
||||
override fun testMangaPages() {
|
||||
val chapter = runBlocking { repository.getDetails(repository.getList(1).last()).chapters!!.first() }
|
||||
val chapter = getMangaItem().chapters!!.first()
|
||||
val pages = runBlocking { repository.getPages(chapter) }
|
||||
Assert.assertFalse(pages.isEmpty())
|
||||
Assert.assertEquals(pages.first().source, MangaSource.READMANGA_RU)
|
||||
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.first()) })
|
||||
TestUtil.assertValidUrl(runBlocking { repository.getPageFullUrl(pages.last()) })
|
||||
}
|
||||
|
||||
@Test
|
||||
override fun testTags() {
|
||||
val tags = getTags()
|
||||
Assert.assertFalse(tags.isEmpty())
|
||||
val tag = tags.first()
|
||||
Assert.assertFalse(tag.title.isBlank())
|
||||
Assert.assertEquals(tag.source, MangaSource.READMANGA_RU)
|
||||
TestUtil.assertValidUrl("https://readmanga.me/list/genre/${tag.key}")
|
||||
}
|
||||
|
||||
companion object : RepositoryTestEnvironment() {
|
||||
|
||||
@JvmStatic
|
||||
@BeforeClass
|
||||
fun setUp() = initialize(ReadmangaRepository::class.java)
|
||||
fun setUp() = initialize(MangaSource.READMANGA_RU)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user