Allow multiple players per test

Refactors the test helpers to use receiver functions so multiple players
can exist in the world per test case.  The AddFriendsTest is an example
of where this is needed.

Additionally, Hamcrest has been replaced with AssertJ for fluent
assertions.
This commit is contained in:
Gary Tierney
2017-06-20 02:13:47 +01:00
parent b532168551
commit 182de0330f
15 changed files with 254 additions and 186 deletions
+7 -7
View File
@@ -1,5 +1,5 @@
import org.apollo.game.model.Position
import org.apollo.game.plugins.testing.KotlinPluginTest
import org.apollo.game.plugin.testing.KotlinPluginTest
import org.junit.Test
import org.mockito.Mockito.verify
@@ -14,21 +14,21 @@ class OpenBankTest() : KotlinPluginTest() {
@Test
fun `Interacting with a bank teller should open the players bank`() {
val bankTeller = spawnNpc(BANK_TELLER_ID, BANK_POSITION)
val bankTeller = world.spawnNpc(BANK_TELLER_ID, BANK_POSITION)
// @todo - these option numbers only match by coincidence, we should be looking up the correct ones
interactWith(bankTeller, option = 2)
waitForActionCompletion()
player.interactWith(bankTeller, option = 2)
player.waitForActionCompletion()
verify(player).openBank()
}
@Test
fun `Interacting with a bank booth object should open the players bank`() {
val bankBooth = spawnObject(BANK_BOOTH_ID, BANK_POSITION)
val bankBooth = world.spawnObject(BANK_BOOTH_ID, BANK_POSITION)
interactWith(bankBooth, option = 2)
waitForActionCompletion()
player.interactWith(bankBooth, option = 2)
player.waitForActionCompletion()
verify(player).openBank()
}
@@ -3,21 +3,19 @@ import org.apollo.game.message.impl.SendFriendMessage
import org.apollo.game.model.entity.setting.PrivacyState
on { AddFriendMessage::class }
.then {
it.addFriend(username)
.then {
it.addFriend(username)
val playerUsername = it.username
val friend = it.world.getPlayer(username)
val friend = it.world.getPlayer(username)
if (friend == null) {
it.send(SendFriendMessage(username, 0))
} else if (friend.friendsWith(playerUsername) || friend.friendPrivacy == PrivacyState.ON) {
if (it.friendPrivacy != PrivacyState.OFF) {
friend.send(SendFriendMessage(playerUsername, it.worldId))
}
if (friend.friendPrivacy != PrivacyState.OFF) {
it.send(SendFriendMessage(username, friend.worldId))
}
}
if (friend == null || friend.friendPrivacy == PrivacyState.OFF) {
it.send(SendFriendMessage(username, 0))
return@then
} else {
it.send(SendFriendMessage(username, friend.worldId))
}
if (friend.friendsWith(it.username) && it.friendPrivacy != PrivacyState.OFF) {
friend.send(SendFriendMessage(it.username, it.worldId))
}
}
@@ -1,10 +1,10 @@
import org.apollo.game.model.Position
import org.apollo.game.model.entity.Skill
import org.apollo.game.plugins.testing.KotlinPluginTest
import org.hamcrest.Matchers.*
import org.junit.Assert.*
import org.apollo.game.plugin.testing.*
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.mockito.Mockito.*
import org.mockito.Mockito.contains
import org.mockito.Mockito.verify
class TrainingDummyTest : KotlinPluginTest() {
@@ -14,30 +14,30 @@ class TrainingDummyTest : KotlinPluginTest() {
}
@Test fun `Hitting the training dummy should give the player attack experience`() {
val dummy = spawnObject(DUMMY_ID, DUMMY_POSITION)
val dummy = world.spawnObject(DUMMY_ID, DUMMY_POSITION)
val skills = player.skillSet
val beforeExp = skills.getExperience(Skill.ATTACK)
interactWith(dummy, option = 2)
waitForActionCompletion()
player.interactWith(dummy, option = 2)
player.waitForActionCompletion()
val afterExp = skills.getExperience(Skill.ATTACK)
assertThat(afterExp, greaterThan(beforeExp))
assertThat(afterExp).isGreaterThan(beforeExp)
}
@Test fun `The player should stop getting attack experience from the training dummy at level 8`() {
val dummy = spawnObject(DUMMY_ID, DUMMY_POSITION)
val dummy = world.spawnObject(DUMMY_ID, DUMMY_POSITION)
val skills = player.skillSet
skills.setMaximumLevel(Skill.ATTACK, 8)
val beforeExp = skills.getExperience(Skill.ATTACK)
interactWith(dummy, option = 2)
waitForActionCompletion()
player.interactWith(dummy, option = 2)
player.waitForActionCompletion()
val afterExp = skills.getExperience(Skill.ATTACK)
verify(player).sendMessage(contains("nothing more you can learn"))
assertThat(afterExp, equalTo(beforeExp))
assertThat(afterExp).isEqualTo(beforeExp)
}
}
}
-29
View File
@@ -1,29 +0,0 @@
/**
* NOTE: This file is a stub, intended only for use within an IDE. It should be updated
* each time [org.apollo.game.plugin.kotlin.KotlinPluginScript] has a new method added to it.
*
* Until IntelliJ IDEA starts to support ScriptTemplateDefinitions this is
* required to resolve references within plugin code.
*/
import org.apollo.game.model.World
import org.apollo.game.plugin.PluginContext
import org.apollo.game.plugin.kotlin.*
import org.apollo.net.message.Message
import kotlin.reflect.KClass
fun <T : Message> on(type: () -> KClass<T>): KotlinMessageHandler<T> {
null!!
}
fun on_command(command: String, privileges: PrivilegeLevel): KotlinCommandHandler {
null!!
}
fun start(callback: (World) -> Unit) {
}
fun stop(callback: (World) -> Unit) {
}
@@ -1,14 +1,15 @@
import org.apollo.cache.def.ItemDefinition
import org.apollo.game.plugin.testing.*
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import kotlin.test.assertEquals
class LookupTests {
class LookupTests : KotlinPluginTest() {
@Test fun itemLookup() {
val testItem = ItemDefinition(0)
testItem.name = "sword"
ItemDefinition.init(arrayOf(testItem))
assertEquals(testItem, lookup_item("sword"))
assertThat(lookup_item("sword")).isEqualTo(testItem);
}
}