From f38eba1c4b0b8cfbfaf32a68d08aba81e3de909e Mon Sep 17 00:00:00 2001 From: Jan Seeger Date: Fri, 29 Sep 2023 16:07:17 +0200 Subject: [PATCH] Add printFlow test for nullable Flows --- .../de/sipgate/waffeleisen/flow/PrintFlowKtTest.kt | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/dachlatten-flow/src/test/java/de/sipgate/waffeleisen/flow/PrintFlowKtTest.kt b/dachlatten-flow/src/test/java/de/sipgate/waffeleisen/flow/PrintFlowKtTest.kt index 4860d12..b8a51f8 100644 --- a/dachlatten-flow/src/test/java/de/sipgate/waffeleisen/flow/PrintFlowKtTest.kt +++ b/dachlatten-flow/src/test/java/de/sipgate/waffeleisen/flow/PrintFlowKtTest.kt @@ -69,6 +69,19 @@ class PrintFlowKtTest { assertEquals(expected, stringBuffer.toString()) } + @Test + fun printFlowWorksWithNullableValues() = runTest { + val flow = flowOf("first", null, "third") + + val resultPrinted = mutableListOf() + val resultPassed = flow.printFlow( + printFunc = { resultPrinted.add(it) } + ).collectAsList() + + assertEquals(listOf("first", null, "third"), resultPassed) + assertEquals(listOf("first", "null", "third"), resultPrinted) + } + private suspend fun Flow.collectAsList() = mutableListOf().apply { this@collectAsList.map(this::add).collect()