Archived
1
0
Fork 0

No longer use Spek

This commit is contained in:
Moritz Ruth 2020-09-09 23:26:13 +02:00
parent 0689944d77
commit 4be30418fb
3 changed files with 180 additions and 180 deletions

View file

@ -34,8 +34,8 @@ dependencies {
// Testing
testImplementation("io.strikt:strikt-core:0.26.1")
testImplementation("org.spekframework.spek2:spek-dsl-jvm:$spekVersion")
testRuntimeOnly("org.spekframework.spek2:spek-runner-junit5:$spekVersion")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.2")
}
tasks {
@ -51,8 +51,6 @@ tasks {
}
test {
useJUnitPlatform {
includeEngines("spek2")
}
useJUnitPlatform()
}
}

View file

@ -1,18 +1,17 @@
package space.blokk.chat
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import org.junit.jupiter.api.Test
import strikt.api.expectThat
import strikt.assertions.isEqualTo
object FormattingCodeTest : Spek({
describe("FormattingCode") {
it("correctly translates to a string") {
class FormattingCodeTest {
@Test
fun `correctly translates to a string`() {
expectThat("${FormattingCode.AQUA}").isEqualTo("§b")
}
it("can be appended to another FormattingCode using the + operator") {
@Test
fun `can be appended to another FormattingCode using the + operator`() {
expectThat(FormattingCode.AQUA + FormattingCode.BLACK).isEqualTo("§b§0")
}
}
})
}

View file

@ -4,22 +4,21 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import org.spekframework.spek2.Spek
import org.spekframework.spek2.style.specification.describe
import org.junit.jupiter.api.Test
import strikt.api.expectThat
import strikt.api.expectThrows
import strikt.assertions.*
import kotlin.system.measureTimeMillis
private abstract class TestEvent : Event()
abstract class TestEvent : Event()
private class FirstEvent : TestEvent()
private class SecondEvent : TestEvent()
object EventBusTest : Spek({
describe("EventBus") {
val eventBus by memoized { EventBus(TestEvent::class, CoroutineScope(Dispatchers.Default)) }
class EventBusTest {
val eventBus = EventBus(TestEvent::class, CoroutineScope(Dispatchers.Default))
it("calls the handler exactly 1 time when the event is emitted 1 time") {
@Test
fun `calls the handler exactly 1 time when the event is emitted 1 time`() {
var calledCount = 0
eventBus.register(object : Listener {
@EventHandler
@ -32,7 +31,8 @@ object EventBusTest : Spek({
expectThat(calledCount).isEqualTo(1)
}
it("calls the handler exactly 3 times when the event is emitted 3 times") {
@Test
fun `calls the handler exactly 3 times when the event is emitted 3 times`() {
var calledCount = 0
eventBus.register(object : Listener {
@EventHandler
@ -51,7 +51,8 @@ object EventBusTest : Spek({
expectThat(calledCount).isEqualTo(3)
}
it("calls no handlers if no event is emitted") {
@Test
fun `calls no handlers if no event is emitted`() {
var onFirstEventCalled = false
var onSecondEventCalled = false
eventBus.register(object : Listener {
@ -72,7 +73,8 @@ object EventBusTest : Spek({
expectThat(onSecondEventCalled).isFalse()
}
it("calls handlers for supertypes of the emitted event") {
@Test
fun `calls handlers for supertypes of the emitted event`() {
var onTestEventCalled = false
var onFirstEventCalled = false
eventBus.register(object : Listener {
@ -93,7 +95,8 @@ object EventBusTest : Spek({
expectThat(onFirstEventCalled).isTrue()
}
it("stops calling handlers after they were unregistered") {
@Test
fun `stops calling handlers after they were unregistered`() {
var called = false
val listener = eventBus.register(object : Listener {
@EventHandler
@ -105,11 +108,11 @@ object EventBusTest : Spek({
eventBus.unregister(listener)
runBlocking { eventBus.emit(FirstEvent()) }
expectThat(called).isFalse()
}
it("throws an error if an event handler function has an invalid signature") {
@Test
fun `throws an error if an event handler function has an invalid signature`() {
expectThrows<EventBus.InvalidEventHandlerException> {
eventBus.register(object : Listener {
@EventHandler
@ -135,7 +138,8 @@ object EventBusTest : Spek({
}
}
it("calls handlers in the right order, sorted by priority") {
@Test
fun `calls handlers in the right order, sorted by priority`() {
val order = mutableListOf<EventPriority>()
eventBus.register(object : Listener {
@ -181,11 +185,11 @@ object EventBusTest : Spek({
})
runBlocking { eventBus.emit(FirstEvent()) }
expectThat(order).isSorted(Comparator.comparing<EventPriority, Int> { it.ordinal })
}
it("suspends until all handlers ran") {
@Test
fun `suspends until all handlers ran`() {
val delay = 2000L
eventBus.register(object : Listener {
@EventHandler
@ -198,5 +202,4 @@ object EventBusTest : Spek({
val duration = measureTimeMillis { runBlocking { eventBus.emit(FirstEvent()) } }
expectThat(duration).isGreaterThanOrEqualTo(delay)
}
}
})
}