001/*
002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
003 * Copyright (C) 2000-2011 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.gui.mapmenu;
021
022import java.awt.GraphicsEnvironment;
023import java.io.File;
024import java.io.IOException;
025import net.sf.gridarta.model.archetype.DuplicateArchetypeException;
026import net.sf.gridarta.model.archetype.TestArchetype;
027import net.sf.gridarta.model.gameobject.TestGameObject;
028import net.sf.gridarta.model.maparchobject.TestMapArchObject;
029import net.sf.gridarta.model.mapcontrol.MapControl;
030import net.sf.gridarta.model.mapcontrol.TestMapControlCreator;
031import net.sf.gridarta.utils.Size2D;
032import org.junit.Assert;
033import org.junit.Test;
034
035/**
036 * Regression tests for {@link MapMenuManager}.
037 * @author Andreas Kirschbaum
038 */
039public class MapMenuManagerTest {
040
041    /**
042     * Checks that {@link MapMenuManager} does not duplicate bookmark entries
043     * when a map is saved.
044     * @throws DuplicateArchetypeException if the test fails
045     * @throws IOException if the test fails
046     */
047    @Test
048    public void testSaveBookmarks() throws DuplicateArchetypeException, IOException {
049        if (GraphicsEnvironment.isHeadless()) {
050            return;
051        }
052
053        final TestMapControlCreator testMapControlCreator = new TestMapControlCreator();
054        final File file = File.createTempFile("gridarta", null);
055        final MapMenuPreferences mapMenuPreferences = new TestMapMenuPreferences();
056        try {
057            final MapControl<TestGameObject, TestMapArchObject, TestArchetype> mapControl1 = testMapControlCreator.newMapControl(file, "name1", new Size2D(1, 1));
058            final MapMenuEntryMap mapMenuEntry = new MapMenuEntryMap(new File("test1"), "title1");
059            mapMenuPreferences.addEntry(mapMenuEntry);
060            Assert.assertEquals(1, mapMenuPreferences.getMapMenu().size());
061            mapControl1.save();
062            Assert.assertEquals(1, mapMenuPreferences.getMapMenu().size());
063        } finally {
064            //noinspection ResultOfMethodCallIgnored
065            file.delete();
066        }
067    }
068
069}