6
6
7
7
import org .junit .Test ;
8
8
9
-
10
9
public class PathUtilTest
11
10
{
12
11
@@ -15,20 +14,19 @@ public void testIsRemoteNull()
15
14
{
16
15
PathUtil .isRemote (null );
17
16
}
18
-
17
+
19
18
@ Test
20
19
public void testIsRemoteTrue ()
21
20
{
22
21
assertTrue (PathUtil .isRemote ("https://example.org" ));
23
22
}
24
-
23
+
25
24
@ Test
26
25
public void testIsRemoteFalse ()
27
26
{
28
27
assertFalse (PathUtil .isRemote ("OCF/path" ));
29
28
}
30
-
31
-
29
+
32
30
@ Test (expected = NullPointerException .class )
33
31
public void testNormalizePathNull ()
34
32
{
@@ -131,7 +129,7 @@ public void testNormalizePathLeadingSlash()
131
129
assertEquals ("/foo" , PathUtil .normalizePath ("/./foo" ));
132
130
assertEquals ("/../foo" , PathUtil .normalizePath ("/../foo" ));
133
131
}
134
-
132
+
135
133
@ Test
136
134
public void testNormalizePathAbsoluteURI ()
137
135
{
@@ -174,7 +172,7 @@ public void testRelativizeAbsoluteWithNullBaseIsReturnedAsIs()
174
172
{
175
173
assertEquals ("http://foo" , PathUtil .resolveRelativeReference (null , "http://foo" ));
176
174
}
177
-
175
+
178
176
@ Test
179
177
public void testRelativizeAbsoluteWithNonNullBaseIsReturnedAsIs ()
180
178
{
@@ -188,31 +186,35 @@ public void testRelativizeAbsoluteSchemes()
188
186
assertEquals ("https://foo?q#f" , PathUtil .resolveRelativeReference (null , "https://foo?q#f" ));
189
187
assertEquals ("data:foo" , PathUtil .resolveRelativeReference (null , "data:foo" ));
190
188
}
191
-
189
+
192
190
@ Test
193
191
public void testRelativizeWithAbsoluteBase ()
194
192
{
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" ));
196
195
}
197
-
196
+
198
197
@ Test
199
198
public void testRelativizeWithAbsoluteBaseAndFragment ()
200
199
{
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" ));
202
202
}
203
203
204
204
@ Test
205
205
public void testRelativizeWithAbsoluteBaseAndQuery ()
206
206
{
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" ));
208
209
}
209
210
210
211
@ Test
211
212
public void testRelativizeWithAbsoluteBaseIsNormalized ()
212
213
{
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" ));
214
216
}
215
-
217
+
216
218
@ Test
217
219
public void testRelativizeWithRelBase ()
218
220
{
@@ -229,15 +231,15 @@ public void testRelativizeWithRelBaseIsNormalized()
229
231
assertEquals ("foo/foo/" , PathUtil .resolveRelativeReference ("foo/" , "foo/" ));
230
232
assertEquals ("bar/foo" , PathUtil .resolveRelativeReference ("foo/.." , "bar/foo" ));
231
233
}
232
-
234
+
233
235
@ Test
234
236
public void testRelativizeFragment ()
235
237
{
236
238
assertEquals ("foo#bar" , PathUtil .resolveRelativeReference ("foo" , "#bar" ));
237
239
assertEquals ("foo/#bar" , PathUtil .resolveRelativeReference ("foo/" , "#bar" ));
238
240
assertEquals ("#bar" , PathUtil .resolveRelativeReference ("." , "#bar" ));
239
241
}
240
-
242
+
241
243
@ Test
242
244
public void testRelativizeDecodes ()
243
245
{
@@ -255,4 +257,23 @@ public void testRemoveAnchor()
255
257
assertEquals (urlWithoutAnchor , PathUtil .removeFragment (urlWithoutAnchor ));
256
258
}
257
259
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
+
258
279
}
0 commit comments