diff --git a/workflow-rx2/src/test/java/com/squareup/workflow/rx2/RxWorkersTest.kt b/workflow-rx2/src/test/java/com/squareup/workflow/rx2/RxWorkersTest.kt index bca6613ab5..4075fe57a8 100644 --- a/workflow-rx2/src/test/java/com/squareup/workflow/rx2/RxWorkersTest.kt +++ b/workflow-rx2/src/test/java/com/squareup/workflow/rx2/RxWorkersTest.kt @@ -15,7 +15,7 @@ */ package com.squareup.workflow.rx2 -import com.squareup.workflow.testing.launchForTestingWith +import com.squareup.workflow.testing.test import io.reactivex.BackpressureStrategy.MISSING import io.reactivex.Flowable import io.reactivex.Maybe @@ -40,7 +40,7 @@ class RxWorkersTest { // Should support out-projected parameters. val worker = (subject as Observable).asWorker() - worker.launchForTestingWith { + worker.test { subject.onNext("foo") assertEquals("foo", nextOutput()) @@ -53,7 +53,7 @@ class RxWorkersTest { val subject = PublishSubject.create() val worker = subject.asWorker() - worker.launchForTestingWith { + worker.test { subject.onComplete() assertFinished() } @@ -63,7 +63,7 @@ class RxWorkersTest { val subject = PublishSubject.create() val worker = subject.asWorker() - worker.launchForTestingWith { + worker.test { subject.onNext("foo") assertEquals("foo", nextOutput()) @@ -76,7 +76,7 @@ class RxWorkersTest { val subject = PublishSubject.create() val worker = subject.asWorker() - worker.launchForTestingWith { + worker.test { subject.onError(ExpectedException()) assertTrue(getException() is ExpectedException) } @@ -90,7 +90,7 @@ class RxWorkersTest { assertEquals(0, subscriptions) - worker.launchForTestingWith { + worker.test { assertEquals(1, subscriptions) } } @@ -103,7 +103,7 @@ class RxWorkersTest { assertEquals(0, disposals) - worker.launchForTestingWith { + worker.test { assertEquals(0, disposals) cancelWorker() assertEquals(1, disposals) @@ -119,7 +119,7 @@ class RxWorkersTest { val worker = (subject.toFlowable(MISSING) as Flowable) .asWorker() - worker.launchForTestingWith { + worker.test { subject.onNext("foo") assertEquals("foo", nextOutput()) @@ -133,7 +133,7 @@ class RxWorkersTest { val worker = subject.toFlowable(MISSING) .asWorker() - worker.launchForTestingWith { + worker.test { subject.onComplete() assertFinished() } @@ -144,7 +144,7 @@ class RxWorkersTest { val worker = subject.toFlowable(MISSING) .asWorker() - worker.launchForTestingWith { + worker.test { subject.onNext("foo") assertEquals("foo", nextOutput()) @@ -158,7 +158,7 @@ class RxWorkersTest { val worker = subject.toFlowable(MISSING) .asWorker() - worker.launchForTestingWith { + worker.test { subject.onError(ExpectedException()) assertTrue(getException() is ExpectedException) } @@ -173,7 +173,7 @@ class RxWorkersTest { assertEquals(0, subscriptions) - worker.launchForTestingWith { + worker.test { assertEquals(1, subscriptions) } } @@ -187,7 +187,7 @@ class RxWorkersTest { assertEquals(0, cancels) - worker.launchForTestingWith { + worker.test { assertEquals(0, cancels) cancelWorker() assertEquals(1, cancels) @@ -202,7 +202,7 @@ class RxWorkersTest { val subject = MaybeSubject.create() val worker = (subject as Maybe).asWorker() - worker.launchForTestingWith { + worker.test { subject.onSuccess("foo") assertEquals("foo", nextOutput()) assertFinished() @@ -213,7 +213,7 @@ class RxWorkersTest { val subject = MaybeSubject.create() val worker = subject.asWorker() - worker.launchForTestingWith { + worker.test { subject.onComplete() assertFinished() } @@ -223,7 +223,7 @@ class RxWorkersTest { val subject = MaybeSubject.create() val worker = subject.asWorker() - worker.launchForTestingWith { + worker.test { subject.onError(ExpectedException()) assertTrue(getException() is ExpectedException) } @@ -237,7 +237,7 @@ class RxWorkersTest { assertEquals(0, subscriptions) - worker.launchForTestingWith { + worker.test { assertEquals(1, subscriptions) } } @@ -250,7 +250,7 @@ class RxWorkersTest { assertEquals(0, cancels) - worker.launchForTestingWith { + worker.test { assertEquals(0, cancels) cancelWorker() assertEquals(1, cancels) @@ -265,7 +265,7 @@ class RxWorkersTest { val subject = SingleSubject.create() val worker = (subject as Single).asWorker() - worker.launchForTestingWith { + worker.test { subject.onSuccess("foo") assertEquals("foo", nextOutput()) assertFinished() @@ -276,7 +276,7 @@ class RxWorkersTest { val subject = SingleSubject.create() val worker = subject.asWorker() - worker.launchForTestingWith { + worker.test { subject.onError(ExpectedException()) assertTrue(getException() is ExpectedException) } @@ -290,7 +290,7 @@ class RxWorkersTest { assertEquals(0, subscriptions) - worker.launchForTestingWith { + worker.test { assertEquals(1, subscriptions) } } @@ -303,7 +303,7 @@ class RxWorkersTest { assertEquals(0, cancels) - worker.launchForTestingWith { + worker.test { assertEquals(0, cancels) cancelWorker() assertEquals(1, cancels) @@ -318,7 +318,7 @@ class RxWorkersTest { val subject = CompletableSubject.create() val worker = subject.asWorker() - worker.launchForTestingWith { + worker.test { subject.onComplete() assertFinished() } @@ -328,7 +328,7 @@ class RxWorkersTest { val subject = CompletableSubject.create() val worker = subject.asWorker() - worker.launchForTestingWith { + worker.test { subject.onError(ExpectedException()) assertTrue(getException() is ExpectedException) } @@ -342,7 +342,7 @@ class RxWorkersTest { assertEquals(0, subscriptions) - worker.launchForTestingWith { + worker.test { assertEquals(1, subscriptions) } } @@ -355,7 +355,7 @@ class RxWorkersTest { assertEquals(0, cancels) - worker.launchForTestingWith { + worker.test { assertEquals(0, cancels) cancelWorker() assertEquals(1, cancels) diff --git a/workflow-testing/api/workflow-testing.api b/workflow-testing/api/workflow-testing.api index 9dc91b3f8d..8d21df15b9 100644 --- a/workflow-testing/api/workflow-testing.api +++ b/workflow-testing/api/workflow-testing.api @@ -52,8 +52,8 @@ public abstract interface class com/squareup/workflow/testing/WorkerTester { } public final class com/squareup/workflow/testing/WorkerTesterKt { - public static final fun launchForTestingWith (Lcom/squareup/workflow/Worker;JLkotlin/jvm/functions/Function2;)V - public static synthetic fun launchForTestingWith$default (Lcom/squareup/workflow/Worker;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V + public static final fun test (Lcom/squareup/workflow/Worker;JLkotlin/jvm/functions/Function2;)V + public static synthetic fun test$default (Lcom/squareup/workflow/Worker;JLkotlin/jvm/functions/Function2;ILjava/lang/Object;)V } public final class com/squareup/workflow/testing/WorkflowTestParams { diff --git a/workflow-testing/src/main/java/com/squareup/workflow/testing/WorkerTester.kt b/workflow-testing/src/main/java/com/squareup/workflow/testing/WorkerTester.kt index 504a636380..35f917d4b8 100644 --- a/workflow-testing/src/main/java/com/squareup/workflow/testing/WorkerTester.kt +++ b/workflow-testing/src/main/java/com/squareup/workflow/testing/WorkerTester.kt @@ -67,7 +67,7 @@ interface WorkerTester { /** * Test a [Worker] by defining assertions on its output within [block]. */ -fun Worker.launchForTestingWith( +fun Worker.test( timeoutMs: Long = DEFAULT_TIMEOUT_MS, block: suspend WorkerTester.() -> Unit ) { diff --git a/workflow-testing/src/test/java/com/squareup/workflow/FlowWorkersTest.kt b/workflow-testing/src/test/java/com/squareup/workflow/FlowWorkersTest.kt index e263e188b9..5d7ee8d468 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow/FlowWorkersTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow/FlowWorkersTest.kt @@ -17,7 +17,7 @@ package com.squareup.workflow -import com.squareup.workflow.testing.launchForTestingWith +import com.squareup.workflow.testing.test import kotlinx.coroutines.CancellationException import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.consumeEach @@ -38,7 +38,7 @@ class FlowWorkersTest { private val worker by lazy { source.asWorker() } @Test fun `flow emits`() { - worker.launchForTestingWith { + worker.test { subject.send("foo") assertEquals("foo", nextOutput()) @@ -48,14 +48,14 @@ class FlowWorkersTest { } @Test fun `flow finishes`() { - worker.launchForTestingWith { + worker.test { subject.close() assertFinished() } } @Test fun `flow finishes after emitting interleaved`() { - worker.launchForTestingWith { + worker.test { subject.send("foo") assertEquals("foo", nextOutput()) @@ -65,7 +65,7 @@ class FlowWorkersTest { } @Test fun `flow finishes after emitting grouped`() { - worker.launchForTestingWith { + worker.test { subject.send("foo") subject.close() @@ -75,7 +75,7 @@ class FlowWorkersTest { } @Test fun `flow throws`() { - worker.launchForTestingWith { + worker.test { subject.close(ExpectedException()) assertTrue(getException() is ExpectedException) } @@ -87,7 +87,7 @@ class FlowWorkersTest { assertEquals(0, collections) - worker.launchForTestingWith { + worker.test { assertEquals(1, collections) } } @@ -98,7 +98,7 @@ class FlowWorkersTest { assertEquals(0, cancellations) - worker.launchForTestingWith { + worker.test { assertEquals(0, cancellations) cancelWorker() assertEquals(1, cancellations) diff --git a/workflow-testing/src/test/java/com/squareup/workflow/LifecycleWorkerTest.kt b/workflow-testing/src/test/java/com/squareup/workflow/LifecycleWorkerTest.kt index 477f361adf..0a190089d0 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow/LifecycleWorkerTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow/LifecycleWorkerTest.kt @@ -17,7 +17,7 @@ package com.squareup.workflow -import com.squareup.workflow.testing.launchForTestingWith +import com.squareup.workflow.testing.test import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.Unconfined import kotlinx.coroutines.flow.launchIn @@ -55,7 +55,7 @@ class LifecycleWorkerTest { } } - worker.launchForTestingWith { + worker.test { assertFalse(onCancelledCalled) cancelWorker() diff --git a/workflow-testing/src/test/java/com/squareup/workflow/WorkerTest.kt b/workflow-testing/src/test/java/com/squareup/workflow/WorkerTest.kt index 234208a0b7..7edc363328 100644 --- a/workflow-testing/src/test/java/com/squareup/workflow/WorkerTest.kt +++ b/workflow-testing/src/test/java/com/squareup/workflow/WorkerTest.kt @@ -17,7 +17,7 @@ package com.squareup.workflow -import com.squareup.workflow.testing.launchForTestingWith +import com.squareup.workflow.testing.test import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.buffer import kotlinx.coroutines.flow.conflate @@ -59,7 +59,7 @@ class WorkerTest { emit("world") } - worker.launchForTestingWith { + worker.test { assertEquals("hello", nextOutput()) assertEquals("world", nextOutput()) assertFinished() @@ -69,7 +69,7 @@ class WorkerTest { @Test fun `create finishes without emitting`() { val worker = Worker.create {} - worker.launchForTestingWith { + worker.test { assertFinished() } } @@ -77,7 +77,7 @@ class WorkerTest { @Test fun `create propagates exceptions`() { val worker = Worker.create { throw ExpectedException() } - worker.launchForTestingWith { + worker.test { assertTrue(getException() is ExpectedException) } } @@ -96,7 +96,7 @@ class WorkerTest { ran = true } - worker.launchForTestingWith { + worker.test { assertTrue(ran) } } @@ -104,7 +104,7 @@ class WorkerTest { @Test fun `createSideEffect finishes`() { val worker = Worker.createSideEffect {} - worker.launchForTestingWith { + worker.test { assertFinished() } } @@ -112,7 +112,7 @@ class WorkerTest { @Test fun `createSideEffect propagates exceptions`() { val worker = Worker.createSideEffect { throw ExpectedException() } - worker.launchForTestingWith { + worker.test { assertTrue(getException() is ExpectedException) } } @@ -120,7 +120,7 @@ class WorkerTest { @Test fun `from emits and finishes`() { val worker = Worker.from { "foo" } - worker.launchForTestingWith { + worker.test { assertEquals("foo", nextOutput()) assertFinished() } @@ -129,7 +129,7 @@ class WorkerTest { @Test fun `from emits null`() { val worker = Worker.from { null } - worker.launchForTestingWith { + worker.test { assertEquals(null, nextOutput()) assertFinished() } @@ -138,7 +138,7 @@ class WorkerTest { @Test fun `fromNullable emits and finishes`() { val worker = Worker.fromNullable { "foo" } - worker.launchForTestingWith { + worker.test { assertEquals("foo", nextOutput()) assertFinished() } @@ -147,7 +147,7 @@ class WorkerTest { @Test fun `fromNullable doesn't emit null`() { val worker = Worker.fromNullable { null } - worker.launchForTestingWith { + worker.test { assertFinished() } } @@ -173,7 +173,7 @@ class WorkerTest { // Run the timer on the test dispatcher so we can control time. .transform { it.flowOn(testDispatcher) } - worker.launchForTestingWith { + worker.test { assertNoOutput() assertNotFinished()