1616
1717package org .springframework .boot .loader .net .protocol .jar ;
1818
19+ import java .net .MalformedURLException ;
1920import java .net .URL ;
2021
2122import org .junit .jupiter .api .BeforeAll ;
@@ -38,51 +39,66 @@ static void setup() {
3839 }
3940
4041 @ 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 );
4449 }
4550
4651 @ 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 );
5056 }
5157
5258 @ 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 );
5663 }
5764
5865 @ 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 );
6270 }
6371
6472 @ 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 );
6877 }
6978
7079 @ 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 );
7484 }
7585
7686 @ 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 );
8091 }
8192
8293 @ 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 ));
86102 }
87103
88104}
0 commit comments