aboutsummaryrefslogtreecommitdiffstats
path: root/kotlinx-coroutines-core/common/test/flow/terminal/LastTest.kt
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-08-23 23:55:41 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-08-23 23:55:41 +0000
commitffe1b7dc19f3fbe1bc4a5f4f1e28c64cd68c5371 (patch)
tree747e5be83c6e6a2e2d9a164ebd03c5e45e6ec952 /kotlinx-coroutines-core/common/test/flow/terminal/LastTest.kt
parent2bbecd60d31b5d0b48847f67e741018f5ae7aa07 (diff)
parent531d55eaeac09ad6cde55687ef802d4235040985 (diff)
downloadplatform_external_kotlinx.coroutines-ffe1b7dc19f3fbe1bc4a5f4f1e28c64cd68c5371.tar.gz
platform_external_kotlinx.coroutines-ffe1b7dc19f3fbe1bc4a5f4f1e28c64cd68c5371.tar.bz2
platform_external_kotlinx.coroutines-ffe1b7dc19f3fbe1bc4a5f4f1e28c64cd68c5371.zip
Snap for 7668063 from 531d55eaeac09ad6cde55687ef802d4235040985 to simpleperf-releasesimpleperf-release
Change-Id: I844c9c61f2e31a265c36a483e1509e0e08c508d6
Diffstat (limited to 'kotlinx-coroutines-core/common/test/flow/terminal/LastTest.kt')
-rw-r--r--kotlinx-coroutines-core/common/test/flow/terminal/LastTest.kt45
1 files changed, 45 insertions, 0 deletions
diff --git a/kotlinx-coroutines-core/common/test/flow/terminal/LastTest.kt b/kotlinx-coroutines-core/common/test/flow/terminal/LastTest.kt
new file mode 100644
index 00000000..e7699ccc
--- /dev/null
+++ b/kotlinx-coroutines-core/common/test/flow/terminal/LastTest.kt
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
+ */
+
+package kotlinx.coroutines.flow
+
+import kotlinx.coroutines.*
+import kotlin.test.*
+
+class LastTest : TestBase() {
+ @Test
+ fun testLast() = runTest {
+ val flow = flowOf(1, 2, 3)
+ assertEquals(3, flow.last())
+ assertEquals(3, flow.lastOrNull())
+ }
+
+ @Test
+ fun testNulls() = runTest {
+ val flow = flowOf(1, null)
+ assertNull(flow.last())
+ assertNull(flow.lastOrNull())
+ }
+
+ @Test
+ fun testNullsLastOrNull() = runTest {
+ val flow = flowOf(null, 1)
+ assertEquals(1, flow.lastOrNull())
+ }
+
+ @Test
+ fun testEmptyFlow() = runTest {
+ assertFailsWith<NoSuchElementException> { emptyFlow<Int>().last() }
+ assertNull(emptyFlow<Int>().lastOrNull())
+ }
+
+ @Test
+ fun testBadClass() = runTest {
+ val instance = BadClass()
+ val flow = flowOf(instance)
+ assertSame(instance, flow.last())
+ assertSame(instance, flow.lastOrNull())
+
+ }
+}