20 package net.sf.gridarta.actions;
22 import java.awt.Point;
40 import org.jetbrains.annotations.NotNull;
41 import org.jetbrains.annotations.Nullable;
42 import org.junit.Assert;
43 import org.junit.Before;
44 import org.junit.Test;
99 assert testMapControlCreator != null;
103 final Point point1 =
new Point(3, 4);
104 Assert.assertTrue(actions.
doExitCopy(
false, mapControl, point1));
108 Assert.assertTrue(actions.
doExitCopy(
true, mapControl, point1));
109 assert testMapControlCreator != null;
114 Assert.assertFalse(actions.
doExitCopy(
false, mapControl, point1));
115 assert testMapControlCreator != null;
128 assert testMapControlCreator != null;
132 final Point point1 =
new Point(3, 4);
133 final Point point2 =
new Point(1, 2);
135 assert testMapControlCreator != null;
139 Assert.assertFalse(actions.
doExitPaste(
false, mapControl, point1));
143 assert mapModelHelper != null;
150 Assert.assertFalse(actions.
doExitPaste(
false, mapControl, point1));
154 assert mapModelHelper != null;
161 Assert.assertTrue(actions.
doExitPaste(
false, mapControl, point1));
162 checkExit(mapModel, point1, 1,
"",
new Point(0, 0));
165 Assert.assertTrue(actions.
doExitPaste(
true, mapControl, point1));
166 checkExit(mapModel, point1, 1,
"b", point2);
179 assert testMapControlCreator != null;
183 final Point point1 =
new Point(3, 4);
184 final Point point2 =
new Point(1, 2);
186 assert testMapControlCreator != null;
193 Assert.assertFalse(actions.
doExitCopy(
true, mapControl1, point1));
196 Assert.assertTrue(actions.
doExitPaste(
true, mapControl1, point1));
209 assert testMapControlCreator != null;
213 assert testMapControlCreator != null;
217 final Point point1 =
new Point(3, 4);
218 final Point point2 =
new Point(1, 2);
220 assert testMapControlCreator != null;
224 Assert.assertFalse(actions.
doExitConnect(
false, mapControl1, point1));
228 assert mapModelHelper != null;
235 Assert.assertFalse(actions.
doExitConnect(
false, mapControl1, point1));
239 assert mapModelHelper != null;
246 Assert.assertFalse(actions.
doExitConnect(
false, mapControl1, point1));
250 assert mapModelHelper != null;
257 Assert.assertTrue(actions.
doExitConnect(
false, mapControl1, point1));
258 checkExit(mapModel1, point1, 1,
"",
new Point(0, 0));
259 checkExit(mapModel2, point2, 0,
"",
new Point(0, 0));
262 Assert.assertTrue(actions.
doExitConnect(
true, mapControl1, point1));
263 checkExit(mapModel1, point1, 1,
"b", point2);
264 checkExit(mapModel2, point2, 0,
"a", point1);
277 assert testMapControlCreator != null;
281 assert testMapControlCreator != null;
285 final Point point1 =
new Point(3, 4);
286 final Point point2 =
new Point(1, 2);
288 assert testMapControlCreator != null;
295 Assert.assertFalse(actions.
doExitConnect(
true, mapControl1, point1));
296 checkExit(mapModel1, point1, 0, null, null);
297 checkExit(mapModel2, point2, 0, null, null);
302 Assert.assertTrue(actions.
doExitConnect(
true, mapControl1, point1));
303 checkExit(mapModel1, point1, 0,
"b", point2);
304 checkExit(mapModel2, point2, 0,
"a", point1);
307 Assert.assertTrue(actions.
doExitConnect(
true, mapControl1, point1));
308 checkExit(mapModel1, point1, 0,
"b", point2);
309 checkExit(mapModel1, point1, 1, null, null);
310 checkExit(mapModel2, point2, 0,
"a", point1);
311 checkExit(mapModel2, point2, 1, null, null);
323 testPath(
"/HallOfSelection",
"/world/world_104_115",
"/world/world_104_115");
324 testPath(
"/world/world_104_115",
"/HallOfSelection",
"/HallOfSelection");
327 testPath(
"/a/b/c/d",
"/a/d/e",
"../../d/e");
328 testPath(
"/a/b/c/d",
"/a/b/d",
"../d");
330 testPath(
"/a/b/c",
"/a/b/c/d",
"c/d");
333 testPath(
"/a/b/c",
"/b/c/d",
"/b/c/d");
345 private void testPath(@NotNull
final String mapPathFrom, @NotNull
final String mapPathTo, @NotNull
final String expectedExitPath) {
349 assert testMapControlCreator != null;
355 assert testMapControlCreator != null;
359 final Point pointFrom =
new Point(3, 4);
360 final Point pointTo =
new Point(1, 2);
362 assert testMapControlCreator != null;
366 assert mapModelHelper != null;
367 mapModelHelper.
insertExit(mapModel, pointFrom);
373 Assert.assertTrue(actions.
doExitPaste(
true, mapControl, pointFrom));
374 checkExit(mapModel, pointFrom, 0, expectedExitPath, pointTo);
394 assert tmpTestMapControlCreator != null;
411 if (thisIndex == index) {
416 if (exitPath == null || exitPoint == null) {
417 Assert.fail(
"exit found but none expected");
418 throw new AssertionError();
421 Assert.assertEquals(exitPath, gameObject.getAttributeString(
BaseObject.
SLAYING));
422 Assert.assertEquals(exitPoint.x, gameObject.getAttributeInt(
BaseObject.
HP));
423 Assert.assertEquals(exitPoint.y, gameObject.getAttributeInt(
BaseObject.
SP));
430 if (exitPath != null || exitPoint != null) {
431 Assert.fail(
"no exit found");
void testPath(@NotNull final String mapPathFrom, @NotNull final String mapPathTo, @NotNull final String expectedExitPath)
Checks that an exit path is correctly generated.
ExitMatcher< TestGameObject, TestMapArchObject, TestArchetype > getExitMatcher()
Returns the ExitMatcher.
void testExitConnect1()
Checks that MapControl, Point) does work.
void setExitLocation(@Nullable ExitLocation exitLocation)
Sets the remembered exit location.
static final int EXIT_TYPE
The archetype type used for "exit" game objects.
static MapPath newMapPath(@NotNull final String string)
Creates a MapPath instance from string representation.
void testPath1()
Checks that exit paths are correctly generated.
A MapModel reflects the data of a map.
static final MapFile MAP_FILE1
The first map file.
void endTransaction()
End a transaction.
Helper class for creating MapModel instances for regression tests.
static final String MAP_NAME1
The first map name.
ExitConnectorActions< TestGameObject, TestMapArchObject, TestArchetype > createActions(@NotNull final ExitConnectorModel model)
Creates a new ExitConnectorActions instance.
Helper class for creating MapControl instances for regression tests.
Regression tests for ExitConnectorActions.
void testExitPaste1()
Checks that MapControl, Point) does work.
A MapArchObject implementation for testing purposes.
void setExitArchetypeName(@NotNull String exitArchetypeName)
Sets the archetype name for creating exit game objects.
String SLAYING
The name of the "slaying" attribute.
MapModel< G, A, R > getMapModel()
Returns the map model.
TestGameObject insertFloor(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts a floorArchetype game object into a map model.
Base package of all Gridarta classes.
ExitConnectorModel implementation for regression tests.
A FileControl implementation for testing purposes.
boolean doExitConnect(final boolean performAction, @NotNull final MapControl< G, A, R > mapControl, @NotNull final Point targetLocation)
Executes the "exit connect" action.
An Exception indicating that an Archetype name is not unique.
String HP
The attribute name of the "hp" attribute.
GameObjects are the objects based on Archetypes found on maps.
static final String MAP_NAME2
The second map name.
Utility class for MapPath related functions.
ArchetypeSet< TestGameObject, TestMapArchObject, TestArchetype > getArchetypeSet()
Returns the ArchetypeSet.
InsertionModeSet< TestGameObject, TestMapArchObject, TestArchetype > getInsertionModeSet()
Returns the InsertionModeSet.
ProjectSettings getProjectSettings()
Returns the ProjectSettings.
TestMapModelHelper newMapModelCreator()
Creates a new TestMapModelHelper instance.
void testExitConnectAuto1()
Checks that MapControl, Point) does work when auto-creating exit objects.
ExitLocation getExitLocation()
Returns the remembered exit location.
TestGameObject insertExit(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point)
Inserts an exitArchetype game object into a map model.
static final MapFile BASE
The base MapFile for the test.
void setAutoCreateExit(boolean autoCreateExit)
Sets whether exit game objects should be auto-created when needed.
Utility class implementing actions that operate on ExitConnectorModels.
Stores information needed by the exit connector.
void setUp()
Initializes the test case.
Stores information about a remembered exit location.
void testExitCopy1()
Checks that MapControl, Point) does work.
void testExitPaste2()
Checks that MapControl, Point) does not crash when connecting to an unsaved map.
boolean doExitCopy(final boolean performAction, @NotNull final MapControl< G, A, R > mapControl, @NotNull final Point location)
Executes the "exit copy" action.
Currently nothing more than a marker interface for unification.
String SP
The attribute name of the "sp" attribute.
static final MapFile MAP_FILE2
The second map file.
An Archetype implementation for testing purposes.
A GameObject implementation for testing purposes.
File getMapsDirectory()
Returns the default maps directory.
void beginTransaction(@NotNull String name)
Starts a new transaction.
void setMapFile(@Nullable MapFile mapFile)
Sets the map file.
TestMapControlCreator testMapControlCreator
The TestMapControlCreator for creating maps.
boolean doExitPaste(final boolean performAction, @NotNull final MapControl< G, A, R > mapControl, @NotNull final Point targetLocation)
Executes the "exit paste" action.
TestMapModelHelper mapModelHelper
The TestMapModelHelper instance.
The location of a map file with a map directory.
MapManager< TestGameObject, TestMapArchObject, TestArchetype > getMapManager()
Returns the MapManager.
static void checkExit(@NotNull final MapModel< TestGameObject, TestMapArchObject, TestArchetype > mapModel, @NotNull final Point point, final int index, @Nullable final String exitPath, @Nullable final Point exitPoint)
Checks that a map model contains an exit game object.
The class Size2D represents a 2d rectangular area.
MapControl< TestGameObject, TestMapArchObject, TestArchetype > newMapControl(@Nullable final MapFile mapFile, @NotNull final String mapName, @NotNull final Size2D mapSize)
Creates a new map control.