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.
fix-openal-soft-deadlink
Paul Speed 5 years ago
parent 36afe829c6
commit 1ffd11fae4
  1. 13
      common.gradle
  2. 98
      jme3-core/src/test/groovy/com/jme3/app/state/AppStateManagerTest.groovy

@ -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',

@ -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);
}
}
}
}
Loading…
Cancel
Save