Fix JarUrlTests

Fix `JarUrlTests` to use the jarFile rather than temp.
This commit is contained in:
Phillip Webb 2023-12-06 15:57:44 -08:00
parent fc1a5033e8
commit 847daf484c

View File

@ -44,43 +44,43 @@ class JarUrlTests {
@BeforeEach
void setup() throws MalformedURLException {
this.jarFile = new File(this.temp, "my.jar");
this.jarFileUrlPath = this.temp.toURI().toURL().toString().substring("file:".length());
this.jarFileUrlPath = this.jarFile.toURI().toURL().toString().substring("file:".length()).replace("!", "%21");
}
@Test
void createWithFileReturnsUrl() {
URL url = JarUrl.create(this.temp);
URL url = JarUrl.create(this.jarFile);
assertThat(url).hasToString("jar:file:%s!/".formatted(this.jarFileUrlPath));
}
@Test
void createWithFileAndEntryReturnsUrl() {
JarEntry entry = new JarEntry("lib.jar");
URL url = JarUrl.create(this.temp, entry);
URL url = JarUrl.create(this.jarFile, entry);
assertThat(url).hasToString("jar:nested:%s/!lib.jar!/".formatted(this.jarFileUrlPath));
}
@Test
void createWithFileAndNullEntryReturnsUrl() {
URL url = JarUrl.create(this.temp, (JarEntry) null);
URL url = JarUrl.create(this.jarFile, (JarEntry) null);
assertThat(url).hasToString("jar:file:%s!/".formatted(this.jarFileUrlPath));
}
@Test
void createWithFileAndNameReturnsUrl() {
URL url = JarUrl.create(this.temp, "lib.jar");
URL url = JarUrl.create(this.jarFile, "lib.jar");
assertThat(url).hasToString("jar:nested:%s/!lib.jar!/".formatted(this.jarFileUrlPath));
}
@Test
void createWithFileAndNullNameReturnsUrl() {
URL url = JarUrl.create(this.temp, (String) null);
URL url = JarUrl.create(this.jarFile, (String) null);
assertThat(url).hasToString("jar:file:%s!/".formatted(this.jarFileUrlPath));
}
@Test
void createWithFileNameAndPathReturnsUrl() {
URL url = JarUrl.create(this.temp, "lib.jar", "com/example/My.class");
URL url = JarUrl.create(this.jarFile, "lib.jar", "com/example/My.class");
assertThat(url).hasToString("jar:nested:%s/!lib.jar!/com/example/My.class".formatted(this.jarFileUrlPath));
}