diff --git a/game/plugin/skills/herblore/src/Herb.kt b/game/plugin/skills/herblore/src/Herb.kt index c80e1edf..5b921f20 100644 --- a/game/plugin/skills/herblore/src/Herb.kt +++ b/game/plugin/skills/herblore/src/Herb.kt @@ -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() diff --git a/game/plugin/skills/herblore/test/CrushIngredientActionTests.kt b/game/plugin/skills/herblore/test/CrushIngredientActionTests.kt new file mode 100644 index 00000000..a81154a6 --- /dev/null +++ b/game/plugin/skills/herblore/test/CrushIngredientActionTests.kt @@ -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 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 = "" } } + + @ItemDefinitions + private val prepared = CrushableIngredient.values() + .map { ItemDefinition(it.id).apply { name = "" } } + } +} \ No newline at end of file diff --git a/game/plugin/skills/herblore/test/IdentifyHerbActionTests.kt b/game/plugin/skills/herblore/test/IdentifyHerbActionTests.kt new file mode 100644 index 00000000..b5273c18 --- /dev/null +++ b/game/plugin/skills/herblore/test/IdentifyHerbActionTests.kt @@ -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 = "" } } + + @ItemDefinitions + val unidentifiedHerbs = Herb.values() + .map { ItemDefinition(it.unidentified).apply { name = "" } } + } +} \ No newline at end of file