Fix spring-boot-loader's tests on Windows
Closes gh-17275
This commit is contained in:
@@ -159,10 +159,10 @@ public class HandlerTests {
|
||||
public void fallbackToJdksJarUrlStreamHandler() throws Exception {
|
||||
File testJar = this.temporaryFolder.newFile("test.jar");
|
||||
TestJarCreator.createTestJar(testJar);
|
||||
URLConnection connection = new URL(null, "jar:file:" + testJar.getAbsolutePath() + "!/nested.jar!/",
|
||||
this.handler).openConnection();
|
||||
URLConnection connection = new URL(null, "jar:" + testJar.toURI().toURL() + "!/nested.jar!/", this.handler)
|
||||
.openConnection();
|
||||
assertThat(connection).isInstanceOf(JarURLConnection.class);
|
||||
URLConnection jdkConnection = new URL(null, "jar:file:file:" + testJar.getAbsolutePath() + "!/nested.jar!/",
|
||||
URLConnection jdkConnection = new URL(null, "jar:file:" + testJar.toURI().toURL() + "!/nested.jar!/",
|
||||
this.handler).openConnection();
|
||||
assertThat(jdkConnection).isNotInstanceOf(JarURLConnection.class);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class JarURLConnectionTests {
|
||||
|
||||
@Test
|
||||
public void connectionToRootUsingAbsoluteUrl() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/");
|
||||
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getContent()).isSameAs(this.jarFile);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class JarURLConnectionTests {
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingAbsoluteUrl() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/1.dat");
|
||||
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/1.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
||||
}
|
||||
@@ -83,14 +83,14 @@ public class JarURLConnectionTests {
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix() throws Exception {
|
||||
URL url = new URL("jar:file:/" + getAbsolutePath() + "!/1.dat");
|
||||
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/1.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingAbsoluteUrlForNestedEntry() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/nested.jar!/3.dat");
|
||||
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/nested.jar!/3.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class JarURLConnectionTests {
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingAbsoluteUrlForEntryFromNestedJarFile() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/nested.jar!/3.dat");
|
||||
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/nested.jar!/3.dat");
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
assertThat(JarURLConnection.get(url, nested).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||
@@ -120,7 +120,7 @@ public class JarURLConnectionTests {
|
||||
|
||||
@Test
|
||||
public void connectionToEntryInNestedJarFromUrlThatUsesExistingUrlAsContext() throws Exception {
|
||||
URL url = new URL(new URL("jar", null, -1, "file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()),
|
||||
URL url = new URL(new URL("jar", null, -1, this.rootJarFile.toURI().toURL() + "!/nested.jar!/", new Handler()),
|
||||
"/3.dat");
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
assertThat(JarURLConnection.get(url, nested).getInputStream())
|
||||
@@ -143,7 +143,7 @@ public class JarURLConnectionTests {
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingWrongAbsoluteUrlForEntryFromNestedJarFile() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/w.jar!/3.dat");
|
||||
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/w.jar!/3.dat");
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
assertThatExceptionOfType(FileNotFoundException.class)
|
||||
.isThrownBy(JarURLConnection.get(url, nested)::getInputStream);
|
||||
@@ -151,21 +151,21 @@ public class JarURLConnectionTests {
|
||||
|
||||
@Test
|
||||
public void getContentLengthReturnsLengthOfUnderlyingEntry() throws Exception {
|
||||
URL url = new URL(new URL("jar", null, -1, "file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()),
|
||||
URL url = new URL(new URL("jar", null, -1, this.rootJarFile.toURI().toURL() + "!/nested.jar!/", new Handler()),
|
||||
"/3.dat");
|
||||
assertThat(url.openConnection().getContentLength()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContentLengthLongReturnsLengthOfUnderlyingEntry() throws Exception {
|
||||
URL url = new URL(new URL("jar", null, -1, "file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()),
|
||||
URL url = new URL(new URL("jar", null, -1, this.rootJarFile.toURI().toURL() + "!/nested.jar!/", new Handler()),
|
||||
"/3.dat");
|
||||
assertThat(url.openConnection().getContentLengthLong()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLastModifiedReturnsLastModifiedTimeOfJarEntry() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/1.dat");
|
||||
URL url = new URL("jar:" + this.rootJarFile.toURI().toURL() + "!/1.dat");
|
||||
JarURLConnection connection = JarURLConnection.get(url, this.jarFile);
|
||||
assertThat(connection.getLastModified()).isEqualTo(connection.getJarEntry().getTime());
|
||||
}
|
||||
@@ -191,10 +191,6 @@ public class JarURLConnectionTests {
|
||||
.isEqualTo("\u00e1/b/\u00c7.class");
|
||||
}
|
||||
|
||||
private String getAbsolutePath() {
|
||||
return this.rootJarFile.getAbsolutePath().replace('\\', '/');
|
||||
}
|
||||
|
||||
private String getRelativePath() {
|
||||
return this.rootJarFile.getPath().replace('\\', '/');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user