Fix LocalRSSDataSource tests
This commit is contained in:
parent
f2daac5068
commit
e548b44ac8
@ -77,6 +77,6 @@ dependencies {
|
||||
api 'io.reactivex.rxjava2:rxandroid:2.1.1'
|
||||
api 'org.jsoup:jsoup:1.13.1'
|
||||
|
||||
debugImplementation 'com.icapps.niddler:niddler:1.2.0'
|
||||
releaseImplementation 'com.icapps.niddler:niddler-noop:1.2.0'
|
||||
debugApi 'com.icapps.niddler:niddler:1.2.0'
|
||||
releaseApi 'com.icapps.niddler:niddler-noop:1.2.0'
|
||||
}
|
||||
|
@ -4,13 +4,16 @@ 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.apiModule
|
||||
import com.readrops.api.utils.ApiUtils
|
||||
import com.readrops.api.utils.AuthInterceptor
|
||||
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
|
||||
@ -20,16 +23,18 @@ 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
|
||||
import org.koin.test.inject
|
||||
import java.net.HttpURLConnection
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4::class)
|
||||
class LocalRSSDataSourceTest : KoinTest {
|
||||
|
||||
private val context: Context by inject()
|
||||
private val context by inject<Context>()
|
||||
private lateinit var url: HttpUrl
|
||||
|
||||
private val mockServer: MockWebServer = MockWebServer()
|
||||
@ -38,7 +43,15 @@ class LocalRSSDataSourceTest : KoinTest {
|
||||
@get:Rule
|
||||
val koinTestRule = KoinTestRule.create {
|
||||
androidContext(InstrumentationRegistry.getInstrumentation().context)
|
||||
modules(apiModule)
|
||||
modules(apiModule, module {
|
||||
single(override = true) {
|
||||
OkHttpClient.Builder()
|
||||
.callTimeout(1, TimeUnit.MINUTES)
|
||||
.readTimeout(1, TimeUnit.HOURS)
|
||||
.addInterceptor(get<AuthInterceptor>())
|
||||
.build()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@Before
|
||||
|
@ -1,7 +1,5 @@
|
||||
package com.readrops.api
|
||||
|
||||
import com.icapps.niddler.core.AndroidNiddler
|
||||
import com.icapps.niddler.core.Niddler
|
||||
import com.icapps.niddler.interceptor.okhttp.NiddlerOkHttpInterceptor
|
||||
import com.readrops.api.localfeed.LocalRSSDataSource
|
||||
import com.readrops.api.services.freshrss.FreshRSSDataSource
|
||||
@ -40,13 +38,13 @@ val apiModule = module {
|
||||
.build()
|
||||
}
|
||||
|
||||
single { AuthInterceptor() }
|
||||
|
||||
single { LocalRSSDataSource(get()) }
|
||||
|
||||
//region freshrss
|
||||
|
||||
single {
|
||||
FreshRSSDataSource(get())
|
||||
}
|
||||
single { FreshRSSDataSource(get()) }
|
||||
|
||||
single {
|
||||
get<Retrofit>(named("freshrssRetrofit"))
|
||||
@ -54,7 +52,7 @@ val apiModule = module {
|
||||
}
|
||||
|
||||
single(named("freshrssRetrofit")) {
|
||||
Retrofit.Builder() // url will be set dynamically in an interceptor
|
||||
Retrofit.Builder() // url will be set dynamically in AuthInterceptor
|
||||
.baseUrl(BASE_URL)
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.client(get<OkHttpClient>())
|
||||
@ -75,9 +73,7 @@ val apiModule = module {
|
||||
|
||||
//region nextcloud news
|
||||
|
||||
single {
|
||||
NextNewsDataSource(get())
|
||||
}
|
||||
single { NextNewsDataSource(get()) }
|
||||
|
||||
single {
|
||||
get<Retrofit>(named("nextcloudNewsRetrofit"))
|
||||
@ -85,7 +81,7 @@ val apiModule = module {
|
||||
}
|
||||
|
||||
single(named("nextcloudNewsRetrofit")) {
|
||||
Retrofit.Builder() // url will be set dynamically in an interceptor
|
||||
Retrofit.Builder() // url will be set dynamically in AuthInterceptor
|
||||
.baseUrl(BASE_URL)
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.client(get<OkHttpClient>())
|
||||
@ -102,18 +98,4 @@ val apiModule = module {
|
||||
}
|
||||
|
||||
//endregion nextcloud news
|
||||
|
||||
single { AuthInterceptor() }
|
||||
|
||||
single<Niddler> {
|
||||
val niddler = AndroidNiddler.Builder()
|
||||
.setNiddlerInformation(AndroidNiddler.fromApplication(get()))
|
||||
.setPort(0)
|
||||
.setMaxStackTraceSize(10)
|
||||
.build()
|
||||
|
||||
niddler.attachToApplication(get())
|
||||
|
||||
niddler.apply { start() }
|
||||
}
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package com.readrops.app
|
||||
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.icapps.niddler.core.AndroidNiddler
|
||||
import com.icapps.niddler.core.Niddler
|
||||
import com.readrops.app.account.AccountViewModel
|
||||
import com.readrops.app.addfeed.AddFeedsViewModel
|
||||
import com.readrops.app.feedsfolders.ManageFeedsFoldersViewModel
|
||||
@ -56,4 +58,16 @@ val appModule = module {
|
||||
single { GlideApp.with(androidApplication()) }
|
||||
|
||||
single { PreferenceManager.getDefaultSharedPreferences(androidContext()) }
|
||||
|
||||
single<Niddler> {
|
||||
val niddler = AndroidNiddler.Builder()
|
||||
.setNiddlerInformation(AndroidNiddler.fromApplication(get()))
|
||||
.setPort(0)
|
||||
.setMaxStackTraceSize(10)
|
||||
.build()
|
||||
|
||||
niddler.attachToApplication(get())
|
||||
|
||||
niddler.apply { start() }
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user