Created
February 21, 2021 12:04
-
-
Save shredderskelton/d91870d18750df8eee671c0c9ed46efa to your computer and use it in GitHub Desktop.
Cold Flow Turbine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Unit Testing Cold Flows with Turbine | |
*/ | |
@Test | |
fun `cold flow - take multiple - Turbine`() { | |
runBlocking { | |
flow { | |
emit("test") | |
emit("test") | |
}.test { | |
assertThat(expectItem()).isEqualTo("test") | |
assertThat(expectItem()).isEqualTo("test") | |
expectComplete() | |
} | |
} | |
} | |
@Test | |
fun `cold flow - take multiple - alternative - Turbine`() { | |
runBlocking { | |
flow { | |
emit("test") | |
emit("test") | |
}.test { | |
val actual = cancelAndConsumeRemainingEvents() | |
assertThat(actual).containsExactly( | |
Event.Item("test"), | |
Event.Item("test"), | |
Event.Complete | |
) | |
} | |
} | |
} | |
@Test | |
fun `cold flow - take too little - Turbine - catches our implementation change!`() { | |
runBlocking { | |
flow { | |
emit("test") | |
emit("test") | |
emit("test") // Added an extra emission, simulating an implementation change | |
}.test { | |
assertThat(expectItem()).isEqualTo("test") | |
assertThat(expectItem()).isEqualTo("test") | |
expectComplete() | |
} | |
} | |
} | |
@Test | |
fun `cold flow - take too much - Turbine -- catches our implementation change!`() { | |
runBlocking { | |
flow { | |
emit("test") | |
// Deleted the second emission, simulating an implementation change | |
}.test { | |
assertThat(expectItem()).isEqualTo("test") | |
assertThat(expectItem()).isEqualTo("test") | |
expectComplete() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment