001/* 002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games. 003 * Copyright (C) 2000-2010 The Gridarta Developers. 004 * 005 * This program is free software; you can redistribute it and/or modify 006 * it under the terms of the GNU General Public License as published by 007 * the Free Software Foundation; either version 2 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License along 016 * with this program; if not, write to the Free Software Foundation, Inc., 017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 018 */ 019 020package net.sf.gridarta.model.baseobject; 021 022import java.awt.Point; 023import net.sf.gridarta.model.anim.AnimationObjects; 024import net.sf.gridarta.model.anim.TestAnimationObjects; 025import net.sf.gridarta.model.archetype.TestArchetype; 026import net.sf.gridarta.model.archetype.TestDefaultArchetype; 027import net.sf.gridarta.model.face.FaceObjectProviders; 028import net.sf.gridarta.model.face.FaceObjects; 029import net.sf.gridarta.model.face.TestFaceObjects; 030import net.sf.gridarta.model.gameobject.GameObject; 031import net.sf.gridarta.model.gameobject.TestGameObject; 032import net.sf.gridarta.model.maparchobject.TestMapArchObject; 033import net.sf.gridarta.model.mapmodel.InsertionMode; 034import net.sf.gridarta.model.mapmodel.MapModel; 035import net.sf.gridarta.model.mapmodel.TestMapModelCreator; 036import net.sf.gridarta.model.mapmodel.TopmostInsertionMode; 037import net.sf.gridarta.utils.ResourceIcons; 038import org.jetbrains.annotations.NotNull; 039import org.jetbrains.annotations.Nullable; 040import org.junit.Assert; 041import org.junit.Test; 042 043/** 044 * Regression tests for {@link AbstractBaseObject}. 045 * @author Andreas Kirschbaum 046 */ 047public class AbstractBaseObjectTest { 048 049 /** 050 * The {@link ResourceIcons} instance. 051 */ 052 @NotNull 053 private final ResourceIcons resourceIcons = new ResourceIcons(); 054 055 /** 056 * Checks that setting the face name does work. 057 */ 058 @Test 059 public void testSetFaceName1() { 060 final AnimationObjects animationObjects = new TestAnimationObjects(); 061 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 062 final TestArchetype archetype = newArchetype("arch", null, faceObjectProviders, animationObjects); 063 Assert.assertNull(archetype.getFaceName()); 064 archetype.setAttributeString("face", "arch_face"); 065 Assert.assertEquals("arch_face", archetype.getFaceName()); 066 final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = newGameObject(archetype, "test", faceObjectProviders, animationObjects); 067 068 // check that default face is archetype face 069 Assert.assertNull(gameObject.getFaceName()); 070 071 // reset face 072 gameObject.setObjectText(""); 073 Assert.assertNull(gameObject.getFaceName()); 074 075 // set face by text change 076 gameObject.setAttributeString("face1", "face1"); 077 Assert.assertNull(gameObject.getFaceName()); 078 gameObject.setAttributeString("face", "face2"); 079 Assert.assertEquals("face2", gameObject.getFaceName()); 080 gameObject.setAttributeString("face2", "face3"); 081 Assert.assertEquals("face2", gameObject.getFaceName()); 082 083 // reset object text ==> face reverts to archetype face 084 gameObject.setObjectText(""); 085 Assert.assertNull(gameObject.getFaceName()); 086 087 // set face by text change 088 gameObject.setObjectText("abc 1\n" + "face face4\n" + "def 2\n"); 089 Assert.assertEquals("face4", gameObject.getFaceName()); 090 091 // unset face by text change 092 gameObject.setObjectText("abc 1\n" + "def 2\n"); 093 Assert.assertNull(gameObject.getFaceName()); 094 095 // set face to archetype face 096 gameObject.setObjectText("abc 1\n" + "face arch_face\n" + "def 2\n"); 097 Assert.assertNull(gameObject.getFaceName()); 098 } 099 100 /** 101 * Checks that a custom face may be changed. 102 */ 103 @Test 104 public void testSetFaceName2() { 105 final AnimationObjects animationObjects = new TestAnimationObjects(); 106 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 107 final TestArchetype archetype = newArchetype("arch", "face arch_face", faceObjectProviders, animationObjects); 108 final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = newGameObject(archetype, "test", faceObjectProviders, animationObjects); 109 110 Assert.assertNull(gameObject.getFaceName()); // default face 111 gameObject.setObjectText("face face1\n"); 112 Assert.assertEquals("face1", gameObject.getFaceName()); 113 gameObject.setObjectText("face face2\n"); 114 Assert.assertEquals("face2", gameObject.getFaceName()); 115 } 116 117 /** 118 * Checks that {@link GameObject#setAttributeString(String, String)} does 119 * work. 120 */ 121 @Test 122 public void testSetAttributeString() { 123 final AnimationObjects animationObjects = new TestAnimationObjects(); 124 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 125 final TestArchetype archetype = newArchetype("arch", "key1 value1\n" + "key2 value2\n", faceObjectProviders, animationObjects); 126 127 final BaseObject<?, ?, ?, ?> gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects); 128 129 Assert.assertEquals("value1", gameObject.getAttributeString("key1")); 130 Assert.assertEquals("value1", gameObject.getAttributeString("key1", true)); 131 Assert.assertEquals("", gameObject.getAttributeString("key1", false)); 132 Assert.assertEquals("value2", gameObject.getAttributeString("key2")); 133 Assert.assertEquals("value2", gameObject.getAttributeString("key2", true)); 134 Assert.assertEquals("", gameObject.getAttributeString("key2", false)); 135 Assert.assertEquals("", gameObject.getAttributeString("key3")); 136 Assert.assertEquals("", gameObject.getAttributeString("key3", true)); 137 Assert.assertEquals("", gameObject.getAttributeString("key3", false)); 138 Assert.assertEquals("", gameObject.getObjectText()); 139 140 gameObject.setAttributeString("key3", "value3"); 141 142 Assert.assertEquals("value1", gameObject.getAttributeString("key1")); 143 Assert.assertEquals("value1", gameObject.getAttributeString("key1", true)); 144 Assert.assertEquals("", gameObject.getAttributeString("key1", false)); 145 Assert.assertEquals("value2", gameObject.getAttributeString("key2")); 146 Assert.assertEquals("value2", gameObject.getAttributeString("key2", true)); 147 Assert.assertEquals("", gameObject.getAttributeString("key2", false)); 148 Assert.assertEquals("value3", gameObject.getAttributeString("key3")); 149 Assert.assertEquals("value3", gameObject.getAttributeString("key3", true)); 150 Assert.assertEquals("value3", gameObject.getAttributeString("key3", false)); 151 Assert.assertEquals("key3 value3\n", gameObject.getObjectText()); 152 153 gameObject.setAttributeString("key2", "VALUE2"); 154 155 Assert.assertEquals("value1", gameObject.getAttributeString("key1")); 156 Assert.assertEquals("value1", gameObject.getAttributeString("key1", true)); 157 Assert.assertEquals("", gameObject.getAttributeString("key1", false)); 158 Assert.assertEquals("VALUE2", gameObject.getAttributeString("key2")); 159 Assert.assertEquals("VALUE2", gameObject.getAttributeString("key2", true)); 160 Assert.assertEquals("VALUE2", gameObject.getAttributeString("key2", false)); 161 Assert.assertEquals("value3", gameObject.getAttributeString("key3")); 162 Assert.assertEquals("value3", gameObject.getAttributeString("key3", true)); 163 Assert.assertEquals("value3", gameObject.getAttributeString("key3", false)); 164 Assert.assertEquals("key3 value3\n" + "key2 VALUE2\n", gameObject.getObjectText()); 165 166 gameObject.setAttributeString("key3", ""); 167 168 Assert.assertEquals("value1", gameObject.getAttributeString("key1")); 169 Assert.assertEquals("value1", gameObject.getAttributeString("key1", true)); 170 Assert.assertEquals("", gameObject.getAttributeString("key1", false)); 171 Assert.assertEquals("VALUE2", gameObject.getAttributeString("key2")); 172 Assert.assertEquals("VALUE2", gameObject.getAttributeString("key2", true)); 173 Assert.assertEquals("VALUE2", gameObject.getAttributeString("key2", false)); 174 Assert.assertEquals("", gameObject.getAttributeString("key3")); 175 Assert.assertEquals("", gameObject.getAttributeString("key3", true)); 176 Assert.assertEquals("", gameObject.getAttributeString("key3", false)); 177 Assert.assertEquals("key2 VALUE2\n", gameObject.getObjectText()); 178 179 gameObject.setAttributeString("key2", "value2"); 180 181 Assert.assertEquals("value1", gameObject.getAttributeString("key1")); 182 Assert.assertEquals("value1", gameObject.getAttributeString("key1", true)); 183 Assert.assertEquals("", gameObject.getAttributeString("key1", false)); 184 Assert.assertEquals("value2", gameObject.getAttributeString("key2")); 185 Assert.assertEquals("value2", gameObject.getAttributeString("key2", true)); 186 Assert.assertEquals("", gameObject.getAttributeString("key2", false)); 187 Assert.assertEquals("", gameObject.getAttributeString("key3")); 188 Assert.assertEquals("", gameObject.getAttributeString("key3", true)); 189 Assert.assertEquals("", gameObject.getAttributeString("key3", false)); 190 Assert.assertEquals("", gameObject.getObjectText()); 191 } 192 193 /** 194 * Checks that caching the "direction" attribute does work. 195 */ 196 @Test 197 public void testDirection1() { 198 final AnimationObjects animationObjects = new TestAnimationObjects(); 199 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 200 final TestArchetype archetype = newArchetype("arch", null, faceObjectProviders, animationObjects); 201 final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = newGameObject(archetype, "test", faceObjectProviders, animationObjects); 202 checkDirection(gameObject, 0); 203 gameObject.setAttributeString("direction", "3"); 204 checkDirection(gameObject, 3); 205 gameObject.removeAttribute("direction"); 206 checkDirection(gameObject, 0); 207 gameObject.setObjectText("direction 3"); 208 checkDirection(gameObject, 3); 209 } 210 211 /** 212 * Checks that caching the "direction" attribute does work. 213 */ 214 @Test 215 public void testDirection2() { 216 final AnimationObjects animationObjects = new TestAnimationObjects(); 217 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 218 final TestArchetype archetype = newArchetype("arch", "direction 2", faceObjectProviders, animationObjects); 219 final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = newGameObject(archetype, "test", faceObjectProviders, animationObjects); 220 checkDirection(gameObject, 2); 221 gameObject.setAttributeString("direction", "3"); 222 checkDirection(gameObject, 3); 223 gameObject.removeAttribute("direction"); 224 checkDirection(gameObject, 2); 225 } 226 227 /** 228 * Checks that caching the "direction" attribute does work. 229 */ 230 @Test 231 public void testDirection3() { 232 final AnimationObjects animationObjects = new TestAnimationObjects(); 233 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 234 final TestArchetype archetype1 = newArchetype("arch", "direction 1", faceObjectProviders, animationObjects); 235 final TestArchetype archetype2 = newArchetype("arch", "direction 2", faceObjectProviders, animationObjects); 236 final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = newGameObject(archetype1, "test", faceObjectProviders, animationObjects); 237 checkDirection(gameObject, 1); 238 gameObject.setArchetype(archetype2); 239 checkDirection(gameObject, 2); 240 gameObject.setAttributeString("direction", "4"); 241 checkDirection(gameObject, 4); 242 gameObject.setArchetype(archetype1); 243 checkDirection(gameObject, 4); 244 gameObject.removeAttribute("direction"); 245 checkDirection(gameObject, 1); 246 } 247 248 /** 249 * Checks that the "direction" attribute of a {@link GameObject} contains 250 * the expected value. 251 * @param gameObject the game object to check 252 * @param direction the expected direction 253 */ 254 private static void checkDirection(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final int direction) { 255 Assert.assertEquals(direction, gameObject.getDirection()); 256 Assert.assertEquals(direction, gameObject.getAttributeInt("direction")); 257 } 258 259 /** 260 * Checks that caching the "type" attribute does work. 261 */ 262 @Test 263 public void testType1() { 264 final AnimationObjects animationObjects = new TestAnimationObjects(); 265 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 266 final TestArchetype archetype = newArchetype("arch", null, faceObjectProviders, animationObjects); 267 final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = newGameObject(archetype, "test", faceObjectProviders, animationObjects); 268 checkType(gameObject, 0); 269 gameObject.setAttributeString("type", "3"); 270 checkType(gameObject, 3); 271 gameObject.removeAttribute("type"); 272 checkType(gameObject, 0); 273 gameObject.setObjectText("type 3"); 274 checkType(gameObject, 3); 275 } 276 277 /** 278 * Checks that caching the "type" attribute does work. 279 */ 280 @Test 281 public void testType2() { 282 final AnimationObjects animationObjects = new TestAnimationObjects(); 283 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 284 final TestArchetype archetype = newArchetype("arch", "type 2", faceObjectProviders, animationObjects); 285 final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = newGameObject(archetype, "test", faceObjectProviders, animationObjects); 286 checkType(gameObject, 2); 287 gameObject.setAttributeString("type", "3"); 288 checkType(gameObject, 3); 289 gameObject.removeAttribute("type"); 290 checkType(gameObject, 2); 291 } 292 293 /** 294 * Checks that caching the "type" attribute does work. 295 */ 296 @Test 297 public void testType3() { 298 final AnimationObjects animationObjects = new TestAnimationObjects(); 299 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 300 final TestArchetype archetype1 = newArchetype("arch", "type 1", faceObjectProviders, animationObjects); 301 final TestArchetype archetype2 = newArchetype("arch", "type 2", faceObjectProviders, animationObjects); 302 final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = newGameObject(archetype1, "test", faceObjectProviders, animationObjects); 303 checkType(gameObject, 1); 304 gameObject.setArchetype(archetype2); 305 checkType(gameObject, 2); 306 gameObject.setAttributeString("type", "4"); 307 checkType(gameObject, 4); 308 gameObject.setArchetype(archetype1); 309 checkType(gameObject, 4); 310 gameObject.removeAttribute("type"); 311 checkType(gameObject, 1); 312 } 313 314 /** 315 * Checks that the {@link BaseObject#TYPE} attribute of a {@link GameObject} 316 * contains the expected value. 317 * @param gameObject the game object to check 318 * @param type the expected direction 319 */ 320 private static void checkType(@NotNull final BaseObject<?, ?, ?, ?> gameObject, final int type) { 321 Assert.assertEquals(type, gameObject.getTypeNo()); 322 Assert.assertEquals(type, gameObject.getAttributeInt(BaseObject.TYPE)); 323 } 324 325 /** 326 * Checks that caching the "name" attribute does work. 327 */ 328 @Test 329 public void testName1() { 330 final AnimationObjects animationObjects = new TestAnimationObjects(); 331 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 332 final TestArchetype archetype = newArchetype("arch", null, faceObjectProviders, animationObjects); 333 final BaseObject<?, ?, ?, ?> gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects); 334 checkName(gameObject, "arch", ""); 335 gameObject.setAttributeString("name", "3"); 336 checkName(gameObject, "3", "3"); 337 gameObject.removeAttribute("name"); 338 checkName(gameObject, "arch", ""); 339 gameObject.setObjectText("name 3"); 340 checkName(gameObject, "3", "3"); 341 } 342 343 /** 344 * Checks that caching the "name" attribute does work. 345 */ 346 @Test 347 public void testName2() { 348 final AnimationObjects animationObjects = new TestAnimationObjects(); 349 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 350 final TestArchetype archetype = newArchetype("arch", "name 2", faceObjectProviders, animationObjects); 351 final BaseObject<?, ?, ?, ?> gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects); 352 checkName(gameObject, "2", "2"); 353 gameObject.setAttributeString("name", "3"); 354 checkName(gameObject, "3", "3"); 355 gameObject.removeAttribute("name"); 356 checkName(gameObject, "2", "2"); 357 } 358 359 /** 360 * Checks that caching the "name" attribute does work. 361 */ 362 @Test 363 public void testName3() { 364 final AnimationObjects animationObjects = new TestAnimationObjects(); 365 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 366 final TestArchetype archetype1 = newArchetype("arch", "name 1", faceObjectProviders, animationObjects); 367 final TestArchetype archetype2 = newArchetype("arch", "name 2", faceObjectProviders, animationObjects); 368 final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = new TestGameObject(archetype1, faceObjectProviders, animationObjects); 369 checkName(gameObject, "1", "1"); 370 gameObject.setArchetype(archetype2); 371 checkName(gameObject, "2", "2"); 372 gameObject.setAttributeString("name", "4"); 373 checkName(gameObject, "4", "4"); 374 gameObject.setArchetype(archetype1); 375 checkName(gameObject, "4", "4"); 376 gameObject.removeAttribute("name"); 377 checkName(gameObject, "1", "1"); 378 } 379 380 /** 381 * Checks that {@link AbstractBaseObject#setAttributeInt(String, int)} works 382 * as expected. 383 */ 384 @Test 385 public void testSetAttributeInt1() { 386 final AnimationObjects animationObjects = new TestAnimationObjects(); 387 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 388 final TestArchetype archetype1 = newArchetype("arch", "a 1\nb 0\nc 2", faceObjectProviders, animationObjects); 389 final BaseObject<?, ?, ?, ?> gameObject = new TestGameObject(archetype1, faceObjectProviders, animationObjects); 390 Assert.assertEquals("", gameObject.getAttributeString("a", false)); 391 Assert.assertEquals("", gameObject.getAttributeString("b", false)); 392 Assert.assertEquals("", gameObject.getAttributeString("c", false)); 393 Assert.assertEquals("", gameObject.getAttributeString("d", false)); 394 395 gameObject.setAttributeInt("a", 1); 396 gameObject.setAttributeInt("b", 0); 397 gameObject.setAttributeInt("c", 2); 398 gameObject.setAttributeInt("d", 0); 399 Assert.assertEquals("", gameObject.getAttributeString("a", false)); 400 Assert.assertEquals("", gameObject.getAttributeString("b", false)); 401 Assert.assertEquals("", gameObject.getAttributeString("c", false)); 402 Assert.assertEquals("", gameObject.getAttributeString("d", false)); 403 404 gameObject.setAttributeInt("a", 0); 405 gameObject.setAttributeInt("b", 1); 406 gameObject.setAttributeInt("c", 0); 407 gameObject.setAttributeInt("d", 2); 408 Assert.assertEquals("0", gameObject.getAttributeString("a", false)); 409 Assert.assertEquals("1", gameObject.getAttributeString("b", false)); 410 Assert.assertEquals("0", gameObject.getAttributeString("c", false)); 411 Assert.assertEquals("2", gameObject.getAttributeString("d", false)); 412 413 gameObject.setAttributeInt("a", 1); 414 gameObject.setAttributeInt("b", 0); 415 gameObject.setAttributeInt("c", 2); 416 gameObject.setAttributeInt("d", 0); 417 Assert.assertEquals("", gameObject.getAttributeString("a", false)); 418 Assert.assertEquals("", gameObject.getAttributeString("b", false)); 419 Assert.assertEquals("", gameObject.getAttributeString("c", false)); 420 Assert.assertEquals("", gameObject.getAttributeString("d", false)); 421 } 422 423 /** 424 * Checks that {@link AbstractBaseObject#toString(String)} works as 425 * expected. 426 */ 427 @Test 428 public void testToString1() { 429 final AnimationObjects animationObjects = new TestAnimationObjects(); 430 final FaceObjectProviders faceObjectProviders = newFaceObjectProviders(); 431 final TestArchetype archetype1 = newArchetype("arch", "level 10", faceObjectProviders, animationObjects); 432 final BaseObject<?, ?, ?, ?> gameObject = new TestGameObject(archetype1, faceObjectProviders, animationObjects); 433 gameObject.setAttributeString("name", "Name"); 434 gameObject.setAttributeString("title", "Title"); 435 436 Assert.assertEquals("format", gameObject.toString("format")); 437 Assert.assertEquals("Name TitleNameName TitleTitle", gameObject.toString("${NAME}${name}${NAME}${title}${other}")); 438 Assert.assertEquals("", gameObject.toString("${other:abc}")); 439 Assert.assertEquals("abc", gameObject.toString("${name:abc}")); 440 Assert.assertEquals("abc", gameObject.toString("${level:abc}")); 441 Assert.assertEquals("test", gameObject.toString("te${other: 1${other}2 }st")); 442 Assert.assertEquals("te 1Name2 st", gameObject.toString("te${name: 1${name}2 }st")); 443 Assert.assertEquals("te 1102 st", gameObject.toString("te${level: 1${level}2 }st")); 444 } 445 446 /** 447 * Checks that {@link BaseObject#setObjectText(String)} ignores attribute 448 * ordering. 449 */ 450 @Test 451 public void testSetObjectTextAttributeOrdering() { 452 final InsertionMode<TestGameObject, TestMapArchObject, TestArchetype> topmostInsertionMode = new TopmostInsertionMode<TestGameObject, TestMapArchObject, TestArchetype>(); 453 final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false); 454 final MapModel<TestGameObject, TestMapArchObject, TestArchetype> mapModel = mapModelCreator.newMapModel(1, 1); 455 mapModel.beginTransaction("test"); 456 try { 457 mapModelCreator.addGameObjectToMap(mapModel, "floor", "1", 0, 0, topmostInsertionMode); 458 } finally { 459 mapModel.endTransaction(); 460 } 461 final TestGameObject gameObject = mapModel.getMapSquare(new Point(0, 0)).iterator().next(); 462 463 mapModel.resetModified(); 464 mapModel.beginTransaction("test"); 465 try { 466 gameObject.setObjectText("a 1\nb 2\n"); 467 } finally { 468 mapModel.endTransaction(); 469 } 470 Assert.assertTrue(mapModel.isModified()); 471 472 mapModel.resetModified(); 473 mapModel.beginTransaction("test"); 474 try { 475 gameObject.setObjectText("b 2\na 1\n"); 476 } finally { 477 mapModel.endTransaction(); 478 } 479 Assert.assertFalse(mapModel.isModified()); 480 } 481 482 /** 483 * Checks that the {@link BaseObject#NAME} attribute of an {@link 484 * GameObject} contains the expected value. 485 * @param gameObject the game object to check 486 * @param name the expected name (cached value) 487 * @param nameAttribute the expected name ("name" attribute) 488 */ 489 private static void checkName(@NotNull final BaseObject<?, ?, ?, ?> gameObject, @NotNull final String name, @NotNull final String nameAttribute) { 490 Assert.assertEquals(name, gameObject.getObjName()); 491 Assert.assertEquals(nameAttribute, gameObject.getAttributeString(BaseObject.NAME)); 492 } 493 494 /** 495 * Creates a new {@link TestArchetype} instance. 496 * @param archetypeName the archetype name 497 * @param objectText the object text to add or <code>null</code> 498 * @param faceObjectProviders the face object providers for looking up 499 * faces 500 * @param animationObjects the animation objects for looking up animations 501 * @return the archetype instance 502 */ 503 @NotNull 504 private static TestArchetype newArchetype(@NotNull final String archetypeName, @Nullable final String objectText, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects) { 505 final TestArchetype archetype = new TestDefaultArchetype(archetypeName, faceObjectProviders, animationObjects); 506 if (objectText != null) { 507 archetype.setObjectText(objectText); 508 } 509 return archetype; 510 } 511 512 /** 513 * Creates a new game object instance. 514 * @param archetype the archetype to create the game object from 515 * @param name the game object's name 516 * @param faceObjectProviders the face object providers for looking up 517 * faces 518 * @param animationObjects the animation objects for looking up animations 519 * @return the game object instance 520 */ 521 @NotNull 522 private static GameObject<TestGameObject, TestMapArchObject, TestArchetype> newGameObject(@NotNull final TestArchetype archetype, @NotNull final String name, @NotNull final FaceObjectProviders faceObjectProviders, @NotNull final AnimationObjects animationObjects) { 523 final GameObject<TestGameObject, TestMapArchObject, TestArchetype> gameObject = new TestGameObject(archetype, faceObjectProviders, animationObjects); 524 gameObject.setAttributeString(BaseObject.NAME, name); 525 return gameObject; 526 } 527 528 /** 529 * Creates a new {@link FaceObjectProviders} instance. 530 * @return the face object providers instance 531 */ 532 private FaceObjectProviders newFaceObjectProviders() { 533 final FaceObjects faceObjects = new TestFaceObjects(); 534 assert resourceIcons != null; 535 return new FaceObjectProviders(0, faceObjects, resourceIcons); 536 } 537 538}