Skip to content

Commit 2feee2b

Browse files
author
Thomas Leing
committed
Use mockk for instantiating challenges
1 parent 7ab7615 commit 2feee2b

File tree

1 file changed

+48
-27
lines changed

1 file changed

+48
-27
lines changed

liveness/src/androidTest/java/com/amplifyframework/ui/liveness/LivenessFlowInstrumentationTest.kt

Lines changed: 48 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import androidx.compose.ui.test.onNodeWithText
1010
import androidx.compose.ui.test.performClick
1111
import androidx.test.platform.app.InstrumentationRegistry
1212
import androidx.test.rule.GrantPermissionRule
13-
import com.amplifyframework.annotations.InternalAmplifyApi
1413
import com.amplifyframework.auth.AuthSession
1514
import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin
1615
import com.amplifyframework.core.Action
@@ -36,6 +35,7 @@ import io.mockk.OfTypeMatcher
3635
import io.mockk.Runs
3736
import io.mockk.every
3837
import io.mockk.just
38+
import io.mockk.mockk
3939
import io.mockk.mockkConstructor
4040
import io.mockk.mockkObject
4141
import io.mockk.mockkStatic
@@ -234,7 +234,7 @@ class LivenessFlowInstrumentationTest {
234234
var completesSuccessfully = false
235235
composeTestRule.setContent {
236236
FaceLivenessDetector(sessionId = sessionId, region = "us-east-1", onComplete = {
237-
completesSuccessfully = true
237+
completesSuccessfully = true
238238
}, onError = { assertTrue(false) })
239239
}
240240

@@ -295,38 +295,59 @@ class LivenessFlowInstrumentationTest {
295295
.fetchSemanticsNodes().size == 1
296296
}
297297

298-
@OptIn(InternalAmplifyApi::class)
299-
val faceTargetChallenge = FaceTargetChallenge(
300-
422f, 683f, 230f, 292f,
301-
FaceTargetMatchingParameters(
302-
0.7f,
303-
0.25f,
304-
0.25f,
305-
0.15f,
306-
0.15f
307-
)
298+
val faceTargetMatchingParameters = mockk<FaceTargetMatchingParameters>()
299+
every { faceTargetMatchingParameters.targetIouThreshold }.returns(0.7f)
300+
every { faceTargetMatchingParameters.targetIouWidthThreshold }.returns(0.25f)
301+
every { faceTargetMatchingParameters.targetIouHeightThreshold }.returns(0.25f)
302+
every { faceTargetMatchingParameters.faceIouWidthThreshold }.returns(0.15f)
303+
every { faceTargetMatchingParameters.faceIouHeightThreshold }.returns(0.15f)
304+
305+
val faceTargetChallenge = mockk<FaceTargetChallenge>()
306+
every { faceTargetChallenge.targetWidth }.returns(422f)
307+
every { faceTargetChallenge.targetHeight }.returns(683f)
308+
every { faceTargetChallenge.targetCenterX }.returns(230f)
309+
every { faceTargetChallenge.targetCenterY }.returns(292f)
310+
every { faceTargetChallenge.faceTargetMatching }.returns(faceTargetMatchingParameters)
311+
312+
val colors = listOf(
313+
RgbColor(0, 0, 0),
314+
RgbColor(0, 255, 255),
315+
RgbColor(255, 0, 0),
316+
RgbColor(0, 255, 0),
317+
RgbColor(0, 0, 255),
318+
RgbColor(255, 255, 0),
319+
RgbColor(0, 255, 0),
320+
RgbColor(255, 0, 0),
308321
)
309-
val colorChallenge = ColorChallenge(
310-
"id",
311-
ColorChallengeType.SEQUENTIAL,
312-
listOf(
313-
ColorDisplayInformation(RgbColor(0,0,0), 75f, false),
314-
ColorDisplayInformation(RgbColor(0,255,255), 475f, false),
315-
ColorDisplayInformation(RgbColor(255,0,0), 475f, false),
316-
ColorDisplayInformation(RgbColor(0,255,0), 475f, false),
317-
ColorDisplayInformation(RgbColor(0,0,255), 475f, false),
318-
ColorDisplayInformation(RgbColor(255,255,0), 475f, false),
319-
ColorDisplayInformation(RgbColor(0,255,0), 475f, false),
320-
ColorDisplayInformation(RgbColor(255,0,0), 475f, false),
321-
)
322+
val durations = listOf(
323+
75f,
324+
475f,
325+
475f,
326+
475f,
327+
475f,
328+
475f,
329+
475f,
330+
475f,
322331
)
332+
val challengeColors = List(colors.size) {
333+
val colorDisplayInformation = mockk<ColorDisplayInformation>()
334+
every { colorDisplayInformation.color }.returns(colors[it])
335+
every { colorDisplayInformation.duration }.returns(durations[it])
336+
every { colorDisplayInformation.shouldScroll }.returns(false)
337+
colorDisplayInformation
338+
}
339+
val colorChallenge = mockk<ColorChallenge>()
340+
every { colorChallenge.challengeId }.returns("id")
341+
every { colorChallenge.challengeType }.returns(ColorChallengeType.SEQUENTIAL)
342+
every { colorChallenge.challengeColors }.returns(challengeColors)
343+
323344
onSessionStarted.captured.accept(
324345
FaceLivenessSession(
325346
listOf(faceTargetChallenge, colorChallenge),
326347
{}, // onVideoEvent
327348
{}, // onChallengeResponseEvent
328-
{} // stopLivenessSession
329-
)
349+
{}, // stopLivenessSession
350+
),
330351
)
331352

332353
composeTestRule.waitUntil(5000) {

0 commit comments

Comments
 (0)