From 720d1f433e0fed0ee48cbebdb8f995e5d5fc7405 Mon Sep 17 00:00:00 2001 From: Fabian Mastenbroek Date: Mon, 13 May 2019 20:45:49 +0200 Subject: bug: Replace initial behavior after starting coroutine This change fixes the bug where suspending immediately after launching the coroutine, without replacing the current behavior causes a failure in the BehaviorInterpreter. This is because the initial behavior was not properly set. --- .../src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'odcsim-core/src/test') diff --git a/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt b/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt index 98486149..d057024c 100644 --- a/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt +++ b/odcsim-core/src/test/kotlin/com/atlarge/odcsim/CoroutinesTest.kt @@ -32,19 +32,32 @@ import com.nhaarman.mockitokotlin2.mock import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.DisplayName import org.junit.jupiter.api.Test +import kotlin.coroutines.suspendCoroutine /** * Test suite for [SuspendingBehavior] using Kotlin Coroutines. */ @DisplayName("Coroutines") internal class CoroutinesTest { - private val ctx = mock>() @Test fun `should immediately return new behavior`() { + val ctx = mock>() val behavior = suspending { empty() } val interpreter = BehaviorInterpreter(behavior) interpreter.start(ctx) assertTrue(interpreter.behavior as Behavior<*> is EmptyBehavior) } + + @Test + fun `should be able to invoke regular suspend methods`() { + val ctx = mock>() + val behavior = suspending { + suspendCoroutine { cont -> } + stopped() + } + val interpreter = BehaviorInterpreter(behavior) + interpreter.start(ctx) + interpreter.interpretMessage(ctx, Unit) + } } -- cgit v1.2.3