Improve test style
Get rid of Hamcrest, which is uncommon in this codebase, and
replace as many `assert` statements from other testing frameworks
as is reasonable with little automation by calls to
`kotlin.test.*`.
diff --git a/reactive/kotlinx-coroutines-rx2/test/CompletableTest.kt b/reactive/kotlinx-coroutines-rx2/test/CompletableTest.kt
index 04e8697..298b32b 100644
--- a/reactive/kotlinx-coroutines-rx2/test/CompletableTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/CompletableTest.kt
@@ -8,9 +8,8 @@
import io.reactivex.disposables.*
import io.reactivex.exceptions.*
import kotlinx.coroutines.*
-import org.hamcrest.core.*
-import org.junit.*
-import org.junit.Assert.*
+import org.junit.Test
+import kotlin.test.*
class CompletableTest : TestBase() {
@Test
@@ -40,8 +39,8 @@
expectUnreached()
}, { error ->
expect(5)
- assertThat(error, IsInstanceOf(RuntimeException::class.java))
- assertThat(error.message, IsEqual("OK"))
+ assertTrue(error is RuntimeException)
+ assertEquals("OK", error.message)
})
expect(3)
yield() // to completable coroutine
@@ -95,7 +94,7 @@
expectUnreached()
} catch (e: RuntimeException) {
finish(4)
- assertThat(e.message, IsEqual("OK"))
+ assertEquals("OK", e.message)
}
}
diff --git a/reactive/kotlinx-coroutines-rx2/test/ConvertTest.kt b/reactive/kotlinx-coroutines-rx2/test/ConvertTest.kt
index 758b632..a433665 100644
--- a/reactive/kotlinx-coroutines-rx2/test/ConvertTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/ConvertTest.kt
@@ -6,8 +6,9 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.*
-import org.junit.*
-import org.junit.Assert.*
+import org.junit.Assert
+import org.junit.Test
+import kotlin.test.*
class ConvertTest : TestBase() {
@Test
@@ -64,9 +65,9 @@
null
}
val maybe1 = d.asMaybe(Dispatchers.Unconfined)
- checkMaybeValue(maybe1, ::assertNull)
+ checkMaybeValue(maybe1, Assert::assertNull)
val maybe2 = d.asMaybe(Dispatchers.Unconfined)
- checkMaybeValue(maybe2, ::assertNull)
+ checkMaybeValue(maybe2, Assert::assertNull)
}
@Test
diff --git a/reactive/kotlinx-coroutines-rx2/test/FlowAsObservableTest.kt b/reactive/kotlinx-coroutines-rx2/test/FlowAsObservableTest.kt
index ab9e402..0908b34 100644
--- a/reactive/kotlinx-coroutines-rx2/test/FlowAsObservableTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/FlowAsObservableTest.kt
@@ -6,9 +6,8 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
-import org.hamcrest.core.*
-import org.junit.*
-import org.junit.Assert.*
+import org.junit.Test
+import kotlin.test.*
class FlowAsObservableTest : TestBase() {
@Test
@@ -39,7 +38,7 @@
expect(2)
observable.subscribe({ expectUnreached() }, { error ->
expect(4)
- assertThat(error, IsInstanceOf(RuntimeException::class.java))
+ assertTrue(error is RuntimeException)
assertEquals("OK", error.message)
})
finish(5)
diff --git a/reactive/kotlinx-coroutines-rx2/test/FlowableTest.kt b/reactive/kotlinx-coroutines-rx2/test/FlowableTest.kt
index aebf999..148d1f9 100644
--- a/reactive/kotlinx-coroutines-rx2/test/FlowableTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/FlowableTest.kt
@@ -6,7 +6,6 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.reactive.*
-import org.hamcrest.core.*
import org.junit.*
import org.junit.Test
import kotlin.test.*
@@ -22,7 +21,7 @@
expect(2)
observable.subscribe { value ->
expect(5)
- Assert.assertThat(value, IsEqual("OK"))
+ assertEquals("OK", value)
}
expect(3)
yield() // to started coroutine
@@ -41,8 +40,8 @@
expectUnreached()
}, { error ->
expect(5)
- Assert.assertThat(error, IsInstanceOf(RuntimeException::class.java))
- Assert.assertThat(error.message, IsEqual("OK"))
+ assertTrue(error is RuntimeException)
+ assertEquals("OK", error.message)
})
expect(3)
yield() // to started coroutine
diff --git a/reactive/kotlinx-coroutines-rx2/test/IntegrationTest.kt b/reactive/kotlinx-coroutines-rx2/test/IntegrationTest.kt
index ca7c0ca..4faebbd 100644
--- a/reactive/kotlinx-coroutines-rx2/test/IntegrationTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/IntegrationTest.kt
@@ -6,12 +6,11 @@
import io.reactivex.*
import kotlinx.coroutines.*
-import org.hamcrest.MatcherAssert.*
-import org.hamcrest.core.*
-import org.junit.*
+import org.junit.Test
import org.junit.runner.*
import org.junit.runners.*
import kotlin.coroutines.*
+import kotlin.test.*
@RunWith(Parameterized::class)
class IntegrationTest(
@@ -44,16 +43,16 @@
// does not send anything
}
assertNSE { observable.awaitFirst() }
- assertThat(observable.awaitFirstOrDefault("OK"), IsEqual("OK"))
- assertThat(observable.awaitFirstOrNull(), IsNull())
- assertThat(observable.awaitFirstOrElse { "ELSE" }, IsEqual("ELSE"))
+ assertEquals("OK", observable.awaitFirstOrDefault("OK"))
+ assertNull(observable.awaitFirstOrNull())
+ assertEquals("ELSE", observable.awaitFirstOrElse { "ELSE" })
assertNSE { observable.awaitLast() }
assertNSE { observable.awaitSingle() }
var cnt = 0
observable.collect {
cnt++
}
- assertThat(cnt, IsEqual(0))
+ assertEquals(0, cnt)
}
@Test
@@ -62,18 +61,18 @@
if (delay) delay(1)
send("OK")
}
- assertThat(observable.awaitFirst(), IsEqual("OK"))
- assertThat(observable.awaitFirstOrDefault("OK"), IsEqual("OK"))
- assertThat(observable.awaitFirstOrNull(), IsEqual("OK"))
- assertThat(observable.awaitFirstOrElse { "ELSE" }, IsEqual("OK"))
- assertThat(observable.awaitLast(), IsEqual("OK"))
- assertThat(observable.awaitSingle(), IsEqual("OK"))
+ assertEquals("OK", observable.awaitFirst())
+ assertEquals("OK", observable.awaitFirstOrDefault("OK"))
+ assertEquals("OK", observable.awaitFirstOrNull())
+ assertEquals("OK", observable.awaitFirstOrElse { "ELSE" })
+ assertEquals("OK", observable.awaitLast())
+ assertEquals("OK", observable.awaitSingle())
var cnt = 0
observable.collect {
- assertThat(it, IsEqual("OK"))
+ assertEquals("OK", it)
cnt++
}
- assertThat(cnt, IsEqual(1))
+ assertEquals(1, cnt)
}
@Test
@@ -85,11 +84,11 @@
if (delay) delay(1)
}
}
- assertThat(observable.awaitFirst(), IsEqual(1))
- assertThat(observable.awaitFirstOrDefault(0), IsEqual(1))
- assertThat(observable.awaitFirstOrNull(), IsEqual(1))
- assertThat(observable.awaitFirstOrElse { 0 }, IsEqual(1))
- assertThat(observable.awaitLast(), IsEqual(n))
+ assertEquals(1, observable.awaitFirst())
+ assertEquals(1, observable.awaitFirstOrDefault(0))
+ assertEquals(1, observable.awaitFirstOrNull())
+ assertEquals(1, observable.awaitFirstOrElse { 0 })
+ assertEquals(n, observable.awaitLast())
assertIAE { observable.awaitSingle() }
checkNumbers(n, observable)
val channel = observable.openSubscription()
@@ -127,9 +126,9 @@
private suspend fun checkNumbers(n: Int, observable: Observable<Int>) {
var last = 0
observable.collect {
- assertThat(it, IsEqual(++last))
+ assertEquals(++last, it)
}
- assertThat(last, IsEqual(n))
+ assertEquals(n, last)
}
@@ -138,7 +137,7 @@
block()
expectUnreached()
} catch (e: Throwable) {
- assertThat(e, IsInstanceOf(IllegalArgumentException::class.java))
+ assertTrue(e is IllegalArgumentException)
}
}
@@ -147,7 +146,7 @@
block()
expectUnreached()
} catch (e: Throwable) {
- assertThat(e, IsInstanceOf(NoSuchElementException::class.java))
+ assertTrue(e is NoSuchElementException)
}
}
}
\ No newline at end of file
diff --git a/reactive/kotlinx-coroutines-rx2/test/MaybeTest.kt b/reactive/kotlinx-coroutines-rx2/test/MaybeTest.kt
index deca961..08427dc 100644
--- a/reactive/kotlinx-coroutines-rx2/test/MaybeTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/MaybeTest.kt
@@ -10,11 +10,11 @@
import io.reactivex.functions.*
import io.reactivex.internal.functions.Functions.*
import kotlinx.coroutines.*
-import org.hamcrest.core.*
import org.junit.*
-import org.junit.Assert.*
+import org.junit.Test
import java.util.concurrent.*
import java.util.concurrent.CancellationException
+import kotlin.test.*
class MaybeTest : TestBase() {
@Before
@@ -32,7 +32,7 @@
expect(2)
maybe.subscribe { value ->
expect(5)
- assertThat(value, IsEqual("OK"))
+ assertEquals("OK", value)
}
expect(3)
yield() // to started coroutine
@@ -67,8 +67,8 @@
expectUnreached()
}, { error ->
expect(5)
- assertThat(error, IsInstanceOf(RuntimeException::class.java))
- assertThat(error.message, IsEqual("OK"))
+ assertTrue(error is RuntimeException)
+ assertEquals("OK", error.message)
})
expect(3)
yield() // to started coroutine
diff --git a/reactive/kotlinx-coroutines-rx2/test/ObservableMultiTest.kt b/reactive/kotlinx-coroutines-rx2/test/ObservableMultiTest.kt
index 6971918..074fcf4 100644
--- a/reactive/kotlinx-coroutines-rx2/test/ObservableMultiTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/ObservableMultiTest.kt
@@ -6,10 +6,9 @@
import io.reactivex.*
import kotlinx.coroutines.*
-import org.junit.*
-import org.junit.Assert.*
+import org.junit.Test
import java.io.*
-import kotlin.experimental.*
+import kotlin.test.*
/**
* Test emitting multiple values with [rxObservable].
diff --git a/reactive/kotlinx-coroutines-rx2/test/ObservableSingleTest.kt b/reactive/kotlinx-coroutines-rx2/test/ObservableSingleTest.kt
index 7604b4a..4454190 100644
--- a/reactive/kotlinx-coroutines-rx2/test/ObservableSingleTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/ObservableSingleTest.kt
@@ -7,8 +7,9 @@
import io.reactivex.*
import kotlinx.coroutines.*
import org.junit.*
-import org.junit.Assert.*
+import org.junit.Test
import java.util.concurrent.*
+import kotlin.test.*
class ObservableSingleTest : TestBase() {
@Before
diff --git a/reactive/kotlinx-coroutines-rx2/test/ObservableSubscriptionSelectTest.kt b/reactive/kotlinx-coroutines-rx2/test/ObservableSubscriptionSelectTest.kt
index 28eb807..3cd3bbf 100644
--- a/reactive/kotlinx-coroutines-rx2/test/ObservableSubscriptionSelectTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/ObservableSubscriptionSelectTest.kt
@@ -6,8 +6,8 @@
import kotlinx.coroutines.*
import kotlinx.coroutines.selects.*
-import org.junit.*
-import org.junit.Assert.*
+import org.junit.Test
+import kotlin.test.*
class ObservableSubscriptionSelectTest : TestBase() {
@Test
diff --git a/reactive/kotlinx-coroutines-rx2/test/ObservableTest.kt b/reactive/kotlinx-coroutines-rx2/test/ObservableTest.kt
index b9f6fe3..4f7fa54 100644
--- a/reactive/kotlinx-coroutines-rx2/test/ObservableTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/ObservableTest.kt
@@ -8,7 +8,6 @@
import io.reactivex.plugins.*
import kotlinx.coroutines.*
import kotlinx.coroutines.CancellationException
-import org.hamcrest.core.*
import org.junit.*
import org.junit.Test
import java.util.concurrent.*
@@ -30,7 +29,7 @@
expect(2)
observable.subscribe { value ->
expect(5)
- Assert.assertThat(value, IsEqual("OK"))
+ assertEquals("OK", value)
}
expect(3)
yield() // to started coroutine
@@ -49,8 +48,8 @@
expectUnreached()
}, { error ->
expect(5)
- Assert.assertThat(error, IsInstanceOf(RuntimeException::class.java))
- Assert.assertThat(error.message, IsEqual("OK"))
+ assertTrue(error is RuntimeException)
+ assertEquals("OK", error.message)
})
expect(3)
yield() // to started coroutine
diff --git a/reactive/kotlinx-coroutines-rx2/test/SchedulerTest.kt b/reactive/kotlinx-coroutines-rx2/test/SchedulerTest.kt
index ca98b45..26dbe8f 100644
--- a/reactive/kotlinx-coroutines-rx2/test/SchedulerTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/SchedulerTest.kt
@@ -6,11 +6,9 @@
import io.reactivex.schedulers.Schedulers
import kotlinx.coroutines.*
-import org.hamcrest.core.IsEqual
-import org.hamcrest.core.IsNot
-import org.junit.Assert.assertThat
import org.junit.Before
import org.junit.Test
+import kotlin.test.*
class SchedulerTest : TestBase() {
@Before
@@ -24,11 +22,11 @@
val mainThread = Thread.currentThread()
withContext(Schedulers.io().asCoroutineDispatcher()) {
val t1 = Thread.currentThread()
- assertThat(t1, IsNot(IsEqual(mainThread)))
+ assertNotSame(t1, mainThread)
expect(2)
delay(100)
val t2 = Thread.currentThread()
- assertThat(t2, IsNot(IsEqual(mainThread)))
+ assertNotSame(t2, mainThread)
expect(3)
}
finish(4)
diff --git a/reactive/kotlinx-coroutines-rx2/test/SingleTest.kt b/reactive/kotlinx-coroutines-rx2/test/SingleTest.kt
index d9581f8..c66188a 100644
--- a/reactive/kotlinx-coroutines-rx2/test/SingleTest.kt
+++ b/reactive/kotlinx-coroutines-rx2/test/SingleTest.kt
@@ -9,10 +9,10 @@
import io.reactivex.exceptions.*
import io.reactivex.functions.*
import kotlinx.coroutines.*
-import org.hamcrest.core.*
import org.junit.*
-import org.junit.Assert.*
+import org.junit.Test
import java.util.concurrent.*
+import kotlin.test.*
class SingleTest : TestBase() {
@Before
@@ -30,7 +30,7 @@
expect(2)
single.subscribe { value ->
expect(5)
- assertThat(value, IsEqual("OK"))
+ assertEquals("OK", value)
}
expect(3)
yield() // to started coroutine
@@ -49,8 +49,8 @@
expectUnreached()
}, { error ->
expect(5)
- assertThat(error, IsInstanceOf(RuntimeException::class.java))
- assertThat(error.message, IsEqual("OK"))
+ assertTrue(error is RuntimeException)
+ assertEquals("OK", error.message)
})
expect(3)
yield() // to started coroutine