Gridarta Editor
AttributeListUtilsTest.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2023 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.io;
21 
34 import org.jetbrains.annotations.NotNull;
35 import org.junit.Assert;
36 import org.junit.Test;
37 
42 public class AttributeListUtilsTest {
43 
48  @Test
49  public void testRemoveAttribute() {
50  checkRemoveAttribute("", "abc", "");
51 
52  checkRemoveAttribute("abc def\n", "abc", "");
53  checkRemoveAttribute("abc def\n", "ab", "abc def\n");
54  checkRemoveAttribute("abc def\n", "abcd", "abc def\n");
55 
56  checkRemoveAttribute("abc def\n" + "ghi jkl\n" + "mno pqr\n", "abc", "ghi jkl\n" + "mno pqr\n");
57  checkRemoveAttribute("abc def\n" + "ghi jkl\n" + "mno pqr\n", "def", "abc def\n" + "ghi jkl\n" + "mno pqr\n");
58  checkRemoveAttribute("abc def\n" + "ghi jkl\n" + "mno pqr\n", "ghi", "abc def\n" + "mno pqr\n");
59  checkRemoveAttribute("abc def\n" + "ghi jkl\n" + "mno pqr\n", "mno", "abc def\n" + "ghi jkl\n");
60 
61  checkRemoveAttribute("abc def\n" + "ghi jkl\n" + "mno pqr\n", "Abc", "abc def\n" + "ghi jkl\n" + "mno pqr\n");
62 
63  checkRemoveAttribute("abc def\n\n" + "ghi jkl\n\n", "xyz", "abc def\n" + "ghi jkl\n");
64  checkRemoveAttribute("\n\n" + "abc def\n\n", "ghi", "abc def\n");
65  checkRemoveAttribute("\n\n" + "abc def\n\n", "abc", "");
66  }
67 
75  private static void checkRemoveAttribute(@NotNull final String attributeList, @NotNull final String key, @NotNull final String expectedResult) {
76  Assert.assertEquals(expectedResult, AttributeListUtils.removeAttribute(attributeList, key));
77  }
78 
83  @Test
84  public void checkDiffArchTextValues1() {
85  Assert.assertEquals("b 3\nd 4\n", AttributeListUtils.diffArchTextValues(newArchetype("a 1\nb 2\nc 3\n"), "b 3\na 1\nd 4\n"));
86  Assert.assertEquals("d 4\nb 3\n", AttributeListUtils.diffArchTextValues(newArchetype("a 1\nb 2\nc 3\n"), "d 4\nb 3\na 1\n"));
87  Assert.assertEquals("b 3\nd 4\n", AttributeListUtils.diffArchTextValues(newArchetype("c 3\nb 2\na 1\n"), "b 3\na 1\nd 4\n"));
88  Assert.assertEquals("d 4\nb 3\n", AttributeListUtils.diffArchTextValues(newArchetype("c 3\nb 2\na 1\n"), "d 4\nb 3\na 1\n"));
89  Assert.assertEquals("e 5\nb 2\nf 6\n", AttributeListUtils.diffArchTextValues(newArchetype("a 1\nc 3\n"), "e 5\nb 2\nf 6\n"));
90  Assert.assertEquals("f 6\nb 2\ne 5\n", AttributeListUtils.diffArchTextValues(newArchetype("a 1\nc 3\n"), "f 6\nb 2\ne 5\n"));
91  }
92 
98  @NotNull
99  private static BaseObject<?, ?, ?, ?> newArchetype(@NotNull final String objectText) {
100  final FaceObjects faceObjects = new TestFaceObjects();
101  final ResourceIcons resourceIcons = new ResourceIcons();
102  final FaceObjectProviders faceObjectProviders = new FaceObjectProviders(0, faceObjects, resourceIcons);
103  final AnimationObjects animationObjects = new TestAnimationObjects();
104  final GameObjectFactory<TestGameObject, TestMapArchObject, TestArchetype> gameObjectFactory = new TestGameObjectFactory(faceObjectProviders, animationObjects);
105  final TestArchetype archetype = gameObjectFactory.newArchetype("arch");
106  archetype.setObjectText(objectText);
107  return archetype;
108  }
109 
110 }
net.sf.gridarta.model.archetype.TestArchetype
An Archetype implementation for testing purposes.
Definition: TestArchetype.java:30
net.sf.gridarta.model.gameobject.GameObjectFactory
Abstract factory for creating GameObject instances.
Definition: GameObjectFactory.java:31
net.sf.gridarta.model.io.AttributeListUtils.removeAttribute
static String removeAttribute(@NotNull final String attributeList, @NotNull final String key)
Removes an attribute from an attribute list.
Definition: AttributeListUtils.java:44
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.anim.AnimationObjects
AnimationObjects is a container for AnimationObjects.
Definition: AnimationObjects.java:30
net.sf.gridarta.model.gameobject.TestGameObject
A GameObject implementation for testing purposes.
Definition: TestGameObject.java:34
net.sf
net.sf.gridarta.model.io.AttributeListUtilsTest
Test for AttributeListUtils.
Definition: AttributeListUtilsTest.java:42
net.sf.gridarta.model.io.AttributeListUtils
Utility class for archetype attribute related functions.
Definition: AttributeListUtils.java:30
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.io.AttributeListUtilsTest.testRemoveAttribute
void testRemoveAttribute()
Test case for String).
Definition: AttributeListUtilsTest.java:49
net.sf.gridarta.model.face.FaceObjectProviders
Provider for faces of GameObjects and Archetypes.
Definition: FaceObjectProviders.java:46
net.sf.gridarta.model.anim.TestAnimationObjects
An AnimationObjects for regression tests.
Definition: TestAnimationObjects.java:26
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.gameobject.GameObjectFactory.newArchetype
R newArchetype(@NotNull String archetypeName)
Creates a new Archetype instance.
net.sf.gridarta.model.io.AttributeListUtilsTest.checkDiffArchTextValues1
void checkDiffArchTextValues1()
Checks that CharSequence) returns correct values.
Definition: AttributeListUtilsTest.java:84
net.sf.gridarta.model.gameobject.TestGameObjectFactory
A GameObjectFactory for regression tests.
Definition: TestGameObjectFactory.java:34
net.sf.gridarta.model.face.FaceObjects
FaceObjects is a container for FaceObjects.
Definition: FaceObjects.java:31
net.sf.gridarta.model.io.AttributeListUtils.diffArchTextValues
static String diffArchTextValues(@NotNull final BaseObject<?, ?, ?, ?> archetype, @NotNull final CharSequence attributes)
Returns all entries from the given attributes that don't exist in an archetype.
Definition: AttributeListUtils.java:93
net.sf.gridarta.model.baseobject.BaseObject
Definition: BaseObject.java:34
net.sf.gridarta.model
net.sf.gridarta.model.baseobject
Definition: AbstractBaseObject.java:20
net.sf.gridarta.model.io.AttributeListUtilsTest.newArchetype
static BaseObject<?, ?, ?, ?> newArchetype(@NotNull final String objectText)
Creates a new archetype.
Definition: AttributeListUtilsTest.java:99
net.sf.gridarta.model.face
The face is the appearance of an object.
Definition: AbstractFaceObjects.java:20
net.sf.gridarta.model.anim
Gridarta can handle frame information of animations and allow the selection of an animation using a t...
Definition: AbstractAnimationObjects.java:20
net.sf.gridarta.model.maparchobject.TestMapArchObject
A MapArchObject implementation for testing purposes.
Definition: TestMapArchObject.java:28
net.sf.gridarta.model.maparchobject
Definition: AbstractMapArchObject.java:20
net.sf.gridarta.utils.ResourceIcons
Creates ImageIcon instances from resources.
Definition: ResourceIcons.java:46
net.sf.gridarta.model.io.AttributeListUtilsTest.checkRemoveAttribute
static void checkRemoveAttribute(@NotNull final String attributeList, @NotNull final String key, @NotNull final String expectedResult)
Calls AttributeListUtils#removeAttribute(String, String) and checks for expected results.
Definition: AttributeListUtilsTest.java:75
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.model.face.TestFaceObjects
A FaceObjects for regression tests.
Definition: TestFaceObjects.java:30