diff --git a/dachlatten-google/build.gradle.kts b/dachlatten-google/build.gradle.kts index 40dac43..69a60d6 100644 --- a/dachlatten-google/build.gradle.kts +++ b/dachlatten-google/build.gradle.kts @@ -8,5 +8,4 @@ dependencies { compileOnly(libs.coroutines.playServices) testImplementation(libs.coroutines.playServices) - testImplementation(libs.bundles.mockk) } diff --git a/dachlatten-google/src/test/kotlin/de/sipgate/dachlatten/google/TaskAwaitResultTest.kt b/dachlatten-google/src/test/kotlin/de/sipgate/dachlatten/google/TaskAwaitResultTest.kt index b3167e1..89d6b66 100644 --- a/dachlatten-google/src/test/kotlin/de/sipgate/dachlatten/google/TaskAwaitResultTest.kt +++ b/dachlatten-google/src/test/kotlin/de/sipgate/dachlatten/google/TaskAwaitResultTest.kt @@ -1,25 +1,22 @@ package de.sipgate.dachlatten.google +import android.app.Activity +import com.google.android.gms.tasks.OnFailureListener +import com.google.android.gms.tasks.OnSuccessListener import com.google.android.gms.tasks.Task -import io.mockk.coEvery -import io.mockk.mockk -import kotlinx.coroutines.tasks.await import kotlinx.coroutines.test.runTest import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertFalse import org.junit.jupiter.api.Assertions.assertInstanceOf import org.junit.jupiter.api.Assertions.assertNull import org.junit.jupiter.api.Assertions.assertTrue -import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test +import java.util.concurrent.Executor class TaskAwaitResultTest { @Test - @Disabled fun resultHandlesSuccessCorrectly() = runTest { - val successfulTask = mockk> { - coEvery { await() } returns "success" - } + val successfulTask = DummyResult(success = "success") val result = successfulTask.awaitResult() assertTrue(result.isSuccess) @@ -29,11 +26,8 @@ class TaskAwaitResultTest { } @Test - @Disabled fun resultHandlesErrorCorrectly() = runTest { - val failingTask = mockk> { - coEvery { await() } throws Exception("you shall not pass!") - } + val failingTask = DummyResult(error = Exception("you shall not pass!")) val result = failingTask.awaitResult() assertFalse(result.isSuccess) @@ -41,4 +35,46 @@ class TaskAwaitResultTest { assertTrue(result.isFailure) assertInstanceOf(Exception::class.java, result.exceptionOrNull()) } + + private class DummyResult( + private val success: T? = null, + private val error: Throwable? = null + ) : Task() { + override fun isComplete(): Boolean = true + + override fun isSuccessful(): Boolean = success != null + + override fun isCanceled(): Boolean = false + + override fun getResult(): T? = success + + override fun getException(): java.lang.Exception? = error as? java.lang.Exception + override fun addOnSuccessListener(p0: Activity, p1: OnSuccessListener): Task { + TODO("Not yet implemented") + } + + override fun addOnSuccessListener(p0: Executor, p1: OnSuccessListener): Task { + TODO("Not yet implemented") + } + + override fun addOnSuccessListener(p0: OnSuccessListener): Task { + TODO("Not yet implemented") + } + + override fun getResult(p0: Class): T? { + TODO("Not yet implemented") + } + + override fun addOnFailureListener(p0: OnFailureListener): Task { + TODO("Not yet implemented") + } + + override fun addOnFailureListener(p0: Executor, p1: OnFailureListener): Task { + TODO("Not yet implemented") + } + + override fun addOnFailureListener(p0: Activity, p1: OnFailureListener): Task { + TODO("Not yet implemented") + } + } }