diff --git a/api/build.gradle b/api/build.gradle index 4fa10611..28b127dd 100644 --- a/api/build.gradle +++ b/api/build.gradle @@ -49,6 +49,7 @@ dependencies { androidTestImplementation 'androidx.test:rules:1.3.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' androidTestImplementation 'com.squareup.okhttp3:mockwebserver:4.9.0' + androidTestImplementation "org.koin:koin-test:2.1.6" testImplementation "org.koin:koin-test:2.1.6" implementation 'com.gitlab.mvysny.konsume-xml:konsume-xml:0.12' diff --git a/api/src/androidTest/java/com/readrops/api/localfeed/LocalRSSDataSourceTest.kt b/api/src/androidTest/java/com/readrops/api/localfeed/LocalRSSDataSourceTest.kt index 34fa8826..bda2241a 100644 --- a/api/src/androidTest/java/com/readrops/api/localfeed/LocalRSSDataSourceTest.kt +++ b/api/src/androidTest/java/com/readrops/api/localfeed/LocalRSSDataSourceTest.kt @@ -4,31 +4,42 @@ import android.accounts.NetworkErrorException import android.content.Context import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry +import com.readrops.api.apiModule import com.readrops.api.utils.ApiUtils import com.readrops.api.utils.exceptions.ParseException import com.readrops.api.utils.exceptions.UnknownFormatException import junit.framework.TestCase.* import okhttp3.Headers import okhttp3.HttpUrl -import okhttp3.OkHttpClient import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer import okio.Buffer 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.test.KoinTest +import org.koin.test.KoinTestRule +import org.koin.test.inject import java.net.HttpURLConnection @RunWith(AndroidJUnit4::class) -class LocalRSSDataSourceTest { +class LocalRSSDataSourceTest : KoinTest { - private val context: Context = InstrumentationRegistry.getInstrumentation().context + private val context: Context by inject() private lateinit var url: HttpUrl private val mockServer: MockWebServer = MockWebServer() - private val localRSSDataSource = LocalRSSDataSource(OkHttpClient()) + private val localRSSDataSource by inject() + + @get:Rule + val koinTestRule = KoinTestRule.create { + androidContext(InstrumentationRegistry.getInstrumentation().context) + modules(apiModule) + } @Before fun before() {