Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 92c77b03 authored by Hasib Prince's avatar Hasib Prince
Browse files

test: unit test added for gplaylogin

parent eebcf131
Loading
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -93,4 +93,10 @@ dependencies {
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.5'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

    testImplementation "org.mockito:mockito-core:5.0.0"
    // Optional -- mockito-kotlin
    testImplementation "org.mockito.kotlin:mockito-kotlin:4.1.0"
    testImplementation 'org.mockito:mockito-inline:5.0.0'
    testImplementation "io.mockk:mockk:1.12.3"
}
 No newline at end of file
+7 −3
Original line number Diff line number Diff line
package app.lounge

import com.aurora.gplayapi.data.models.PlayResponse
import com.aurora.gplayapi.network.IHttpClient

class FakeGplayHttpClient : IHttpClient {

    var shouldThrowException = false

    override fun get(url: String, headers: Map<String, String>): PlayResponse {
        TODO("Not yet implemented")
    }
@@ -25,7 +26,10 @@ class FakeGplayHttpClient : IHttpClient {
    }

    override fun post(url: String, headers: Map<String, String>, body: ByteArray): PlayResponse {
        TODO("Not yet implemented")
        if (shouldThrowException) {
            throw RuntimeException()
        }
        return PlayResponse()
    }

    override fun post(
+34 −0
Original line number Diff line number Diff line
package app.lounge

import app.lounge.login.google.GoogleLoginApi
import app.lounge.login.google.GoogleLoginApiImpl
import app.lounge.networking.GplayHttpClient
import app.lounge.networking.NetworkResult
import com.aurora.gplayapi.data.models.AuthData
import com.aurora.gplayapi.helpers.AuthHelper
import com.aurora.gplayapi.helpers.AuthValidator
import io.mockk.every
import io.mockk.mockkObject
import kotlinx.coroutines.runBlocking
import okhttp3.OkHttpClient
import org.junit.Test
import org.mockito.Mockito
import java.util.concurrent.TimeUnit

class GoogleLoginApiTest {

    private val gplayHttpClient = GplayHttpClient(getOkHttpClient())

    private fun getOkHttpClient(
        timeoutInMillisecond: Long = 10000L
    ): OkHttpClient = OkHttpClient.Builder()
        .callTimeout(timeoutInMillisecond, TimeUnit.MILLISECONDS)
        .build()
    private val gplayHttpClient = FakeGplayHttpClient()

    private val googleLoginApi: GoogleLoginApi = GoogleLoginApiImpl(gplayHttpClient)
    private var googleLoginApi: GoogleLoginApi = GoogleLoginApiImpl(gplayHttpClient)

    @Test
    fun testFetchAASTokenSuccess() = runBlocking {
        val result = googleLoginApi.fetchAASToken("aa@aa.com", "123432w3")
         assert(result is NetworkResult.Success)
    }

    @Test
    fun testFetchAASTokenError() = runBlocking {
        gplayHttpClient.shouldThrowException = true
        val result = googleLoginApi.fetchAASToken("aa@aa.com", "123432w3")
        assert(result is NetworkResult.Error)
    }
}
 No newline at end of file