Fix all parsers issues

This commit is contained in:
Koitharu
2020-03-18 19:12:27 +02:00
parent 0d041e9a0a
commit cae27dda05
5 changed files with 66 additions and 42 deletions

View File

@@ -1,12 +0,0 @@
package org.koitharu.kotatsu.parsers
interface MangaParserTest {
fun testMangaList()
fun testMangaDetails()
fun testMangaPages()
fun testTags()
}

View File

@@ -6,23 +6,23 @@ import java.net.URL
object AssertX {
fun assertContentType(url: String, type: String, subtype: String? = null) {
Assert.assertFalse("URL is empty", url.isEmpty())
val cn = URL(url).openConnection() as HttpURLConnection
cn.requestMethod = "HEAD"
cn.connect()
when (val code = cn.responseCode) {
HttpURLConnection.HTTP_MOVED_PERM,
HttpURLConnection.HTTP_MOVED_TEMP -> assertContentType(cn.getHeaderField("Location"), type, subtype)
HttpURLConnection.HTTP_OK -> {
val ct = cn.contentType.substringBeforeLast(';').split("/")
Assert.assertEquals(type, ct.first())
if (subtype != null) {
Assert.assertEquals(subtype, ct.last())
}
}
else -> Assert.fail("Invalid response code $code")
}
}
fun assertContentType(url: String, type: String, subtype: String? = null) {
Assert.assertFalse("URL is empty", url.isEmpty())
val cn = URL(url).openConnection() as HttpURLConnection
cn.requestMethod = "HEAD"
cn.connect()
when (val code = cn.responseCode) {
HttpURLConnection.HTTP_MOVED_PERM,
HttpURLConnection.HTTP_MOVED_TEMP -> assertContentType(cn.getHeaderField("Location"), type, subtype)
HttpURLConnection.HTTP_OK -> {
val ct = cn.contentType.substringBeforeLast(';').split("/")
Assert.assertEquals(type, ct.first())
if (subtype != null) {
Assert.assertEquals(subtype, ct.last())
}
}
else -> Assert.fail("Invalid response code $code")
}
}
}