mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
Make progress in segregating game model data; move some fields from forge.AllZone to forge.model.FGameState.
Left delegate methods in AllZone, marking their Javadoc (in English) for future deprecation. Added some rudimentary tests on forge.model.FModel's getGameState and resetGameState methods. Bug: 154
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package forge.model;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import org.testng.annotations.AfterTest;
|
||||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import forge.Singletons;
|
||||
import forge.properties.ForgePreferences;
|
||||
|
||||
/**
|
||||
@@ -15,20 +17,49 @@ import forge.properties.ForgePreferences;
|
||||
public class FModelTest {
|
||||
|
||||
|
||||
private FModel model;
|
||||
|
||||
/**
|
||||
* Test constructor, close, and construct again.
|
||||
* Set up before each test, creating a default model.
|
||||
*
|
||||
* @throws FileNotFoundException indirectly
|
||||
*/
|
||||
@BeforeTest
|
||||
public final void setUp() throws FileNotFoundException {
|
||||
model = new FModel(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Close the model after each test if it isn't null.
|
||||
*/
|
||||
@AfterTest
|
||||
public final void tearDown() {
|
||||
if (model != null) {
|
||||
try {
|
||||
model.close();
|
||||
}
|
||||
catch (Throwable ignored) {
|
||||
// ignore exceptions during close.
|
||||
}
|
||||
}
|
||||
|
||||
model = null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test constructor (via setUp), close, and construct again.
|
||||
* @throws FileNotFoundException if something is really wrong
|
||||
*/
|
||||
@Test
|
||||
public final void test_ctor_close_ctor() throws FileNotFoundException { // NOPMD by Braids on 8/12/11 10:36 AM
|
||||
final FModel modelA = new FModel(null);
|
||||
assertNotNull(modelA, "modelA is not null");
|
||||
modelA.close();
|
||||
assertNotNull(model, "model is not null");
|
||||
model.close();
|
||||
|
||||
System.err.println("log test"); // NOPMD by Braids on 8/12/11 10:36 AM
|
||||
|
||||
final FModel modelB = new FModel(null);
|
||||
assertNotNull(modelB, "modelB is not null");
|
||||
model = new FModel(null);
|
||||
assertNotNull(model, "model is not null");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,10 +67,8 @@ public class FModelTest {
|
||||
* @throws FileNotFoundException if something is really wrong
|
||||
*/
|
||||
@Test
|
||||
public final void test_getVersion() throws FileNotFoundException { // NOPMD by Braids on 8/12/11 10:36 AM
|
||||
final FModel model = new FModel(null);
|
||||
public final void test_getVersion() throws FileNotFoundException {
|
||||
final String version = model.getBuildInfo().getVersion();
|
||||
model.close();
|
||||
|
||||
assertEquals(version, "SVN", "version is default");
|
||||
}
|
||||
@@ -50,12 +79,8 @@ public class FModelTest {
|
||||
*/
|
||||
@Test
|
||||
public final void test_getBuildID() throws FileNotFoundException { // NOPMD by Braids on 8/12/11 10:36 AM
|
||||
final FModel model = new FModel(null);
|
||||
|
||||
// Just test for an unexpected exception.
|
||||
model.getBuildInfo().getBuildID();
|
||||
|
||||
model.close();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,12 +89,26 @@ public class FModelTest {
|
||||
*/
|
||||
@Test
|
||||
public final void test_getPreferences() throws FileNotFoundException {
|
||||
final FModel model = new FModel(null);
|
||||
try {
|
||||
ForgePreferences prefs = model.getPreferences();
|
||||
assertNotNull(prefs, "prefs instance is not null");
|
||||
} finally {
|
||||
model.close();
|
||||
}
|
||||
ForgePreferences prefs = model.getPreferences();
|
||||
assertNotNull(prefs, "prefs instance is not null");
|
||||
}
|
||||
|
||||
/**
|
||||
* Test resetGameState and getGameState.
|
||||
*/
|
||||
@Test
|
||||
public final void test_resetGameState_getGameState() {
|
||||
Singletons.setModel(model);
|
||||
assertNull(model.getGameState(), "game state has not yet been initialized");
|
||||
|
||||
FGameState state1 = model.resetGameState();
|
||||
assertNotNull(state1, "first state is OK");
|
||||
|
||||
FGameState state2 = model.resetGameState();
|
||||
assertNotNull(state1, "first state is OK");
|
||||
assertNotEquals(state1, state2, "first and second states are different");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user