Skip to content

Commit a5ae1de

Browse files
committed
Fix spring-boot-loader's tests on Windows
Closes gh-17275
1 parent 7e5ca6d commit a5ae1de

File tree

2 files changed

+13
-17
lines changed

2 files changed

+13
-17
lines changed

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/HandlerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ public void urlWithQuery() throws MalformedURLException {
159159
public void fallbackToJdksJarUrlStreamHandler() throws Exception {
160160
File testJar = this.temporaryFolder.newFile("test.jar");
161161
TestJarCreator.createTestJar(testJar);
162-
URLConnection connection = new URL(null, "jar:file:" + testJar.getAbsolutePath() + "!/nested.jar!/",
163-
this.handler).openConnection();
162+
URLConnection connection = new URL(null, "jar:" + testJar.toURI().toURL() + "!/nested.jar!/", this.handler)
163+
.openConnection();
164164
assertThat(connection).isInstanceOf(JarURLConnection.class);
165-
URLConnection jdkConnection = new URL(null, "jar:file:file:" + testJar.getAbsolutePath() + "!/nested.jar!/",
165+
URLConnection jdkConnection = new URL(null, "jar:file:" + testJar.toURI().toURL() + "!/nested.jar!/",
166166
this.handler).openConnection();
167167
assertThat(jdkConnection).isNotInstanceOf(JarURLConnection.class);
168168
}

spring-boot-project/spring-boot-tools/spring-boot-loader/src/test/java/org/springframework/boot/loader/jar/JarURLConnectionTests.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void setup() throws Exception {
5757

5858
@Test
5959
public void connectionToRootUsingAbsoluteUrl() throws Exception {
60-
URL url = new URL("jar:file:" + getAbsolutePath() + "!/");
60+
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/");
6161
assertThat(JarURLConnection.get(url, this.jarFile).getContent()).isSameAs(this.jarFile);
6262
}
6363

@@ -69,7 +69,7 @@ public void connectionToRootUsingRelativeUrl() throws Exception {
6969

7070
@Test
7171
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");
7373
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
7474
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
7575
}
@@ -83,14 +83,14 @@ public void connectionToEntryUsingRelativeUrl() throws Exception {
8383

8484
@Test
8585
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");
8787
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
8888
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
8989
}
9090

9191
@Test
9292
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");
9494
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
9595
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
9696
}
@@ -104,7 +104,7 @@ public void connectionToEntryUsingRelativeUrlForNestedEntry() throws Exception {
104104

105105
@Test
106106
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");
108108
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
109109
assertThat(JarURLConnection.get(url, nested).getInputStream())
110110
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
@@ -120,7 +120,7 @@ public void connectionToEntryUsingRelativeUrlForEntryFromNestedJarFile() throws
120120

121121
@Test
122122
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()),
124124
"/3.dat");
125125
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
126126
assertThat(JarURLConnection.get(url, nested).getInputStream())
@@ -143,29 +143,29 @@ public void connectionToEntryWithEncodedSpaceNestedEntry() throws Exception {
143143

144144
@Test
145145
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");
147147
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
148148
assertThatExceptionOfType(FileNotFoundException.class)
149149
.isThrownBy(JarURLConnection.get(url, nested)::getInputStream);
150150
}
151151

152152
@Test
153153
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()),
155155
"/3.dat");
156156
assertThat(url.openConnection().getContentLength()).isEqualTo(1);
157157
}
158158

159159
@Test
160160
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()),
162162
"/3.dat");
163163
assertThat(url.openConnection().getContentLengthLong()).isEqualTo(1);
164164
}
165165

166166
@Test
167167
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");
169169
JarURLConnection connection = JarURLConnection.get(url, this.jarFile);
170170
assertThat(connection.getLastModified()).isEqualTo(connection.getJarEntry().getTime());
171171
}
@@ -191,10 +191,6 @@ public void jarEntryNameWithMixtureOfEncodedAndUnencodedDoubleByteCharacters() {
191191
.isEqualTo("\u00e1/b/\u00c7.class");
192192
}
193193

194-
private String getAbsolutePath() {
195-
return this.rootJarFile.getAbsolutePath().replace('\\', '/');
196-
}
197-
198194
private String getRelativePath() {
199195
return this.rootJarFile.getPath().replace('\\', '/');
200196
}

0 commit comments

Comments
 (0)