Gridarta Editor
PathManagerUtilsTest.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.utils;
21 
22 import org.junit.Assert;
23 import org.junit.Test;
24 
29 public class PathManagerUtilsTest {
30 
34  @Test
35  public void testPath() {
36  Assert.assertEquals("Expecting trailing slash from directories being removed.", "/foo", PathManagerUtils.path("/foo/"));
37  Assert.assertEquals("Expecting file: URIs being converted to URIs without scheme.", "/foo", PathManagerUtils.path("file:/foo/"));
38  Assert.assertEquals("Expecting multiple // characters to be collapsed.", "/foo/bar", PathManagerUtils.path("//foo///bar"));
39  }
40 
45  @Test
46  public void testAbsoluteToRelative() {
47  Assert.assertEquals("../stoneglow/stoneglow_0000", PathManagerUtils.absoluteToRelative("/relic/castle_0000", "/stoneglow/stoneglow_0000"));
48  Assert.assertEquals("../stoneglow/stoneglow_0000", PathManagerUtils.absoluteToRelative("/relic/", "/stoneglow/stoneglow_0000"));
49  }
50 
55  @Test
56  public void testRelativeToAbsolute() {
57  Assert.assertEquals("/stoneglow/stoneglow_0000", PathManagerUtils.relativeToAbsolute("/relic/castle_0000", "../stoneglow/stoneglow_0000"));
58  Assert.assertEquals("/stoneglow/stoneglow_0000", PathManagerUtils.relativeToAbsolute("/relic/", "../stoneglow/stoneglow_0000"));
59  Assert.assertEquals("/stoneglow/stoneglow_0000", PathManagerUtils.relativeToAbsolute("/relic/castle_0000", "/stoneglow/stoneglow_0000"));
60  Assert.assertEquals("/stoneglow/stoneglow_0000", PathManagerUtils.relativeToAbsolute("/relic/", "/stoneglow/stoneglow_0000"));
61  }
62 
66  @Test
67  public void testIsRelative() {
68  Assert.assertTrue(PathManagerUtils.isRelative("../stoneglow/stoneglow_0000"));
69  Assert.assertTrue(PathManagerUtils.isRelative("stoneglow/stoneglow_0000"));
70  Assert.assertFalse(PathManagerUtils.isRelative("/stoneglow/stoneglow_0000"));
71  Assert.assertTrue(PathManagerUtils.isRelative(""));
72  }
73 
77  @Test
78  public void testIsAbsolute() {
79  Assert.assertFalse(PathManagerUtils.isAbsolute("../stoneglow/stoneglow_0000"));
80  Assert.assertFalse(PathManagerUtils.isAbsolute("stoneglow/stoneglow_0000"));
81  Assert.assertTrue(PathManagerUtils.isAbsolute("/stoneglow/stoneglow_0000"));
82  Assert.assertFalse(PathManagerUtils.isAbsolute(""));
83  }
84 
85 }
net.sf.gridarta.utils.PathManagerUtils.absoluteToRelative
static String absoluteToRelative(@NotNull final String reference, @NotNull final String absolute)
Converts an absolute path to a relative path.
Definition: PathManagerUtils.java:137
net.sf.gridarta.utils.PathManagerUtilsTest.testIsRelative
void testIsRelative()
Test case for PathManagerUtils#isRelative(String).
Definition: PathManagerUtilsTest.java:67
net.sf.gridarta.utils.PathManagerUtils.path
static String path(@NotNull final CharSequence str)
Creates a reasonable path.
Definition: PathManagerUtils.java:205
net.sf.gridarta.utils.PathManagerUtilsTest.testRelativeToAbsolute
void testRelativeToAbsolute()
Test case for String).
Definition: PathManagerUtilsTest.java:56
net.sf.gridarta.utils.PathManagerUtilsTest.testAbsoluteToRelative
void testAbsoluteToRelative()
Test case for String).
Definition: PathManagerUtilsTest.java:46
net.sf.gridarta.utils.PathManagerUtilsTest
Test for PathManagerUtils.
Definition: PathManagerUtilsTest.java:29
net.sf.gridarta.utils.PathManagerUtils.isAbsolute
static boolean isAbsolute(@NotNull final String path)
Check whether a path is absolute.
Definition: PathManagerUtils.java:86
net.sf.gridarta.utils.PathManagerUtilsTest.testIsAbsolute
void testIsAbsolute()
Test case for PathManagerUtils#isAbsolute(String).
Definition: PathManagerUtilsTest.java:78
net.sf.gridarta.utils.PathManagerUtils
Utility class for converting relative map paths to absolute map paths and vice versa.
Definition: PathManagerUtils.java:31
net.sf.gridarta.utils.PathManagerUtils.isRelative
static boolean isRelative(@NotNull final String path)
Check whether a path is relative.
Definition: PathManagerUtils.java:97
net.sf.gridarta.utils.PathManagerUtils.relativeToAbsolute
static String relativeToAbsolute(@NotNull final String reference, @NotNull final String relative)
Converts a relative path to an absolute path.
Definition: PathManagerUtils.java:111
net.sf.gridarta.utils.PathManagerUtilsTest.testPath
void testPath()
Test case for PathManagerUtils#path(CharSequence).
Definition: PathManagerUtilsTest.java:35