Move api androidTest/ tests to test/
It's useless to make an instrumented test if Context is only used to retrieve a resource file. It can be done with classLoader
This commit is contained in:
parent
749145b305
commit
a8e3a689d5
@ -48,7 +48,7 @@ dependencies {
|
||||
androidTestImplementation 'androidx.test:runner:1.3.0'
|
||||
androidTestImplementation 'androidx.test:rules:1.3.0'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
|
||||
androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.9.0'
|
||||
testImplementation 'com.squareup.okhttp3:mockwebserver:4.9.0'
|
||||
androidTestImplementation "org.koin:koin-test:2.1.6"
|
||||
testImplementation "org.koin:koin-test:2.1.6"
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
package com.readrops.api.utils
|
||||
|
||||
import android.net.Uri
|
||||
import com.readrops.api.services.Credentials
|
||||
import com.readrops.api.services.freshrss.FreshRSSService
|
||||
import com.readrops.api.services.nextcloudnews.NextNewsService
|
||||
import com.readrops.db.entities.account.Account
|
||||
import com.readrops.db.entities.account.AccountType
|
||||
import okhttp3.Interceptor
|
||||
import okhttp3.Response
|
||||
import java.lang.IllegalArgumentException
|
||||
import java.net.URI
|
||||
|
||||
class AuthInterceptor(var credentials: Credentials? = null) : Interceptor {
|
||||
|
||||
@ -18,11 +13,11 @@ class AuthInterceptor(var credentials: Credentials? = null) : Interceptor {
|
||||
|
||||
if (credentials != null) {
|
||||
if (credentials!!.url != null) {
|
||||
val uri = Uri.parse(credentials!!.url)
|
||||
val uri = URI.create(credentials!!.url)
|
||||
urlBuilder
|
||||
.scheme(uri.scheme!!)
|
||||
.host(uri.host!!)
|
||||
.encodedPath(uri.encodedPath + chain.request().url.encodedPath)
|
||||
.encodedPath(uri.path + chain.request().url.encodedPath)
|
||||
}
|
||||
|
||||
if (credentials!!.authorization != null) {
|
||||
|
9
api/src/test/java/com/readrops/api/TestUtils.kt
Normal file
9
api/src/test/java/com/readrops/api/TestUtils.kt
Normal file
@ -0,0 +1,9 @@
|
||||
package com.readrops.api
|
||||
|
||||
import java.io.InputStream
|
||||
|
||||
object TestUtils {
|
||||
|
||||
fun loadResource(path: String): InputStream =
|
||||
javaClass.classLoader?.getResourceAsStream(path)!!
|
||||
}
|
@ -1,10 +1,7 @@
|
||||
package com.readrops.api.localfeed
|
||||
|
||||
import android.accounts.NetworkErrorException
|
||||
import android.content.Context
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.icapps.niddler.interceptor.okhttp.NiddlerOkHttpInterceptor
|
||||
import com.readrops.api.TestUtils
|
||||
import com.readrops.api.apiModule
|
||||
import com.readrops.api.utils.ApiUtils
|
||||
import com.readrops.api.utils.AuthInterceptor
|
||||
@ -21,8 +18,6 @@ import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.koin.android.ext.koin.androidContext
|
||||
import org.koin.dsl.module
|
||||
import org.koin.test.KoinTest
|
||||
import org.koin.test.KoinTestRule
|
||||
@ -31,10 +26,8 @@ import java.net.HttpURLConnection
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class LocalRSSDataSourceTest : KoinTest {
|
||||
|
||||
private val context by inject<Context>()
|
||||
private lateinit var url: HttpUrl
|
||||
|
||||
private val mockServer: MockWebServer = MockWebServer()
|
||||
@ -42,7 +35,6 @@ class LocalRSSDataSourceTest : KoinTest {
|
||||
|
||||
@get:Rule
|
||||
val koinTestRule = KoinTestRule.create {
|
||||
androidContext(InstrumentationRegistry.getInstrumentation().context)
|
||||
modules(apiModule, module {
|
||||
single(override = true) {
|
||||
OkHttpClient.Builder()
|
||||
@ -67,7 +59,7 @@ class LocalRSSDataSourceTest : KoinTest {
|
||||
|
||||
@Test
|
||||
fun successfulQueryTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss_feed.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss_feed.xml")
|
||||
|
||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/xml; charset=UTF-8")
|
||||
@ -91,7 +83,7 @@ class LocalRSSDataSourceTest : KoinTest {
|
||||
|
||||
@Test
|
||||
fun headersTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss_feed.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss_feed.xml")
|
||||
|
||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.addHeader("Content-Type", "application/rss+xml; charset=UTF-8")
|
||||
@ -108,7 +100,7 @@ class LocalRSSDataSourceTest : KoinTest {
|
||||
|
||||
@Test
|
||||
fun jsonFeedTest() {
|
||||
val stream = context.resources.assets.open("localfeed/json/json_feed.json")
|
||||
val stream = TestUtils.loadResource("localfeed/json/json_feed.json")
|
||||
|
||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/feed+json")
|
||||
@ -122,7 +114,7 @@ class LocalRSSDataSourceTest : KoinTest {
|
||||
|
||||
@Test
|
||||
fun specialCasesAtomTest() {
|
||||
val stream = context.resources.assets.open("localfeed/atom/atom_feed_no_url_siteurl.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/atom/atom_feed_no_url_siteurl.xml")
|
||||
|
||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/atom+xml")
|
||||
@ -136,7 +128,7 @@ class LocalRSSDataSourceTest : KoinTest {
|
||||
|
||||
@Test
|
||||
fun specialCasesRSS1Test() {
|
||||
val stream = context.resources.assets.open("localfeed/rss1/rss1_feed_no_url_siteurl.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss1/rss1_feed_no_url_siteurl.xml")
|
||||
|
||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/rdf+xml")
|
@ -7,18 +7,23 @@ import com.readrops.api.localfeed.rss1.RSS1ItemsAdapter
|
||||
import com.readrops.api.localfeed.rss2.RSS2FeedAdapter
|
||||
import com.readrops.api.localfeed.rss2.RSS2ItemsAdapter
|
||||
import junit.framework.TestCase.assertTrue
|
||||
import org.junit.Assert
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.ExpectedException
|
||||
|
||||
class XmlAdapterTest {
|
||||
|
||||
@get:Rule
|
||||
val expectedException: ExpectedException = ExpectedException.none()
|
||||
|
||||
@Test
|
||||
fun xmlFeedAdapterFactoryTest() {
|
||||
assertTrue(XmlAdapter.xmlFeedAdapterFactory(LocalRSSHelper.RSSType.RSS_1) is RSS1FeedAdapter)
|
||||
assertTrue(XmlAdapter.xmlFeedAdapterFactory(LocalRSSHelper.RSSType.RSS_2) is RSS2FeedAdapter)
|
||||
assertTrue(XmlAdapter.xmlFeedAdapterFactory(LocalRSSHelper.RSSType.ATOM) is ATOMFeedAdapter)
|
||||
|
||||
Assert.assertThrows(IllegalArgumentException::class.java) { XmlAdapter.xmlFeedAdapterFactory(LocalRSSHelper.RSSType.UNKNOWN) }
|
||||
expectedException.expect(IllegalArgumentException::class.java)
|
||||
XmlAdapter.xmlFeedAdapterFactory(LocalRSSHelper.RSSType.UNKNOWN)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -27,6 +32,7 @@ class XmlAdapterTest {
|
||||
assertTrue(XmlAdapter.xmlItemsAdapterFactory(LocalRSSHelper.RSSType.RSS_2) is RSS2ItemsAdapter)
|
||||
assertTrue(XmlAdapter.xmlItemsAdapterFactory(LocalRSSHelper.RSSType.ATOM) is ATOMItemsAdapter)
|
||||
|
||||
Assert.assertThrows(IllegalArgumentException::class.java) { XmlAdapter.xmlItemsAdapterFactory(LocalRSSHelper.RSSType.UNKNOWN) }
|
||||
expectedException.expect(IllegalArgumentException::class.java)
|
||||
XmlAdapter.xmlItemsAdapterFactory(LocalRSSHelper.RSSType.UNKNOWN)
|
||||
}
|
||||
}
|
@ -1,22 +1,16 @@
|
||||
package com.readrops.api.localfeed.atom
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.readrops.api.TestUtils
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ATOMFeedAdapterTest {
|
||||
|
||||
private val context: Context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
||||
private val adapter = ATOMFeedAdapter()
|
||||
|
||||
@Test
|
||||
fun normalCasesTest() {
|
||||
val stream = context.assets.open("localfeed/atom/atom_feed.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/atom/atom_feed.xml")
|
||||
|
||||
val feed = adapter.fromXml(stream)
|
||||
|
@ -1,25 +1,24 @@
|
||||
package com.readrops.api.localfeed.atom
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.readrops.api.TestUtils
|
||||
import com.readrops.api.utils.DateUtils
|
||||
import com.readrops.api.utils.exceptions.ParseException
|
||||
import junit.framework.TestCase.*
|
||||
import org.junit.Assert
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import junit.framework.TestCase.assertNotNull
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.rules.ExpectedException
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class ATOMItemsAdapterTest {
|
||||
|
||||
private val context: Context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
||||
private val adapter = ATOMItemsAdapter()
|
||||
|
||||
@get:Rule
|
||||
val expectedException: ExpectedException = ExpectedException.none()
|
||||
|
||||
@Test
|
||||
fun normalCasesTest() {
|
||||
val stream = context.resources.assets.open("localfeed/atom/atom_items.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/atom/atom_items.xml")
|
||||
|
||||
val items = adapter.fromXml(stream)
|
||||
val item = items[0]
|
||||
@ -36,7 +35,7 @@ class ATOMItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun noDateTest() {
|
||||
val stream = context.resources.assets.open("localfeed/atom/atom_items_no_date.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/atom/atom_items_no_date.xml")
|
||||
|
||||
val item = adapter.fromXml(stream).first()
|
||||
assertNotNull(item.pubDate)
|
||||
@ -44,18 +43,22 @@ class ATOMItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun noTitleTest() {
|
||||
val stream = context.resources.assets.open("localfeed/atom/atom_items_no_title.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/atom/atom_items_no_title.xml")
|
||||
|
||||
val exception = Assert.assertThrows(ParseException::class.java) { adapter.fromXml(stream) }
|
||||
assertTrue(exception.message!!.contains("Item title is required"))
|
||||
expectedException.expect(ParseException::class.java)
|
||||
expectedException.expectMessage("Item title is required")
|
||||
|
||||
adapter.fromXml(stream)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun noLinkTest() {
|
||||
val stream = context.resources.assets.open("localfeed/atom/atom_items_no_link.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/atom/atom_items_no_link.xml")
|
||||
|
||||
val exception = Assert.assertThrows(ParseException::class.java) { adapter.fromXml(stream) }
|
||||
assertTrue(exception.message!!.contains("Item link is required"))
|
||||
expectedException.expect(ParseException::class.java)
|
||||
expectedException.expectMessage("Item link is required")
|
||||
|
||||
adapter.fromXml(stream)
|
||||
}
|
||||
|
||||
}
|
@ -1,28 +1,22 @@
|
||||
package com.readrops.api.localfeed.json
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.readrops.api.TestUtils
|
||||
import com.readrops.db.entities.Feed
|
||||
import com.squareup.moshi.Moshi
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import okio.Buffer
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class JSONFeedAdapterTest {
|
||||
|
||||
private val context: Context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
||||
private val adapter = Moshi.Builder()
|
||||
.add(JSONFeedAdapter())
|
||||
.build()
|
||||
.adapter<Feed>(Feed::class.java)
|
||||
.adapter(Feed::class.java)
|
||||
|
||||
@Test
|
||||
fun normalCasesTest() {
|
||||
val stream = context.assets.open("localfeed/json/json_feed.json")
|
||||
val stream = TestUtils.loadResource("localfeed/json/json_feed.json")
|
||||
|
||||
val feed = adapter.fromJson(Buffer().readFrom(stream))!!
|
||||
|
@ -1,33 +1,32 @@
|
||||
package com.readrops.api.localfeed.json
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.readrops.api.TestUtils
|
||||
import com.readrops.api.utils.DateUtils
|
||||
import com.readrops.api.utils.exceptions.ParseException
|
||||
import com.readrops.db.entities.Item
|
||||
import com.squareup.moshi.Moshi
|
||||
import com.squareup.moshi.Types
|
||||
import junit.framework.TestCase.*
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import junit.framework.TestCase.assertNotNull
|
||||
import okio.Buffer
|
||||
import org.junit.Assert
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.rules.ExpectedException
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class JSONItemsAdapterTest {
|
||||
|
||||
private val context: Context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
||||
private val adapter = Moshi.Builder()
|
||||
.add(Types.newParameterizedType(List::class.java, Item::class.java), JSONItemsAdapter())
|
||||
.build()
|
||||
.adapter<List<Item>>(Types.newParameterizedType(List::class.java, Item::class.java))
|
||||
|
||||
@get:Rule
|
||||
val expectedException: ExpectedException = ExpectedException.none()
|
||||
|
||||
@Test
|
||||
fun normalCasesTest() {
|
||||
val stream = context.resources.assets.open("localfeed/json/json_feed.json")
|
||||
val stream = TestUtils.loadResource("localfeed/json/json_feed.json")
|
||||
|
||||
val items = adapter.fromJson(Buffer().readFrom(stream))!!
|
||||
val item = items.first()
|
||||
@ -43,7 +42,7 @@ class JSONItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun otherCasesTest() {
|
||||
val stream = context.resources.assets.open("localfeed/json/json_items_other_cases.json")
|
||||
val stream = TestUtils.loadResource("localfeed/json/json_items_other_cases.json")
|
||||
|
||||
val item = adapter.fromJson(Buffer().readFrom(stream))!!.first()
|
||||
|
||||
@ -55,7 +54,7 @@ class JSONItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun nullDateTest() {
|
||||
val stream = context.resources.assets.open("localfeed/json/json_items_no_date.json")
|
||||
val stream = TestUtils.loadResource("localfeed/json/json_items_no_date.json")
|
||||
|
||||
val item = adapter.fromJson(Buffer().readFrom(stream))!!.first()
|
||||
assertNotNull(item.pubDate)
|
||||
@ -63,18 +62,22 @@ class JSONItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun nullTitleTest() {
|
||||
val stream = context.resources.assets.open("localfeed/json/json_items_no_title.json")
|
||||
val stream = TestUtils.loadResource("localfeed/json/json_items_no_title.json")
|
||||
|
||||
val exception = Assert.assertThrows(ParseException::class.java) { adapter.fromJson(Buffer().readFrom(stream)) }
|
||||
assertTrue(exception.message!!.contains("Item title is required"))
|
||||
expectedException.expect(ParseException::class.java)
|
||||
expectedException.expectMessage("Item title is required")
|
||||
|
||||
adapter.fromJson(Buffer().readFrom(stream))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nullLinkTest() {
|
||||
val stream = context.resources.assets.open("localfeed/json/json_items_no_link.json")
|
||||
val stream = TestUtils.loadResource("localfeed/json/json_items_no_link.json")
|
||||
|
||||
val exception = Assert.assertThrows(ParseException::class.java) { adapter.fromJson(Buffer().readFrom(stream)) }
|
||||
assertTrue(exception.message!!.contains("Item link is required"))
|
||||
expectedException.expect(ParseException::class.java)
|
||||
expectedException.expectMessage("Item link is required")
|
||||
|
||||
adapter.fromJson(Buffer().readFrom(stream))
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +1,16 @@
|
||||
package com.readrops.api.localfeed.rss1
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.readrops.api.TestUtils
|
||||
import junit.framework.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class RSS1FeedAdapterTest {
|
||||
|
||||
private val context: Context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
||||
private val adapter = RSS1FeedAdapter()
|
||||
|
||||
@Test
|
||||
fun normalCaseTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss1/rss1_feed.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss1/rss1_feed.xml")
|
||||
|
||||
val feed = adapter.fromXml(stream)
|
||||
|
@ -1,25 +1,24 @@
|
||||
package com.readrops.api.localfeed.rss1
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.readrops.api.TestUtils
|
||||
import com.readrops.api.utils.DateUtils
|
||||
import com.readrops.api.utils.exceptions.ParseException
|
||||
import junit.framework.TestCase.*
|
||||
import org.junit.Assert
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import junit.framework.TestCase.assertNotNull
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.rules.ExpectedException
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class RSS1ItemsAdapterTest {
|
||||
|
||||
private val context: Context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
||||
private val adapter = RSS1ItemsAdapter()
|
||||
|
||||
@get:Rule
|
||||
val expectedException: ExpectedException = ExpectedException.none()
|
||||
|
||||
@Test
|
||||
fun normalCasesTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss1/rss1_feed.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss1/rss1_feed.xml")
|
||||
|
||||
val items = adapter.fromXml(stream)
|
||||
val item = items.first()
|
||||
@ -38,7 +37,7 @@ class RSS1ItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun specialCasesTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss1/rss1_items_special_cases.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss1/rss1_items_special_cases.xml")
|
||||
|
||||
val item = adapter.fromXml(stream).first()
|
||||
|
||||
@ -49,7 +48,7 @@ class RSS1ItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun nullDateTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss1/rss1_items_no_date.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss1/rss1_items_no_date.xml")
|
||||
|
||||
val item = adapter.fromXml(stream).first()
|
||||
assertNotNull(item.pubDate)
|
||||
@ -57,17 +56,21 @@ class RSS1ItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun nullTitleTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss1/rss1_items_no_title.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss1/rss1_items_no_title.xml")
|
||||
|
||||
val exception = Assert.assertThrows(ParseException::class.java) { adapter.fromXml(stream) }
|
||||
assertTrue(exception.message!!.contains("Item title is required"))
|
||||
expectedException.expect(ParseException::class.java)
|
||||
expectedException.expectMessage("Item title is required")
|
||||
|
||||
adapter.fromXml(stream)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun nullLinkTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss1/rss1_items_no_link.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss1/rss1_items_no_link.xml")
|
||||
|
||||
val exception = Assert.assertThrows(ParseException::class.java) { adapter.fromXml(stream) }
|
||||
assertTrue(exception.message!!.contains("RSS1 link or about element is required"))
|
||||
expectedException.expect(ParseException::class.java)
|
||||
expectedException.expectMessage("RSS1 link or about element is required")
|
||||
|
||||
adapter.fromXml(stream)
|
||||
}
|
||||
}
|
@ -1,23 +1,18 @@
|
||||
package com.readrops.api.localfeed.rss2
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.readrops.api.TestUtils
|
||||
import com.readrops.api.utils.exceptions.ParseException
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class RSS2FeedAdapterTest {
|
||||
|
||||
private val context: Context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
||||
private val adapter = RSS2FeedAdapter()
|
||||
|
||||
@Test
|
||||
fun normalCasesTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss2/rss_full_feed.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss2/rss_full_feed.xml")
|
||||
|
||||
val feed = adapter.fromXml(stream)
|
||||
|
||||
@ -30,7 +25,7 @@ class RSS2FeedAdapterTest {
|
||||
|
||||
@Test(expected = ParseException::class)
|
||||
fun nullTitleTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss2/rss_feed_special_cases.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss2/rss_feed_special_cases.xml")
|
||||
adapter.fromXml(stream)
|
||||
}
|
||||
}
|
@ -1,25 +1,24 @@
|
||||
package com.readrops.api.localfeed.rss2
|
||||
|
||||
import android.content.Context
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import com.readrops.api.TestUtils
|
||||
import com.readrops.api.utils.DateUtils
|
||||
import com.readrops.api.utils.exceptions.ParseException
|
||||
import junit.framework.TestCase.*
|
||||
import org.junit.Assert
|
||||
import junit.framework.TestCase.assertEquals
|
||||
import junit.framework.TestCase.assertNotNull
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.rules.ExpectedException
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class RSS2ItemsAdapterTest {
|
||||
|
||||
private val context: Context = InstrumentationRegistry.getInstrumentation().context
|
||||
|
||||
private val adapter = RSS2ItemsAdapter()
|
||||
|
||||
@get:Rule
|
||||
val expectedException: ExpectedException = ExpectedException.none()
|
||||
|
||||
@Test
|
||||
fun normalCasesTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss_feed.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss_feed.xml")
|
||||
|
||||
val items = adapter.fromXml(stream)
|
||||
val item = items.first()
|
||||
@ -35,7 +34,7 @@ class RSS2ItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun otherNamespacesTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss2/rss_items_other_namespaces.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss2/rss_items_other_namespaces.xml")
|
||||
val item = adapter.fromXml(stream).first()
|
||||
|
||||
assertEquals(item.guid, "guid")
|
||||
@ -46,7 +45,7 @@ class RSS2ItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun noDateTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss2/rss_items_no_date.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss2/rss_items_no_date.xml")
|
||||
val item = adapter.fromXml(stream).first()
|
||||
|
||||
assertNotNull(item.pubDate)
|
||||
@ -54,23 +53,27 @@ class RSS2ItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun noTitleTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss2/rss_items_no_title.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss2/rss_items_no_title.xml")
|
||||
|
||||
val exception = Assert.assertThrows(ParseException::class.java) { adapter.fromXml(stream) }
|
||||
assertTrue(exception.message!!.contains("Item title is required"))
|
||||
expectedException.expect(ParseException::class.java)
|
||||
expectedException.expectMessage("Item title is required")
|
||||
|
||||
adapter.fromXml(stream)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun noLinkTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss2/rss_items_no_link.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss2/rss_items_no_link.xml")
|
||||
|
||||
val exception = Assert.assertThrows(ParseException::class.java) { adapter.fromXml(stream) }
|
||||
assertTrue(exception.message!!.contains("Item link is required"))
|
||||
expectedException.expect(ParseException::class.java)
|
||||
expectedException.expectMessage("Item link is required")
|
||||
|
||||
adapter.fromXml(stream)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun enclosureTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss2/rss_items_enclosure.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss2/rss_items_enclosure.xml")
|
||||
val item = adapter.fromXml(stream).first()
|
||||
|
||||
assertEquals(item.imageLink, "https://image1.jpg")
|
||||
@ -78,7 +81,7 @@ class RSS2ItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun mediaContentTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss2/rss_items_media_content.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss2/rss_items_media_content.xml")
|
||||
val items = adapter.fromXml(stream)
|
||||
|
||||
assertEquals(items.first().imageLink, "https://image1.jpg")
|
||||
@ -87,7 +90,7 @@ class RSS2ItemsAdapterTest {
|
||||
|
||||
@Test
|
||||
fun mediaGroupTest() {
|
||||
val stream = context.resources.assets.open("localfeed/rss2/rss_items_media_group.xml")
|
||||
val stream = TestUtils.loadResource("localfeed/rss2/rss_items_media_group.xml")
|
||||
val item = adapter.fromXml(stream).first()
|
||||
|
||||
assertEquals(item.imageLink, "https://image1.jpg")
|
@ -67,7 +67,7 @@ class JsonReaderExtensionsTest {
|
||||
reader.beginObject()
|
||||
reader.nextName()
|
||||
|
||||
assertEquals(reader.nextNullableString(), "value")
|
||||
assertEquals(reader.nextNonEmptyString(), "value")
|
||||
reader.endObject()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user