001/*
002 * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
003 * Copyright (C) 2000-2010 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.model.io;
021
022import org.junit.Assert;
023import org.junit.Test;
024
025/**
026 * Test for {@link PathManager}.
027 * @author <a href="mailto:cher@riedquat.de">Christian Hujer</a>
028 */
029public class PathManagerTest {
030
031    /**
032     * Test case for {@link PathManager#path(CharSequence)}.
033     */
034    @Test
035    public void testPath() {
036        Assert.assertEquals("Expecting trailing slash from directories being removed.", "/foo", PathManager.path("/foo/"));
037        Assert.assertEquals("Expecting file: URIs being converted to URIs without scheme.", "/foo", PathManager.path("file:/foo/"));
038        Assert.assertEquals("Expecting multiple // characters to be collapsed.", "/foo/bar", PathManager.path("//foo///bar"));
039    }
040
041    /**
042     * Test case for {@link PathManager#absoluteToRelative(String, String)}.
043     */
044    @Test
045    public void testAbsoluteToRelative() {
046        Assert.assertEquals("../stoneglow/stoneglow_0000", PathManager.absoluteToRelative("/relic/castle_0000", "/stoneglow/stoneglow_0000"));
047        Assert.assertEquals("../stoneglow/stoneglow_0000", PathManager.absoluteToRelative("/relic/", "/stoneglow/stoneglow_0000"));
048    }
049
050    /**
051     * Test case for {@link PathManager#absoluteToRelative(String, String)}.
052     */
053    @Test
054    public void testRelativeToAbsolute() {
055        Assert.assertEquals("/stoneglow/stoneglow_0000", PathManager.relativeToAbsolute("/relic/castle_0000", "../stoneglow/stoneglow_0000"));
056        Assert.assertEquals("/stoneglow/stoneglow_0000", PathManager.relativeToAbsolute("/relic/", "../stoneglow/stoneglow_0000"));
057        Assert.assertEquals("/stoneglow/stoneglow_0000", PathManager.relativeToAbsolute("/relic/castle_0000", "/stoneglow/stoneglow_0000"));
058        Assert.assertEquals("/stoneglow/stoneglow_0000", PathManager.relativeToAbsolute("/relic/", "/stoneglow/stoneglow_0000"));
059    }
060
061    /**
062     * Test case for {@link PathManager#isRelative(String)}.
063     */
064    @Test
065    public void testIsRelative() {
066        Assert.assertTrue(PathManager.isRelative("../stoneglow/stoneglow_0000"));
067        Assert.assertTrue(PathManager.isRelative("stoneglow/stoneglow_0000"));
068        Assert.assertFalse(PathManager.isRelative("/stoneglow/stoneglow_0000"));
069        Assert.assertTrue(PathManager.isRelative(""));
070    }
071
072    /**
073     * Test case for {@link PathManager#isAbsolute(String)}.
074     */
075    @Test
076    public void testIsAbsolute() {
077        Assert.assertFalse(PathManager.isAbsolute("../stoneglow/stoneglow_0000"));
078        Assert.assertFalse(PathManager.isAbsolute("stoneglow/stoneglow_0000"));
079        Assert.assertTrue(PathManager.isAbsolute("/stoneglow/stoneglow_0000"));
080        Assert.assertFalse(PathManager.isAbsolute(""));
081    }
082
083}