@@ -57,7 +57,7 @@ public void setup() throws Exception {
57
57
58
58
@ Test
59
59
public void connectionToRootUsingAbsoluteUrl () throws Exception {
60
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/" );
60
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/" );
61
61
assertThat (JarURLConnection .get (url , this .jarFile ).getContent ()).isSameAs (this .jarFile );
62
62
}
63
63
@@ -69,7 +69,7 @@ public void connectionToRootUsingRelativeUrl() throws Exception {
69
69
70
70
@ Test
71
71
public void connectionToEntryUsingAbsoluteUrl () throws Exception {
72
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/1.dat" );
72
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/1.dat" );
73
73
assertThat (JarURLConnection .get (url , this .jarFile ).getInputStream ())
74
74
.hasSameContentAs (new ByteArrayInputStream (new byte [] { 1 }));
75
75
}
@@ -83,14 +83,14 @@ public void connectionToEntryUsingRelativeUrl() throws Exception {
83
83
84
84
@ Test
85
85
public void connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix () throws Exception {
86
- URL url = new URL ("jar:file:/ " + getAbsolutePath () + "!/1.dat" );
86
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/1.dat" );
87
87
assertThat (JarURLConnection .get (url , this .jarFile ).getInputStream ())
88
88
.hasSameContentAs (new ByteArrayInputStream (new byte [] { 1 }));
89
89
}
90
90
91
91
@ Test
92
92
public void connectionToEntryUsingAbsoluteUrlForNestedEntry () throws Exception {
93
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/nested.jar!/3.dat" );
93
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/nested.jar!/3.dat" );
94
94
assertThat (JarURLConnection .get (url , this .jarFile ).getInputStream ())
95
95
.hasSameContentAs (new ByteArrayInputStream (new byte [] { 3 }));
96
96
}
@@ -104,7 +104,7 @@ public void connectionToEntryUsingRelativeUrlForNestedEntry() throws Exception {
104
104
105
105
@ Test
106
106
public void connectionToEntryUsingAbsoluteUrlForEntryFromNestedJarFile () throws Exception {
107
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/nested.jar!/3.dat" );
107
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/nested.jar!/3.dat" );
108
108
JarFile nested = this .jarFile .getNestedJarFile (this .jarFile .getEntry ("nested.jar" ));
109
109
assertThat (JarURLConnection .get (url , nested ).getInputStream ())
110
110
.hasSameContentAs (new ByteArrayInputStream (new byte [] { 3 }));
@@ -120,7 +120,7 @@ public void connectionToEntryUsingRelativeUrlForEntryFromNestedJarFile() throws
120
120
121
121
@ Test
122
122
public void connectionToEntryInNestedJarFromUrlThatUsesExistingUrlAsContext () throws Exception {
123
- URL url = new URL (new URL ("jar" , null , -1 , "file:" + getAbsolutePath () + "!/nested.jar!/" , new Handler ()),
123
+ URL url = new URL (new URL ("jar" , null , -1 , this . rootJarFile . toURI (). toURL () + "!/nested.jar!/" , new Handler ()),
124
124
"/3.dat" );
125
125
JarFile nested = this .jarFile .getNestedJarFile (this .jarFile .getEntry ("nested.jar" ));
126
126
assertThat (JarURLConnection .get (url , nested ).getInputStream ())
@@ -143,29 +143,29 @@ public void connectionToEntryWithEncodedSpaceNestedEntry() throws Exception {
143
143
144
144
@ Test
145
145
public void connectionToEntryUsingWrongAbsoluteUrlForEntryFromNestedJarFile () throws Exception {
146
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/w.jar!/3.dat" );
146
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/w.jar!/3.dat" );
147
147
JarFile nested = this .jarFile .getNestedJarFile (this .jarFile .getEntry ("nested.jar" ));
148
148
assertThatExceptionOfType (FileNotFoundException .class )
149
149
.isThrownBy (JarURLConnection .get (url , nested )::getInputStream );
150
150
}
151
151
152
152
@ Test
153
153
public void getContentLengthReturnsLengthOfUnderlyingEntry () throws Exception {
154
- URL url = new URL (new URL ("jar" , null , -1 , "file:" + getAbsolutePath () + "!/nested.jar!/" , new Handler ()),
154
+ URL url = new URL (new URL ("jar" , null , -1 , this . rootJarFile . toURI (). toURL () + "!/nested.jar!/" , new Handler ()),
155
155
"/3.dat" );
156
156
assertThat (url .openConnection ().getContentLength ()).isEqualTo (1 );
157
157
}
158
158
159
159
@ Test
160
160
public void getContentLengthLongReturnsLengthOfUnderlyingEntry () throws Exception {
161
- URL url = new URL (new URL ("jar" , null , -1 , "file:" + getAbsolutePath () + "!/nested.jar!/" , new Handler ()),
161
+ URL url = new URL (new URL ("jar" , null , -1 , this . rootJarFile . toURI (). toURL () + "!/nested.jar!/" , new Handler ()),
162
162
"/3.dat" );
163
163
assertThat (url .openConnection ().getContentLengthLong ()).isEqualTo (1 );
164
164
}
165
165
166
166
@ Test
167
167
public void getLastModifiedReturnsLastModifiedTimeOfJarEntry () throws Exception {
168
- URL url = new URL ("jar:file: " + getAbsolutePath () + "!/1.dat" );
168
+ URL url = new URL ("jar:" + this . rootJarFile . toURI (). toURL () + "!/1.dat" );
169
169
JarURLConnection connection = JarURLConnection .get (url , this .jarFile );
170
170
assertThat (connection .getLastModified ()).isEqualTo (connection .getJarEntry ().getTime ());
171
171
}
@@ -191,10 +191,6 @@ public void jarEntryNameWithMixtureOfEncodedAndUnencodedDoubleByteCharacters() {
191
191
.isEqualTo ("\u00e1 /b/\u00c7 .class" );
192
192
}
193
193
194
- private String getAbsolutePath () {
195
- return this .rootJarFile .getAbsolutePath ().replace ('\\' , '/' );
196
- }
197
-
198
194
private String getRelativePath () {
199
195
return this .rootJarFile .getPath ().replace ('\\' , '/' );
200
196
}
0 commit comments