mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 00:38:18 +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:
@@ -10,5 +10,5 @@ plugin {
|
||||
"tlf30"
|
||||
]
|
||||
|
||||
dependencies = ["api"]
|
||||
dependencies = ["api", "util:lookup"]
|
||||
}
|
||||
@@ -8,6 +8,6 @@ enum class Gem(val id: Int) { // TODO add gem drop chances
|
||||
|
||||
companion object {
|
||||
private val GEMS = Gem.values().associateBy({ it.id }, { it })
|
||||
fun lookup(id: Int): Gem? = GEMS[id]
|
||||
operator fun get(id: Int): Gem? = GEMS[id]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
import org.apollo.game.action.ActionBlock
|
||||
import org.apollo.game.action.AsyncDistancedAction
|
||||
import org.apollo.game.message.impl.ObjectActionMessage
|
||||
import org.apollo.game.model.Position
|
||||
import org.apollo.game.model.World
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.obj.GameObject
|
||||
import org.apollo.game.plugin.api.*
|
||||
import org.apollo.game.plugin.skills.mining.Ore
|
||||
import org.apollo.game.plugin.skills.mining.Pickaxe
|
||||
import org.apollo.net.message.Message
|
||||
import java.util.*
|
||||
|
||||
class MiningAction(
|
||||
player: Player,
|
||||
private val tool: Pickaxe,
|
||||
private val target: MiningTarget
|
||||
) : AsyncDistancedAction<Player>(PULSES, true, player, target.position, ORE_SIZE) {
|
||||
|
||||
companion object {
|
||||
private const val PULSES = 0
|
||||
private const val ORE_SIZE = 1
|
||||
|
||||
/**
|
||||
* Starts a [MiningAction] for the specified [Player], terminating the [Message] that triggered it.
|
||||
*/
|
||||
fun start(message: ObjectActionMessage, player: Player, ore: Ore) {
|
||||
val pickaxe = Pickaxe.bestFor(player)
|
||||
|
||||
if (pickaxe == null) {
|
||||
player.sendMessage("You do not have a pickaxe for which you have the level to use.")
|
||||
} else {
|
||||
val target = MiningTarget(message.id, message.position, ore)
|
||||
val action = MiningAction(player, pickaxe, target)
|
||||
|
||||
player.startAction(action)
|
||||
}
|
||||
|
||||
message.terminate()
|
||||
}
|
||||
}
|
||||
|
||||
override fun action(): ActionBlock = {
|
||||
mob.turnTo(position)
|
||||
|
||||
if (!target.skillRequirementsMet(mob)) {
|
||||
mob.sendMessage("You do not have the required level to mine this rock.")
|
||||
stop()
|
||||
}
|
||||
|
||||
mob.sendMessage("You swing your pick at the rock.")
|
||||
mob.playAnimation(tool.animation)
|
||||
|
||||
wait(tool.pulses)
|
||||
|
||||
if (!target.isValid(mob.world)) {
|
||||
stop()
|
||||
}
|
||||
|
||||
val successChance = rand(100)
|
||||
|
||||
if (target.isSuccessful(mob, successChance)) {
|
||||
if (mob.inventory.freeSlots() == 0) {
|
||||
mob.inventory.forceCapacityExceeded()
|
||||
stop()
|
||||
}
|
||||
|
||||
if (target.reward(mob)) {
|
||||
mob.sendMessage("You manage to mine some ${target.oreName()}")
|
||||
target.deplete(mob.world)
|
||||
|
||||
stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as MiningAction
|
||||
return mob == other.mob && target == other.target
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = Objects.hash(mob, target)
|
||||
|
||||
}
|
||||
|
||||
data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore) {
|
||||
|
||||
/**
|
||||
* Get the [GameObject] represented by this target.
|
||||
*
|
||||
* @todo: api: shouldn't be as verbose
|
||||
*/
|
||||
private fun getObject(world: World): GameObject? {
|
||||
val region = world.regionRepository.fromPosition(position)
|
||||
return region.findObject(position, objectId).orElse(null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Deplete this mining resource from the [World], and schedule it to be respawned
|
||||
* in a number of ticks specified by the [Ore].
|
||||
*/
|
||||
fun deplete(world: World) {
|
||||
world.expireObject(getObject(world)!!, ore.objects[objectId]!!, ore.respawn)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the [Player] was successful in mining this ore with a random success [chance] value between 0 and 100.
|
||||
*/
|
||||
fun isSuccessful(mob: Player, chance: Int): Boolean {
|
||||
val percent = (ore.chance * mob.mining.current + ore.chanceOffset) * 100
|
||||
return chance < percent
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if this target is still valid in the [World] (i.e. has not been [deplete]d).
|
||||
*/
|
||||
fun isValid(world: World) = getObject(world) != null
|
||||
|
||||
/**
|
||||
* Get the normalized name of the [Ore] represented by this target.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
fun reward(player: Player): Boolean {
|
||||
val hasInventorySpace = player.inventory.add(ore.id)
|
||||
|
||||
if (hasInventorySpace) {
|
||||
player.mining.experience += ore.exp
|
||||
}
|
||||
|
||||
return hasInventorySpace
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the [mob] has met the skill requirements to mine te [Ore] represented by
|
||||
* this [MiningTarget].
|
||||
*/
|
||||
fun skillRequirementsMet(mob: Player) = mob.mining.current < ore.level
|
||||
}
|
||||
|
||||
@@ -1,19 +1,5 @@
|
||||
import org.apollo.game.action.ActionBlock
|
||||
import org.apollo.game.action.AsyncDistancedAction
|
||||
import org.apollo.game.message.impl.ObjectActionMessage
|
||||
import org.apollo.game.model.Position
|
||||
import org.apollo.game.model.World
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.obj.GameObject
|
||||
import org.apollo.game.plugin.api.Definitions
|
||||
import org.apollo.game.plugin.api.expireObject
|
||||
import org.apollo.game.plugin.api.findObject
|
||||
import org.apollo.game.plugin.api.mining
|
||||
import org.apollo.game.plugin.api.rand
|
||||
import org.apollo.game.plugin.skills.mining.Ore
|
||||
import org.apollo.game.plugin.skills.mining.Pickaxe
|
||||
import org.apollo.net.message.Message
|
||||
import java.util.Objects
|
||||
|
||||
on { ObjectActionMessage::class }
|
||||
.where { option == Actions.MINING }
|
||||
@@ -35,99 +21,6 @@ on { ObjectActionMessage::class }
|
||||
}
|
||||
}
|
||||
|
||||
class MiningAction(
|
||||
player: Player,
|
||||
private val tool: Pickaxe,
|
||||
private val target: MiningTarget
|
||||
) : AsyncDistancedAction<Player>(PULSES, true, player, target.position, ORE_SIZE) {
|
||||
|
||||
companion object {
|
||||
private const val PULSES = 0
|
||||
private const val ORE_SIZE = 1
|
||||
|
||||
/**
|
||||
* Starts a [MiningAction] for the specified [Player], terminating the [Message] that triggered it.
|
||||
*/
|
||||
fun start(message: ObjectActionMessage, player: Player, ore: Ore) {
|
||||
val pickaxe = Pickaxe.bestFor(player)
|
||||
|
||||
if (pickaxe == null) {
|
||||
player.sendMessage("You do not have a pickaxe for which you have the level to use.")
|
||||
} else {
|
||||
val target = MiningTarget(message.id, message.position, ore)
|
||||
val action = MiningAction(player, pickaxe, target)
|
||||
|
||||
player.startAction(action)
|
||||
}
|
||||
|
||||
message.terminate()
|
||||
}
|
||||
}
|
||||
|
||||
override fun action(): ActionBlock = {
|
||||
mob.turnTo(position)
|
||||
|
||||
val level = mob.mining.current
|
||||
if (level < target.ore.level) {
|
||||
mob.sendMessage("You do not have the required level to mine this rock.")
|
||||
stop()
|
||||
}
|
||||
|
||||
mob.sendMessage("You swing your pick at the rock.")
|
||||
mob.playAnimation(tool.animation)
|
||||
|
||||
wait(tool.pulses)
|
||||
|
||||
val obj = target.getObject(mob.world)
|
||||
if (obj == null) {
|
||||
stop()
|
||||
}
|
||||
|
||||
if (target.isSuccessful(mob)) {
|
||||
if (mob.inventory.freeSlots() == 0) {
|
||||
mob.inventory.forceCapacityExceeded()
|
||||
stop()
|
||||
}
|
||||
|
||||
if (mob.inventory.add(target.ore.id)) {
|
||||
val oreName = Definitions.item(target.ore.id)!!.name.toLowerCase()
|
||||
mob.sendMessage("You manage to mine some $oreName")
|
||||
|
||||
mob.mining.experience += target.ore.exp
|
||||
mob.world.expireObject(obj!!, target.ore.objects[target.objectId]!!, target.ore.respawn)
|
||||
stop()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as MiningAction
|
||||
return mob == other.mob && target == other.target
|
||||
}
|
||||
|
||||
override fun hashCode(): Int = Objects.hash(mob, target)
|
||||
|
||||
}
|
||||
|
||||
data class MiningTarget(val objectId: Int, val position: Position, val ore: Ore) {
|
||||
|
||||
fun getObject(world: World): GameObject? {
|
||||
val region = world.regionRepository.fromPosition(position)
|
||||
return region.findObject(position, objectId).orElse(null)
|
||||
}
|
||||
|
||||
fun isSuccessful(mob: Player): Boolean {
|
||||
val offset = if (ore.chanceOffset) 1 else 0
|
||||
val percent = (ore.chance * mob.mining.current + offset) * 100
|
||||
|
||||
return rand(100) < percent
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private object Actions {
|
||||
const val MINING = 1
|
||||
const val PROSPECTING = 2
|
||||
|
||||
@@ -17,12 +17,12 @@ enum class Ore(
|
||||
val exp: Double,
|
||||
val respawn: Int,
|
||||
val chance: Double,
|
||||
val chanceOffset: Boolean = false
|
||||
val chanceOffset: Double = 0.0
|
||||
) {
|
||||
CLAY(CLAY_OBJECTS, id = 434, level = 1, exp = 5.0, respawn = 1, chance = 0.0085, chanceOffset = true),
|
||||
COPPER(COPPER_OBJECTS, id = 436, level = 1, exp = 17.5, respawn = 4, chance = 0.0085, chanceOffset = true),
|
||||
TIN(TIN_OBJECTS, id = 438, level = 1, exp = 17.5, respawn = 4, chance = 0.0085, chanceOffset = true),
|
||||
IRON(IRON_OBJECTS, id = 440, level = 15, exp = 35.0, respawn = 9, chance = 0.0085, chanceOffset = true),
|
||||
CLAY(CLAY_OBJECTS, id = 434, level = 1, exp = 5.0, respawn = 1, chance = 0.0085, chanceOffset = 0.45),
|
||||
COPPER(COPPER_OBJECTS, id = 436, level = 1, exp = 17.5, respawn = 4, chance = 0.0085, chanceOffset = 0.45),
|
||||
TIN(TIN_OBJECTS, id = 438, level = 1, exp = 17.5, respawn = 4, chance = 0.0085, chanceOffset = 0.45),
|
||||
IRON(IRON_OBJECTS, id = 440, level = 15, exp = 35.0, respawn = 9, chance = 0.0085, chanceOffset = 0.45),
|
||||
COAL(COAL_OBJECTS, id = 453, level = 30, exp = 50.0, respawn = 50, chance = 0.004),
|
||||
GOLD(GOLD_OBJECTS, id = 444, level = 40, exp = 65.0, respawn = 100, chance = 0.003),
|
||||
SILVER(SILVER_OBJECTS, id = 442, level = 20, exp = 40.0, respawn = 100, chance = 0.0085),
|
||||
|
||||
@@ -7,7 +7,7 @@ import org.apollo.game.plugin.api.mining
|
||||
enum class Pickaxe(val id: Int, val level: Int, animation: Int, val pulses: Int) {
|
||||
BRONZE(id = 1265, level = 1, animation = 625, pulses = 8),
|
||||
ITRON(id = 1267, level = 1, animation = 626, pulses = 7),
|
||||
STEEL(id = 1269, level = 1, animation = 627, pulses = 6),
|
||||
STEEL(id = 1269, level = 6, animation = 627, pulses = 6),
|
||||
MITHRIL(id = 1273, level = 21, animation = 629, pulses = 5),
|
||||
ADAMANT(id = 1271, level = 31, animation = 628, pulses = 4),
|
||||
RUNE(id = 1275, level = 41, animation = 624, pulses = 3);
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
|
||||
import io.mockk.every
|
||||
import io.mockk.spyk
|
||||
import io.mockk.staticMockk
|
||||
import io.mockk.verify
|
||||
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.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.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
|
||||
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
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@TestMock
|
||||
lateinit var action: ActionCapture
|
||||
|
||||
@Test
|
||||
fun `Attempting to mine a rock we don't have the skill to should send the player a message`() {
|
||||
val obj = world.spawnObject(1, player.position)
|
||||
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")) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Mining a rock we have the skill to mine should eventually reward ore and experience`() {
|
||||
val (tinId, expiredTinId) = TIN_OBJ_IDS
|
||||
val obj = world.spawnObject(tinId, player.position)
|
||||
val target = spyk(MiningTarget(obj.id, obj.position, Ore.TIN))
|
||||
staticMockk("org.apollo.game.plugin.api.WorldKt").mock()
|
||||
|
||||
every { target.skillRequirementsMet(player) } returns true
|
||||
every { target.isSuccessful(player, any()) } returns true
|
||||
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")) }
|
||||
after(action.complete()) {
|
||||
verify { player.sendMessage("You manage to mine some <ore_type>") }
|
||||
verify { world.expireObject(obj, expiredTinId, Ore.TIN.respawn) }
|
||||
|
||||
assertTrue(player.inventory.contains(Ore.TIN.id))
|
||||
assertEquals(player.skillSet.getExperience(Skill.MINING), Ore.TIN.exp)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import org.apollo.cache.def.ItemDefinition
|
||||
import org.apollo.game.model.entity.Player
|
||||
import org.apollo.game.model.entity.Skill
|
||||
import org.apollo.game.plugin.skills.mining.Pickaxe
|
||||
import org.apollo.game.plugin.testing.junit.ApolloTestingExtension
|
||||
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.extension.ExtendWith
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
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
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(Pickaxe::class)
|
||||
fun `No pickaxe is chosen if none are available`(pickaxe: Pickaxe) {
|
||||
player.skillSet.setCurrentLevel(Skill.MINING, pickaxe.level)
|
||||
|
||||
assertEquals(null, Pickaxe.bestFor(player))
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(Pickaxe::class)
|
||||
fun `The highest level pickaxe is chosen when available`(pickaxe: Pickaxe) {
|
||||
player.skillSet.setCurrentLevel(Skill.MINING, pickaxe.level)
|
||||
player.inventory.add(pickaxe.id)
|
||||
|
||||
assertEquals(pickaxe, Pickaxe.bestFor(player))
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(Pickaxe::class)
|
||||
fun `Only pickaxes the player has are chosen`(pickaxe: Pickaxe) {
|
||||
player.skillSet.setCurrentLevel(Skill.MINING, pickaxe.level)
|
||||
player.inventory.add(Pickaxe.BRONZE.id)
|
||||
|
||||
assertEquals(Pickaxe.BRONZE, Pickaxe.bestFor(player))
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Pickaxe::class)
|
||||
fun `Pickaxes can be chosen from equipment as well as inventory`(pickaxe: Pickaxe) {
|
||||
player.skillSet.setCurrentLevel(Skill.MINING, pickaxe.level)
|
||||
player.inventory.add(pickaxe.id)
|
||||
|
||||
assertEquals(pickaxe, Pickaxe.bestFor(player))
|
||||
}
|
||||
|
||||
|
||||
@ParameterizedTest
|
||||
@EnumSource(value = Pickaxe::class)
|
||||
fun `Pickaxes with a level requirement higher than the player's are ignored`(pickaxe: Pickaxe) {
|
||||
player.skillSet.setCurrentLevel(Skill.MINING, pickaxe.level)
|
||||
player.inventory.add(pickaxe.id)
|
||||
|
||||
Pickaxe.values()
|
||||
.filter { it.level > pickaxe.level }
|
||||
.forEach { player.inventory.add(it.id) }
|
||||
|
||||
assertEquals(pickaxe, Pickaxe.bestFor(player))
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
|
||||
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.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
|
||||
|
||||
@ExtendWith(ApolloTestingExtension::class)
|
||||
class ProspectingTests {
|
||||
|
||||
@ItemDefinitions
|
||||
fun ores() = Ore.values().map {
|
||||
ItemDefinition(it.id).also { it.name = "<ore_type>" }
|
||||
}
|
||||
|
||||
@TestMock
|
||||
lateinit var player: Player
|
||||
|
||||
@TestMock
|
||||
lateinit var action: ActionCapture
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(MiningTestDataProvider::class)
|
||||
fun `Prospecting a rock should reveal the type of ore it contains`(data: MiningTestData) {
|
||||
player.interactWithObject(data.rockId, 2)
|
||||
|
||||
verifyAfter(action.ticks(1)) { player.sendMessage(contains("examine the rock")) }
|
||||
verifyAfter(action.complete()) { player.sendMessage(contains("This rock contains <ore_type>")) }
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ArgumentsSource(MiningTestDataProvider::class)
|
||||
fun `Prospecting an expired rock should reveal it contains no ore`(data: MiningTestData) {
|
||||
player.interactWithObject(data.expiredRockId, 2)
|
||||
|
||||
verifyAfter(action.complete()) { player.sendMessage(contains("no ore available in this rock")) }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import org.apollo.game.plugin.skills.mining.Ore
|
||||
import org.junit.jupiter.api.extension.ExtensionContext
|
||||
import org.junit.jupiter.params.provider.Arguments
|
||||
import org.junit.jupiter.params.provider.ArgumentsProvider
|
||||
import java.util.stream.Stream
|
||||
|
||||
data class MiningTestData(val rockId: Int, val expiredRockId: Int, val ore: Ore)
|
||||
|
||||
fun miningTestData(): Collection<MiningTestData> = Ore.values()
|
||||
.flatMap { ore -> ore.objects.map { MiningTestData(it.key, it.value, ore) } }
|
||||
.toList()
|
||||
|
||||
class MiningTestDataProvider : ArgumentsProvider {
|
||||
override fun provideArguments(context: ExtensionContext?): Stream<out Arguments> {
|
||||
return miningTestData().map { Arguments { arrayOf(it) } }.stream()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user