Add tests for api plugin

This commit is contained in:
Major-
2018-08-25 01:14:56 +01:00
parent fd52ee6026
commit f4aa3aae4e
13 changed files with 422 additions and 81 deletions
+3 -3
View File
@@ -28,9 +28,9 @@ enum class Fish(val id: Int, val level: Int, val experience: Double, catchSuffix
/**
* The name of this fish, formatted so it can be inserted into a message.
*/
val catchMessage = "You catch ${catchSuffix ?: "a ${catchName()}."}"
val catchMessage by lazy { "You catch ${catchSuffix ?: "a ${catchName()}."}" }
private fun catchName() = Definitions.item(id)!!.name.toLowerCase().removePrefix("raw ")
private fun catchName() = Definitions.item(id).name.toLowerCase().removePrefix("raw ")
}
@@ -59,7 +59,7 @@ enum class FishingTool(
/**
* The name of this tool, formatted so it can be inserted into a message.
*/
val formattedName = Definitions.item(id)!!.name.toLowerCase()
val formattedName by lazy { Definitions.item(id).name.toLowerCase() }
}
+2 -2
View File
@@ -94,7 +94,7 @@ data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore)
fun deplete(world: World) {
val obj = world.findObject(position, objectId)!!
world.expireObject(obj, ore.objects[objectId]!!, ore.respawn)
world.replaceObject(obj, ore.objects[objectId]!!, ore.respawn)
}
/**
@@ -113,7 +113,7 @@ data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore)
/**
* Get the normalized name of the [Ore] represented by this target.
*/
fun oreName() = Definitions.item(ore.id)!!.name.toLowerCase()
fun oreName() = Definitions.item(ore.id).name.toLowerCase()
/**
* Reward a [player] with experience and ore if they have the inventory capacity to take a new ore.
@@ -7,7 +7,7 @@ import org.apollo.cache.def.ItemDefinition
import org.apollo.game.model.World
import org.apollo.game.model.entity.Player
import org.apollo.game.model.entity.Skill
import org.apollo.game.plugin.api.expireObject
import org.apollo.game.plugin.api.replaceObject
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
@@ -59,7 +59,7 @@ class MiningActionTests {
every { target.skillRequirementsMet(player) } returns true
every { target.isSuccessful(player, any()) } returns true
every { world.expireObject(obj, any(), any()) } answers { }
every { world.replaceObject(obj, any(), any()) } answers { }
player.skillSet.setCurrentLevel(Skill.MINING, Ore.TIN.level)
player.startAction(MiningAction(player, Pickaxe.BRONZE, target))
@@ -70,7 +70,7 @@ class MiningActionTests {
after(action.complete()) {
verify { player.sendMessage("You manage to mine some <ore_type>") }
verify { world.expireObject(obj, expiredTinId, Ore.TIN.respawn) }
verify { world.replaceObject(obj, expiredTinId, Ore.TIN.respawn) }
assertTrue(player.inventory.contains(Ore.TIN.id))
assertEquals(player.skillSet.getExperience(Skill.MINING), Ore.TIN.exp)
@@ -88,7 +88,7 @@ class WoodcuttingAction(
val obj = target.getObject(mob.world) ?: stop()
if (mob.inventory.add(target.tree.id)) {
val logName = Definitions.item(target.tree.id)!!.name.toLowerCase()
val logName = Definitions.item(target.tree.id).name.toLowerCase()
mob.sendMessage("You managed to cut some $logName.")
mob.woodcutting.experience += target.tree.exp
}
@@ -97,7 +97,7 @@ class WoodcuttingAction(
// respawn time: http://runescape.wikia.com/wiki/Trees
val respawn = TimeUnit.SECONDS.toMillis(MINIMUM_RESPAWN_TIME + rand(150)) / GameConstants.PULSE_DELAY
mob.world.expireObject(obj, target.tree.stump, respawn.toInt())
mob.world.replaceObject(obj, target.tree.stump, respawn.toInt())
stop()
}
}