mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-04-29 22:27:31 +00:00
test(config): 调整 BotAccount 的单元测试代码.
调整代码有利于后续更新测试用例时减少出错的可能性(虽然基本不换), 修复一个词汇错误.
This commit is contained in:
parent
c662b970f0
commit
dbc4232dd6
@ -2,6 +2,7 @@ package net.lamgc.scalabot
|
|||||||
|
|
||||||
import com.github.stefanbirkner.systemlambda.SystemLambda
|
import com.github.stefanbirkner.systemlambda.SystemLambda
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
|
import com.google.gson.JsonObject
|
||||||
import io.mockk.every
|
import io.mockk.every
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import io.mockk.verify
|
import io.mockk.verify
|
||||||
@ -26,18 +27,19 @@ internal class BotAccountTest {
|
|||||||
fun deserializerTest() {
|
fun deserializerTest() {
|
||||||
val accountId = abs(Random().nextInt()).toLong()
|
val accountId = abs(Random().nextInt()).toLong()
|
||||||
val creatorId = abs(Random().nextInt()).toLong()
|
val creatorId = abs(Random().nextInt()).toLong()
|
||||||
val botAccount = Gson().fromJson(
|
val botAccountJsonObject = Gson().fromJson(
|
||||||
"""
|
"""
|
||||||
{
|
{
|
||||||
"name": "TestBot",
|
"name": "TestBot",
|
||||||
"token": "${accountId}:AAHErDroUTznQsOd_oZPJ6cQEj4Z5mGHO10",
|
"token": "${accountId}:AAHErDroUTznQsOd_oZPJ6cQEj4Z5mGHO10",
|
||||||
"creatorId": $creatorId
|
"creatorId": $creatorId
|
||||||
}
|
}
|
||||||
""".trimIndent(), BotAccount::class.java
|
""".trimIndent(), JsonObject::class.java
|
||||||
)
|
)
|
||||||
assertEquals("TestBot", botAccount.name)
|
val botAccount = Gson().fromJson(botAccountJsonObject, BotAccount::class.java)
|
||||||
assertEquals("${accountId}:AAHErDroUTznQsOd_oZPJ6cQEj4Z5mGHO10", botAccount.token)
|
assertEquals(botAccountJsonObject["name"].asString, botAccount.name)
|
||||||
assertEquals(accountId, botAccount.id, "Botaccount ID does not match expectations.")
|
assertEquals(botAccountJsonObject["token"].asString, botAccount.token)
|
||||||
|
assertEquals(accountId, botAccount.id, "BotAccount ID does not match expectations.")
|
||||||
assertEquals(creatorId, botAccount.creatorId)
|
assertEquals(creatorId, botAccount.creatorId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user