16
16
17
17
package org .springframework .boot .loader .net .protocol .jar ;
18
18
19
+ import java .net .MalformedURLException ;
19
20
import java .net .URL ;
20
21
21
22
import org .junit .jupiter .api .BeforeAll ;
@@ -38,51 +39,66 @@ static void setup() {
38
39
}
39
40
40
41
@ Test
41
- void getCreatesKey () throws Exception {
42
- URL url = new URL ("jar:nested:/my.jar/!mynested.jar!/my/path" );
43
- assertThat (JarFileUrlKey .get (url )).isEqualTo ("jar:nested:/my.jar/!mynested.jar!/my/path" );
42
+ void equalsAndHashCode () throws Exception {
43
+ JarFileUrlKey k1 = key ("jar:nested:/my.jar/!mynested.jar!/my/path" );
44
+ JarFileUrlKey k2 = key ("jar:nested:/my.jar/!mynested.jar!/my/path" );
45
+ JarFileUrlKey k3 = key ("jar:nested:/my.jar/!mynested.jar!/my/path2" );
46
+ assertThat (k1 .hashCode ()).isEqualTo (k2 .hashCode ())
47
+ .isEqualTo ("nested:/my.jar/!mynested.jar!/my/path" .hashCode ());
48
+ assertThat (k1 ).isEqualTo (k1 ).isEqualTo (k2 ).isNotEqualTo (k3 );
44
49
}
45
50
46
51
@ Test
47
- void getWhenUppercaseProtocolCreatesKey () throws Exception {
48
- URL url = new URL ("JAR:nested:/my.jar/!mynested.jar!/my/path" );
49
- assertThat (JarFileUrlKey .get (url )).isEqualTo ("jar:nested:/my.jar/!mynested.jar!/my/path" );
52
+ void equalsWhenUppercaseAndLowercaseProtocol () throws Exception {
53
+ JarFileUrlKey k1 = key ("JAR:nested:/my.jar/!mynested.jar!/my/path" );
54
+ JarFileUrlKey k2 = key ("jar:nested:/my.jar/!mynested.jar!/my/path" );
55
+ assertThat (k1 ).isEqualTo (k2 );
50
56
}
51
57
52
58
@ Test
53
- void getWhenHasHostAndPortCreatesKey () throws Exception {
54
- URL url = new URL ("https://example.com:1234/test" );
55
- assertThat (JarFileUrlKey .get (url )).isEqualTo ("https:example.com:1234/test" );
59
+ void equalsWhenHasHostAndPort () throws Exception {
60
+ JarFileUrlKey k1 = key ("https://example.com:1234/test" );
61
+ JarFileUrlKey k2 = key ("https://example.com:1234/test" );
62
+ assertThat (k1 ).isEqualTo (k2 );
56
63
}
57
64
58
65
@ Test
59
- void getWhenHasUppercaseHostCreatesKey () throws Exception {
60
- URL url = new URL ("https://EXAMPLE.com:1234/test" );
61
- assertThat (JarFileUrlKey .get (url )).isEqualTo ("https:example.com:1234/test" );
66
+ void equalsWhenHasUppercaseAndLowercaseHost () throws Exception {
67
+ JarFileUrlKey k1 = key ("https://EXAMPLE.com:1234/test" );
68
+ JarFileUrlKey k2 = key ("https://example.com:1234/test" );
69
+ assertThat (k1 ).isEqualTo (k2 );
62
70
}
63
71
64
72
@ Test
65
- void getWhenHasNoPortCreatesKeyWithDefaultPort () throws Exception {
66
- URL url = new URL ("https://EXAMPLE.com/test" );
67
- assertThat (JarFileUrlKey .get (url )).isEqualTo ("https:example.com:443/test" );
73
+ void equalsWhenHasNoPortUsesDefaultPort () throws Exception {
74
+ JarFileUrlKey k1 = key ("https://EXAMPLE.com/test" );
75
+ JarFileUrlKey k2 = key ("https://example.com:443/test" );
76
+ assertThat (k1 ).isEqualTo (k2 );
68
77
}
69
78
70
79
@ Test
71
- void getWhenHasNoFileCreatesKey () throws Exception {
72
- URL url = new URL ("https://EXAMPLE.com" );
73
- assertThat (JarFileUrlKey .get (url )).isEqualTo ("https:example.com:443" );
80
+ void equalsWhenHasNoFile () throws Exception {
81
+ JarFileUrlKey k1 = key ("https://EXAMPLE.com" );
82
+ JarFileUrlKey k2 = key ("https://example.com:443" );
83
+ assertThat (k1 ).isEqualTo (k2 );
74
84
}
75
85
76
86
@ Test
77
- void getWhenHasRuntimeRefCreatesKey () throws Exception {
78
- URL url = new URL ("jar:nested:/my.jar/!mynested.jar!/my/path#runtime" );
79
- assertThat (JarFileUrlKey .get (url )).isEqualTo ("jar:nested:/my.jar/!mynested.jar!/my/path#runtime" );
87
+ void equalsWhenHasRuntimeRef () throws Exception {
88
+ JarFileUrlKey k1 = key ("jar:nested:/my.jar/!mynested.jar!/my/path#runtime" );
89
+ JarFileUrlKey k2 = key ("jar:nested:/my.jar/!mynested.jar!/my/path#runtime" );
90
+ assertThat (k1 ).isEqualTo (k2 );
80
91
}
81
92
82
93
@ Test
83
- void getWhenHasOtherRefCreatesKeyWithoutRef () throws Exception {
84
- URL url = new URL ("jar:nested:/my.jar/!mynested.jar!/my/path#example" );
85
- assertThat (JarFileUrlKey .get (url )).isEqualTo ("jar:nested:/my.jar/!mynested.jar!/my/path" );
94
+ void equalsWhenHasOtherRefIgnoresRefs () throws Exception {
95
+ JarFileUrlKey k1 = key ("jar:nested:/my.jar/!mynested.jar!/my/path#example" );
96
+ JarFileUrlKey k2 = key ("jar:nested:/my.jar/!mynested.jar!/my/path" );
97
+ assertThat (k1 ).isEqualTo (k2 );
98
+ }
99
+
100
+ private JarFileUrlKey key (String spec ) throws MalformedURLException {
101
+ return new JarFileUrlKey (new URL (spec ));
86
102
}
87
103
88
104
}
0 commit comments