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:
Gary Tierney
2018-08-19 22:28:41 +01:00
parent e255bd195e
commit 248a7d97d9
56 changed files with 1327 additions and 463 deletions
@@ -299,7 +299,7 @@ public final class World {
playerRepository.add(player);
players.put(NameUtil.encodeBase37(username), player);
logger.info("Registered player: " + player + " [count=" + playerRepository.size() + "]");
logger.finest("Registered player: " + player + " [count=" + playerRepository.size() + "]");
}
/**
@@ -359,7 +359,7 @@ public final class World {
region.removeEntity(player);
playerRepository.remove(player);
logger.info("Unregistered player: " + player + " [count=" + playerRepository.size() + "]");
logger.finest("Unregistered player: " + player + " [count=" + playerRepository.size() + "]");
}
/**
@@ -235,6 +235,15 @@ public abstract class Mob extends Entity {
return firstDirection;
}
/**
* Gets the current action, if any, of this mob.
*
* @return The action.
*/
public final Action<?> getAction() {
return action;
}
/**
* Gets the index of this mob.
*
@@ -337,6 +346,15 @@ public abstract class Mob extends Entity {
return definition.map(NpcDefinition::getSize).orElse(1);
}
/**
* Check whether this mob has a current active {@link Action}.
*
* @return {@code true} if this mob has a non-null {@link Action}.
*/
public final boolean hasAction() {
return action != null;
}
/**
* Returns whether or not this mob has an {@link NpcDefinition}.
*
@@ -55,7 +55,7 @@ class ActionCoroutine : Continuation<Unit> {
* Create a new `ActionCoroutine` and immediately execute the given `block`, returning a continuation that
* can be resumed.
*/
fun start(block: ActionBlock) : ActionCoroutine {
fun start(block: ActionBlock): ActionCoroutine {
val coroutine = ActionCoroutine()
val continuation = block.createCoroutineUnchecked(coroutine, coroutine)
@@ -95,10 +95,7 @@ class ActionCoroutine : Continuation<Unit> {
* Update this continuation and check if the condition for the next step to be resumed is satisfied.
*/
fun pulse() {
val nextStep = next.getAndSet(null)
if (nextStep == null) {
return
}
val nextStep = next.getAndSet(null) ?: return
val condition = nextStep.condition
val continuation = nextStep.continuation
@@ -120,11 +117,13 @@ class ActionCoroutine : Continuation<Unit> {
/**
* Stop execution of this continuation.
*/
suspend fun stop() {
return suspendCancellableCoroutine(true) { cont ->
suspend fun stop(): Nothing {
suspendCancellableCoroutine<Unit>(true) { cont ->
next.set(null)
cont.cancel()
}
error("Tried to resume execution a coroutine that should have been cancelled.")
}
/**
@@ -1,7 +1,7 @@
package org.apollo.game.action
import org.apollo.game.action.ActionCoroutine
import org.junit.Assert.*
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class ActionCoroutineTest {
@@ -29,7 +29,6 @@ class ActionCoroutineTest {
fun `Coroutine cancels on stop() calls`() {
val coroutine = ActionCoroutine.start {
stop()
wait(1)
}
assertTrue(coroutine.stopped())