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.map.renderer;
021
022import net.sf.gridarta.model.archetype.TestArchetype;
023import net.sf.gridarta.model.gameobject.GameObjectFactory;
024import net.sf.gridarta.model.gameobject.TestGameObject;
025import net.sf.gridarta.model.io.GameObjectParser;
026import net.sf.gridarta.model.maparchobject.TestMapArchObject;
027import net.sf.gridarta.model.mapmodel.TestMapModelCreator;
028import org.junit.Assert;
029import org.junit.Test;
030
031/**
032 * Regression tests for {@link ToolTipAppender}.
033 * @author Andreas Kirschbaum
034 */
035public class ToolTipAppenderTest {
036
037    /**
038     * Checks that HTML tags are correctly encoded in tooltip.
039     */
040    @Test
041    public void testEmbeddedHtml1() {
042        final TestMapModelCreator mapModelCreator = new TestMapModelCreator(false);
043        final GameObjectParser<TestGameObject, TestMapArchObject, TestArchetype> gameObjectParser = mapModelCreator.newGameObjectParser();
044        final ToolTipAppender<TestGameObject, TestMapArchObject, TestArchetype> toolTipAppender = new ToolTipAppender<TestGameObject, TestMapArchObject, TestArchetype>(gameObjectParser);
045        final GameObjectFactory<TestGameObject, TestMapArchObject, TestArchetype> gameObjectFactory = mapModelCreator.getGameObjectFactory();
046        final TestArchetype archetype = gameObjectFactory.newArchetype("arch");
047        final TestGameObject gameObject = gameObjectFactory.createGameObject(archetype);
048        gameObject.setAttributeString("<key>", "<value>&<value>");
049        toolTipAppender.appendGameObject(gameObject, false, "");
050        final String tooltip = toolTipAppender.finish();
051        Assert.assertEquals("<html><b>arch</b><br>&lt;key&gt; &lt;value&gt;&amp;&lt;value&gt;", tooltip);
052    }
053
054}