From ba964ccce2410ea2b20314469a39874885b60cb1 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Wed, 7 Aug 2024 15:01:38 +0200 Subject: [PATCH] Fix FeverDataSource tests --- .../{adapters => }/FeverDataSourceTest.kt | 44 +++++++++---------- 1 file changed, 20 insertions(+), 24 deletions(-) rename api/src/test/java/com/readrops/api/services/fever/{adapters => }/FeverDataSourceTest.kt (59%) diff --git a/api/src/test/java/com/readrops/api/services/fever/adapters/FeverDataSourceTest.kt b/api/src/test/java/com/readrops/api/services/fever/FeverDataSourceTest.kt similarity index 59% rename from api/src/test/java/com/readrops/api/services/fever/adapters/FeverDataSourceTest.kt rename to api/src/test/java/com/readrops/api/services/fever/FeverDataSourceTest.kt index 92c07fa2..61ec5874 100644 --- a/api/src/test/java/com/readrops/api/services/fever/adapters/FeverDataSourceTest.kt +++ b/api/src/test/java/com/readrops/api/services/fever/FeverDataSourceTest.kt @@ -1,19 +1,15 @@ -package com.readrops.api.services.fever.adapters +package com.readrops.api.services.fever import com.readrops.api.TestUtils import com.readrops.api.apiModule -import com.readrops.api.services.fever.FeverCredentials -import com.readrops.api.services.fever.FeverDataSource import com.readrops.api.utils.ApiUtils import com.readrops.api.utils.AuthInterceptor -import com.readrops.api.utils.exceptions.LoginFailedException -import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.test.runTest import okhttp3.OkHttpClient import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer import okio.Buffer import org.junit.After -import org.junit.Assert.assertThrows import org.junit.Before import org.junit.Rule import org.junit.Test @@ -24,6 +20,8 @@ import org.koin.test.KoinTestRule import org.koin.test.get import java.net.HttpURLConnection import java.util.concurrent.TimeUnit +import kotlin.test.assertFalse +import kotlin.test.assertTrue class FeverDataSourceTest : KoinTest { @@ -49,40 +47,38 @@ class FeverDataSourceTest : KoinTest { modules(apiModule, module { single { OkHttpClient.Builder() - .callTimeout(1, TimeUnit.MINUTES) - .readTimeout(1, TimeUnit.HOURS) - .addInterceptor(get()) - .build() + .callTimeout(1, TimeUnit.MINUTES) + .readTimeout(1, TimeUnit.HOURS) + .addInterceptor(get()) + .build() } }) } @Test - fun loginSuccessfulTest() { + fun loginSuccessfulTest() = runTest { val stream = TestUtils.loadResource("services/fever/successful_auth.json") - mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) + mockServer.enqueue( + MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) .addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/json") - .setBody(Buffer().readFrom(stream))) + .setBody(Buffer().readFrom(stream)) + ) - runBlocking { - dataSource.login("","") - } + assertTrue { dataSource.login("", "") } } @Test - fun loginFailedTest() { + fun loginFailedTest() = runTest { val stream = TestUtils.loadResource("services/fever/failed_auth.json") - mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) + mockServer.enqueue( + MockResponse().setResponseCode(HttpURLConnection.HTTP_OK) .addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/json") - .setBody(Buffer().readFrom(stream))) + .setBody(Buffer().readFrom(stream)) + ) - assertThrows(LoginFailedException::class.java) { - runBlocking { - dataSource.login("","") - } - } + assertFalse { dataSource.login("", "") } } } \ No newline at end of file