Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test parseRecentReleaseJson #92

Merged
merged 1 commit into from
Oct 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ package kitefoundation.tech.domain.utils

import divyansh.tech.animeclassroom.ResultWrapper.Success
import divyansh.tech.animeclassroom.models.home.AnimeDetailModel
import divyansh.tech.animeclassroom.models.home.AnimeModel
import divyansh.tech.animeclassroom.utils.Parser.parseAnimeDetails
import divyansh.tech.animeclassroom.utils.Parser.parsePopularAnimeJson
import divyansh.tech.animeclassroom.utils.Parser.parseRecentReleaseJson
import kotlinx.coroutines.runBlocking
import org.junit.Assert.*
import org.junit.Ignore
import org.junit.Test
import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.lang.Exception
import java.util.*

class ParserTest {
Expand Down Expand Up @@ -49,11 +49,22 @@ class ParserTest {
val response = html.let { parsePopularAnimeJson(it) }

assertEquals(response.data?.size, 2)

assertEquals(response.data?.first()?.name, "Jujutsu Kaisen (TV)")
assertEquals(response.data?.first()?.imageUrl, "https://gogocdn.net/cover/jujutsu-kaisen-tv.png")
assertEquals(response.data?.first()?.releaseDate, "2020")
assertEquals(response.data?.first()?.animeUrl, "/category/jujutsu-kaisen-tv")
assertNull(response.data?.first()?.episodeUrl)
assertNull(response.data?.first()?.episodeNumber)
assertNull(response.data?.first()?.genre)

assertEquals(response.data?.last()?.name, "Jujutsu Kaisen (TV) (Dub)")
assertEquals(response.data?.last()?.imageUrl, "https://gogocdn.net/cover/jujutsu-kaisen-tv-dub.png")
assertEquals(response.data?.last()?.releaseDate, "2020")
assertEquals(response.data?.last()?.animeUrl, "/category/jujutsu-kaisen-tv-dub")
assertNull(response.data?.last()?.episodeUrl)
assertNull(response.data?.last()?.episodeNumber)
assertNull(response.data?.last()?.genre)
}

@Test
Expand All @@ -73,6 +84,47 @@ class ParserTest {
assertEquals(response.message, "Index 0 out of bounds for length 0")
}

@Test
fun parseRecentReleaseJsonTest(): Unit = runBlocking {
val html = FileUtil.readFileFromResources("popularAnime.html")
val response = html.let { parseRecentReleaseJson(it) }

assertEquals((response.data as ArrayList<*>).size, 60)

assertEquals(((response.data as ArrayList<*>).first() as AnimeModel).name, "Assault Lily: Fruits")
assertEquals(((response.data as ArrayList<*>).first() as AnimeModel).imageUrl, "https://gogocdn.net/cover/assault-lily-fruits.png")
assertNull(((response.data as ArrayList<*>).first() as AnimeModel).releaseDate)
assertNull(((response.data as ArrayList<*>).first() as AnimeModel).animeUrl)
assertEquals(((response.data as ArrayList<*>).first() as AnimeModel).episodeUrl, "/assault-lily-fruits-episode-7")
assertEquals(((response.data as ArrayList<*>).first() as AnimeModel).episodeNumber, "Episode 7")
assertNull(((response.data as ArrayList<*>).first() as AnimeModel).genre)

assertEquals(((response.data as ArrayList<*>).last() as AnimeModel).name, "Yu☆Gi☆Oh!: Sevens")
assertEquals(((response.data as ArrayList<*>).last() as AnimeModel).imageUrl, "https://gogocdn.net/cover/yugioh-sevens.png")
assertNull(((response.data as ArrayList<*>).last() as AnimeModel).releaseDate)
assertNull(((response.data as ArrayList<*>).last() as AnimeModel).animeUrl)
assertEquals(((response.data as ArrayList<*>).last() as AnimeModel).episodeUrl, "/yugioh-sevens-episode-69")
assertEquals(((response.data as ArrayList<*>).last() as AnimeModel).episodeNumber, "Episode 69")
assertNull(((response.data as ArrayList<*>).last() as AnimeModel).genre)
}

@Test
fun parseRecentReleaseJsonEmptyTest(): Unit = runBlocking {
val html = ""
val response = html.let { parseRecentReleaseJson(it) }

assertTrue((response.data as Collection<*>).isNullOrEmpty())
}

@Test
fun parseRecentReleaseJsonExceptionTest(): Unit = runBlocking {
val html = FileUtil.readFileFromResources("popularAnimeErro.html")
val response = html.let { parseRecentReleaseJson(it) }

assertNull(response.data)
assertEquals(response.message, "Index 0 out of bounds for length 0")
}

object FileUtil {
@Throws(IOException::class)
fun readFileFromResources(fileName: String): String {
Expand Down
Loading