1package com.peachpasswords.sync23import kotlinx.coroutines.async4import kotlinx.coroutines.test.runCurrent5import kotlinx.coroutines.test.runTest6import org.junit.Assert.assertFalse7import org.junit.Assert.assertTrue8import org.junit.Test9101112131415class SourceConsentGateTest {1617 @Test fun a_grant_waits_until_someone_decides() = runTest {18 val gate = SourceConsentGate()19 val decision = async { gate.await() }20 runCurrent()2122 assertFalse("must not approve before a decision exists", decision.isCompleted)2324 gate.resolve(true)25 assertTrue(decision.await())26 }2728 @Test fun leaving_the_screen_denies_rather_than_hanging() = runTest {29 val gate = SourceConsentGate()30 val decision = async { gate.await() }31 runCurrent()3233 gate.resolve(false)34 assertFalse(decision.await())35 }3637 @Test fun an_answer_with_no_live_prompt_is_ignored() = runTest {38 val gate = SourceConsentGate()39 gate.resolve(true)4041 val decision = async { gate.await() }42 runCurrent()43 assertFalse("a stale answer must not pre-approve a later prompt", decision.isCompleted)44 decision.cancel()45 }46}