parent
13ceea5bba
commit
a395679b95
|
@ -52,30 +52,28 @@ public class JarURLConnectionTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void connectionToRootUsingAbsoluteUrl() throws Exception {
|
public void connectionToRootUsingAbsoluteUrl() throws Exception {
|
||||||
URL absoluteUrl = new URL(
|
URL absoluteUrl = new URL("jar:file:" + getAbsolutePath() + "!/");
|
||||||
"jar:file:" + this.rootJarFile.getAbsoluteFile() + "!/");
|
|
||||||
assertThat(new JarURLConnection(absoluteUrl, this.jarFile).getContent())
|
assertThat(new JarURLConnection(absoluteUrl, this.jarFile).getContent())
|
||||||
.isSameAs(this.jarFile);
|
.isSameAs(this.jarFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void connectionToRootUsingRelativeUrl() throws Exception {
|
public void connectionToRootUsingRelativeUrl() throws Exception {
|
||||||
URL relativeUrl = new URL("jar:file:" + this.rootJarFile + "!/");
|
URL relativeUrl = new URL("jar:file:" + getRelativePath() + "!/");
|
||||||
assertThat(new JarURLConnection(relativeUrl, this.jarFile).getContent())
|
assertThat(new JarURLConnection(relativeUrl, this.jarFile).getContent())
|
||||||
.isSameAs(this.jarFile);
|
.isSameAs(this.jarFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void connectionToEntryUsingAbsoluteUrl() throws Exception {
|
public void connectionToEntryUsingAbsoluteUrl() throws Exception {
|
||||||
URL absoluteUrl = new URL(
|
URL absoluteUrl = new URL("jar:file:" + getAbsolutePath() + "!/1.dat");
|
||||||
"jar:file:" + this.rootJarFile.getAbsoluteFile() + "!/1.dat");
|
|
||||||
assertThat(new JarURLConnection(absoluteUrl, this.jarFile).getInputStream())
|
assertThat(new JarURLConnection(absoluteUrl, this.jarFile).getInputStream())
|
||||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void connectionToEntryUsingRelativeUrl() throws Exception {
|
public void connectionToEntryUsingRelativeUrl() throws Exception {
|
||||||
URL relativeUrl = new URL("jar:file:" + this.rootJarFile + "!/1.dat");
|
URL relativeUrl = new URL("jar:file:" + getRelativePath() + "!/1.dat");
|
||||||
assertThat(new JarURLConnection(relativeUrl, this.jarFile).getInputStream())
|
assertThat(new JarURLConnection(relativeUrl, this.jarFile).getInputStream())
|
||||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
||||||
}
|
}
|
||||||
|
@ -83,8 +81,7 @@ public class JarURLConnectionTests {
|
||||||
@Test
|
@Test
|
||||||
public void connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix()
|
public void connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
URL absoluteUrl = new URL(
|
URL absoluteUrl = new URL("jar:file:/" + getAbsolutePath() + "!/1.dat");
|
||||||
"jar:file:/" + this.rootJarFile.getAbsoluteFile() + "!/1.dat");
|
|
||||||
assertThat(new JarURLConnection(absoluteUrl, this.jarFile).getInputStream())
|
assertThat(new JarURLConnection(absoluteUrl, this.jarFile).getInputStream())
|
||||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
||||||
}
|
}
|
||||||
|
@ -92,16 +89,25 @@ public class JarURLConnectionTests {
|
||||||
@Test
|
@Test
|
||||||
public void connectionToEntryUsingAbsoluteUrlForNestedEntry() throws Exception {
|
public void connectionToEntryUsingAbsoluteUrlForNestedEntry() throws Exception {
|
||||||
URL absoluteUrl = new URL(
|
URL absoluteUrl = new URL(
|
||||||
"jar:file:" + this.rootJarFile.getAbsoluteFile() + "!/nested.jar!/3.dat");
|
"jar:file:" + getAbsolutePath() + "!/nested.jar!/3.dat");
|
||||||
assertThat(new JarURLConnection(absoluteUrl, this.jarFile).getInputStream())
|
assertThat(new JarURLConnection(absoluteUrl, this.jarFile).getInputStream())
|
||||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void connectionToEntryUsingRelativeUrlForNestedEntry() throws Exception {
|
public void connectionToEntryUsingRelativeUrlForNestedEntry() throws Exception {
|
||||||
URL relativeUrl = new URL("jar:file:" + this.rootJarFile + "!/nested.jar!/3.dat");
|
URL relativeUrl = new URL(
|
||||||
|
"jar:file:" + getRelativePath() + "!/nested.jar!/3.dat");
|
||||||
assertThat(new JarURLConnection(relativeUrl, this.jarFile).getInputStream())
|
assertThat(new JarURLConnection(relativeUrl, this.jarFile).getInputStream())
|
||||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getAbsolutePath() {
|
||||||
|
return this.rootJarFile.getAbsolutePath().replace('\\', '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getRelativePath() {
|
||||||
|
return this.rootJarFile.getPath().replace('\\', '/');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue