mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-03 00:38:21 +00:00
Add tests for most command plugins
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
import io.mockk.verify
|
||||
import org.apollo.game.command.Command
|
||||
import org.apollo.game.model.Animation
|
||||
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.TestMock
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class AnimateCommandTests {
|
||||
|
||||
@TestMock
|
||||
lateinit var world: World
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@Test
|
||||
fun `Plays the animation provided as input`() {
|
||||
player.privilegeLevel = PrivilegeLevel.MODERATOR
|
||||
world.commandDispatcher.dispatch(player, Command("animate", arrayOf("1")))
|
||||
|
||||
verify { player.playAnimation(Animation(1)) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
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.TestMock
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class BankCommandTests {
|
||||
|
||||
@TestMock
|
||||
lateinit var world: World
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@Test
|
||||
fun `Opens bank when used`() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
world.commandDispatcher.dispatch(player, Command("bank", emptyArray()))
|
||||
|
||||
verify { player.openBank() }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import io.mockk.verify
|
||||
import io.mockk.verifyOrder
|
||||
import io.mockk.verifySequence
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import org.apollo.cache.def.NpcDefinition
|
||||
import org.apollo.cache.def.ObjectDefinition
|
||||
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.assertions.startsWith
|
||||
import org.apollo.game.plugin.testing.assertions.strEq
|
||||
import org.apollo.game.plugin.testing.junit.ApolloTestingExtension
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.ItemDefinitions
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.NpcDefinitions
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.ObjectDefinitions
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.TestMock
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class BroadcastCommandTests {
|
||||
|
||||
@TestMock
|
||||
lateinit var world: World
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@Test
|
||||
fun `Shows basic information on an item`() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
world.commandDispatcher.dispatch(player, Command("broadcast", arrayOf("msg")))
|
||||
|
||||
verify {
|
||||
player.sendMessage("[Broadcast] Test: msg")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
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.ItemDefinitions
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.TestMock
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class ItemCommandTests {
|
||||
|
||||
@TestMock
|
||||
lateinit var world: World
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@Test
|
||||
fun `Defaults to an amount of 1`() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
world.commandDispatcher.dispatch(player, Command("item", arrayOf("1")))
|
||||
|
||||
assertEquals(1, player.inventory.getAmount(1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Adds item of specified amount to inventory`() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
world.commandDispatcher.dispatch(player, Command("item", arrayOf("1", "10")))
|
||||
|
||||
assertEquals(10, player.inventory.getAmount(1))
|
||||
}
|
||||
|
||||
companion object {
|
||||
@ItemDefinitions
|
||||
val items = listOf(ItemDefinition(1))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import io.mockk.verify
|
||||
import io.mockk.verifyOrder
|
||||
import io.mockk.verifySequence
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import org.apollo.cache.def.NpcDefinition
|
||||
import org.apollo.cache.def.ObjectDefinition
|
||||
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.assertions.startsWith
|
||||
import org.apollo.game.plugin.testing.assertions.strEq
|
||||
import org.apollo.game.plugin.testing.junit.ApolloTestingExtension
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.ItemDefinitions
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.NpcDefinitions
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.ObjectDefinitions
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.TestMock
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class LookupCommandTests {
|
||||
|
||||
@TestMock
|
||||
lateinit var world: World
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@Test
|
||||
fun `Shows basic information on an item`() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
world.commandDispatcher.dispatch(player, Command("iteminfo", arrayOf("1")))
|
||||
|
||||
verify {
|
||||
player.sendMessage("Item 1 is called <item_name> and is not members only.")
|
||||
player.sendMessage("Its description is `<description>`.")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Shows basic information on an npc`() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
world.commandDispatcher.dispatch(player, Command("npcinfo", arrayOf("1")))
|
||||
|
||||
verify {
|
||||
player.sendMessage("Npc 1 is called <npc_name> and has a combat level of 126.")
|
||||
player.sendMessage("Its description is `<description>`.")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Shows basic information on an object`() {
|
||||
player.privilegeLevel = PrivilegeLevel.ADMINISTRATOR
|
||||
world.commandDispatcher.dispatch(player, Command("objectinfo", arrayOf("1")))
|
||||
|
||||
verify {
|
||||
player.sendMessage("Object 1 is called <object_name> (width=1, length=1).")
|
||||
player.sendMessage("Its description is `<description>`.")
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
@ItemDefinitions
|
||||
val items = listOf(ItemDefinition(1).apply {
|
||||
name = "<item_name>"
|
||||
description = "<description>"
|
||||
isMembersOnly = false
|
||||
})
|
||||
|
||||
@NpcDefinitions
|
||||
val npcs = listOf(NpcDefinition(1).apply {
|
||||
name = "<npc_name>"
|
||||
combatLevel = 126
|
||||
description = "<description>"
|
||||
})
|
||||
|
||||
@ObjectDefinitions
|
||||
val objects = listOf(ObjectDefinition(1).apply {
|
||||
name = "<object_name>"
|
||||
description = "<description>"
|
||||
width = 1
|
||||
length = 1
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user