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