From 1ffd11fae400963d51876e19d0222852777320a0 Mon Sep 17 00:00:00 2001 From: Paul Speed Date: Sun, 15 Sep 2019 20:54:53 -0400 Subject: [PATCH] Added a basic unit test for some of the AppStateManager functionality. (Specifically the stuff that deals with IDs.) Also added the ability to use groovy tests for those who like a little testing but aren't complete masochists. --- common.gradle | 13 +++ .../jme3/app/state/AppStateManagerTest.groovy | 98 +++++++++++++++++++ 2 files changed, 111 insertions(+) create mode 100644 jme3-core/src/test/groovy/com/jme3/app/state/AppStateManagerTest.groovy diff --git a/common.gradle b/common.gradle index 80b22904d..cf44dea51 100644 --- a/common.gradle +++ b/common.gradle @@ -3,6 +3,7 @@ // apply plugin: 'java' +apply plugin: 'groovy' apply plugin: 'maven' group = 'org.jmonkeyengine' @@ -26,8 +27,20 @@ dependencies { testCompile group: 'junit', name: 'junit', version: '4.12' testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.19' testCompile group: 'org.easytesting', name: 'fest-assert-core', version: '2.0M10' + testCompile 'org.codehaus.groovy:groovy-all:2.5.8' } + +// Uncomment if you want to see the status of every test that is run and +// the test output. +/* +test { + testLogging { + events "passed", "skipped", "failed", "standardOut", "standardError" + } +} +*/ + jar { manifest { attributes 'Implementation-Title': 'jMonkeyEngine', diff --git a/jme3-core/src/test/groovy/com/jme3/app/state/AppStateManagerTest.groovy b/jme3-core/src/test/groovy/com/jme3/app/state/AppStateManagerTest.groovy new file mode 100644 index 000000000..45e39c1b7 --- /dev/null +++ b/jme3-core/src/test/groovy/com/jme3/app/state/AppStateManagerTest.groovy @@ -0,0 +1,98 @@ +package com.jme3.app.state; + +import com.jme3.app.LegacyApplication; + +class AppStateManagerTest { + + static class AttachTest extends GroovyTestCase { + + void testDuplicateId() { + def state1 = new AbstractAppState("test1") {}; + def state2 = new AbstractAppState("test1") {}; + + def app = new LegacyApplication(); + + app.getStateManager().attach(state1); + + shouldFail(IllegalArgumentException) { + app.getStateManager().attach(state2); + } + } + + void testDuplicateNullId() { + // Make sure that two states without an ID can + // still be registered. + def state1 = new AbstractAppState() {}; + def state2 = new AbstractAppState() {}; + + def app = new LegacyApplication(); + + app.getStateManager().attach(state1); + app.getStateManager().attach(state2); + } + } + + static class GetStateWithIdTest extends GroovyTestCase { + void testIdHit() { + def state = new AbstractAppState("test1") {}; + def app = new LegacyApplication(); + + app.stateManager.attach(state); + + assertNotNull app.stateManager.getState("test1", AppState.class); + } + + void testIdMiss() { + def state = new AbstractAppState("test1") {}; + def app = new LegacyApplication(); + + app.stateManager.attach(state); + + assertNull app.stateManager.getState("test2", AppState.class); + } + + void testDetached() { + def state = new AbstractAppState("test1") {}; + def app = new LegacyApplication(); + + app.stateManager.attach(state); + app.stateManager.detach(state); + + assertNull app.stateManager.getState("test2", AppState.class); + } + } + + static class StateForIdTest extends GroovyTestCase { + void testIdHit() { + def state = new AbstractAppState("test1") {}; + def app = new LegacyApplication(); + + app.stateManager.attach(state); + + assertNotNull app.stateManager.stateForId("test1", AppState.class); + } + + void testIdMiss() { + def state = new AbstractAppState("test1") {}; + def app = new LegacyApplication(); + + app.stateManager.attach(state); + + shouldFail(IllegalArgumentException) { + app.stateManager.stateForId("test2", AppState.class); + } + } + + void testDetached() { + def state = new AbstractAppState("test1") {}; + def app = new LegacyApplication(); + + app.stateManager.attach(state); + app.stateManager.detach(state); + + shouldFail(IllegalArgumentException) { + app.stateManager.stateForId("test2", AppState.class); + } + } + } +}