add unit tests

This commit is contained in:
kageru 2019-06-08 21:52:47 +02:00
parent da8b717831
commit 3fd802682b
Signed by: kageru
GPG Key ID: 8282A2BEA4ADA3D2
4 changed files with 55 additions and 1 deletions

View File

@ -20,10 +20,17 @@ repositories {
mavenCentral()
}
val test by tasks.getting(Test::class) {
useJUnitPlatform { }
}
dependencies {
compile("com.moandjiezana.toml:toml4j:0.7.2")
implementation(kotlin("stdlib-jdk8"))
implementation("org.javacord:javacord:3.0.4")
compile("com.moandjiezana.toml:toml4j:0.7.2")
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.3.2")
testImplementation("io.mockk:mockk:1.9")
}
tasks.withType<KotlinCompile> {

View File

@ -1,2 +1,28 @@
package moe.kageru.kagebot
import io.kotlintest.shouldBe
import io.kotlintest.specs.StringSpec
class CommandTest : StringSpec({
"should match prefix command" {
testMessage("!ping", "pong")
}
"should match contains command" {
testMessage("the trigger is somewhere in this message", "found it")
}
"should match regex command" {
testMessage("AcsdB", "regex matched")
}
"should ping author" {
testMessage("answer me", "<@1> there you go")
}
}) {
companion object {
fun testMessage(content: String, result: String) {
val calls = mutableListOf<String>()
Kagebot.processMessage(TestUtil.mockMessage(content, capturedCalls = calls))
calls.size shouldBe 1
calls[0] shouldBe result
}
}
}

View File

@ -1,2 +1,10 @@
package moe.kageru.kagebot
import io.kotlintest.shouldNotBe
import io.kotlintest.specs.StringSpec
class ConfigTest : StringSpec({
"should properly parse default config" {
Config.config shouldNotBe null
}
})

View File

@ -1,2 +1,15 @@
package moe.kageru.kagebot
import io.mockk.every
import io.mockk.mockk
import org.javacord.api.event.message.MessageCreateEvent
object TestUtil {
fun mockMessage(content: String, author: Long = 1, capturedCalls: MutableList<String> = mutableListOf()): MessageCreateEvent {
val message = mockk<MessageCreateEvent>()
every { message.messageContent } returns content
every { message.messageAuthor.id } returns author
every { message.channel.sendMessage(capture(capturedCalls)) } returns mockk()
return message
}
}