Skip to content

Commit

Permalink
Fix type parameter for expectWorker accepting Worker instance.
Browse files Browse the repository at this point in the history
The worker type should be unbounded, _not_ the same as the _Workflow's_ output type.
  • Loading branch information
zach-klippenstein committed Feb 15, 2020
1 parent e935fd0 commit e041de0
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ interface RenderTester<PropsT, StateT, OutputT : Any, RenderingT> {
/* ktlint-disable parameter-list-wrapping */
fun <PropsT, StateT, OutputT : Any, RenderingT>
RenderTester<PropsT, StateT, OutputT, RenderingT>.expectWorker(
doesSameWorkAs: Worker<OutputT>,
doesSameWorkAs: Worker<*>,
key: String = "",
output: EmittedOutput<OutputT>? = null
): RenderTester<PropsT, StateT, OutputT, RenderingT> = expectWorker(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,43 @@ class RealRenderTesterTest {
tester.expectWorker(matchesWhen = { true })
}

@Test fun `expectWorker taking Worker matches`() {
val worker = object : Worker<String> {
override fun doesSameWorkAs(otherWorker: Worker<*>) = otherWorker === this
override fun run() = emptyFlow<Nothing>()
}
val workflow = Workflow.stateless<Unit, Nothing, Unit> {
runningWorker(worker) { noAction() }
}

workflow.renderTester(Unit)
.expectWorker(worker)
.render()
}

@Test fun `expectWorker taking Worker doesn't match`() {
val worker1 = object : Worker<String> {
override fun doesSameWorkAs(otherWorker: Worker<*>) = otherWorker === this
override fun toString(): String = "Worker1"
override fun run() = emptyFlow<Nothing>()
}
val worker2 = object : Worker<String> {
override fun doesSameWorkAs(otherWorker: Worker<*>) = otherWorker === this
override fun toString(): String = "Worker2"
override fun run() = emptyFlow<Nothing>()
}
val workflow = Workflow.stateless<Unit, Nothing, Unit> {
runningWorker(worker1) { noAction() }
}
val tester = workflow.renderTester(Unit)
.expectWorker(worker2)

val error = assertFailsWith<AssertionError> {
tester.render()
}
assertEquals("Tried to render unexpected worker Worker1.", error.message)
}

@Test fun `sending to sink throws when called multiple times`() {
class TestAction(private val name: String) : WorkflowAction<Unit, Nothing> {
override fun Updater<Unit, Nothing>.apply() {}
Expand Down

0 comments on commit e041de0

Please sign in to comment.