Add herblore tests

This commit is contained in:
Gary Tierney
2018-08-26 21:54:33 +01:00
parent d323571c39
commit 1f7eb78ddb
3 changed files with 130 additions and 1 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ enum class Herb(
DWARF_WEED(identified = 267, unidentified = 217, level = 70, experience = 13.8),
TORSTOL(identified = 269, unidentified = 219, level = 75, experience = 15.0);
val identifiedName: String = Definitions.item(identified)!!.name
val identifiedName by lazy { Definitions.item(identified)!!.name }
companion object {
private val identified = Herb.values().map(Herb::identified).toHashSet()
@@ -0,0 +1,63 @@
import org.apollo.cache.def.ItemDefinition
import org.apollo.game.model.entity.Player
import org.apollo.game.plugin.testing.assertions.after
import org.apollo.game.plugin.testing.assertions.startsWith
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.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
@ExtendWith(ApolloTestingExtension::class)
internal class CrushIngredientActionTests {
@TestMock
lateinit var player: Player
@TestMock
lateinit var action: ActionCapture
private val ingredient = CrushableIngredient.BIRDS_NEST
@BeforeEach
internal fun startAction() {
player.inventory.add(ingredient.uncrushed)
player.startAction(CrushIngredientAction(player, ingredient))
}
@Test
internal fun `Preparing an uncrushed ingredient rewards a new ingredient after 2 ticks`() {
after(action.ticks(2), "ingredient removed and new ingredient added") {
assertEquals(0, player.inventory.getAmount(ingredient.uncrushed))
assertEquals(1, player.inventory.getAmount(ingredient.id))
}
}
@Test
internal fun `Preparing an uncrushed ingredient should send a message to the player after 2 ticks`() {
verifyAfter(action.ticks(2), "notification message sent to the player") {
player.sendMessage(startsWith("You carefully grind the <unprepared_ingredient> to dust"))
}
}
@Test
internal fun `Preparing an uncrushed ingredient should play an animation on the first tick`() {
verifyAfter(action.ticks(1), "grinding animation played") {
player.playAnimation(match { it.id == 364 })
}
}
private companion object {
@ItemDefinitions
private val ingredients = CrushableIngredient.values()
.map { ItemDefinition(it.uncrushed).apply { name = "<unprepared_ingredient>" } }
@ItemDefinitions
private val prepared = CrushableIngredient.values()
.map { ItemDefinition(it.id).apply { name = "<prepared_ingredient>" } }
}
}
@@ -0,0 +1,66 @@
import org.apollo.cache.def.ItemDefinition
import org.apollo.game.model.Item
import org.apollo.game.model.entity.Player
import org.apollo.game.model.entity.Skill
import org.apollo.game.plugin.testing.assertions.after
import org.apollo.game.plugin.testing.assertions.startsWith
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.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
@ExtendWith(ApolloTestingExtension::class)
internal class IdentifyHerbActionTests {
@TestMock
lateinit var player: Player
@TestMock
lateinit var action: ActionCapture
private val herb = Herb.GUAM_LEAF
@BeforeEach
internal fun startAction() {
player.inventory.set(0, Item(herb.unidentified))
player.startAction(IdentifyHerbAction(player, 0, herb))
}
@Test
internal fun `Identifying a herb should send a message if the player doesnt have the required level`() {
player.skillSet.setCurrentLevel(Skill.HERBLORE, 0)
verifyAfter(action.complete(), "level requirement message sent to player") {
player.sendMessage(startsWith("You need a Herblore level of"))
}
}
@Test
internal fun `Identifying a herb should remove the undentified herb`() {
after(action.complete()) {
assertEquals(0, player.inventory.getAmount(herb.unidentified))
}
}
@Test
internal fun `Identifying a herb should add the identified herb to the players inventory`() {
after(action.complete()) {
assertEquals(1, player.inventory.getAmount(herb.identified))
}
}
private companion object {
@ItemDefinitions
val identifiedHerbs = Herb.values()
.map { ItemDefinition(it.identified).apply { name = "<identified_herb>" } }
@ItemDefinitions
val unidentifiedHerbs = Herb.values()
.map { ItemDefinition(it.unidentified).apply { name = "<unidentified_herb>" } }
}
}