mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-05 08:40:08 +00:00
Support npc and object definitions in plugin tests
This commit is contained in:
@@ -22,7 +22,11 @@ object Definitions {
|
||||
}
|
||||
|
||||
fun npc(id: Int): NpcDefinition? {
|
||||
return NpcDefinition.lookup(id)
|
||||
try {
|
||||
return NpcDefinition.lookup(id)
|
||||
} catch (e: NullPointerException) {
|
||||
throw RuntimeException("Failed to find npc $id: count=${NpcDefinition.count()}")
|
||||
}
|
||||
}
|
||||
|
||||
fun npc(name: String): NpcDefinition? {
|
||||
|
||||
@@ -12,13 +12,13 @@ import org.apollo.game.plugin.skills.mining.Ore
|
||||
import org.apollo.game.plugin.skills.mining.Pickaxe
|
||||
import org.apollo.game.plugin.skills.mining.TIN_OBJECTS
|
||||
import org.apollo.game.plugin.testing.assertions.after
|
||||
import org.apollo.game.plugin.testing.assertions.contains
|
||||
import org.apollo.game.plugin.testing.assertions.verifyAfter
|
||||
import org.apollo.game.plugin.testing.junit.ApolloTestingExtension
|
||||
import org.apollo.game.plugin.testing.junit.api.ActionCapture
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.ItemDefinitions
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.TestMock
|
||||
import org.apollo.game.plugin.testing.junit.api.interactions.spawnObject
|
||||
import org.apollo.game.plugin.testing.assertions.contains
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
@@ -26,14 +26,6 @@ import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class MiningActionTests {
|
||||
private val TIN_OBJ_IDS = TIN_OBJECTS.entries.first()
|
||||
|
||||
@ItemDefinitions
|
||||
fun ores() = Ore.values()
|
||||
.map { ItemDefinition(it.id).also { it.name = "<ore_type>" } }
|
||||
|
||||
@ItemDefinitions
|
||||
fun pickaxes() = listOf(ItemDefinition(Pickaxe.BRONZE.id))
|
||||
|
||||
@TestMock
|
||||
lateinit var world: World
|
||||
@@ -50,8 +42,12 @@ class MiningActionTests {
|
||||
val target = spyk(MiningTarget(obj.id, obj.position, Ore.TIN))
|
||||
|
||||
every { target.skillRequirementsMet(player) } returns false
|
||||
|
||||
player.startAction(MiningAction(player, Pickaxe.BRONZE, target))
|
||||
verifyAfter(action.complete()) { player.sendMessage(contains("do not have the required level")) }
|
||||
|
||||
verifyAfter(action.complete()) {
|
||||
player.sendMessage(contains("do not have the required level"))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,12 +59,15 @@ class MiningActionTests {
|
||||
|
||||
every { target.skillRequirementsMet(player) } returns true
|
||||
every { target.isSuccessful(player, any()) } returns true
|
||||
every { world.expireObject(obj, any(), any()) } answers {}
|
||||
every { world.expireObject(obj, any(), any()) } answers { }
|
||||
|
||||
player.skillSet.setCurrentLevel(Skill.MINING, Ore.TIN.level)
|
||||
player.startAction(MiningAction(player, Pickaxe.BRONZE, target))
|
||||
|
||||
verifyAfter(action.ticks(1)) { player.sendMessage(contains("You swing your pick")) }
|
||||
verifyAfter(action.ticks(1)) {
|
||||
player.sendMessage(contains("You swing your pick"))
|
||||
}
|
||||
|
||||
after(action.complete()) {
|
||||
verify { player.sendMessage("You manage to mine some <ore_type>") }
|
||||
verify { world.expireObject(obj, expiredTinId, Ore.TIN.respawn) }
|
||||
@@ -77,4 +76,16 @@ class MiningActionTests {
|
||||
assertEquals(player.skillSet.getExperience(Skill.MINING), Ore.TIN.exp)
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
private val TIN_OBJ_IDS = TIN_OBJECTS.entries.first()
|
||||
|
||||
@ItemDefinitions
|
||||
fun ores() = Ore.values()
|
||||
.map { ItemDefinition(it.id).apply { name = "<ore_type>" } }
|
||||
|
||||
@ItemDefinitions
|
||||
fun pickaxes() = listOf(ItemDefinition(Pickaxe.BRONZE.id))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,11 +13,6 @@ import org.junit.jupiter.params.provider.EnumSource
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class PickaxeTests {
|
||||
|
||||
@ItemDefinitions
|
||||
fun pickaxes() = Pickaxe.values().map {
|
||||
ItemDefinition(it.id).apply { isStackable = false }
|
||||
}
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@@ -72,4 +67,11 @@ class PickaxeTests {
|
||||
assertEquals(pickaxe, Pickaxe.bestFor(player))
|
||||
}
|
||||
|
||||
private companion object {
|
||||
@ItemDefinitions
|
||||
fun pickaxes() = Pickaxe.values().map {
|
||||
ItemDefinition(it.id).apply { isStackable = false }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,13 +2,13 @@
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.plugin.skills.mining.Ore
|
||||
import org.apollo.game.plugin.testing.assertions.contains
|
||||
import org.apollo.game.plugin.testing.assertions.verifyAfter
|
||||
import org.apollo.game.plugin.testing.junit.ApolloTestingExtension
|
||||
import org.apollo.game.plugin.testing.junit.api.ActionCapture
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.ItemDefinitions
|
||||
import org.apollo.game.plugin.testing.junit.api.annotations.TestMock
|
||||
import org.apollo.game.plugin.testing.junit.api.interactions.interactWithObject
|
||||
import org.apollo.game.plugin.testing.assertions.contains
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource
|
||||
@@ -16,11 +16,6 @@ import org.junit.jupiter.params.provider.ArgumentsSource
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class ProspectingTests {
|
||||
|
||||
@ItemDefinitions
|
||||
fun ores() = Ore.values().map {
|
||||
ItemDefinition(it.id).also { it.name = "<ore_type>" }
|
||||
}
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@@ -43,4 +38,12 @@ class ProspectingTests {
|
||||
|
||||
verifyAfter(action.complete()) { player.sendMessage(contains("no ore available in this rock")) }
|
||||
}
|
||||
|
||||
private companion object {
|
||||
@ItemDefinitions
|
||||
fun ores() = Ore.values().map {
|
||||
ItemDefinition(it.id).also { it.name = "<ore_type>" }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,11 +26,6 @@ class BuryBoneTests {
|
||||
@TestMock
|
||||
lateinit var action: ActionCapture
|
||||
|
||||
@ItemDefinitions
|
||||
fun bones(): Collection<ItemDefinition> {
|
||||
return Bone.values().map { ItemDefinition(it.id) }
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Bone::class)
|
||||
fun `Burying a bone should send a message`(bone: Bone) {
|
||||
@@ -69,4 +64,11 @@ class BuryBoneTests {
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
@ItemDefinitions
|
||||
fun bones(): Collection<ItemDefinition> {
|
||||
return Bone.values().map { ItemDefinition(it.id) }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,11 +13,6 @@ import org.junit.jupiter.params.provider.EnumSource
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class AxeTests {
|
||||
|
||||
@ItemDefinitions
|
||||
fun axes() = Axe.values().map {
|
||||
ItemDefinition(it.id).apply { isStackable = false }
|
||||
}
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@@ -69,4 +64,11 @@ class AxeTests {
|
||||
assertEquals(axe, Axe.bestFor(player))
|
||||
}
|
||||
|
||||
private companion object {
|
||||
@ItemDefinitions
|
||||
fun axes() = Axe.values().map {
|
||||
ItemDefinition(it.id).apply { isStackable = false }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,19 +20,11 @@ import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.ArgumentsSource
|
||||
import java.util.*
|
||||
import java.util.Random
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class WoodcuttingTests {
|
||||
|
||||
@ItemDefinitions
|
||||
fun logs() = woodcuttingTestData().map {
|
||||
ItemDefinition(it.tree.id).also { it.name = "<tree_type>" }
|
||||
}
|
||||
|
||||
@ItemDefinitions
|
||||
fun tools() = listOf(ItemDefinition(Axe.BRONZE.id))
|
||||
|
||||
@TestMock
|
||||
lateinit var action: ActionCapture
|
||||
|
||||
@@ -85,4 +77,14 @@ class WoodcuttingTests {
|
||||
assertEquals(1, player.inventory.getAmount(data.tree.id))
|
||||
}
|
||||
}
|
||||
|
||||
private companion object {
|
||||
@ItemDefinitions
|
||||
fun logs() = woodcuttingTestData().map {
|
||||
ItemDefinition(it.tree.id).also { it.name = "<tree_type>" }
|
||||
}
|
||||
|
||||
@ItemDefinitions
|
||||
fun tools() = listOf(ItemDefinition(Axe.BRONZE.id))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user