66
77import org .junit .Test ;
88
9-
109public class PathUtilTest
1110{
1211
@@ -15,20 +14,19 @@ public void testIsRemoteNull()
1514 {
1615 PathUtil .isRemote (null );
1716 }
18-
17+
1918 @ Test
2019 public void testIsRemoteTrue ()
2120 {
2221 assertTrue (PathUtil .isRemote ("https://example.org" ));
2322 }
24-
23+
2524 @ Test
2625 public void testIsRemoteFalse ()
2726 {
2827 assertFalse (PathUtil .isRemote ("OCF/path" ));
2928 }
30-
31-
29+
3230 @ Test (expected = NullPointerException .class )
3331 public void testNormalizePathNull ()
3432 {
@@ -131,7 +129,7 @@ public void testNormalizePathLeadingSlash()
131129 assertEquals ("/foo" , PathUtil .normalizePath ("/./foo" ));
132130 assertEquals ("/../foo" , PathUtil .normalizePath ("/../foo" ));
133131 }
134-
132+
135133 @ Test
136134 public void testNormalizePathAbsoluteURI ()
137135 {
@@ -174,7 +172,7 @@ public void testRelativizeAbsoluteWithNullBaseIsReturnedAsIs()
174172 {
175173 assertEquals ("http://foo" , PathUtil .resolveRelativeReference (null , "http://foo" ));
176174 }
177-
175+
178176 @ Test
179177 public void testRelativizeAbsoluteWithNonNullBaseIsReturnedAsIs ()
180178 {
@@ -188,31 +186,35 @@ public void testRelativizeAbsoluteSchemes()
188186 assertEquals ("https://foo?q#f" , PathUtil .resolveRelativeReference (null , "https://foo?q#f" ));
189187 assertEquals ("data:foo" , PathUtil .resolveRelativeReference (null , "data:foo" ));
190188 }
191-
189+
192190 @ Test
193191 public void testRelativizeWithAbsoluteBase ()
194192 {
195- assertEquals ("http://example.org/foo" , PathUtil .resolveRelativeReference ("http://example.org/" , "foo" ));
193+ assertEquals ("http://example.org/foo" ,
194+ PathUtil .resolveRelativeReference ("http://example.org/" , "foo" ));
196195 }
197-
196+
198197 @ Test
199198 public void testRelativizeWithAbsoluteBaseAndFragment ()
200199 {
201- assertEquals ("http://example.org/foo" , PathUtil .resolveRelativeReference ("http://example.org/#bar" , "foo" ));
200+ assertEquals ("http://example.org/foo" ,
201+ PathUtil .resolveRelativeReference ("http://example.org/#bar" , "foo" ));
202202 }
203203
204204 @ Test
205205 public void testRelativizeWithAbsoluteBaseAndQuery ()
206206 {
207- assertEquals ("http://example.org/foo" , PathUtil .resolveRelativeReference ("http://example.org/?test#bar" , "foo" ));
207+ assertEquals ("http://example.org/foo" ,
208+ PathUtil .resolveRelativeReference ("http://example.org/?test#bar" , "foo" ));
208209 }
209210
210211 @ Test
211212 public void testRelativizeWithAbsoluteBaseIsNormalized ()
212213 {
213- assertEquals ("http://example.org/foo" , PathUtil .resolveRelativeReference ("http://example.org/foo/../bar" , "bar/../foo" ));
214+ assertEquals ("http://example.org/foo" ,
215+ PathUtil .resolveRelativeReference ("http://example.org/foo/../bar" , "bar/../foo" ));
214216 }
215-
217+
216218 @ Test
217219 public void testRelativizeWithRelBase ()
218220 {
@@ -229,15 +231,15 @@ public void testRelativizeWithRelBaseIsNormalized()
229231 assertEquals ("foo/foo/" , PathUtil .resolveRelativeReference ("foo/" , "foo/" ));
230232 assertEquals ("bar/foo" , PathUtil .resolveRelativeReference ("foo/.." , "bar/foo" ));
231233 }
232-
234+
233235 @ Test
234236 public void testRelativizeFragment ()
235237 {
236238 assertEquals ("foo#bar" , PathUtil .resolveRelativeReference ("foo" , "#bar" ));
237239 assertEquals ("foo/#bar" , PathUtil .resolveRelativeReference ("foo/" , "#bar" ));
238240 assertEquals ("#bar" , PathUtil .resolveRelativeReference ("." , "#bar" ));
239241 }
240-
242+
241243 @ Test
242244 public void testRelativizeDecodes ()
243245 {
@@ -255,4 +257,23 @@ public void testRemoveAnchor()
255257 assertEquals (urlWithoutAnchor , PathUtil .removeFragment (urlWithoutAnchor ));
256258 }
257259
260+ @ Test
261+ public void testRemoveWorkingDirectory ()
262+ {
263+ String OLD_USER_DIR = System .getProperty ("user.dir" );
264+
265+ assertEquals (null , PathUtil .removeWorkingDirectory (null ));
266+ assertEquals ("" , PathUtil .removeWorkingDirectory ("" ));
267+
268+ System .setProperty ("user.dir" , "/user" );
269+ assertEquals ("./epub" , PathUtil .removeWorkingDirectory ("/user/epub" ));
270+
271+ assertEquals ("/prefix/user/epub" , PathUtil .removeWorkingDirectory ("/prefix/user/epub" ));
272+
273+ System .setProperty ("user.dir" , "/" );
274+ assertEquals ("/dir/epub" , PathUtil .removeWorkingDirectory ("/dir/epub" ));
275+
276+ System .setProperty ("user.dir" , OLD_USER_DIR );
277+ }
278+
258279}
0 commit comments