Skip to content

Commit

Permalink
Add test dispatchers provider
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Sep 15, 2023
1 parent e505e31 commit 3764cfb
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@
*/
package dev.sasikanth.rss.reader.network

import dev.sasikanth.rss.reader.TestDispatchersProvider
import dev.sasikanth.rss.reader.atomXmlContent
import dev.sasikanth.rss.reader.feedUrl
import dev.sasikanth.rss.reader.models.remote.FeedPayload
import dev.sasikanth.rss.reader.models.remote.PostPayload
import dev.sasikanth.rss.reader.rssXmlContent
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest

@OptIn(ExperimentalCoroutinesApi::class)
class AndroidFeedParserTest {

private val feedParser = AndroidFeedParser(ioDispatcher = UnconfinedTestDispatcher())
private val feedParser = AndroidFeedParser(dispatchersProvider = TestDispatchersProvider())

@Test
fun parsingRssFeedShouldWorkCorrectly() = runTest {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright 2023 Sasikanth Miriyampalli
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dev.sasikanth.rss.reader

import dev.sasikanth.rss.reader.utils.DispatchersProvider
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.test.UnconfinedTestDispatcher

class TestDispatchersProvider : DispatchersProvider {

override val main: CoroutineDispatcher
get() = UnconfinedTestDispatcher()

override val io: CoroutineDispatcher
get() = UnconfinedTestDispatcher()

override val default: CoroutineDispatcher
get() = UnconfinedTestDispatcher()
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,19 @@
*/
package dev.sasikanth.rss.reader.network

import dev.sasikanth.rss.reader.TestDispatchersProvider
import dev.sasikanth.rss.reader.atomXmlContent
import dev.sasikanth.rss.reader.feedUrl
import dev.sasikanth.rss.reader.models.remote.FeedPayload
import dev.sasikanth.rss.reader.models.remote.PostPayload
import dev.sasikanth.rss.reader.rssXmlContent
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest

@OptIn(ExperimentalCoroutinesApi::class)
class IOSFeedParserTest {

private val feedParser = IOSFeedParser(ioDispatcher = UnconfinedTestDispatcher())
private val feedParser = IOSFeedParser(dispatchersProvider = TestDispatchersProvider())

@Test
fun parsingRssFeedShouldWorkCorrectly() = runTest {
Expand Down

0 comments on commit 3764cfb

Please sign in to comment.