Move tests to JUnit 5 wherever possible
This commit is contained in:
@@ -32,8 +32,7 @@ import java.util.jar.JarOutputStream;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.loader.archive.Archive;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
@@ -45,11 +44,11 @@ import org.springframework.util.FileCopyUtils;
|
||||
*/
|
||||
public abstract class AbstractExecutableArchiveLauncherTests {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temp = new TemporaryFolder();
|
||||
@TempDir
|
||||
File tempDir;
|
||||
|
||||
protected File createJarArchive(String name, String entryPrefix) throws IOException {
|
||||
File archive = this.temp.newFile(name);
|
||||
File archive = new File(this.tempDir, name);
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(archive));
|
||||
jarOutputStream.putNextEntry(new JarEntry(entryPrefix + "/"));
|
||||
jarOutputStream.putNextEntry(new JarEntry(entryPrefix + "/classes/"));
|
||||
@@ -69,7 +68,8 @@ public abstract class AbstractExecutableArchiveLauncherTests {
|
||||
}
|
||||
|
||||
protected File explode(File archive) throws IOException {
|
||||
File exploded = this.temp.newFolder("exploded");
|
||||
File exploded = new File(this.tempDir, "exploded");
|
||||
exploded.mkdirs();
|
||||
JarFile jarFile = new JarFile(archive);
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.loader.archive.Archive;
|
||||
import org.springframework.boot.loader.archive.ExplodedArchive;
|
||||
@@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class JarLauncherTests extends AbstractExecutableArchiveLauncherTests {
|
||||
class JarLauncherTests extends AbstractExecutableArchiveLauncherTests {
|
||||
|
||||
@Test
|
||||
public void explodedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath() throws Exception {
|
||||
void explodedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath() throws Exception {
|
||||
File explodedRoot = explode(createJarArchive("archive.jar", "BOOT-INF"));
|
||||
JarLauncher launcher = new JarLauncher(new ExplodedArchive(explodedRoot, true));
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
@@ -46,7 +46,7 @@ public class JarLauncherTests extends AbstractExecutableArchiveLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void archivedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath() throws Exception {
|
||||
void archivedJarHasOnlyBootInfClassesAndContentsOfBootInfLibOnClasspath() throws Exception {
|
||||
File jarRoot = createJarArchive("archive.jar", "BOOT-INF");
|
||||
JarLauncher launcher = new JarLauncher(new JarFileArchive(jarRoot));
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
|
||||
@@ -19,9 +19,8 @@ package org.springframework.boot.loader;
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.loader.jar.JarFile;
|
||||
|
||||
@@ -35,42 +34,42 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
@SuppressWarnings("resource")
|
||||
public class LaunchedURLClassLoaderTests {
|
||||
class LaunchedURLClassLoaderTests {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@TempDir
|
||||
File tempDir;
|
||||
|
||||
@Test
|
||||
public void resolveResourceFromArchive() throws Exception {
|
||||
void resolveResourceFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, getClass().getClassLoader());
|
||||
assertThat(loader.getResource("demo/Application.java")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourcesFromArchive() throws Exception {
|
||||
void resolveResourcesFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, getClass().getClassLoader());
|
||||
assertThat(loader.getResources("demo/Application.java").hasMoreElements()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRootPathFromArchive() throws Exception {
|
||||
void resolveRootPathFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, getClass().getClassLoader());
|
||||
assertThat(loader.getResource("")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRootResourcesFromArchive() throws Exception {
|
||||
void resolveRootResourcesFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") }, getClass().getClassLoader());
|
||||
assertThat(loader.getResources("").hasMoreElements()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveFromNested() throws Exception {
|
||||
File file = this.temporaryFolder.newFile();
|
||||
void resolveFromNested() throws Exception {
|
||||
File file = new File(this.tempDir, "test.jar");
|
||||
TestJarCreator.createTestJar(file);
|
||||
JarFile jarFile = new JarFile(file);
|
||||
URL url = jarFile.getUrl();
|
||||
@@ -81,8 +80,8 @@ public class LaunchedURLClassLoaderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveFromNestedWhileThreadIsInterrupted() throws Exception {
|
||||
File file = this.temporaryFolder.newFile();
|
||||
void resolveFromNestedWhileThreadIsInterrupted() throws Exception {
|
||||
File file = new File(this.tempDir, "test.jar");
|
||||
TestJarCreator.createTestJar(file);
|
||||
JarFile jarFile = new JarFile(file);
|
||||
URL url = jarFile.getUrl();
|
||||
|
||||
@@ -28,16 +28,17 @@ import java.util.jar.Attributes;
|
||||
import java.util.jar.Manifest;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.loader.archive.Archive;
|
||||
import org.springframework.boot.loader.archive.ExplodedArchive;
|
||||
import org.springframework.boot.loader.archive.JarFileArchive;
|
||||
import org.springframework.boot.testsupport.rule.OutputCapture;
|
||||
import org.springframework.boot.testsupport.system.CapturedOutput;
|
||||
import org.springframework.boot.testsupport.system.OutputCaptureExtension;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
@@ -50,23 +51,24 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class PropertiesLauncherTests {
|
||||
@ExtendWith(OutputCaptureExtension.class)
|
||||
class PropertiesLauncherTests {
|
||||
|
||||
@Rule
|
||||
public OutputCapture output = new OutputCapture();
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@TempDir
|
||||
File tempDir;
|
||||
|
||||
private ClassLoader contextClassLoader;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
private CapturedOutput capturedOutput;
|
||||
|
||||
@BeforeEach
|
||||
public void setup(CapturedOutput capturedOutput) {
|
||||
this.contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
System.setProperty("loader.home", new File("src/test/resources").getAbsolutePath());
|
||||
this.capturedOutput = capturedOutput;
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void close() {
|
||||
Thread.currentThread().setContextClassLoader(this.contextClassLoader);
|
||||
System.clearProperty("loader.home");
|
||||
@@ -79,14 +81,14 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultHome() {
|
||||
void testDefaultHome() {
|
||||
System.clearProperty("loader.home");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getHomeDirectory()).isEqualTo(new File(System.getProperty("user.dir")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAlternateHome() throws Exception {
|
||||
void testAlternateHome() throws Exception {
|
||||
System.setProperty("loader.home", "src/test/resources/home");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getHomeDirectory()).isEqualTo(new File(System.getProperty("loader.home")));
|
||||
@@ -94,21 +96,21 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonExistentHome() {
|
||||
void testNonExistentHome() {
|
||||
System.setProperty("loader.home", "src/test/resources/nonexistent");
|
||||
assertThatIllegalStateException().isThrownBy(PropertiesLauncher::new)
|
||||
.withMessageContaining("Invalid source folder").withCauseInstanceOf(IllegalArgumentException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedMain() throws Exception {
|
||||
void testUserSpecifiedMain() throws Exception {
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getMainClass()).isEqualTo("demo.Application");
|
||||
assertThat(System.getProperty("loader.main")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedConfigName() throws Exception {
|
||||
void testUserSpecifiedConfigName() throws Exception {
|
||||
System.setProperty("loader.config.name", "foo");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getMainClass()).isEqualTo("my.Application");
|
||||
@@ -116,21 +118,21 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRootOfClasspathFirst() throws Exception {
|
||||
void testRootOfClasspathFirst() throws Exception {
|
||||
System.setProperty("loader.config.name", "bar");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getMainClass()).isEqualTo("my.BarApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedDotPath() {
|
||||
void testUserSpecifiedDotPath() {
|
||||
System.setProperty("loader.path", ".");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()).isEqualTo("[.]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedSlashPath() throws Exception {
|
||||
void testUserSpecifiedSlashPath() throws Exception {
|
||||
System.setProperty("loader.path", "jars/");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString()).isEqualTo("[jars/]");
|
||||
@@ -139,7 +141,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedWildcardPath() throws Exception {
|
||||
void testUserSpecifiedWildcardPath() throws Exception {
|
||||
System.setProperty("loader.path", "jars/*");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
@@ -149,7 +151,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedJarPath() throws Exception {
|
||||
void testUserSpecifiedJarPath() throws Exception {
|
||||
System.setProperty("loader.path", "jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
@@ -159,7 +161,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedRootOfJarPath() throws Exception {
|
||||
void testUserSpecifiedRootOfJarPath() throws Exception {
|
||||
System.setProperty("loader.path", "jar:file:./src/test/resources/nested-jars/app.jar!/");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
@@ -170,7 +172,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedRootOfJarPathWithDot() throws Exception {
|
||||
void testUserSpecifiedRootOfJarPathWithDot() throws Exception {
|
||||
System.setProperty("loader.path", "nested-jars/app.jar!/./");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
@@ -179,7 +181,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedRootOfJarPathWithDotAndJarPrefix() throws Exception {
|
||||
void testUserSpecifiedRootOfJarPathWithDotAndJarPrefix() throws Exception {
|
||||
System.setProperty("loader.path", "jar:file:./src/test/resources/nested-jars/app.jar!/./");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
@@ -187,7 +189,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedJarFileWithNestedArchives() throws Exception {
|
||||
void testUserSpecifiedJarFileWithNestedArchives() throws Exception {
|
||||
System.setProperty("loader.path", "nested-jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
@@ -197,7 +199,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedNestedJarPath() throws Exception {
|
||||
void testUserSpecifiedNestedJarPath() throws Exception {
|
||||
System.setProperty("loader.path", "nested-jars/app.jar!/foo.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
@@ -206,7 +208,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedDirectoryContainingJarFileWithNestedArchives() throws Exception {
|
||||
void testUserSpecifiedDirectoryContainingJarFileWithNestedArchives() throws Exception {
|
||||
System.setProperty("loader.path", "nested-jars");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
@@ -215,7 +217,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedJarPathWithDot() throws Exception {
|
||||
void testUserSpecifiedJarPathWithDot() throws Exception {
|
||||
System.setProperty("loader.path", "./jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
@@ -225,7 +227,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedClassLoader() throws Exception {
|
||||
void testUserSpecifiedClassLoader() throws Exception {
|
||||
System.setProperty("loader.path", "jars/app.jar");
|
||||
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
@@ -235,7 +237,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedClassPathOrder() throws Exception {
|
||||
void testUserSpecifiedClassPathOrder() throws Exception {
|
||||
System.setProperty("loader.path", "more-jars/app.jar,jars/app.jar");
|
||||
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
@@ -246,7 +248,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCustomClassLoaderCreation() throws Exception {
|
||||
void testCustomClassLoaderCreation() throws Exception {
|
||||
System.setProperty("loader.classLoader", TestLoader.class.getName());
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
ClassLoader loader = launcher.createClassLoader(archives());
|
||||
@@ -272,7 +274,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedConfigPathWins() throws Exception {
|
||||
void testUserSpecifiedConfigPathWins() throws Exception {
|
||||
|
||||
System.setProperty("loader.config.name", "foo");
|
||||
System.setProperty("loader.config.location", "classpath:bar.properties");
|
||||
@@ -281,21 +283,21 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemPropertySpecifiedMain() throws Exception {
|
||||
void testSystemPropertySpecifiedMain() throws Exception {
|
||||
System.setProperty("loader.main", "foo.Bar");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getMainClass()).isEqualTo("foo.Bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemPropertiesSet() {
|
||||
void testSystemPropertiesSet() {
|
||||
System.setProperty("loader.system", "true");
|
||||
new PropertiesLauncher();
|
||||
assertThat(System.getProperty("loader.main")).isEqualTo("demo.Application");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgsEnhanced() throws Exception {
|
||||
void testArgsEnhanced() throws Exception {
|
||||
System.setProperty("loader.args", "foo");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(Arrays.asList(launcher.getArgs("bar")).toString()).isEqualTo("[foo, bar]");
|
||||
@@ -303,12 +305,12 @@ public class PropertiesLauncherTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testLoadPathCustomizedUsingManifest() throws Exception {
|
||||
System.setProperty("loader.home", this.temporaryFolder.getRoot().getAbsolutePath());
|
||||
void testLoadPathCustomizedUsingManifest() throws Exception {
|
||||
System.setProperty("loader.home", this.tempDir.getAbsolutePath());
|
||||
Manifest manifest = new Manifest();
|
||||
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
|
||||
manifest.getMainAttributes().putValue("Loader-Path", "/foo.jar, /bar");
|
||||
File manifestFile = new File(this.temporaryFolder.getRoot(), "META-INF/MANIFEST.MF");
|
||||
File manifestFile = new File(this.tempDir, "META-INF/MANIFEST.MF");
|
||||
manifestFile.getParentFile().mkdirs();
|
||||
manifest.write(new FileOutputStream(manifestFile));
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
@@ -316,15 +318,16 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testManifestWithPlaceholders() throws Exception {
|
||||
void testManifestWithPlaceholders() throws Exception {
|
||||
System.setProperty("loader.home", "src/test/resources/placeholders");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertThat(launcher.getMainClass()).isEqualTo("demo.FooApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void encodedFileUrlLoaderPathIsHandledCorrectly() throws Exception {
|
||||
File loaderPath = this.temporaryFolder.newFolder("loader path");
|
||||
void encodedFileUrlLoaderPathIsHandledCorrectly() throws Exception {
|
||||
File loaderPath = new File(this.tempDir, "loader path");
|
||||
loaderPath.mkdir();
|
||||
System.setProperty("loader.path", loaderPath.toURI().toURL().toString());
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
@@ -339,7 +342,7 @@ public class PropertiesLauncherTests {
|
||||
while (!timeout && count < 100) {
|
||||
count++;
|
||||
Thread.sleep(50L);
|
||||
timeout = this.output.toString().contains(value);
|
||||
timeout = this.capturedOutput.toString().contains(value);
|
||||
}
|
||||
assertThat(timeout).as("Timed out waiting for (" + value + ")").isTrue();
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.boot.loader.archive.Archive;
|
||||
import org.springframework.boot.loader.archive.ExplodedArchive;
|
||||
@@ -33,10 +33,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class WarLauncherTests extends AbstractExecutableArchiveLauncherTests {
|
||||
class WarLauncherTests extends AbstractExecutableArchiveLauncherTests {
|
||||
|
||||
@Test
|
||||
public void explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath() throws Exception {
|
||||
void explodedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath() throws Exception {
|
||||
File explodedRoot = explode(createJarArchive("archive.war", "WEB-INF"));
|
||||
WarLauncher launcher = new WarLauncher(new ExplodedArchive(explodedRoot, true));
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
@@ -46,7 +46,7 @@ public class WarLauncherTests extends AbstractExecutableArchiveLauncherTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void archivedWarHasOnlyWebInfClassesAndContentsOWebInfLibOnClasspath() throws Exception {
|
||||
void archivedWarHasOnlyWebInfClassesAndContentsOWebInfLibOnClasspath() throws Exception {
|
||||
File jarRoot = createJarArchive("archive.war", "WEB-INF");
|
||||
WarLauncher launcher = new WarLauncher(new JarFileArchive(jarRoot));
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
|
||||
@@ -26,13 +26,13 @@ import java.net.URLClassLoader;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.loader.TestJarCreator;
|
||||
import org.springframework.boot.loader.archive.Archive.Entry;
|
||||
@@ -47,16 +47,16 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class ExplodedArchiveTests {
|
||||
class ExplodedArchiveTests {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@TempDir
|
||||
File tempDir;
|
||||
|
||||
private File rootFolder;
|
||||
|
||||
private ExplodedArchive archive;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
createArchive();
|
||||
}
|
||||
@@ -66,11 +66,11 @@ public class ExplodedArchiveTests {
|
||||
}
|
||||
|
||||
private void createArchive(String folderName) throws Exception {
|
||||
File file = this.temporaryFolder.newFile();
|
||||
File file = new File(this.tempDir, "test.jar");
|
||||
TestJarCreator.createTestJar(file);
|
||||
|
||||
this.rootFolder = (StringUtils.hasText(folderName) ? this.temporaryFolder.newFolder(folderName)
|
||||
: this.temporaryFolder.newFolder());
|
||||
this.rootFolder = (StringUtils.hasText(folderName) ? new File(this.tempDir, folderName)
|
||||
: new File(this.tempDir, UUID.randomUUID().toString()));
|
||||
JarFile jarFile = new JarFile(file);
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
@@ -98,36 +98,36 @@ public class ExplodedArchiveTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getManifest() throws Exception {
|
||||
void getManifest() throws Exception {
|
||||
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By")).isEqualTo("j1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntries() {
|
||||
void getEntries() {
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(this.archive);
|
||||
assertThat(entries.size()).isEqualTo(12);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUrl() throws Exception {
|
||||
void getUrl() throws Exception {
|
||||
assertThat(this.archive.getUrl()).isEqualTo(this.rootFolder.toURI().toURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUrlWithSpaceInPath() throws Exception {
|
||||
void getUrlWithSpaceInPath() throws Exception {
|
||||
createArchive("spaces in the name");
|
||||
assertThat(this.archive.getUrl()).isEqualTo(this.rootFolder.toURI().toURL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNestedArchive() throws Exception {
|
||||
void getNestedArchive() throws Exception {
|
||||
Entry entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
assertThat(nested.getUrl().toString()).isEqualTo(this.rootFolder.toURI() + "nested.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedDirArchive() throws Exception {
|
||||
void nestedDirArchive() throws Exception {
|
||||
Entry entry = getEntriesMap(this.archive).get("d/");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
Map<String, Entry> nestedEntries = getEntriesMap(nested);
|
||||
@@ -136,14 +136,14 @@ public class ExplodedArchiveTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveEntriesForRoot() {
|
||||
void getNonRecursiveEntriesForRoot() {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("/"), false);
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size()).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveManifest() throws Exception {
|
||||
void getNonRecursiveManifest() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"));
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
@@ -151,7 +151,7 @@ public class ExplodedArchiveTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveManifestEvenIfNonRecursive() throws Exception {
|
||||
void getNonRecursiveManifestEvenIfNonRecursive() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"), false);
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
@@ -159,7 +159,7 @@ public class ExplodedArchiveTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResourceAsStream() throws Exception {
|
||||
void getResourceAsStream() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"));
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
@@ -168,7 +168,7 @@ public class ExplodedArchiveTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResourceAsStreamNonRecursive() throws Exception {
|
||||
void getResourceAsStreamNonRecursive() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"), false);
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
|
||||
@@ -28,10 +28,9 @@ import java.util.jar.JarOutputStream;
|
||||
import java.util.zip.CRC32;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.loader.TestJarCreator;
|
||||
import org.springframework.boot.loader.archive.Archive.Entry;
|
||||
@@ -46,10 +45,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class JarFileArchiveTests {
|
||||
class JarFileArchiveTests {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@TempDir
|
||||
File tempDir;
|
||||
|
||||
private File rootJarFile;
|
||||
|
||||
@@ -57,44 +56,44 @@ public class JarFileArchiveTests {
|
||||
|
||||
private String rootJarFileUrl;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
setup(false);
|
||||
}
|
||||
|
||||
private void setup(boolean unpackNested) throws Exception {
|
||||
this.rootJarFile = this.temporaryFolder.newFile();
|
||||
this.rootJarFile = new File(this.tempDir, "root.jar");
|
||||
this.rootJarFileUrl = this.rootJarFile.toURI().toString();
|
||||
TestJarCreator.createTestJar(this.rootJarFile, unpackNested);
|
||||
this.archive = new JarFileArchive(this.rootJarFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getManifest() throws Exception {
|
||||
void getManifest() throws Exception {
|
||||
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By")).isEqualTo("j1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntries() {
|
||||
void getEntries() {
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(this.archive);
|
||||
assertThat(entries.size()).isEqualTo(12);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUrl() throws Exception {
|
||||
void getUrl() throws Exception {
|
||||
URL url = this.archive.getUrl();
|
||||
assertThat(url.toString()).isEqualTo(this.rootJarFileUrl);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNestedArchive() throws Exception {
|
||||
void getNestedArchive() throws Exception {
|
||||
Entry entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
assertThat(nested.getUrl().toString()).isEqualTo("jar:" + this.rootJarFileUrl + "!/nested.jar!/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNestedUnpackedArchive() throws Exception {
|
||||
void getNestedUnpackedArchive() throws Exception {
|
||||
setup(true);
|
||||
Entry entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
@@ -103,7 +102,7 @@ public class JarFileArchiveTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unpackedLocationsAreUniquePerArchive() throws Exception {
|
||||
void unpackedLocationsAreUniquePerArchive() throws Exception {
|
||||
setup(true);
|
||||
Entry entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
URL firstNested = this.archive.getNestedArchive(entry).getUrl();
|
||||
@@ -114,7 +113,7 @@ public class JarFileArchiveTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unpackedLocationsFromSameArchiveShareSameParent() throws Exception {
|
||||
void unpackedLocationsFromSameArchiveShareSameParent() throws Exception {
|
||||
setup(true);
|
||||
File nested = new File(
|
||||
this.archive.getNestedArchive(getEntriesMap(this.archive).get("nested.jar")).getUrl().toURI());
|
||||
@@ -124,16 +123,16 @@ public class JarFileArchiveTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zip64ArchivesAreHandledGracefully() throws IOException {
|
||||
File file = this.temporaryFolder.newFile("test.jar");
|
||||
void zip64ArchivesAreHandledGracefully() throws IOException {
|
||||
File file = new File(this.tempDir, "test.jar");
|
||||
FileCopyUtils.copy(writeZip64Jar(), file);
|
||||
assertThatIllegalStateException().isThrownBy(() -> new JarFileArchive(file))
|
||||
.withMessageContaining("Zip64 archives are not supported");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nestedZip64ArchivesAreHandledGracefully() throws IOException {
|
||||
File file = this.temporaryFolder.newFile("test.jar");
|
||||
void nestedZip64ArchivesAreHandledGracefully() throws IOException {
|
||||
File file = new File(this.tempDir, "test.jar");
|
||||
JarOutputStream output = new JarOutputStream(new FileOutputStream(file));
|
||||
JarEntry zip64JarEntry = new JarEntry("nested/zip64.jar");
|
||||
output.putNextEntry(zip64JarEntry);
|
||||
|
||||
@@ -27,11 +27,10 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -44,7 +43,7 @@ import static org.assertj.core.api.Assertions.assertThatNullPointerException;
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class RandomAccessDataFileTests {
|
||||
class RandomAccessDataFileTests {
|
||||
|
||||
private static final byte[] BYTES;
|
||||
|
||||
@@ -55,18 +54,15 @@ public class RandomAccessDataFileTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
private File tempFile;
|
||||
|
||||
private RandomAccessDataFile file;
|
||||
|
||||
private InputStream inputStream;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
this.tempFile = this.temporaryFolder.newFile();
|
||||
@BeforeEach
|
||||
public void setup(@TempDir File tempDir) throws Exception {
|
||||
this.tempFile = new File(tempDir, "tempFile");
|
||||
FileOutputStream outputStream = new FileOutputStream(this.tempFile);
|
||||
outputStream.write(BYTES);
|
||||
outputStream.close();
|
||||
@@ -74,74 +70,74 @@ public class RandomAccessDataFileTests {
|
||||
this.inputStream = this.file.getInputStream();
|
||||
}
|
||||
|
||||
@After
|
||||
@AfterEach
|
||||
public void cleanup() throws Exception {
|
||||
this.inputStream.close();
|
||||
this.file.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fileNotNull() {
|
||||
void fileNotNull() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new RandomAccessDataFile(null))
|
||||
.withMessageContaining("File must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fileExists() {
|
||||
void fileExists() {
|
||||
File file = new File("/does/not/exist");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new RandomAccessDataFile(file))
|
||||
.withMessageContaining(String.format("File %s must exist", file.getAbsolutePath()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readWithOffsetAndLengthShouldRead() throws Exception {
|
||||
void readWithOffsetAndLengthShouldRead() throws Exception {
|
||||
byte[] read = this.file.read(2, 3);
|
||||
assertThat(read).isEqualTo(new byte[] { 2, 3, 4 });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readWhenOffsetIsBeyondEOFShouldThrowException() throws Exception {
|
||||
void readWhenOffsetIsBeyondEOFShouldThrowException() throws Exception {
|
||||
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> this.file.read(257, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readWhenOffsetIsBeyondEndOfSubsectionShouldThrowException() throws Exception {
|
||||
void readWhenOffsetIsBeyondEndOfSubsectionShouldThrowException() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(0, 10);
|
||||
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> subsection.read(11, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readWhenOffsetPlusLengthGreaterThanEOFShouldThrowException() throws Exception {
|
||||
void readWhenOffsetPlusLengthGreaterThanEOFShouldThrowException() throws Exception {
|
||||
assertThatExceptionOfType(EOFException.class).isThrownBy(() -> this.file.read(256, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readWhenOffsetPlusLengthGreaterThanEndOfSubsectionShouldThrowException() throws Exception {
|
||||
void readWhenOffsetPlusLengthGreaterThanEndOfSubsectionShouldThrowException() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(0, 10);
|
||||
assertThatExceptionOfType(EOFException.class).isThrownBy(() -> subsection.read(10, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamRead() throws Exception {
|
||||
void inputStreamRead() throws Exception {
|
||||
for (int i = 0; i <= 255; i++) {
|
||||
assertThat(this.inputStream.read()).isEqualTo(i);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadNullBytes() throws Exception {
|
||||
void inputStreamReadNullBytes() throws Exception {
|
||||
assertThatNullPointerException().isThrownBy(() -> this.inputStream.read(null))
|
||||
.withMessage("Bytes must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadNullBytesWithOffset() throws Exception {
|
||||
void inputStreamReadNullBytesWithOffset() throws Exception {
|
||||
assertThatNullPointerException().isThrownBy(() -> this.inputStream.read(null, 0, 1))
|
||||
.withMessage("Bytes must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadBytes() throws Exception {
|
||||
void inputStreamReadBytes() throws Exception {
|
||||
byte[] b = new byte[256];
|
||||
int amountRead = this.inputStream.read(b);
|
||||
assertThat(b).isEqualTo(BYTES);
|
||||
@@ -149,7 +145,7 @@ public class RandomAccessDataFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadOffsetBytes() throws Exception {
|
||||
void inputStreamReadOffsetBytes() throws Exception {
|
||||
byte[] b = new byte[7];
|
||||
this.inputStream.skip(1);
|
||||
int amountRead = this.inputStream.read(b, 2, 3);
|
||||
@@ -158,7 +154,7 @@ public class RandomAccessDataFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadMoreBytesThanAvailable() throws Exception {
|
||||
void inputStreamReadMoreBytesThanAvailable() throws Exception {
|
||||
byte[] b = new byte[257];
|
||||
int amountRead = this.inputStream.read(b);
|
||||
assertThat(b).startsWith(BYTES);
|
||||
@@ -166,7 +162,7 @@ public class RandomAccessDataFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadPastEnd() throws Exception {
|
||||
void inputStreamReadPastEnd() throws Exception {
|
||||
this.inputStream.skip(255);
|
||||
assertThat(this.inputStream.read()).isEqualTo(0xFF);
|
||||
assertThat(this.inputStream.read()).isEqualTo(-1);
|
||||
@@ -174,7 +170,7 @@ public class RandomAccessDataFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadZeroLength() throws Exception {
|
||||
void inputStreamReadZeroLength() throws Exception {
|
||||
byte[] b = new byte[] { 0x0F };
|
||||
int amountRead = this.inputStream.read(b, 0, 0);
|
||||
assertThat(b).isEqualTo(new byte[] { 0x0F });
|
||||
@@ -183,62 +179,62 @@ public class RandomAccessDataFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamSkip() throws Exception {
|
||||
void inputStreamSkip() throws Exception {
|
||||
long amountSkipped = this.inputStream.skip(4);
|
||||
assertThat(this.inputStream.read()).isEqualTo(4);
|
||||
assertThat(amountSkipped).isEqualTo(4L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamSkipMoreThanAvailable() throws Exception {
|
||||
void inputStreamSkipMoreThanAvailable() throws Exception {
|
||||
long amountSkipped = this.inputStream.skip(257);
|
||||
assertThat(this.inputStream.read()).isEqualTo(-1);
|
||||
assertThat(amountSkipped).isEqualTo(256L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamSkipPastEnd() throws Exception {
|
||||
void inputStreamSkipPastEnd() throws Exception {
|
||||
this.inputStream.skip(256);
|
||||
long amountSkipped = this.inputStream.skip(1);
|
||||
assertThat(amountSkipped).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subsectionNegativeOffset() {
|
||||
void subsectionNegativeOffset() {
|
||||
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> this.file.getSubsection(-1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subsectionNegativeLength() {
|
||||
void subsectionNegativeLength() {
|
||||
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> this.file.getSubsection(0, -1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subsectionZeroLength() throws Exception {
|
||||
void subsectionZeroLength() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(0, 0);
|
||||
assertThat(subsection.getInputStream().read()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subsectionTooBig() {
|
||||
void subsectionTooBig() {
|
||||
this.file.getSubsection(0, 256);
|
||||
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> this.file.getSubsection(0, 257));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subsectionTooBigWithOffset() {
|
||||
void subsectionTooBigWithOffset() {
|
||||
this.file.getSubsection(1, 255);
|
||||
assertThatExceptionOfType(IndexOutOfBoundsException.class).isThrownBy(() -> this.file.getSubsection(1, 256));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subsection() throws Exception {
|
||||
void subsection() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(1, 1);
|
||||
assertThat(subsection.getInputStream().read()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadPastSubsection() throws Exception {
|
||||
void inputStreamReadPastSubsection() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(1, 2);
|
||||
InputStream inputStream = subsection.getInputStream();
|
||||
assertThat(inputStream.read()).isEqualTo(1);
|
||||
@@ -247,7 +243,7 @@ public class RandomAccessDataFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadBytesPastSubsection() throws Exception {
|
||||
void inputStreamReadBytesPastSubsection() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(1, 2);
|
||||
InputStream inputStream = subsection.getInputStream();
|
||||
byte[] b = new byte[3];
|
||||
@@ -257,7 +253,7 @@ public class RandomAccessDataFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamSkipPastSubsection() throws Exception {
|
||||
void inputStreamSkipPastSubsection() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(1, 2);
|
||||
InputStream inputStream = subsection.getInputStream();
|
||||
assertThat(inputStream.skip(3)).isEqualTo(2L);
|
||||
@@ -265,17 +261,17 @@ public class RandomAccessDataFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamSkipNegative() throws Exception {
|
||||
void inputStreamSkipNegative() throws Exception {
|
||||
assertThat(this.inputStream.skip(-1)).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFile() {
|
||||
void getFile() {
|
||||
assertThat(this.file.getFile()).isEqualTo(this.tempFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void concurrentReads() throws Exception {
|
||||
void concurrentReads() throws Exception {
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(20);
|
||||
List<Future<Boolean>> results = new ArrayList<>();
|
||||
for (int i = 0; i < 100; i++) {
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.boot.loader.jar;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -27,30 +27,30 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Phillip Webb
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class AsciiBytesTests {
|
||||
class AsciiBytesTests {
|
||||
|
||||
private static final char NO_SUFFIX = 0;
|
||||
|
||||
@Test
|
||||
public void createFromBytes() {
|
||||
void createFromBytes() {
|
||||
AsciiBytes bytes = new AsciiBytes(new byte[] { 65, 66 });
|
||||
assertThat(bytes.toString()).isEqualTo("AB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFromBytesWithOffset() {
|
||||
void createFromBytesWithOffset() {
|
||||
AsciiBytes bytes = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2);
|
||||
assertThat(bytes.toString()).isEqualTo("BC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFromString() {
|
||||
void createFromString() {
|
||||
AsciiBytes bytes = new AsciiBytes("AB");
|
||||
assertThat(bytes.toString()).isEqualTo("AB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void length() {
|
||||
void length() {
|
||||
AsciiBytes b1 = new AsciiBytes(new byte[] { 65, 66 });
|
||||
AsciiBytes b2 = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2);
|
||||
assertThat(b1.length()).isEqualTo(2);
|
||||
@@ -58,7 +58,7 @@ public class AsciiBytesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startWith() {
|
||||
void startWith() {
|
||||
AsciiBytes abc = new AsciiBytes(new byte[] { 65, 66, 67 });
|
||||
AsciiBytes ab = new AsciiBytes(new byte[] { 65, 66 });
|
||||
AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67 }, 1, 2);
|
||||
@@ -70,7 +70,7 @@ public class AsciiBytesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void endsWith() {
|
||||
void endsWith() {
|
||||
AsciiBytes abc = new AsciiBytes(new byte[] { 65, 66, 67 });
|
||||
AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67 }, 1, 2);
|
||||
AsciiBytes ab = new AsciiBytes(new byte[] { 65, 66 });
|
||||
@@ -82,7 +82,7 @@ public class AsciiBytesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void substringFromBeingIndex() {
|
||||
void substringFromBeingIndex() {
|
||||
AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 });
|
||||
assertThat(abcd.substring(0).toString()).isEqualTo("ABCD");
|
||||
assertThat(abcd.substring(1).toString()).isEqualTo("BCD");
|
||||
@@ -93,7 +93,7 @@ public class AsciiBytesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void substring() {
|
||||
void substring() {
|
||||
AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 });
|
||||
assertThat(abcd.substring(0, 4).toString()).isEqualTo("ABCD");
|
||||
assertThat(abcd.substring(1, 3).toString()).isEqualTo("BC");
|
||||
@@ -103,7 +103,7 @@ public class AsciiBytesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeAndEquals() {
|
||||
void hashCodeAndEquals() {
|
||||
AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 });
|
||||
AsciiBytes bc = new AsciiBytes(new byte[] { 66, 67 });
|
||||
AsciiBytes bc_substring = new AsciiBytes(new byte[] { 65, 66, 67, 68 }).substring(1, 3);
|
||||
@@ -119,22 +119,22 @@ public class AsciiBytesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeSameAsString() {
|
||||
void hashCodeSameAsString() {
|
||||
hashCodeSameAsString("abcABC123xyz!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeSameAsStringWithSpecial() {
|
||||
void hashCodeSameAsStringWithSpecial() {
|
||||
hashCodeSameAsString("special/\u00EB.dat");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeSameAsStringWithCyrillicCharacters() {
|
||||
void hashCodeSameAsStringWithCyrillicCharacters() {
|
||||
hashCodeSameAsString("\u0432\u0435\u0441\u043D\u0430");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeSameAsStringWithEmoji() {
|
||||
void hashCodeSameAsStringWithEmoji() {
|
||||
hashCodeSameAsString("\ud83d\udca9");
|
||||
}
|
||||
|
||||
@@ -143,22 +143,22 @@ public class AsciiBytesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesSameAsString() {
|
||||
void matchesSameAsString() {
|
||||
matchesSameAsString("abcABC123xyz!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesSameAsStringWithSpecial() {
|
||||
void matchesSameAsStringWithSpecial() {
|
||||
matchesSameAsString("special/\u00EB.dat");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesSameAsStringWithCyrillicCharacters() {
|
||||
void matchesSameAsStringWithCyrillicCharacters() {
|
||||
matchesSameAsString("\u0432\u0435\u0441\u043D\u0430");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesDifferentLengths() {
|
||||
void matchesDifferentLengths() {
|
||||
assertThat(new AsciiBytes("abc").matches("ab", NO_SUFFIX)).isFalse();
|
||||
assertThat(new AsciiBytes("abc").matches("abcd", NO_SUFFIX)).isFalse();
|
||||
assertThat(new AsciiBytes("abc").matches("abc", NO_SUFFIX)).isTrue();
|
||||
@@ -168,23 +168,23 @@ public class AsciiBytesTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesSuffix() {
|
||||
void matchesSuffix() {
|
||||
assertThat(new AsciiBytes("ab").matches("a", 'b')).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void matchesSameAsStringWithEmoji() {
|
||||
void matchesSameAsStringWithEmoji() {
|
||||
matchesSameAsString("\ud83d\udca9");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeFromInstanceMatchesHashCodeFromString() {
|
||||
void hashCodeFromInstanceMatchesHashCodeFromString() {
|
||||
String name = "fonts/宋体/simsun.ttf";
|
||||
assertThat(new AsciiBytes(name).hashCode()).isEqualTo(AsciiBytes.hashCode(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void instanceCreatedFromCharSequenceMatchesSameCharSequence() {
|
||||
void instanceCreatedFromCharSequenceMatchesSameCharSequence() {
|
||||
String name = "fonts/宋体/simsun.ttf";
|
||||
assertThat(new AsciiBytes(name).matches(name, NO_SUFFIX)).isTrue();
|
||||
}
|
||||
|
||||
@@ -21,10 +21,9 @@ import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.loader.TestJarCreator;
|
||||
import org.springframework.boot.loader.data.RandomAccessData;
|
||||
@@ -37,24 +36,21 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class CentralDirectoryParserTests {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
class CentralDirectoryParserTests {
|
||||
|
||||
private File jarFile;
|
||||
|
||||
private RandomAccessData jarData;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
this.jarFile = this.temporaryFolder.newFile();
|
||||
@BeforeEach
|
||||
public void setup(@TempDir File tempDir) throws Exception {
|
||||
this.jarFile = new File(tempDir, "test.jar");
|
||||
TestJarCreator.createTestJar(this.jarFile);
|
||||
this.jarData = new RandomAccessDataFile(this.jarFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void visitsInOrder() throws Exception {
|
||||
void visitsInOrder() throws Exception {
|
||||
MockCentralDirectoryVisitor visitor = new MockCentralDirectoryVisitor();
|
||||
CentralDirectoryParser parser = new CentralDirectoryParser();
|
||||
parser.addVisitor(visitor);
|
||||
@@ -64,7 +60,7 @@ public class CentralDirectoryParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void visitRecords() throws Exception {
|
||||
void visitRecords() throws Exception {
|
||||
Collector collector = new Collector();
|
||||
CentralDirectoryParser parser = new CentralDirectoryParser();
|
||||
parser.addVisitor(collector);
|
||||
|
||||
@@ -21,9 +21,8 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.loader.TestJarCreator;
|
||||
|
||||
@@ -34,15 +33,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class HandlerTests {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
class HandlerTests {
|
||||
|
||||
private final Handler handler = new Handler();
|
||||
|
||||
@Test
|
||||
public void parseUrlWithJarRootContextAndAbsoluteSpecThatUsesContext() throws MalformedURLException {
|
||||
void parseUrlWithJarRootContextAndAbsoluteSpecThatUsesContext() throws MalformedURLException {
|
||||
String spec = "/entry.txt";
|
||||
URL context = createUrl("file:example.jar!/");
|
||||
this.handler.parseURL(context, spec, 0, spec.length());
|
||||
@@ -50,7 +46,7 @@ public class HandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseUrlWithDirectoryEntryContextAndAbsoluteSpecThatUsesContext() throws MalformedURLException {
|
||||
void parseUrlWithDirectoryEntryContextAndAbsoluteSpecThatUsesContext() throws MalformedURLException {
|
||||
String spec = "/entry.txt";
|
||||
URL context = createUrl("file:example.jar!/dir/");
|
||||
this.handler.parseURL(context, spec, 0, spec.length());
|
||||
@@ -58,7 +54,7 @@ public class HandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseUrlWithJarRootContextAndRelativeSpecThatUsesContext() throws MalformedURLException {
|
||||
void parseUrlWithJarRootContextAndRelativeSpecThatUsesContext() throws MalformedURLException {
|
||||
String spec = "entry.txt";
|
||||
URL context = createUrl("file:example.jar!/");
|
||||
this.handler.parseURL(context, spec, 0, spec.length());
|
||||
@@ -66,7 +62,7 @@ public class HandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseUrlWithDirectoryEntryContextAndRelativeSpecThatUsesContext() throws MalformedURLException {
|
||||
void parseUrlWithDirectoryEntryContextAndRelativeSpecThatUsesContext() throws MalformedURLException {
|
||||
String spec = "entry.txt";
|
||||
URL context = createUrl("file:example.jar!/dir/");
|
||||
this.handler.parseURL(context, spec, 0, spec.length());
|
||||
@@ -74,7 +70,7 @@ public class HandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseUrlWithFileEntryContextAndRelativeSpecThatUsesContext() throws MalformedURLException {
|
||||
void parseUrlWithFileEntryContextAndRelativeSpecThatUsesContext() throws MalformedURLException {
|
||||
String spec = "entry.txt";
|
||||
URL context = createUrl("file:example.jar!/dir/file");
|
||||
this.handler.parseURL(context, spec, 0, spec.length());
|
||||
@@ -82,7 +78,7 @@ public class HandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseUrlWithSpecThatIgnoresContext() throws MalformedURLException {
|
||||
void parseUrlWithSpecThatIgnoresContext() throws MalformedURLException {
|
||||
JarFile.registerUrlProtocolHandler();
|
||||
String spec = "jar:file:/other.jar!/nested!/entry.txt";
|
||||
URL context = createUrl("file:example.jar!/dir/file");
|
||||
@@ -91,73 +87,72 @@ public class HandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameFileReturnsFalseForUrlsWithDifferentProtocols() throws MalformedURLException {
|
||||
void sameFileReturnsFalseForUrlsWithDifferentProtocols() throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(new URL("jar:file:foo.jar!/content.txt"), new URL("file:/foo.jar"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameFileReturnsFalseForDifferentFileInSameJar() throws MalformedURLException {
|
||||
void sameFileReturnsFalseForDifferentFileInSameJar() throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(new URL("jar:file:foo.jar!/the/path/to/the/first/content.txt"),
|
||||
new URL("jar:file:/foo.jar!/content.txt"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameFileReturnsFalseForSameFileInDifferentJars() throws MalformedURLException {
|
||||
void sameFileReturnsFalseForSameFileInDifferentJars() throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(new URL("jar:file:/the/path/to/the/first.jar!/content.txt"),
|
||||
new URL("jar:file:/second.jar!/content.txt"))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameFileReturnsTrueForSameFileInSameJar() throws MalformedURLException {
|
||||
void sameFileReturnsTrueForSameFileInSameJar() throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(new URL("jar:file:/the/path/to/the/first.jar!/content.txt"),
|
||||
new URL("jar:file:/the/path/to/the/first.jar!/content.txt"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameFileReturnsTrueForUrlsThatReferenceSameFileViaNestedArchiveAndFromRootOfJar()
|
||||
void sameFileReturnsTrueForUrlsThatReferenceSameFileViaNestedArchiveAndFromRootOfJar()
|
||||
throws MalformedURLException {
|
||||
assertThat(this.handler.sameFile(new URL("jar:file:/test.jar!/BOOT-INF/classes!/foo.txt"),
|
||||
new URL("jar:file:/test.jar!/BOOT-INF/classes/foo.txt"))).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodesAreEqualForUrlsThatReferenceSameFileViaNestedArchiveAndFromRootOfJar()
|
||||
throws MalformedURLException {
|
||||
void hashCodesAreEqualForUrlsThatReferenceSameFileViaNestedArchiveAndFromRootOfJar() throws MalformedURLException {
|
||||
assertThat(this.handler.hashCode(new URL("jar:file:/test.jar!/BOOT-INF/classes!/foo.txt")))
|
||||
.isEqualTo(this.handler.hashCode(new URL("jar:file:/test.jar!/BOOT-INF/classes/foo.txt")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlWithSpecReferencingParentDirectory() throws MalformedURLException {
|
||||
void urlWithSpecReferencingParentDirectory() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd",
|
||||
"../folderB/b.xsd");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlWithSpecReferencingAncestorDirectoryOutsideJarStopsAtJarRoot() throws MalformedURLException {
|
||||
void urlWithSpecReferencingAncestorDirectoryOutsideJarStopsAtJarRoot() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd",
|
||||
"../../../../../../folderB/b.xsd");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlWithSpecReferencingCurrentDirectory() throws MalformedURLException {
|
||||
void urlWithSpecReferencingCurrentDirectory() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes!/xsd/folderA/a.xsd",
|
||||
"./folderB/./b.xsd");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlWithRef() throws MalformedURLException {
|
||||
void urlWithRef() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes", "!/foo.txt#alpha");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urlWithQuery() throws MalformedURLException {
|
||||
void urlWithQuery() throws MalformedURLException {
|
||||
assertStandardAndCustomHandlerUrlsAreEqual("file:/test.jar!/BOOT-INF/classes", "!/foo.txt?alpha");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fallbackToJdksJarUrlStreamHandler() throws Exception {
|
||||
File testJar = this.temporaryFolder.newFile("test.jar");
|
||||
void fallbackToJdksJarUrlStreamHandler(@TempDir File tempDir) throws Exception {
|
||||
File testJar = new File(tempDir, "test.jar");
|
||||
TestJarCreator.createTestJar(testJar);
|
||||
URLConnection connection = new URL(null, "jar:file:" + testJar.getAbsolutePath() + "!/nested.jar!/",
|
||||
this.handler).openConnection();
|
||||
|
||||
@@ -32,10 +32,9 @@ import java.util.jar.Manifest;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.loader.TestJarCreator;
|
||||
import org.springframework.boot.loader.data.RandomAccessDataFile;
|
||||
@@ -55,28 +54,28 @@ import static org.mockito.Mockito.verify;
|
||||
* @author Martin Lau
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class JarFileTests {
|
||||
class JarFileTests {
|
||||
|
||||
private static final String PROTOCOL_HANDLER = "java.protocol.handler.pkgs";
|
||||
|
||||
private static final String HANDLERS_PACKAGE = "org.springframework.boot.loader";
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@TempDir
|
||||
File tempDir;
|
||||
|
||||
private File rootJarFile;
|
||||
|
||||
private JarFile jarFile;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
this.rootJarFile = this.temporaryFolder.newFile();
|
||||
this.rootJarFile = new File(this.tempDir, "root.jar");
|
||||
TestJarCreator.createTestJar(this.rootJarFile);
|
||||
this.jarFile = new JarFile(this.rootJarFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jdkJarFile() throws Exception {
|
||||
void jdkJarFile() throws Exception {
|
||||
// Sanity checks to see how the default jar file operates
|
||||
java.util.jar.JarFile jarFile = new java.util.jar.JarFile(this.rootJarFile);
|
||||
Enumeration<java.util.jar.JarEntry> entries = jarFile.entries();
|
||||
@@ -102,26 +101,26 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFromFile() throws Exception {
|
||||
void createFromFile() throws Exception {
|
||||
JarFile jarFile = new JarFile(this.rootJarFile);
|
||||
assertThat(jarFile.getName()).isNotNull();
|
||||
jarFile.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getManifest() throws Exception {
|
||||
void getManifest() throws Exception {
|
||||
assertThat(this.jarFile.getManifest().getMainAttributes().getValue("Built-By")).isEqualTo("j1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getManifestEntry() throws Exception {
|
||||
void getManifestEntry() throws Exception {
|
||||
ZipEntry entry = this.jarFile.getJarEntry("META-INF/MANIFEST.MF");
|
||||
Manifest manifest = new Manifest(this.jarFile.getInputStream(entry));
|
||||
assertThat(manifest.getMainAttributes().getValue("Built-By")).isEqualTo("j1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntries() {
|
||||
void getEntries() {
|
||||
Enumeration<java.util.jar.JarEntry> entries = this.jarFile.entries();
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/MANIFEST.MF");
|
||||
@@ -139,21 +138,21 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSpecialResourceViaClassLoader() throws Exception {
|
||||
void getSpecialResourceViaClassLoader() throws Exception {
|
||||
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { this.jarFile.getUrl() });
|
||||
assertThat(urlClassLoader.getResource("special/\u00EB.dat")).isNotNull();
|
||||
urlClassLoader.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getJarEntry() {
|
||||
void getJarEntry() {
|
||||
java.util.jar.JarEntry entry = this.jarFile.getJarEntry("1.dat");
|
||||
assertThat(entry).isNotNull();
|
||||
assertThat(entry.getName()).isEqualTo("1.dat");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInputStream() throws Exception {
|
||||
void getInputStream() throws Exception {
|
||||
InputStream inputStream = this.jarFile.getInputStream(this.jarFile.getEntry("1.dat"));
|
||||
assertThat(inputStream.available()).isEqualTo(1);
|
||||
assertThat(inputStream.read()).isEqualTo(1);
|
||||
@@ -162,19 +161,19 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getName() {
|
||||
void getName() {
|
||||
assertThat(this.jarFile.getName()).isEqualTo(this.rootJarFile.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSize() throws Exception {
|
||||
void getSize() throws Exception {
|
||||
try (ZipFile zip = new ZipFile(this.rootJarFile)) {
|
||||
assertThat(this.jarFile.size()).isEqualTo(zip.size());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntryTime() throws Exception {
|
||||
void getEntryTime() throws Exception {
|
||||
java.util.jar.JarFile jdkJarFile = new java.util.jar.JarFile(this.rootJarFile);
|
||||
assertThat(this.jarFile.getEntry("META-INF/MANIFEST.MF").getTime())
|
||||
.isEqualTo(jdkJarFile.getEntry("META-INF/MANIFEST.MF").getTime());
|
||||
@@ -182,7 +181,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void close() throws Exception {
|
||||
void close() throws Exception {
|
||||
RandomAccessDataFile randomAccessDataFile = spy(new RandomAccessDataFile(this.rootJarFile));
|
||||
JarFile jarFile = new JarFile(randomAccessDataFile);
|
||||
jarFile.close();
|
||||
@@ -190,7 +189,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUrl() throws Exception {
|
||||
void getUrl() throws Exception {
|
||||
URL url = this.jarFile.getUrl();
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/");
|
||||
JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
|
||||
@@ -203,7 +202,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createEntryUrl() throws Exception {
|
||||
void createEntryUrl() throws Exception {
|
||||
URL url = new URL(this.jarFile.getUrl(), "1.dat");
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/1.dat");
|
||||
JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
|
||||
@@ -219,7 +218,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMissingEntryUrl() throws Exception {
|
||||
void getMissingEntryUrl() throws Exception {
|
||||
URL url = new URL(this.jarFile.getUrl(), "missing.dat");
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/missing.dat");
|
||||
assertThatExceptionOfType(FileNotFoundException.class)
|
||||
@@ -227,14 +226,14 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUrlStream() throws Exception {
|
||||
void getUrlStream() throws Exception {
|
||||
URL url = this.jarFile.getUrl();
|
||||
url.openConnection();
|
||||
assertThatIOException().isThrownBy(url::openStream);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntryUrlStream() throws Exception {
|
||||
void getEntryUrlStream() throws Exception {
|
||||
URL url = new URL(this.jarFile.getUrl(), "1.dat");
|
||||
url.openConnection();
|
||||
InputStream stream = url.openStream();
|
||||
@@ -243,7 +242,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNestedJarFile() throws Exception {
|
||||
void getNestedJarFile() throws Exception {
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
|
||||
Enumeration<java.util.jar.JarEntry> entries = nestedJarFile.entries();
|
||||
@@ -276,7 +275,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNestedJarDirectory() throws Exception {
|
||||
void getNestedJarDirectory() throws Exception {
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile.getEntry("d/"));
|
||||
|
||||
Enumeration<java.util.jar.JarEntry> entries = nestedJarFile.entries();
|
||||
@@ -293,7 +292,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNestedJarEntryUrl() throws Exception {
|
||||
void getNestedJarEntryUrl() throws Exception {
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
URL url = nestedJarFile.getJarEntry("3.dat").getUrl();
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat");
|
||||
@@ -303,7 +302,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createUrlFromString() throws Exception {
|
||||
void createUrlFromString() throws Exception {
|
||||
JarFile.registerUrlProtocolHandler();
|
||||
String spec = "jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat";
|
||||
URL url = new URL(spec);
|
||||
@@ -318,12 +317,12 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createNonNestedUrlFromString() throws Exception {
|
||||
void createNonNestedUrlFromString() throws Exception {
|
||||
nonNestedJarFileFromString("jar:" + this.rootJarFile.toURI() + "!/2.dat");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createNonNestedUrlFromPathString() throws Exception {
|
||||
void createNonNestedUrlFromPathString() throws Exception {
|
||||
nonNestedJarFileFromString("jar:" + this.rootJarFile.toPath().toUri() + "!/2.dat");
|
||||
}
|
||||
|
||||
@@ -341,28 +340,28 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDirectoryInputStream() throws Exception {
|
||||
void getDirectoryInputStream() throws Exception {
|
||||
InputStream inputStream = this.jarFile.getInputStream(this.jarFile.getEntry("d/"));
|
||||
assertThat(inputStream).isNotNull();
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDirectoryInputStreamWithoutSlash() throws Exception {
|
||||
void getDirectoryInputStreamWithoutSlash() throws Exception {
|
||||
InputStream inputStream = this.jarFile.getInputStream(this.jarFile.getEntry("d"));
|
||||
assertThat(inputStream).isNotNull();
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensibleToString() throws Exception {
|
||||
void sensibleToString() throws Exception {
|
||||
assertThat(this.jarFile.toString()).isEqualTo(this.rootJarFile.getPath());
|
||||
assertThat(this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar")).toString())
|
||||
.isEqualTo(this.rootJarFile.getPath() + "!/nested.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void verifySignedJar() throws Exception {
|
||||
void verifySignedJar() throws Exception {
|
||||
String classpath = System.getProperty("java.class.path");
|
||||
String[] entries = classpath.split(System.getProperty("path.separator"));
|
||||
String signedJarFile = null;
|
||||
@@ -389,8 +388,8 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarFileWithScriptAtTheStart() throws Exception {
|
||||
File file = this.temporaryFolder.newFile();
|
||||
void jarFileWithScriptAtTheStart() throws Exception {
|
||||
File file = new File(this.tempDir, "test.jar");
|
||||
InputStream sourceJarContent = new FileInputStream(this.rootJarFile);
|
||||
FileOutputStream outputStream = new FileOutputStream(file);
|
||||
StreamUtils.copy("#/bin/bash", Charset.defaultCharset(), outputStream);
|
||||
@@ -403,7 +402,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cannotLoadMissingJar() throws Exception {
|
||||
void cannotLoadMissingJar() throws Exception {
|
||||
// relates to gh-1070
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
URL nestedUrl = nestedJarFile.getUrl();
|
||||
@@ -412,7 +411,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerUrlProtocolHandlerWithNoExistingRegistration() {
|
||||
void registerUrlProtocolHandlerWithNoExistingRegistration() {
|
||||
String original = System.getProperty(PROTOCOL_HANDLER);
|
||||
try {
|
||||
System.clearProperty(PROTOCOL_HANDLER);
|
||||
@@ -431,7 +430,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerUrlProtocolHandlerAddsToExistingRegistration() {
|
||||
void registerUrlProtocolHandlerAddsToExistingRegistration() {
|
||||
String original = System.getProperty(PROTOCOL_HANDLER);
|
||||
try {
|
||||
System.setProperty(PROTOCOL_HANDLER, "com.example");
|
||||
@@ -450,16 +449,16 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarFileCanBeDeletedOnceItHasBeenClosed() throws Exception {
|
||||
File temp = this.temporaryFolder.newFile();
|
||||
TestJarCreator.createTestJar(temp);
|
||||
JarFile jf = new JarFile(temp);
|
||||
void jarFileCanBeDeletedOnceItHasBeenClosed() throws Exception {
|
||||
File jar = new File(this.tempDir, "test.jar");
|
||||
TestJarCreator.createTestJar(jar);
|
||||
JarFile jf = new JarFile(jar);
|
||||
jf.close();
|
||||
assertThat(temp.delete()).isTrue();
|
||||
assertThat(jar.delete()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createUrlFromStringWithContextWhenNotFound() throws Exception {
|
||||
void createUrlFromStringWithContextWhenNotFound() throws Exception {
|
||||
// gh-12483
|
||||
JarURLConnection.setUseFastExceptions(true);
|
||||
try {
|
||||
@@ -477,7 +476,7 @@ public class JarFileTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiReleaseEntry() throws Exception {
|
||||
void multiReleaseEntry() throws Exception {
|
||||
JarFile multiRelease = this.jarFile.getNestedJarFile(this.jarFile.getEntry("multi-release.jar"));
|
||||
ZipEntry entry = multiRelease.getEntry("multi-release.dat");
|
||||
assertThat(entry.getName()).isEqualTo("multi-release.dat");
|
||||
|
||||
@@ -21,10 +21,9 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.loader.TestJarCreator;
|
||||
import org.springframework.boot.loader.jar.JarURLConnection.JarEntryName;
|
||||
@@ -39,71 +38,68 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Phillip Webb
|
||||
* @author Rostyslav Dudka
|
||||
*/
|
||||
public class JarURLConnectionTests {
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder(new File("target"));
|
||||
class JarURLConnectionTests {
|
||||
|
||||
private File rootJarFile;
|
||||
|
||||
private JarFile jarFile;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
this.rootJarFile = this.temporaryFolder.newFile();
|
||||
@BeforeEach
|
||||
public void setup(@TempDir File tempDir) throws Exception {
|
||||
this.rootJarFile = new File(tempDir, "root.jar");
|
||||
TestJarCreator.createTestJar(this.rootJarFile);
|
||||
this.jarFile = new JarFile(this.rootJarFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToRootUsingAbsoluteUrl() throws Exception {
|
||||
void connectionToRootUsingAbsoluteUrl() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getContent()).isSameAs(this.jarFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToRootUsingRelativeUrl() throws Exception {
|
||||
void connectionToRootUsingRelativeUrl() throws Exception {
|
||||
URL url = new URL("jar:file:" + getRelativePath() + "!/");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getContent()).isSameAs(this.jarFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingAbsoluteUrl() throws Exception {
|
||||
void connectionToEntryUsingAbsoluteUrl() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/1.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingRelativeUrl() throws Exception {
|
||||
void connectionToEntryUsingRelativeUrl() throws Exception {
|
||||
URL url = new URL("jar:file:" + getRelativePath() + "!/1.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix() throws Exception {
|
||||
void connectionToEntryUsingAbsoluteUrlWithFileColonSlashSlashPrefix() throws Exception {
|
||||
URL url = new URL("jar:file:/" + getAbsolutePath() + "!/1.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 1 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingAbsoluteUrlForNestedEntry() throws Exception {
|
||||
void connectionToEntryUsingAbsoluteUrlForNestedEntry() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/nested.jar!/3.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingRelativeUrlForNestedEntry() throws Exception {
|
||||
void connectionToEntryUsingRelativeUrlForNestedEntry() throws Exception {
|
||||
URL url = new URL("jar:file:" + getRelativePath() + "!/nested.jar!/3.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingAbsoluteUrlForEntryFromNestedJarFile() throws Exception {
|
||||
void connectionToEntryUsingAbsoluteUrlForEntryFromNestedJarFile() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/nested.jar!/3.dat");
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
assertThat(JarURLConnection.get(url, nested).getInputStream())
|
||||
@@ -111,7 +107,7 @@ public class JarURLConnectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingRelativeUrlForEntryFromNestedJarFile() throws Exception {
|
||||
void connectionToEntryUsingRelativeUrlForEntryFromNestedJarFile() throws Exception {
|
||||
URL url = new URL("jar:file:" + getRelativePath() + "!/nested.jar!/3.dat");
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
assertThat(JarURLConnection.get(url, nested).getInputStream())
|
||||
@@ -119,7 +115,7 @@ public class JarURLConnectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryInNestedJarFromUrlThatUsesExistingUrlAsContext() throws Exception {
|
||||
void connectionToEntryInNestedJarFromUrlThatUsesExistingUrlAsContext() throws Exception {
|
||||
URL url = new URL(new URL("jar", null, -1, "file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()),
|
||||
"/3.dat");
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
@@ -128,21 +124,21 @@ public class JarURLConnectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryWithSpaceNestedEntry() throws Exception {
|
||||
void connectionToEntryWithSpaceNestedEntry() throws Exception {
|
||||
URL url = new URL("jar:file:" + getRelativePath() + "!/space nested.jar!/3.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryWithEncodedSpaceNestedEntry() throws Exception {
|
||||
void connectionToEntryWithEncodedSpaceNestedEntry() throws Exception {
|
||||
URL url = new URL("jar:file:" + getRelativePath() + "!/space%20nested.jar!/3.dat");
|
||||
assertThat(JarURLConnection.get(url, this.jarFile).getInputStream())
|
||||
.hasSameContentAs(new ByteArrayInputStream(new byte[] { 3 }));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void connectionToEntryUsingWrongAbsoluteUrlForEntryFromNestedJarFile() throws Exception {
|
||||
void connectionToEntryUsingWrongAbsoluteUrlForEntryFromNestedJarFile() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/w.jar!/3.dat");
|
||||
JarFile nested = this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
assertThatExceptionOfType(FileNotFoundException.class)
|
||||
@@ -150,43 +146,43 @@ public class JarURLConnectionTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContentLengthReturnsLengthOfUnderlyingEntry() throws Exception {
|
||||
void getContentLengthReturnsLengthOfUnderlyingEntry() throws Exception {
|
||||
URL url = new URL(new URL("jar", null, -1, "file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()),
|
||||
"/3.dat");
|
||||
assertThat(url.openConnection().getContentLength()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getContentLengthLongReturnsLengthOfUnderlyingEntry() throws Exception {
|
||||
void getContentLengthLongReturnsLengthOfUnderlyingEntry() throws Exception {
|
||||
URL url = new URL(new URL("jar", null, -1, "file:" + getAbsolutePath() + "!/nested.jar!/", new Handler()),
|
||||
"/3.dat");
|
||||
assertThat(url.openConnection().getContentLengthLong()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLastModifiedReturnsLastModifiedTimeOfJarEntry() throws Exception {
|
||||
void getLastModifiedReturnsLastModifiedTimeOfJarEntry() throws Exception {
|
||||
URL url = new URL("jar:file:" + getAbsolutePath() + "!/1.dat");
|
||||
JarURLConnection connection = JarURLConnection.get(url, this.jarFile);
|
||||
assertThat(connection.getLastModified()).isEqualTo(connection.getJarEntry().getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarEntryBasicName() {
|
||||
void jarEntryBasicName() {
|
||||
assertThat(new JarEntryName(new StringSequence("a/b/C.class")).toString()).isEqualTo("a/b/C.class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarEntryNameWithSingleByteEncodedCharacters() {
|
||||
void jarEntryNameWithSingleByteEncodedCharacters() {
|
||||
assertThat(new JarEntryName(new StringSequence("%61/%62/%43.class")).toString()).isEqualTo("a/b/C.class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarEntryNameWithDoubleByteEncodedCharacters() {
|
||||
void jarEntryNameWithDoubleByteEncodedCharacters() {
|
||||
assertThat(new JarEntryName(new StringSequence("%c3%a1/b/C.class")).toString()).isEqualTo("\u00e1/b/C.class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarEntryNameWithMixtureOfEncodedAndUnencodedDoubleByteCharacters() {
|
||||
void jarEntryNameWithMixtureOfEncodedAndUnencodedDoubleByteCharacters() {
|
||||
assertThat(new JarEntryName(new StringSequence("%c3%a1/b/\u00c7.class")).toString())
|
||||
.isEqualTo("\u00e1/b/\u00c7.class");
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.boot.loader.jar;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
@@ -27,55 +27,55 @@ import static org.assertj.core.api.Assertions.assertThatNullPointerException;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class StringSequenceTests {
|
||||
class StringSequenceTests {
|
||||
|
||||
@Test
|
||||
public void createWhenSourceIsNullShouldThrowException() {
|
||||
void createWhenSourceIsNullShouldThrowException() {
|
||||
assertThatNullPointerException().isThrownBy(() -> new StringSequence(null))
|
||||
.withMessage("Source must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWithIndexWhenSourceIsNullShouldThrowException() {
|
||||
void createWithIndexWhenSourceIsNullShouldThrowException() {
|
||||
assertThatNullPointerException().isThrownBy(() -> new StringSequence(null, 0, 0))
|
||||
.withMessage("Source must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenStartIsLessThanZeroShouldThrowException() {
|
||||
void createWhenStartIsLessThanZeroShouldThrowException() {
|
||||
assertThatExceptionOfType(StringIndexOutOfBoundsException.class)
|
||||
.isThrownBy(() -> new StringSequence("x", -1, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createWhenEndIsGreaterThanLengthShouldThrowException() {
|
||||
void createWhenEndIsGreaterThanLengthShouldThrowException() {
|
||||
assertThatExceptionOfType(StringIndexOutOfBoundsException.class)
|
||||
.isThrownBy(() -> new StringSequence("x", 0, 2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFromString() {
|
||||
void createFromString() {
|
||||
assertThat(new StringSequence("test").toString()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subSequenceWithJustStartShouldReturnSubSequence() {
|
||||
void subSequenceWithJustStartShouldReturnSubSequence() {
|
||||
assertThat(new StringSequence("smiles").subSequence(1).toString()).isEqualTo("miles");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subSequenceShouldReturnSubSequence() {
|
||||
void subSequenceShouldReturnSubSequence() {
|
||||
assertThat(new StringSequence("hamburger").subSequence(4, 8).toString()).isEqualTo("urge");
|
||||
assertThat(new StringSequence("smiles").subSequence(1, 5).toString()).isEqualTo("mile");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subSequenceWhenCalledMultipleTimesShouldReturnSubSequence() {
|
||||
void subSequenceWhenCalledMultipleTimesShouldReturnSubSequence() {
|
||||
assertThat(new StringSequence("hamburger").subSequence(4, 8).subSequence(1, 3).toString()).isEqualTo("rg");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subSequenceWhenEndPastExistingEndShouldThrowException() {
|
||||
void subSequenceWhenEndPastExistingEndShouldThrowException() {
|
||||
StringSequence sequence = new StringSequence("abcde").subSequence(1, 4);
|
||||
assertThat(sequence.toString()).isEqualTo("bcd");
|
||||
assertThat(sequence.subSequence(2, 3).toString()).isEqualTo("d");
|
||||
@@ -83,7 +83,7 @@ public class StringSequenceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subSequenceWhenStartPastExistingEndShouldThrowException() {
|
||||
void subSequenceWhenStartPastExistingEndShouldThrowException() {
|
||||
StringSequence sequence = new StringSequence("abcde").subSequence(1, 4);
|
||||
assertThat(sequence.toString()).isEqualTo("bcd");
|
||||
assertThat(sequence.subSequence(2, 3).toString()).isEqualTo("d");
|
||||
@@ -91,24 +91,24 @@ public class StringSequenceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEmptyWhenEmptyShouldReturnTrue() {
|
||||
void isEmptyWhenEmptyShouldReturnTrue() {
|
||||
assertThat(new StringSequence("").isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEmptyWhenNotEmptyShouldReturnFalse() {
|
||||
void isEmptyWhenNotEmptyShouldReturnFalse() {
|
||||
assertThat(new StringSequence("x").isEmpty()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lengthShouldReturnLength() {
|
||||
void lengthShouldReturnLength() {
|
||||
StringSequence sequence = new StringSequence("hamburger");
|
||||
assertThat(sequence.length()).isEqualTo(9);
|
||||
assertThat(sequence.subSequence(4, 8).length()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void charAtShouldReturnChar() {
|
||||
void charAtShouldReturnChar() {
|
||||
StringSequence sequence = new StringSequence("hamburger");
|
||||
assertThat(sequence.charAt(0)).isEqualTo('h');
|
||||
assertThat(sequence.charAt(1)).isEqualTo('a');
|
||||
@@ -117,7 +117,7 @@ public class StringSequenceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void indexOfCharShouldReturnIndexOf() {
|
||||
void indexOfCharShouldReturnIndexOf() {
|
||||
StringSequence sequence = new StringSequence("aabbaacc");
|
||||
assertThat(sequence.indexOf('a')).isEqualTo(0);
|
||||
assertThat(sequence.indexOf('b')).isEqualTo(2);
|
||||
@@ -125,7 +125,7 @@ public class StringSequenceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void indexOfStringShouldReturnIndexOf() {
|
||||
void indexOfStringShouldReturnIndexOf() {
|
||||
StringSequence sequence = new StringSequence("aabbaacc");
|
||||
assertThat(sequence.indexOf("a")).isEqualTo(0);
|
||||
assertThat(sequence.indexOf("b")).isEqualTo(2);
|
||||
@@ -133,7 +133,7 @@ public class StringSequenceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void indexOfStringFromIndexShouldReturnIndexOf() {
|
||||
void indexOfStringFromIndexShouldReturnIndexOf() {
|
||||
StringSequence sequence = new StringSequence("aabbaacc");
|
||||
assertThat(sequence.indexOf("a", 2)).isEqualTo(4);
|
||||
assertThat(sequence.indexOf("b", 3)).isEqualTo(3);
|
||||
@@ -141,13 +141,13 @@ public class StringSequenceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeShouldBeSameAsString() {
|
||||
void hashCodeShouldBeSameAsString() {
|
||||
assertThat(new StringSequence("hamburger").hashCode()).isEqualTo("hamburger".hashCode());
|
||||
assertThat(new StringSequence("hamburger").subSequence(4, 8).hashCode()).isEqualTo("urge".hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equalsWhenSameContentShouldMatch() {
|
||||
void equalsWhenSameContentShouldMatch() {
|
||||
StringSequence a = new StringSequence("hamburger").subSequence(4, 8);
|
||||
StringSequence b = new StringSequence("urge");
|
||||
StringSequence c = new StringSequence("urgh");
|
||||
@@ -155,50 +155,50 @@ public class StringSequenceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notEqualsWhenSequencesOfDifferentLength() {
|
||||
void notEqualsWhenSequencesOfDifferentLength() {
|
||||
StringSequence a = new StringSequence("abcd");
|
||||
StringSequence b = new StringSequence("ef");
|
||||
assertThat(a).isNotEqualTo(b);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startsWithWhenExactMatch() {
|
||||
void startsWithWhenExactMatch() {
|
||||
assertThat(new StringSequence("abc").startsWith("abc")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startsWithWhenLongerAndStartsWith() {
|
||||
void startsWithWhenLongerAndStartsWith() {
|
||||
assertThat(new StringSequence("abcd").startsWith("abc")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startsWithWhenLongerAndDoesNotStartWith() {
|
||||
void startsWithWhenLongerAndDoesNotStartWith() {
|
||||
assertThat(new StringSequence("abcd").startsWith("abx")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startsWithWhenShorterAndDoesNotStartWith() {
|
||||
void startsWithWhenShorterAndDoesNotStartWith() {
|
||||
assertThat(new StringSequence("ab").startsWith("abc")).isFalse();
|
||||
assertThat(new StringSequence("ab").startsWith("c")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startsWithOffsetWhenExactMatch() {
|
||||
void startsWithOffsetWhenExactMatch() {
|
||||
assertThat(new StringSequence("xabc").startsWith("abc", 1)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startsWithOffsetWhenLongerAndStartsWith() {
|
||||
void startsWithOffsetWhenLongerAndStartsWith() {
|
||||
assertThat(new StringSequence("xabcd").startsWith("abc", 1)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startsWithOffsetWhenLongerAndDoesNotStartWith() {
|
||||
void startsWithOffsetWhenLongerAndDoesNotStartWith() {
|
||||
assertThat(new StringSequence("xabcd").startsWith("abx", 1)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void startsWithOffsetWhenShorterAndDoesNotStartWith() {
|
||||
void startsWithOffsetWhenShorterAndDoesNotStartWith() {
|
||||
assertThat(new StringSequence("xab").startsWith("abc", 1)).isFalse();
|
||||
assertThat(new StringSequence("xab").startsWith("c", 1)).isFalse();
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@
|
||||
|
||||
package org.springframework.boot.loader.util;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -27,35 +27,35 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class SystemPropertyUtilsTests {
|
||||
class SystemPropertyUtilsTests {
|
||||
|
||||
@BeforeClass
|
||||
public static void init() {
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
System.setProperty("foo", "bar");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void close() {
|
||||
@AfterEach
|
||||
public void close() {
|
||||
System.clearProperty("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVanillaPlaceholder() {
|
||||
void testVanillaPlaceholder() {
|
||||
assertThat(SystemPropertyUtils.resolvePlaceholders("${foo}")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultValue() {
|
||||
void testDefaultValue() {
|
||||
assertThat(SystemPropertyUtils.resolvePlaceholders("${bar:foo}")).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedPlaceholder() {
|
||||
void testNestedPlaceholder() {
|
||||
assertThat(SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}")).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnvVar() {
|
||||
void testEnvVar() {
|
||||
assertThat(SystemPropertyUtils.getProperty("lang")).isEqualTo(System.getenv("LANG"));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user