Skip to content

Commit

Permalink
Add printFlow test for nullable Flows
Browse files Browse the repository at this point in the history
  • Loading branch information
janseeger committed Sep 29, 2023
1 parent 691c7e9 commit f38eba1
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,19 @@ class PrintFlowKtTest {
assertEquals(expected, stringBuffer.toString())
}

@Test
fun printFlowWorksWithNullableValues() = runTest {
val flow = flowOf("first", null, "third")

val resultPrinted = mutableListOf<String>()
val resultPassed = flow.printFlow(
printFunc = { resultPrinted.add(it) }
).collectAsList()

assertEquals(listOf("first", null, "third"), resultPassed)
assertEquals(listOf("first", "null", "third"), resultPrinted)
}

private suspend fun <T> Flow<T>.collectAsList() =
mutableListOf<T>().apply {
this@collectAsList.map(this::add).collect()
Expand Down

0 comments on commit f38eba1

Please sign in to comment.