From 8aec040fbcb3e08ff6969015f8d0d473266d8b3a Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Sat, 4 Sep 2021 18:18:53 +0200 Subject: [PATCH] Remove old getRSSContentTYpe method --- .../readrops/api/localfeed/LocalRSSHelper.kt | 33 +-------- .../api/localfeed/LocalRSSHelperTest.kt | 69 +++++++++---------- 2 files changed, 36 insertions(+), 66 deletions(-) diff --git a/api/src/main/java/com/readrops/api/localfeed/LocalRSSHelper.kt b/api/src/main/java/com/readrops/api/localfeed/LocalRSSHelper.kt index 8dc01da5..40bb5f6a 100644 --- a/api/src/main/java/com/readrops/api/localfeed/LocalRSSHelper.kt +++ b/api/src/main/java/com/readrops/api/localfeed/LocalRSSHelper.kt @@ -13,10 +13,6 @@ object LocalRSSHelper { private const val JSONFEED_CONTENT_TYPE = "application/feed+json" private const val JSON_CONTENT_TYPE = "application/json" - private const val RSS_1_REGEX = " RSSType.RSS_1 - RSS_2_REGEX.toRegex().containsMatchIn(string) -> RSSType.RSS_2 - ATOM_REGEX.toRegex().containsMatchIn(string) -> RSSType.ATOM - else -> RSSType.UNKNOWN - } - - reader.close() - content.close() - return type - } - @JvmStatic - fun isRSSType(type: String?): Boolean { - return if (type != null) getRSSType(type) != RSSType.UNKNOWN else false - } + fun isRSSType(type: String?): Boolean = + if (type != null) getRSSType(type) != RSSType.UNKNOWN else false fun guessRSSType(konsumer: Konsumer): RSSType = when { konsumer.checkRoot(RSS_1_ROOT_NAME) -> RSSType.RSS_1 diff --git a/api/src/test/java/com/readrops/api/localfeed/LocalRSSHelperTest.kt b/api/src/test/java/com/readrops/api/localfeed/LocalRSSHelperTest.kt index 74414ce6..5ec458e4 100644 --- a/api/src/test/java/com/readrops/api/localfeed/LocalRSSHelperTest.kt +++ b/api/src/test/java/com/readrops/api/localfeed/LocalRSSHelperTest.kt @@ -1,5 +1,7 @@ package com.readrops.api.localfeed +import com.gitlab.mvysny.konsumexml.Names +import com.gitlab.mvysny.konsumexml.konsumeXml import junit.framework.TestCase.* import org.junit.Test import java.io.ByteArrayInputStream @@ -31,49 +33,46 @@ class LocalRSSHelperTest { } @Test - fun rss1ContentTest() { - assertEquals(LocalRSSHelper.getRSSContentType(ByteArrayInputStream( - """ - - + + + + """.trimIndent() + val konsumer = xml.konsumeXml().nextElement(Names.of("RDF"))!! - @Test - fun rss2ContentTest() { - assertEquals(LocalRSSHelper.getRSSContentType(ByteArrayInputStream( - """ - """.toByteArray() - )), LocalRSSHelper.RSSType.RSS_2) + assertEquals(LocalRSSHelper.guessRSSType(konsumer), LocalRSSHelper.RSSType.RSS_1) } @Test - fun atomContentTest() { - assertEquals(LocalRSSHelper.getRSSContentType(ByteArrayInputStream( - """ - - """.toByteArray() - )), LocalRSSHelper.RSSType.ATOM) + fun guessRSSTypeATOMTest() { + val xml = """ + + + + + """.trimIndent() + + val konsumer = xml.konsumeXml().nextElement(Names.of("feed"))!! + + assertEquals(LocalRSSHelper.guessRSSType(konsumer), LocalRSSHelper.RSSType.ATOM) + } @Test - fun unknownContentTest() { - assertEquals(LocalRSSHelper.getRSSContentType(ByteArrayInputStream( - """ - - - """.trimMargin().toByteArray() - )), LocalRSSHelper.RSSType.UNKNOWN) + fun guessRSSTypeRSS2Test() { + val xml = """ + + + + + """.trimIndent() + + val konsumer = xml.konsumeXml().nextElement(Names.of("rss"))!! + + assertEquals(LocalRSSHelper.guessRSSType(konsumer), LocalRSSHelper.RSSType.RSS_2) }