1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.properties.spi.config.support;
17
18 import static org.hamcrest.MatcherAssert.assertThat;
19 import static org.hamcrest.Matchers.is;
20
21 import java.net.MalformedURLException;
22 import java.net.URL;
23
24 import org.junit.Test;
25
26 import de.smartics.testdoc.annotations.Uut;
27
28 @Uut(type = UrlUtil.class)
29 public class UrlUtilTest
30 {
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47 @Test
48 public void testShortenJarURLContainingMetaInf() throws MalformedURLException
49 {
50 final URL url =
51 new URL(
52 "jar:file:/D:/jboss/jboss-as-7.1.1.Final/modules/javax/servlet/api/main/jboss-servlet-api_3.0_spec-1.0.0.Final.jar!/META-INF");
53 final URL shortenedUrl = UrlUtil.shortenUrl(url, "/META-INF");
54 assertThat(shortenedUrl + "META-INF", is(url.toString()));
55 }
56
57 @Test
58 public void testShortenFileURLContainingMetaInf()
59 throws MalformedURLException
60 {
61 final URL url =
62 new URL(
63 "file:/D:/jboss/jboss-as-7.1.1.Final/modules/sun/jdk/main/service-loader-resources/META-INF");
64 final URL shortenedUrl = UrlUtil.shortenUrl(url, "/META-INF");
65 assertThat(shortenedUrl + "META-INF", is(url.toString()));
66 }
67
68 @Test
69 public void testShortenJarURLContainingNothing() throws MalformedURLException
70 {
71 final URL url =
72 new URL(
73 "jar:file:/D:/jboss/jboss-as-7.1.1.Final/modules/javax/servlet/api/main/jboss-servlet-api_3.0_spec-1.0.0.Final.jar!/");
74 final URL shortenedUrl = UrlUtil.shortenUrl(url, "");
75 assertThat(shortenedUrl.toString(), is(url.toString()));
76 }
77
78 @Test
79 public void testShortenFileURLContainingNothingEndingWithSlash()
80 throws MalformedURLException
81 {
82 final URL url =
83 new URL(
84 "file:/D:/jboss/jboss-as-7.1.1.Final/modules/sun/jdk/main/service-loader-resources/");
85 final URL shortenedUrl = UrlUtil.shortenUrl(url, "");
86 assertThat(shortenedUrl.toString(), is(url.toString()));
87 }
88
89 @Test
90 public void testShortenFileURLContainingNothingNotEndingWithSlash()
91 throws MalformedURLException
92 {
93 final URL url =
94 new URL(
95 "file:/D:/jboss/jboss-as-7.1.1.Final/modules/sun/jdk/main/service-loader-resources");
96 final URL shortenedUrl = UrlUtil.shortenUrl(url, "");
97 assertThat(shortenedUrl.toString(), is(url.toString() + "/"));
98 }
99
100 }