Skip to content

Commit

Permalink
Update CredentialsManagerMethodCallHandlerTest.kt
Browse files Browse the repository at this point in the history
  • Loading branch information
poovamraj committed Jul 11, 2023
1 parent e70d70f commit df56941
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.auth0.auth0_flutter

import android.app.Activity
import android.content.Context
import android.content.SharedPreferences
import com.auth0.auth0_flutter.request_handlers.credentials_manager.ClearCredentialsRequestHandler
import com.auth0.auth0_flutter.request_handlers.credentials_manager.CredentialsManagerRequestHandler
Expand Down Expand Up @@ -33,12 +34,14 @@ class CredentialsManagerMethodCallHandlerTest {
arguments: HashMap<String, Any?> = defaultArguments,
requestHandlers: List<CredentialsManagerRequestHandler>,
activity: Activity? = null,
context: Context? = null,
onResult: (Result) -> Unit,
) {
val handler = CredentialsManagerMethodCallHandler(requestHandlers)
val mockResult = mock<Result>()

handler.activity = if (activity === null) mock() else activity
handler.context = if (context === null) mock() else context

handler.onMethodCall(MethodCall(method, arguments), mockResult)
onResult(mockResult)
Expand Down Expand Up @@ -69,15 +72,17 @@ class CredentialsManagerMethodCallHandlerTest {
`when`(clearCredentialsHandler.method).thenReturn("credentialsManager#clearCredentials")

val activity: Activity = mock()
val context: Context = mock()
val mockPrefs: SharedPreferences = mock()

`when`(activity.getSharedPreferences(any(), any()))
`when`(context.getSharedPreferences(any(), any()))
.thenReturn(mockPrefs)

val handler = CredentialsManagerMethodCallHandler(listOf(clearCredentialsHandler))
val mockResult = mock<Result>()

handler.activity = activity
handler.context = context
handler.credentialsManager = mock()

handler.onMethodCall(MethodCall(clearCredentialsHandler.method, defaultArguments), mockResult)
Expand All @@ -92,15 +97,17 @@ class CredentialsManagerMethodCallHandlerTest {
`when`(clearCredentialsHandler.method).thenReturn("credentialsManager#clearCredentials")

val activity: Activity = mock()
val context: Context = mock()
val mockPrefs: SharedPreferences = mock()

`when`(activity.getSharedPreferences(any(), any()))
`when`(context.getSharedPreferences(any(), any()))
.thenReturn(mockPrefs)

val handler = CredentialsManagerMethodCallHandler(listOf(clearCredentialsHandler))
val mockResult = mock<Result>()

handler.activity = activity
handler.context = context
handler.credentialsManager = mock()

handler.onMethodCall(MethodCall(clearCredentialsHandler.method, defaultArguments + hashMapOf("localAuthentication" to hashMapOf("title" to "test", "description" to "test description"))), mockResult)
Expand All @@ -115,15 +122,17 @@ class CredentialsManagerMethodCallHandlerTest {
`when`(clearCredentialsHandler.method).thenReturn("credentialsManager#clearCredentials")

val activity: Activity = mock()
val context: Context = mock()
val mockPrefs: SharedPreferences = mock()

`when`(activity.getSharedPreferences(any(), any()))
`when`(context.getSharedPreferences(any(), any()))
.thenReturn(mockPrefs)

val handler = CredentialsManagerMethodCallHandler(listOf(clearCredentialsHandler))
val mockResult = mock<Result>()

handler.activity = activity
handler.context = context
handler.credentialsManager = mock()

handler.onMethodCall(MethodCall(clearCredentialsHandler.method, defaultArguments + hashMapOf("localAuthentication" to hashMapOf<String, String>())), mockResult)
Expand All @@ -140,14 +149,15 @@ class CredentialsManagerMethodCallHandlerTest {
`when`(hasValidCredentialsHandler.method).thenReturn("credentialsManager#hasValidCredentials")

val activity: Activity = mock()
val context: Context = mock()
val mockPrefs: SharedPreferences = mock()

`when`(activity.getSharedPreferences(any(), any()))
`when`(context.getSharedPreferences(any(), any()))
.thenReturn(mockPrefs)

runCallHandler(clearCredentialsHandler.method, activity = activity, requestHandlers = listOf(clearCredentialsHandler, hasValidCredentialsHandler)) {
verify(clearCredentialsHandler).handle(any(), eq(activity), any(), any())
verify(hasValidCredentialsHandler, times(0)).handle(any(), eq(activity), any(), any())
runCallHandler(clearCredentialsHandler.method, activity = activity, context = context, requestHandlers = listOf(clearCredentialsHandler, hasValidCredentialsHandler)) {
verify(clearCredentialsHandler).handle(any(), eq(context), any(), any())
verify(hasValidCredentialsHandler, times(0)).handle(any(), eq(context), any(), any())
}
}

Expand Down

0 comments on commit df56941

Please sign in to comment.