diff --git a/app/build.gradle b/app/build.gradle index 941bda11cfa63af46ec962966bcd2846e6de6429..72dada80fb10856b090bf89b75b39461127f189b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -234,9 +234,11 @@ dependencies { // Coroutines def coroutines_version = "1.6.0" + def test_kotlin_version = "1.6.0" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version" implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version" testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version" + testImplementation "org.jetbrains.kotlin:kotlin-test:$test_kotlin_version" // Room def roomVersion = "2.4.1" diff --git a/app/src/test/java/foundation/e/apps/gplay/GplyHttpClientTest.kt b/app/src/test/java/foundation/e/apps/gplay/GplyHttpClientTest.kt index b0217740b32fef206355b8b586f771eba58e3647..f83637ca627ecc8370814b3db960af0fe2cac882 100644 --- a/app/src/test/java/foundation/e/apps/gplay/GplyHttpClientTest.kt +++ b/app/src/test/java/foundation/e/apps/gplay/GplyHttpClientTest.kt @@ -44,6 +44,7 @@ import org.mockito.Mock import org.mockito.Mockito import org.mockito.MockitoAnnotations import org.mockito.kotlin.any +import kotlin.test.assertFailsWith @OptIn(ExperimentalCoroutinesApi::class) class GplyHttpClientTest { @@ -122,31 +123,28 @@ class GplyHttpClientTest { @Test fun testPostAuthFailedWhenStatus429() = runTest { initMocksForStatus429() - try { - gPlayHttpClient.postAuth(FakeCall.FAKE_URL, "".toByteArray()) - } catch (e: Exception) { - assert429(e) + val exception = assertFailsWith { + gPlayHttpClient.get(FakeCall.FAKE_URL, mapOf(), mapOf()) } + assert429(exception) } @Test fun testGetWithMapParamsFailedWhenStatus429() = runTest { initMocksForStatus429() - try { + val exception = assertFailsWith { gPlayHttpClient.get(FakeCall.FAKE_URL, mapOf(), mapOf()) - } catch (e: Exception) { - assert429(e) } + assert429(exception) } @Test fun testGetWithStringParamsFailedWhenStatus429() = runTest { initMocksForStatus429() - try { - gPlayHttpClient.get(FakeCall.FAKE_URL, mapOf(), "") - } catch (e: Exception) { - assert429(e) + val exception = assertFailsWith { + gPlayHttpClient.get(FakeCall.FAKE_URL, mapOf(), mapOf()) } + assert429(exception) } private fun initMocksForStatus401() { @@ -157,10 +155,7 @@ class GplyHttpClientTest { } private suspend fun assert429(e: Exception) { - assertTrue( - "Status429", - e is GplayHttpRequestException && e.status == GPlayHttpClient.STATUS_CODE_TOO_MANY_REQUESTS - ) + assertTrue(e is GplayHttpRequestException && e.status == GPlayHttpClient.STATUS_CODE_TOO_MANY_REQUESTS) val event = EventBus.events.first() assertTrue(event is AppEvent.TooManyRequests) }