mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add tests for remaining commands
This commit is contained in:
@@ -35,16 +35,27 @@ on_command("spawn", PrivilegeLevel.ADMINISTRATOR)
|
||||
if (arguments.size == 1) {
|
||||
position = player.position
|
||||
} else {
|
||||
var height = player.position.height
|
||||
if (arguments.size == 4) {
|
||||
val x = Ints.tryParse(arguments[1])
|
||||
val y = Ints.tryParse(arguments[2])
|
||||
|
||||
if (x == null || y == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
|
||||
val height = if (arguments.size == 4) {
|
||||
val h = Ints.tryParse(arguments[3])
|
||||
if (h == null) {
|
||||
player.sendMessage(invalidSyntax)
|
||||
return@then
|
||||
}
|
||||
height = h
|
||||
|
||||
h
|
||||
} else {
|
||||
player.position.height
|
||||
}
|
||||
position = Position(arguments[1].toInt(), arguments[2].toInt(), height)
|
||||
|
||||
position = Position(x, y, height)
|
||||
}
|
||||
|
||||
player.world.register(Npc(player.world, id, position))
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
import io.mockk.verify
|
||||
import org.apollo.game.command.Command
|
||||
import org.apollo.game.model.World
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||
import org.apollo.game.plugin.testing.junit.ApolloTestingExtension
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.Name
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.TestMock
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class PunishCommandTests {
|
||||
|
||||
@TestMock
|
||||
lateinit var world: World
|
||||
|
||||
@TestMock
|
||||
lateinit var admin: Player
|
||||
|
||||
@TestMock
|
||||
@Name("player_two")
|
||||
lateinit var player: Player
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
admin.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Staff can mute players`() {
|
||||
world.commandDispatcher.dispatch(admin, Command("mute", arrayOf("player_two")))
|
||||
|
||||
verify {
|
||||
player.setMuted(true)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Staff can unmute players`() {
|
||||
player.isMuted = true
|
||||
world.commandDispatcher.dispatch(admin, Command("unmute", arrayOf("player_two")))
|
||||
|
||||
verify {
|
||||
player.setMuted(false)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Staff cant mute admins`() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
world.commandDispatcher.dispatch(admin, Command("unmute", arrayOf("player_two")))
|
||||
|
||||
verify {
|
||||
admin.sendMessage("You cannot perform this action on Administrators.")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Cant mute players that arent online`() {
|
||||
world.commandDispatcher.dispatch(admin, Command("mute", arrayOf("player555")))
|
||||
|
||||
verify {
|
||||
admin.sendMessage("That player does not exist.")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Staff can ban players`() {
|
||||
world.commandDispatcher.dispatch(admin, Command("ban", arrayOf("player_two")))
|
||||
|
||||
verify {
|
||||
player.ban()
|
||||
player.logout()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Staff cant ban admins`() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
world.commandDispatcher.dispatch(admin, Command("ban", arrayOf("player_two")))
|
||||
|
||||
verify {
|
||||
admin.sendMessage("You cannot perform this action on Administrators.")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Cant ban players that arent online`() {
|
||||
world.commandDispatcher.dispatch(admin, Command("ban", arrayOf("player555")))
|
||||
|
||||
verify {
|
||||
admin.sendMessage("That player does not exist.")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,18 @@
|
||||
import io.mockk.verify
|
||||
import org.apollo.game.command.Command
|
||||
import org.apollo.game.model.World
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.Skill
|
||||
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||
import org.apollo.game.plugin.testing.assertions.contains
|
||||
import org.apollo.game.plugin.testing.junit.ApolloTestingExtension
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.TestMock
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.ValueSource
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class SkillCommandTests {
|
||||
@@ -18,13 +23,53 @@ class SkillCommandTests {
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Max stats to 99`() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
world.commandDispatcher.dispatch(player, Command("max", emptyArray()))
|
||||
|
||||
for (stat in 0 until Skill.RUNECRAFT) {
|
||||
assertEquals(99, player.skillSet.getCurrentLevel(stat))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Set skill to given level`() {
|
||||
world.commandDispatcher.dispatch(player, Command("level", arrayOf("1", "99")))
|
||||
|
||||
assertEquals(99, player.skillSet.getCurrentLevel(1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Set skill to given experience`() {
|
||||
world.commandDispatcher.dispatch(player, Command("xp", arrayOf("1", "50")))
|
||||
|
||||
assertEquals(50.0, player.skillSet.getExperience(1))
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "::{0}")
|
||||
@ValueSource(strings = [
|
||||
"level 50 100",
|
||||
"level 15 100",
|
||||
"level <garbage> 100",
|
||||
"level 15 <garbage>",
|
||||
"level",
|
||||
"xp",
|
||||
"xp 50 <garbage>",
|
||||
"xp <garbage> 50"
|
||||
])
|
||||
fun `Help message shown on invalid syntax`(command: String) {
|
||||
val args = command.split(" ").toMutableList()
|
||||
val cmd = args.removeAt(0)
|
||||
|
||||
world.commandDispatcher.dispatch(player, Command(cmd, args.toTypedArray()))
|
||||
|
||||
verify {
|
||||
player.sendMessage(contains("Invalid syntax"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import io.mockk.verify
|
||||
import org.apollo.cache.def.NpcDefinition
|
||||
import org.apollo.game.command.Command
|
||||
import org.apollo.game.model.Position
|
||||
import org.apollo.game.model.World
|
||||
import org.apollo.game.model.entity.Npc
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.setting.PrivilegeLevel
|
||||
import org.apollo.game.plugin.testing.assertions.contains
|
||||
import org.apollo.game.plugin.testing.junit.ApolloTestingExtension
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.NpcDefinitions
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.TestMock
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.ValueSource
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class SpawnCommandTests {
|
||||
|
||||
@TestMock
|
||||
lateinit var world: World
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Spawns NPC at players position by default`() {
|
||||
world.commandDispatcher.dispatch(player, Command("spawn", arrayOf("1")))
|
||||
|
||||
verify {
|
||||
world.register(match<Npc> {
|
||||
it.id == 1 && it.position == player.position
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Spawn NPC at given position`() {
|
||||
world.commandDispatcher.dispatch(player, Command("spawn", arrayOf("1", "5", "5")))
|
||||
|
||||
verify {
|
||||
world.register(match<Npc> {
|
||||
it.id == 1 && it.position == Position(5, 5)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "::spawn {0}")
|
||||
@ValueSource(strings = [
|
||||
"<garbage>",
|
||||
"1 2",
|
||||
"1 2 <garbage>",
|
||||
"1 2 3 <garbage>"
|
||||
])
|
||||
fun `Help message on invalid syntax`(args: String) {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
world.commandDispatcher.dispatch(player, Command("spawn", args.split(" ").toTypedArray()))
|
||||
|
||||
verify {
|
||||
player.sendMessage(contains("Invalid syntax"))
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@NpcDefinitions
|
||||
val npcs = listOf(NpcDefinition(1))
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,6 @@ class TeleportCommandTests {
|
||||
assertEquals(Position(1, 2, 1), player.position)
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
fun `Shows current position information`() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
@@ -66,5 +65,4 @@ class TeleportCommandTests {
|
||||
player.sendMessage(contains("Invalid syntax"))
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user