add unit tests
This commit is contained in:
parent
da8b717831
commit
3fd802682b
@ -20,10 +20,17 @@ repositories {
|
|||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val test by tasks.getting(Test::class) {
|
||||||
|
useJUnitPlatform { }
|
||||||
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
compile("com.moandjiezana.toml:toml4j:0.7.2")
|
||||||
implementation(kotlin("stdlib-jdk8"))
|
implementation(kotlin("stdlib-jdk8"))
|
||||||
implementation("org.javacord:javacord:3.0.4")
|
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> {
|
tasks.withType<KotlinCompile> {
|
||||||
|
@ -1,2 +1,28 @@
|
|||||||
package moe.kageru.kagebot
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,2 +1,10 @@
|
|||||||
package moe.kageru.kagebot
|
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
|
||||||
|
}
|
||||||
|
})
|
@ -1,2 +1,15 @@
|
|||||||
package moe.kageru.kagebot
|
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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user