Gridarta Editor
MapMenuManagerTest.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.gui.mapmenu;
21 
22 import java.awt.GraphicsEnvironment;
23 import java.io.File;
24 import java.io.IOException;
31 import net.sf.gridarta.utils.Size2D;
32 import org.junit.Assert;
33 import org.junit.Test;
34 
39 public class MapMenuManagerTest {
40 
46  @Test
47  public void testSaveBookmarks() throws IOException {
48  if (GraphicsEnvironment.isHeadless()) {
49  return;
50  }
51 
52  final TestMapControlCreator testMapControlCreator = new TestMapControlCreator();
53  final File file = File.createTempFile("gridarta", null);
54  final MapMenuPreferences mapMenuPreferences = new TestMapMenuPreferences(new PathManager(testMapControlCreator.getProjectSettings()));
55  try {
56  final PathManager pathManager = testMapControlCreator.getPathManager();
57  final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl1 = testMapControlCreator.newMapControl(pathManager.getMapFile(file), "name1", new Size2D(1, 1));
58  final MapMenuEntryMap mapMenuEntry = new MapMenuEntryMap(pathManager.getMapFile(new File("test1")), "title1");
59  mapMenuPreferences.addEntry(mapMenuEntry);
60  Assert.assertEquals(1, mapMenuPreferences.getMapMenu().size());
61  mapControl1.save();
62  Assert.assertEquals(1, mapMenuPreferences.getMapMenu().size());
63  } finally {
64  //noinspection ResultOfMethodCallIgnored
65  file.delete();
66  }
67  }
68 
69 }
net.sf.gridarta.model.archetype.TestArchetype
An Archetype implementation for testing purposes.
Definition: TestArchetype.java:30
net.sf.gridarta.gui.mapmenu.MapMenuPreferences.getMapMenu
MapMenu getMapMenu()
Returns the managed MapMenu.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.gameobject.TestGameObject
A GameObject implementation for testing purposes.
Definition: TestGameObject.java:34
net.sf
net.sf.gridarta.model.io.PathManager
This class contains methods for converting relative map paths to absolute map paths and vice versa.
Definition: PathManager.java:39
net.sf.gridarta.gui.mapmenu.MapMenuPreferences
Manages a MapMenu instance, implementing constraints for recent or bookmark menus.
Definition: MapMenuPreferences.java:29
net.sf.gridarta.model.archetype
Definition: AbstractArchetype.java:20
net.sf.gridarta.model.mapcontrol
Definition: DefaultMapControl.java:20
net.sf.gridarta.gui.mapmenu.MapMenuPreferences.addEntry
void addEntry(@NotNull MapMenuEntryMap mapMenuEntry)
Adds a new entry to the menu.
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.getPathManager
PathManager getPathManager()
Returns the PathManager.
Definition: TestMapControlCreator.java:188
net.sf.gridarta.model.mapcontrol.TestMapControlCreator
Helper class for creating MapControl instances for regression tests.
Definition: TestMapControlCreator.java:68
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net
net.sf.gridarta.model.io.PathManager.getMapFile
MapFile getMapFile(@NotNull final AbsoluteMapPath mapPath)
Returns a MapFile instance from an AbsoluteMapPath.
Definition: PathManager.java:72
net.sf.gridarta.gui.mapmenu.MapMenuManagerTest
Regression tests for MapMenuManager.
Definition: MapMenuManagerTest.java:39
net.sf.gridarta.model.mapcontrol.MapControl.save
void save()
Saves the map to a file.
net.sf.gridarta.model.io
Reading and writing of maps, handling of paths.
Definition: AbstractAnimationObjectsReader.java:20
net.sf.gridarta.gui.mapmenu.MapMenuManagerTest.testSaveBookmarks
void testSaveBookmarks()
Checks that MapMenuManager does not duplicate bookmark entries when a map is saved.
Definition: MapMenuManagerTest.java:47
net.sf.gridarta.gui.mapmenu.MapMenu.size
int size()
Returns the number of entries in this menu.
Definition: MapMenu.java:350
net.sf.gridarta.model
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.getProjectSettings
ProjectSettings getProjectSettings()
Returns the ProjectSettings.
Definition: TestMapControlCreator.java:197
net.sf.gridarta.model.mapcontrol.TestMapControlCreator.newMapControl
MapControl< TestGameObject, TestMapArchObject, TestArchetype > newMapControl(@Nullable final MapFile mapFile, @NotNull final String mapName, @NotNull final Size2D mapSize)
Creates a new map control.
Definition: TestMapControlCreator.java:176
net.sf.gridarta.model.mapcontrol.MapControl
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
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.gui.mapmenu.MapMenuEntryMap
A MapMenuEntry that represents a map.
Definition: MapMenuEntryMap.java:29
net.sf.gridarta.utils.Size2D
The class Size2D represents a 2d rectangular area.
Definition: Size2D.java:30
net.sf.gridarta.utils
Definition: ActionBuilderUtils.java:20
net.sf.gridarta.gui.mapmenu.TestMapMenuPreferences
An AbstractMapMenuPreferences implementation for regression tests.
Definition: TestMapMenuPreferences.java:29