mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-05 08:40:08 +00:00
Update plugin test framework to junit5
Updates the testing infrastructure to use the latest relesae of junit and leverages the new extension mechanism to create an easy to use testing framework. Also adds additional test coverage for several plugins.
This commit is contained in:
@@ -1,16 +1,24 @@
|
||||
package org.apollo.plugin.consumables
|
||||
|
||||
import org.apollo.game.message.impl.ItemOptionMessage
|
||||
import io.mockk.verify
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.Skill
|
||||
import org.apollo.game.plugin.testing.KotlinPluginTest
|
||||
import org.apollo.game.plugin.testing.mockito.KotlinMockitoExtensions.matches
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.mockito.Mockito.never
|
||||
import org.mockito.Mockito.verify
|
||||
import org.apollo.game.plugin.testing.assertions.contains
|
||||
import org.apollo.game.plugin.testing.assertions.after
|
||||
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.TestMock
|
||||
import org.apollo.game.plugin.testing.junit.api.interactions.interactWithItem
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.TestInstance
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
class FoodOrDrinkTests : KotlinPluginTest() {
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
class FoodOrDrinkTests {
|
||||
|
||||
companion object {
|
||||
const val TEST_FOOD_NAME = "test_food"
|
||||
@@ -25,9 +33,14 @@ class FoodOrDrinkTests : KotlinPluginTest() {
|
||||
const val MAX_HP_LEVEL = 10
|
||||
}
|
||||
|
||||
@Before override fun setup() {
|
||||
super.setup()
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@TestMock
|
||||
lateinit var action: ActionCapture
|
||||
|
||||
@BeforeEach
|
||||
fun setup() {
|
||||
val skills = player.skillSet
|
||||
skills.setCurrentLevel(Skill.HITPOINTS, HP_LEVEL)
|
||||
skills.setMaximumLevel(Skill.HITPOINTS, MAX_HP_LEVEL)
|
||||
@@ -36,51 +49,47 @@ class FoodOrDrinkTests : KotlinPluginTest() {
|
||||
drink("test_drink", TEST_DRINK_ID, TEST_DRINK_RESTORATION)
|
||||
}
|
||||
|
||||
@Test fun `Consuming food or drink should restore the players hitpoints`() {
|
||||
@Test
|
||||
fun `Consuming food or drink should restore the players hitpoints`() {
|
||||
val expectedHpLevel = TEST_FOOD_RESTORATION + HP_LEVEL
|
||||
|
||||
player.notify(ItemOptionMessage(1, -1, TEST_FOOD_ID, 1))
|
||||
player.waitForActionCompletion()
|
||||
player.interactWithItem(TEST_FOOD_ID, option = 1, slot = 1)
|
||||
|
||||
val currentHpLevel = player.skillSet.getCurrentLevel(Skill.HITPOINTS)
|
||||
assertThat(currentHpLevel).isEqualTo(expectedHpLevel)
|
||||
after(action.complete()) {
|
||||
assertEquals(expectedHpLevel, player.skillSet.getCurrentLevel(Skill.HITPOINTS))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun `A message should be sent notifying the player if the item restored hitpoints`() {
|
||||
player.notify(ItemOptionMessage(1, -1, TEST_FOOD_ID, 1))
|
||||
player.waitForActionCompletion()
|
||||
@Test
|
||||
fun `A message should be sent notifying the player if the item restored hitpoints`() {
|
||||
player.interactWithItem(TEST_FOOD_ID, option = 1, slot = 1)
|
||||
|
||||
verify(player).sendMessage(matches {
|
||||
assertThat(this).contains("heals some health")
|
||||
})
|
||||
verifyAfter(action.complete()) { player.sendMessage("It heals some health.") }
|
||||
}
|
||||
|
||||
@Test fun `A message should not be sent to the player if the item did not restore hitpoints`() {
|
||||
@Test
|
||||
fun `A message should not be sent to the player if the item did not restore hitpoints`() {
|
||||
player.skillSet.setCurrentLevel(Skill.HITPOINTS, MAX_HP_LEVEL)
|
||||
player.notify(ItemOptionMessage(1, -1, TEST_FOOD_ID, 1))
|
||||
player.waitForActionCompletion()
|
||||
player.interactWithItem(TEST_FOOD_ID, option = 1, slot = 1)
|
||||
|
||||
verify(player, never()).sendMessage(matches {
|
||||
assertThat(this).contains("heals some health")
|
||||
})
|
||||
after(action.complete()) {
|
||||
verify(exactly = 0) { player.sendMessage(contains("it heals some")) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun `A message should be sent saying the player has drank an item when consuming a drink`() {
|
||||
player.notify(ItemOptionMessage(1, -1, TEST_DRINK_ID, 1))
|
||||
player.waitForActionCompletion()
|
||||
@Test
|
||||
fun `A message should be sent saying the player has drank an item when consuming a drink`() {
|
||||
player.interactWithItem(TEST_DRINK_ID, option = 1, slot = 1)
|
||||
|
||||
verifyAfter(action.complete()) { player.sendMessage("You drink the ${TEST_DRINK_NAME}.") }
|
||||
|
||||
verify(player).sendMessage(matches {
|
||||
assertThat(this).contains("You drink the ${TEST_DRINK_NAME}")
|
||||
})
|
||||
}
|
||||
|
||||
@Test fun `A message should be sent saying the player has eaten an item when consuming food`() {
|
||||
player.notify(ItemOptionMessage(1, -1, TEST_FOOD_ID, 1))
|
||||
player.waitForActionCompletion()
|
||||
@Test
|
||||
fun `A message should be sent saying the player has eaten an item when consuming food`() {
|
||||
player.interactWithItem(TEST_FOOD_ID, option = 1, slot = 1)
|
||||
|
||||
verify(player).sendMessage(matches {
|
||||
assertThat(this).contains("You eat the ${TEST_FOOD_NAME}")
|
||||
})
|
||||
verifyAfter(action.complete()) { player.sendMessage("You eat the ${TEST_FOOD_NAME}.") }
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user