// Copyright (c) 2003-present, Jodd Team (http://jodd.org)
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

package jodd.util;

import jodd.io.PathUtil;
import org.junit.Test;

import java.nio.file.Path;
import java.nio.file.Paths;

import static org.junit.Assert.assertEquals;

public class PathUtilTest {

	@Test
	public void testResolve() {
		Path base = Paths.get("/aaa/bbb");

		Path path = PathUtil.resolve(base, "ccc");
		assertEquals("/aaa/bbb/ccc", path.toString());

		path = PathUtil.resolve(base, "ccc/");
		assertEquals("/aaa/bbb/ccc", path.toString());

		path = PathUtil.resolve(base, "/ccc");
		assertEquals("/aaa/bbb/ccc", path.toString());

		path = PathUtil.resolve(base, "ccc", "ddd");
		assertEquals("/aaa/bbb/ccc/ddd", path.toString());

		path = PathUtil.resolve(base, "/ccc", "ddd/");
		assertEquals("/aaa/bbb/ccc/ddd", path.toString());

		path = PathUtil.resolve(base, "/ccc/", "/ddd/");
		assertEquals("/aaa/bbb/ccc/ddd", path.toString());
	}
}

@@ -1445,16 +1445,37 @@
 .Test;%0A%0A
+import java.io.File;%0A
 import j
@@ -1657,16 +1657,24 @@
 ths.get(
+fixpath(
 %22/aaa/bb
@@ -1676,16 +1676,17 @@
 aa/bbb%22)
+)
 ;%0A%0A%09%09Pat
@@ -1732,32 +1732,40 @@
 %0A%09%09assertEquals(
+fixpath(
 %22/aaa/bbb/ccc%22, 
@@ -1754,32 +1754,33 @@
 h(%22/aaa/bbb/ccc%22
+)
 , path.toString(
@@ -1820,15 +1820,24 @@
 se, 
+fixpath(
 %22ccc/%22)
+)
 ;%0A%09%09
@@ -1841,32 +1841,40 @@
 %0A%09%09assertEquals(
+fixpath(
 %22/aaa/bbb/ccc%22, 
@@ -1863,32 +1863,33 @@
 h(%22/aaa/bbb/ccc%22
+)
 , path.toString(
@@ -1929,15 +1929,24 @@
 se, 
+fixpath(
 %22/ccc%22)
+)
 ;%0A%09%09
@@ -1950,32 +1950,40 @@
 %0A%09%09assertEquals(
+fixpath(
 %22/aaa/bbb/ccc%22, 
@@ -1980,16 +1980,17 @@
 bbb/ccc%22
+)
 , path.t
@@ -2056,32 +2056,40 @@
 %0A%09%09assertEquals(
+fixpath(
 %22/aaa/bbb/ccc/dd
@@ -2082,32 +2082,33 @@
 aaa/bbb/ccc/ddd%22
+)
 , path.toString(
@@ -2148,23 +2148,41 @@
 se, 
+fixpath(
 %22/ccc%22
+)
 , 
+fixpath(
 %22ddd/%22)
+)
 ;%0A%09%09
@@ -2186,32 +2186,40 @@
 %0A%09%09assertEquals(
+fixpath(
 %22/aaa/bbb/ccc/dd
@@ -2212,32 +2212,33 @@
 aaa/bbb/ccc/ddd%22
+)
 , path.toString(
@@ -2278,25 +2278,42 @@
 se, 
+fixpath(
 %22/ccc/%22
+)
 , 
+fixpath(
 %22/ddd/%22)
 ;%0A%09%09
@@ -2308,16 +2308,17 @@
 %22/ddd/%22)
+)
 ;%0A%09%09asse
@@ -2326,16 +2326,24 @@
 tEquals(
+fixpath(
 %22/aaa/bb
@@ -2352,16 +2352,17 @@
 ccc/ddd%22
+)
 , path.t
@@ -2375,11 +2375,110 @@
 g());%0A%09%7D
+%0A%0A%09private String fixpath(String path) %7B%0A%09%09return StringUtil.replace(path, %22/%22, File.separator);%0A%09%7D
 %0A%7D%0A

Fix tests for Micro$oft Windows.