• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3  */
4 
5 package kotlinx.coroutines.time
6 
7 import kotlinx.coroutines.TestBase
8 import kotlinx.coroutines.flow.flow
9 import kotlinx.coroutines.flow.toList
10 import kotlinx.coroutines.withVirtualTime
11 import org.junit.Test
12 import java.time.Duration
13 import kotlin.test.assertEquals
14 
15 class FlowDebounceTest : TestBase() {
16     @Test
<lambda>null17     public fun testBasic() = withVirtualTime {
18         expect(1)
19         val flow = flow {
20             expect(3)
21             emit("A")
22             delay(Duration.ofMillis(1500))
23             emit("B")
24             delay(Duration.ofMillis(500))
25             emit("C")
26             delay(Duration.ofMillis(250))
27             emit("D")
28             delay(Duration.ofMillis(2000))
29             emit("E")
30             expect(4)
31         }
32 
33         expect(2)
34         val result = flow.debounce(Duration.ofMillis(1000)).toList()
35         assertEquals(listOf("A", "D", "E"), result)
36         finish(5)
37     }
38 }