Use AssertJ in spring-boot-tools
See gh-5083
This commit is contained in:
@@ -28,8 +28,7 @@ import org.mockito.MockitoAnnotations;
|
||||
|
||||
import org.springframework.boot.loader.archive.Archive.Entry;
|
||||
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
||||
/**
|
||||
@@ -87,8 +86,8 @@ public class ExecutableArchiveLauncherTests {
|
||||
}
|
||||
|
||||
private void assertClassLoaderUrls(ClassLoader classLoader, URL[] urls) {
|
||||
assertTrue(classLoader instanceof URLClassLoader);
|
||||
assertArrayEquals(urls, ((URLClassLoader) classLoader).getURLs());
|
||||
assertThat(classLoader).isInstanceOf(URLClassLoader.class);
|
||||
assertThat(((URLClassLoader) classLoader).getURLs()).isEqualTo(urls);
|
||||
}
|
||||
|
||||
private void doWithTccl(ClassLoader classLoader, Callable<?> action)
|
||||
|
||||
@@ -23,8 +23,7 @@ import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link InputArgumentsJavaAgentDetector}
|
||||
@@ -38,24 +37,25 @@ public class InputArgumentsJavaAgentDetectorTests {
|
||||
throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar"));
|
||||
assertFalse(detector.isJavaAgentJar(
|
||||
new File("something-else.jar").getCanonicalFile().toURI().toURL()));
|
||||
assertThat(detector.isJavaAgentJar(
|
||||
new File("something-else.jar").getCanonicalFile().toURI().toURL()))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleJavaAgent() throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar"));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
assertThat(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void singleJavaAgentWithOptions() throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar=a=alpha,b=bravo"));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
assertThat(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL())).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -63,10 +63,11 @@ public class InputArgumentsJavaAgentDetectorTests {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar",
|
||||
"-javaagent:my-other-agent.jar"));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-other-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
assertThat(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL())).isTrue();
|
||||
assertThat(detector.isJavaAgentJar(
|
||||
new File("my-other-agent.jar").getCanonicalFile().toURI().toURL()))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,11 +25,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.loader.jar.JarFile;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link LaunchedURLClassLoader}.
|
||||
@@ -47,13 +43,13 @@ public class LaunchedURLClassLoaderTests {
|
||||
public void resolveResourceFromWindowsFilesystem() throws Exception {
|
||||
// This path is invalid - it should return null even on Windows.
|
||||
// A regular URLClassLoader will deal with it gracefully.
|
||||
assertNull(getClass().getClassLoader()
|
||||
.getResource("c:\\Users\\user\\bar.properties"));
|
||||
assertThat(getClass().getClassLoader()
|
||||
.getResource("c:\\Users\\user\\bar.properties")).isNull();
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
// So we should too...
|
||||
assertNull(loader.getResource("c:\\Users\\user\\bar.properties"));
|
||||
assertThat(loader.getResource("c:\\Users\\user\\bar.properties")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,7 +57,7 @@ public class LaunchedURLClassLoaderTests {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertNotNull(loader.getResource("demo/Application.java"));
|
||||
assertThat(loader.getResource("demo/Application.java")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,7 +65,8 @@ public class LaunchedURLClassLoaderTests {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertTrue(loader.getResources("demo/Application.java").hasMoreElements());
|
||||
assertThat(loader.getResources("demo/Application.java").hasMoreElements())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,7 +74,7 @@ public class LaunchedURLClassLoaderTests {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertNotNull(loader.getResource(""));
|
||||
assertThat(loader.getResource("")).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,7 +82,7 @@ public class LaunchedURLClassLoaderTests {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertTrue(loader.getResources("").hasMoreElements());
|
||||
assertThat(loader.getResources("").hasMoreElements()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,8 +94,8 @@ public class LaunchedURLClassLoaderTests {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { url },
|
||||
null);
|
||||
URL resource = loader.getResource("nested.jar!/3.dat");
|
||||
assertThat(resource.toString(), equalTo(url + "nested.jar!/3.dat"));
|
||||
assertThat(resource.openConnection().getInputStream().read(), equalTo(3));
|
||||
assertThat(resource.toString()).isEqualTo(url + "nested.jar!/3.dat");
|
||||
assertThat(resource.openConnection().getInputStream().read()).isEqualTo(3);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,13 +34,7 @@ import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.boot.loader.archive.Archive;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -78,31 +72,32 @@ public class PropertiesLauncherTests {
|
||||
@Test
|
||||
public void testDefaultHome() {
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals(new File(System.getProperty("loader.home")),
|
||||
launcher.getHomeDirectory());
|
||||
assertThat(launcher.getHomeDirectory())
|
||||
.isEqualTo(new File(System.getProperty("loader.home")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedMain() throws Exception {
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("demo.Application", launcher.getMainClass());
|
||||
assertNull(System.getProperty("loader.main"));
|
||||
assertThat(launcher.getMainClass()).isEqualTo("demo.Application");
|
||||
assertThat(System.getProperty("loader.main")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedConfigName() throws Exception {
|
||||
System.setProperty("loader.config.name", "foo");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("my.Application", launcher.getMainClass());
|
||||
assertEquals("[etc/]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
assertThat(launcher.getMainClass()).isEqualTo("my.Application");
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[etc/]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUserSpecifiedDotPath() throws Exception {
|
||||
System.setProperty("loader.path", ".");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[.]", ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[.]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -110,8 +105,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/*");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[jars/]");
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -121,8 +116,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[jars/app.jar]");
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -132,8 +127,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "./jars/app.jar");
|
||||
System.setProperty("loader.main", "demo.Application");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[jars/app.jar]");
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -143,8 +138,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "jars/app.jar");
|
||||
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[jars/app.jar]");
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -154,8 +149,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.path", "more-jars/app.jar,jars/app.jar");
|
||||
System.setProperty("loader.classLoader", URLClassLoader.class.getName());
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[more-jars/app.jar, jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
assertThat(ReflectionTestUtils.getField(launcher, "paths").toString())
|
||||
.isEqualTo("[more-jars/app.jar, jars/app.jar]");
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello Other World");
|
||||
}
|
||||
@@ -165,8 +160,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.classLoader", TestLoader.class.getName());
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
ClassLoader loader = launcher.createClassLoader(Collections.<Archive>emptyList());
|
||||
assertNotNull(loader);
|
||||
assertEquals(TestLoader.class.getName(), loader.getClass().getName());
|
||||
assertThat(loader).isNotNull();
|
||||
assertThat(loader.getClass().getName()).isEqualTo(TestLoader.class.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -175,28 +170,29 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.config.name", "foo");
|
||||
System.setProperty("loader.config.location", "classpath:bar.properties");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("my.BarApplication", launcher.getMainClass());
|
||||
assertThat(launcher.getMainClass()).isEqualTo("my.BarApplication");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemPropertySpecifiedMain() throws Exception {
|
||||
System.setProperty("loader.main", "foo.Bar");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("foo.Bar", launcher.getMainClass());
|
||||
assertThat(launcher.getMainClass()).isEqualTo("foo.Bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemPropertiesSet() throws Exception {
|
||||
System.setProperty("loader.system", "true");
|
||||
new PropertiesLauncher();
|
||||
assertEquals("demo.Application", System.getProperty("loader.main"));
|
||||
assertThat(System.getProperty("loader.main")).isEqualTo("demo.Application");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testArgsEnhanced() throws Exception {
|
||||
System.setProperty("loader.args", "foo");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("[foo, bar]", Arrays.asList(launcher.getArgs("bar")).toString());
|
||||
assertThat(Arrays.asList(launcher.getArgs("bar")).toString())
|
||||
.isEqualTo("[foo, bar]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -208,8 +204,7 @@ public class PropertiesLauncherTests {
|
||||
}
|
||||
List<Archive> nonAgentArchives = new PropertiesLauncher(this.javaAgentDetector)
|
||||
.getClassPathArchives();
|
||||
assertThat(nonAgentArchives.size(),
|
||||
is(equalTo(allArchives.size() - parentUrls.length)));
|
||||
assertThat(nonAgentArchives).hasSize(allArchives.size() - parentUrls.length);
|
||||
for (URL url : parentUrls) {
|
||||
verify(this.javaAgentDetector).isJavaAgentJar(url);
|
||||
}
|
||||
@@ -223,7 +218,7 @@ public class PropertiesLauncherTests {
|
||||
Thread.sleep(50L);
|
||||
timeout = this.output.toString().contains(value);
|
||||
}
|
||||
assertTrue("Timed out waiting for (" + value + ")", timeout);
|
||||
assertThat(timeout).as("Timed out waiting for (" + value + ")").isTrue();
|
||||
}
|
||||
|
||||
public static class TestLoader extends URLClassLoader {
|
||||
|
||||
@@ -38,9 +38,7 @@ import org.springframework.boot.loader.archive.ExplodedArchive;
|
||||
import org.springframework.boot.loader.archive.JarFileArchive;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link WarLauncher}
|
||||
@@ -61,28 +59,23 @@ public class WarLauncherTests {
|
||||
webInfLib.mkdirs();
|
||||
File webInfLibFoo = new File(webInfLib, "foo.jar");
|
||||
new JarOutputStream(new FileOutputStream(webInfLibFoo)).close();
|
||||
|
||||
WarLauncher launcher = new WarLauncher(new ExplodedArchive(warRoot, true));
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertEquals(2, archives.size());
|
||||
|
||||
assertThat(getUrls(archives), hasItems(webInfClasses.toURI().toURL(),
|
||||
new URL("jar:" + webInfLibFoo.toURI().toURL() + "!/")));
|
||||
assertThat(archives).hasSize(2);
|
||||
assertThat(getUrls(archives)).containsOnly(webInfClasses.toURI().toURL(),
|
||||
new URL("jar:" + webInfLibFoo.toURI().toURL() + "!/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void archivedWarHasOnlyWebInfClassesAndContentsOfWebInfLibOnClasspath()
|
||||
throws Exception {
|
||||
File warRoot = createWarArchive();
|
||||
|
||||
WarLauncher launcher = new WarLauncher(new JarFileArchive(warRoot));
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertEquals(2, archives.size());
|
||||
|
||||
assertThat(getUrls(archives),
|
||||
hasItems(new URL("jar:" + warRoot.toURI().toURL()
|
||||
+ "!/WEB-INF/classes!/"),
|
||||
new URL("jar:" + warRoot.toURI().toURL() + "!/WEB-INF/lib/foo.jar!/")));
|
||||
assertThat(archives).hasSize(2);
|
||||
assertThat(getUrls(archives)).containsOnly(
|
||||
new URL("jar:" + warRoot.toURI().toURL() + "!/WEB-INF/classes!/"),
|
||||
new URL("jar:" + warRoot.toURI().toURL() + "!/WEB-INF/lib/foo.jar!/"));
|
||||
}
|
||||
|
||||
private Set<URL> getUrls(List<Archive> archives) throws MalformedURLException {
|
||||
@@ -96,14 +89,11 @@ public class WarLauncherTests {
|
||||
private File createWarArchive() throws IOException, FileNotFoundException {
|
||||
File warRoot = new File("target/archive.war");
|
||||
warRoot.delete();
|
||||
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(
|
||||
new FileOutputStream(warRoot));
|
||||
|
||||
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/"));
|
||||
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/classes/"));
|
||||
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/lib/"));
|
||||
|
||||
JarEntry webInfLibFoo = new JarEntry("WEB-INF/lib/foo.jar");
|
||||
webInfLibFoo.setMethod(ZipEntry.STORED);
|
||||
ByteArrayOutputStream fooJarStream = new ByteArrayOutputStream();
|
||||
@@ -114,7 +104,6 @@ public class WarLauncherTests {
|
||||
webInfLibFoo.setCrc(crc32.getValue());
|
||||
jarOutputStream.putNextEntry(webInfLibFoo);
|
||||
jarOutputStream.write(fooJarStream.toByteArray());
|
||||
|
||||
jarOutputStream.close();
|
||||
return warRoot;
|
||||
}
|
||||
|
||||
@@ -38,10 +38,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.boot.loader.TestJarCreator;
|
||||
import org.springframework.boot.loader.archive.Archive.Entry;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ExplodedArchive}.
|
||||
@@ -93,29 +90,29 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getManifest() throws Exception {
|
||||
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By"),
|
||||
equalTo("j1"));
|
||||
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By"))
|
||||
.isEqualTo("j1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntries() throws Exception {
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(this.archive);
|
||||
assertThat(entries.size(), equalTo(10));
|
||||
assertThat(entries.size()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUrl() throws Exception {
|
||||
URL url = this.archive.getUrl();
|
||||
assertThat(new File(URLDecoder.decode(url.getFile(), "UTF-8")),
|
||||
equalTo(this.rootFolder));
|
||||
assertThat(new File(URLDecoder.decode(url.getFile(), "UTF-8")))
|
||||
.isEqualTo(this.rootFolder);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNestedArchive() throws Exception {
|
||||
Entry entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
assertThat(nested.getUrl().toString(),
|
||||
equalTo("jar:" + this.rootFolder.toURI() + "nested.jar!/"));
|
||||
assertThat(nested.getUrl().toString())
|
||||
.isEqualTo("jar:" + this.rootFolder.toURI() + "nested.jar!/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -123,43 +120,44 @@ public class ExplodedArchiveTests {
|
||||
Entry entry = getEntriesMap(this.archive).get("d/");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
Map<String, Entry> nestedEntries = getEntriesMap(nested);
|
||||
assertThat(nestedEntries.size(), equalTo(1));
|
||||
assertThat(nested.getUrl().toString(),
|
||||
equalTo("file:" + this.rootFolder.toURI().getPath() + "d/"));
|
||||
assertThat(nestedEntries.size()).isEqualTo(1);
|
||||
assertThat(nested.getUrl().toString())
|
||||
.isEqualTo("file:" + this.rootFolder.toURI().getPath() + "d/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveEntriesForRoot() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("/"), false);
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size(), greaterThan(1));
|
||||
assertThat(entries.size()).isGreaterThan(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveManifest() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"));
|
||||
assertNotNull(archive.getManifest());
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size(), equalTo(4));
|
||||
assertThat(entries.size()).isEqualTo(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveManifestEvenIfNonRecursive() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"),
|
||||
false);
|
||||
assertNotNull(archive.getManifest());
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size(), equalTo(3));
|
||||
assertThat(entries.size()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getResourceAsStream() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"));
|
||||
assertNotNull(archive.getManifest());
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml"));
|
||||
assertThat(loader.getResourceAsStream("META-INF/spring/application.xml"))
|
||||
.isNotNull();
|
||||
loader.close();
|
||||
}
|
||||
|
||||
@@ -167,9 +165,10 @@ public class ExplodedArchiveTests {
|
||||
public void getResourceAsStreamNonRecursive() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"),
|
||||
false);
|
||||
assertNotNull(archive.getManifest());
|
||||
assertThat(archive.getManifest()).isNotNull();
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml"));
|
||||
assertThat(loader.getResourceAsStream("META-INF/spring/application.xml"))
|
||||
.isNotNull();
|
||||
loader.close();
|
||||
}
|
||||
|
||||
@@ -180,4 +179,5 @@ public class ExplodedArchiveTests {
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,12 +29,7 @@ import org.junit.rules.TemporaryFolder;
|
||||
import org.springframework.boot.loader.TestJarCreator;
|
||||
import org.springframework.boot.loader.archive.Archive.Entry;
|
||||
|
||||
import static org.hamcrest.Matchers.endsWith;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link JarFileArchive}.
|
||||
@@ -67,28 +62,28 @@ public class JarFileArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getManifest() throws Exception {
|
||||
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By"),
|
||||
equalTo("j1"));
|
||||
assertThat(this.archive.getManifest().getMainAttributes().getValue("Built-By"))
|
||||
.isEqualTo("j1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntries() throws Exception {
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(this.archive);
|
||||
assertThat(entries.size(), equalTo(10));
|
||||
assertThat(entries.size()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUrl() throws Exception {
|
||||
URL url = this.archive.getUrl();
|
||||
assertThat(url.toString(), equalTo("jar:" + this.rootJarFileUrl + "!/"));
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFileUrl + "!/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getNestedArchive() throws Exception {
|
||||
Entry entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
assertThat(nested.getUrl().toString(),
|
||||
equalTo("jar:" + this.rootJarFileUrl + "!/nested.jar!/"));
|
||||
assertThat(nested.getUrl().toString())
|
||||
.isEqualTo("jar:" + this.rootJarFileUrl + "!/nested.jar!/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,8 +91,8 @@ public class JarFileArchiveTests {
|
||||
setup(true);
|
||||
Entry entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
Archive nested = this.archive.getNestedArchive(entry);
|
||||
assertThat(nested.getUrl().toString(), startsWith("file:"));
|
||||
assertThat(nested.getUrl().toString(), endsWith("/nested.jar"));
|
||||
assertThat(nested.getUrl().toString()).startsWith("file:");
|
||||
assertThat(nested.getUrl().toString()).endsWith("/nested.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,7 +103,7 @@ public class JarFileArchiveTests {
|
||||
setup(true);
|
||||
entry = getEntriesMap(this.archive).get("nested.jar");
|
||||
URL secondNested = this.archive.getNestedArchive(entry).getUrl();
|
||||
assertThat(secondNested, is(not(equalTo(firstNested))));
|
||||
assertThat(secondNested).isNotEqualTo(firstNested);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,7 +117,7 @@ public class JarFileArchiveTests {
|
||||
.getNestedArchive(
|
||||
getEntriesMap(this.archive).get("another-nested.jar"))
|
||||
.getUrl().toURI());
|
||||
assertThat(nested.getParent(), is(equalTo(anotherNested.getParent())));
|
||||
assertThat(nested.getParent()).isEqualTo(anotherNested.getParent());
|
||||
}
|
||||
|
||||
private Map<String, Archive.Entry> getEntriesMap(Archive archive) {
|
||||
@@ -132,4 +127,5 @@ public class JarFileArchiveTests {
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,13 +16,14 @@
|
||||
|
||||
package org.springframework.boot.loader.data;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.boot.loader.data.RandomAccessData.ResourceAccess;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link ByteArrayRandomAccessData}.
|
||||
@@ -35,9 +36,9 @@ public class ByteArrayRandomAccessDataTests {
|
||||
public void testGetInputStream() throws Exception {
|
||||
byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
|
||||
RandomAccessData data = new ByteArrayRandomAccessData(bytes);
|
||||
assertThat(FileCopyUtils.copyToByteArray(
|
||||
data.getInputStream(ResourceAccess.PER_READ)), equalTo(bytes));
|
||||
assertThat(data.getSize(), equalTo((long) bytes.length));
|
||||
InputStream inputStream = data.getInputStream(ResourceAccess.PER_READ);
|
||||
assertThat(FileCopyUtils.copyToByteArray(inputStream)).isEqualTo(bytes);
|
||||
assertThat(data.getSize()).isEqualTo(bytes.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -45,10 +46,10 @@ public class ByteArrayRandomAccessDataTests {
|
||||
byte[] bytes = new byte[] { 0, 1, 2, 3, 4, 5 };
|
||||
RandomAccessData data = new ByteArrayRandomAccessData(bytes);
|
||||
data = data.getSubsection(1, 4).getSubsection(1, 2);
|
||||
assertThat(
|
||||
FileCopyUtils
|
||||
.copyToByteArray(data.getInputStream(ResourceAccess.PER_READ)),
|
||||
equalTo(new byte[] { 2, 3 }));
|
||||
assertThat(data.getSize(), equalTo(2L));
|
||||
InputStream inputStream = data.getInputStream(ResourceAccess.PER_READ);
|
||||
assertThat(FileCopyUtils.copyToByteArray(inputStream))
|
||||
.isEqualTo(new byte[] { 2, 3 });
|
||||
assertThat(data.getSize()).isEqualTo(2L);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
@@ -37,11 +36,9 @@ import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import org.springframework.boot.loader.ByteArrayStartsWith;
|
||||
import org.springframework.boot.loader.data.RandomAccessData.ResourceAccess;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link RandomAccessDataFile}.
|
||||
@@ -118,7 +115,7 @@ public class RandomAccessDataFileTests {
|
||||
@Test
|
||||
public void inputStreamRead() throws Exception {
|
||||
for (int i = 0; i <= 255; i++) {
|
||||
assertThat(this.inputStream.read(), equalTo(i));
|
||||
assertThat(this.inputStream.read()).isEqualTo(i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,8 +137,8 @@ public class RandomAccessDataFileTests {
|
||||
public void inputStreamReadBytes() throws Exception {
|
||||
byte[] b = new byte[256];
|
||||
int amountRead = this.inputStream.read(b);
|
||||
assertThat(b, equalTo(BYTES));
|
||||
assertThat(amountRead, equalTo(256));
|
||||
assertThat(b).isEqualTo(BYTES);
|
||||
assertThat(amountRead).isEqualTo(256);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,54 +146,54 @@ public class RandomAccessDataFileTests {
|
||||
byte[] b = new byte[7];
|
||||
this.inputStream.skip(1);
|
||||
int amountRead = this.inputStream.read(b, 2, 3);
|
||||
assertThat(b, equalTo(new byte[] { 0, 0, 1, 2, 3, 0, 0 }));
|
||||
assertThat(amountRead, equalTo(3));
|
||||
assertThat(b).isEqualTo(new byte[] { 0, 0, 1, 2, 3, 0, 0 });
|
||||
assertThat(amountRead).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadMoreBytesThanAvailable() throws Exception {
|
||||
byte[] b = new byte[257];
|
||||
int amountRead = this.inputStream.read(b);
|
||||
assertThat(b, startsWith(BYTES));
|
||||
assertThat(amountRead, equalTo(256));
|
||||
assertThat(b).startsWith(BYTES);
|
||||
assertThat(amountRead).isEqualTo(256);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadPastEnd() throws Exception {
|
||||
this.inputStream.skip(255);
|
||||
assertThat(this.inputStream.read(), equalTo(0xFF));
|
||||
assertThat(this.inputStream.read(), equalTo(-1));
|
||||
assertThat(this.inputStream.read(), equalTo(-1));
|
||||
assertThat(this.inputStream.read()).isEqualTo(0xFF);
|
||||
assertThat(this.inputStream.read()).isEqualTo(-1);
|
||||
assertThat(this.inputStream.read()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadZeroLength() throws Exception {
|
||||
byte[] b = new byte[] { 0x0F };
|
||||
int amountRead = this.inputStream.read(b, 0, 0);
|
||||
assertThat(b, equalTo(new byte[] { 0x0F }));
|
||||
assertThat(amountRead, equalTo(0));
|
||||
assertThat(this.inputStream.read(), equalTo(0));
|
||||
assertThat(b).isEqualTo(new byte[] { 0x0F });
|
||||
assertThat(amountRead).isEqualTo(0);
|
||||
assertThat(this.inputStream.read()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamSkip() throws Exception {
|
||||
long amountSkipped = this.inputStream.skip(4);
|
||||
assertThat(this.inputStream.read(), equalTo(4));
|
||||
assertThat(amountSkipped, equalTo(4L));
|
||||
assertThat(this.inputStream.read()).isEqualTo(4);
|
||||
assertThat(amountSkipped).isEqualTo(4L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamSkipMoreThanAvailable() throws Exception {
|
||||
long amountSkipped = this.inputStream.skip(257);
|
||||
assertThat(this.inputStream.read(), equalTo(-1));
|
||||
assertThat(amountSkipped, equalTo(256L));
|
||||
assertThat(this.inputStream.read()).isEqualTo(-1);
|
||||
assertThat(amountSkipped).isEqualTo(256L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamSkipPastEnd() throws Exception {
|
||||
this.inputStream.skip(256);
|
||||
long amountSkipped = this.inputStream.skip(1);
|
||||
assertThat(amountSkipped, equalTo(0L));
|
||||
assertThat(amountSkipped).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,8 +211,8 @@ public class RandomAccessDataFileTests {
|
||||
@Test
|
||||
public void subsectionZeroLength() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(0, 0);
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read(),
|
||||
equalTo(-1));
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read())
|
||||
.isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -235,16 +232,17 @@ public class RandomAccessDataFileTests {
|
||||
@Test
|
||||
public void subsection() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(1, 1);
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read(), equalTo(1));
|
||||
assertThat(subsection.getInputStream(ResourceAccess.PER_READ).read())
|
||||
.isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamReadPastSubsection() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(1, 2);
|
||||
InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
|
||||
assertThat(inputStream.read(), equalTo(1));
|
||||
assertThat(inputStream.read(), equalTo(2));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
assertThat(inputStream.read()).isEqualTo(1);
|
||||
assertThat(inputStream.read()).isEqualTo(2);
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -253,26 +251,26 @@ public class RandomAccessDataFileTests {
|
||||
InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
|
||||
byte[] b = new byte[3];
|
||||
int amountRead = inputStream.read(b);
|
||||
assertThat(b, equalTo(new byte[] { 1, 2, 0 }));
|
||||
assertThat(amountRead, equalTo(2));
|
||||
assertThat(b).isEqualTo(new byte[] { 1, 2, 0 });
|
||||
assertThat(amountRead).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamSkipPastSubsection() throws Exception {
|
||||
RandomAccessData subsection = this.file.getSubsection(1, 2);
|
||||
InputStream inputStream = subsection.getInputStream(ResourceAccess.PER_READ);
|
||||
assertThat(inputStream.skip(3), equalTo(2L));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
assertThat(inputStream.skip(3)).isEqualTo(2L);
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void inputStreamSkipNegative() throws Exception {
|
||||
assertThat(this.inputStream.skip(-1), equalTo(0L));
|
||||
assertThat(this.inputStream.skip(-1)).isEqualTo(0L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getFile() throws Exception {
|
||||
assertThat(this.file.getFile(), equalTo(this.tempFile));
|
||||
assertThat(this.file.getFile()).isEqualTo(this.tempFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -294,7 +292,7 @@ public class RandomAccessDataFileTests {
|
||||
}));
|
||||
}
|
||||
for (Future<Boolean> future : results) {
|
||||
assertThat(future.get(), equalTo(true));
|
||||
assertThat(future.get()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,11 +306,7 @@ public class RandomAccessDataFileTests {
|
||||
Field filesField = filePool.getClass().getDeclaredField("files");
|
||||
filesField.setAccessible(true);
|
||||
Queue<?> queue = (Queue<?>) filesField.get(filePool);
|
||||
assertThat(queue.size(), equalTo(0));
|
||||
}
|
||||
|
||||
private static Matcher<? super byte[]> startsWith(byte[] bytes) {
|
||||
return new ByteArrayStartsWith(bytes);
|
||||
assertThat(queue.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -20,9 +20,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link AsciiBytes}.
|
||||
@@ -37,27 +35,27 @@ public class AsciiBytesTests {
|
||||
@Test
|
||||
public void createFromBytes() throws Exception {
|
||||
AsciiBytes bytes = new AsciiBytes(new byte[] { 65, 66 });
|
||||
assertThat(bytes.toString(), equalTo("AB"));
|
||||
assertThat(bytes.toString()).isEqualTo("AB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFromBytesWithOffset() throws Exception {
|
||||
AsciiBytes bytes = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2);
|
||||
assertThat(bytes.toString(), equalTo("BC"));
|
||||
assertThat(bytes.toString()).isEqualTo("BC");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createFromString() throws Exception {
|
||||
AsciiBytes bytes = new AsciiBytes("AB");
|
||||
assertThat(bytes.toString(), equalTo("AB"));
|
||||
assertThat(bytes.toString()).isEqualTo("AB");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void length() throws Exception {
|
||||
AsciiBytes b1 = new AsciiBytes(new byte[] { 65, 66 });
|
||||
AsciiBytes b2 = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2);
|
||||
assertThat(b1.length(), equalTo(2));
|
||||
assertThat(b2.length(), equalTo(2));
|
||||
assertThat(b1.length()).isEqualTo(2);
|
||||
assertThat(b2.length()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,10 +64,10 @@ public class AsciiBytesTests {
|
||||
AsciiBytes ab = new AsciiBytes(new byte[] { 65, 66 });
|
||||
AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67 }, 1, 2);
|
||||
AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 });
|
||||
assertThat(abc.startsWith(abc), equalTo(true));
|
||||
assertThat(abc.startsWith(ab), equalTo(true));
|
||||
assertThat(abc.startsWith(bc), equalTo(false));
|
||||
assertThat(abc.startsWith(abcd), equalTo(false));
|
||||
assertThat(abc.startsWith(abc)).isTrue();
|
||||
assertThat(abc.startsWith(ab)).isTrue();
|
||||
assertThat(abc.startsWith(bc)).isFalse();
|
||||
assertThat(abc.startsWith(abcd)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,20 +76,20 @@ public class AsciiBytesTests {
|
||||
AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67 }, 1, 2);
|
||||
AsciiBytes ab = new AsciiBytes(new byte[] { 65, 66 });
|
||||
AsciiBytes aabc = new AsciiBytes(new byte[] { 65, 65, 66, 67 });
|
||||
assertThat(abc.endsWith(abc), equalTo(true));
|
||||
assertThat(abc.endsWith(bc), equalTo(true));
|
||||
assertThat(abc.endsWith(ab), equalTo(false));
|
||||
assertThat(abc.endsWith(aabc), equalTo(false));
|
||||
assertThat(abc.endsWith(abc)).isTrue();
|
||||
assertThat(abc.endsWith(bc)).isTrue();
|
||||
assertThat(abc.endsWith(ab)).isFalse();
|
||||
assertThat(abc.endsWith(aabc)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void substringFromBeingIndex() throws Exception {
|
||||
AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 });
|
||||
assertThat(abcd.substring(0).toString(), equalTo("ABCD"));
|
||||
assertThat(abcd.substring(1).toString(), equalTo("BCD"));
|
||||
assertThat(abcd.substring(2).toString(), equalTo("CD"));
|
||||
assertThat(abcd.substring(3).toString(), equalTo("D"));
|
||||
assertThat(abcd.substring(4).toString(), equalTo(""));
|
||||
assertThat(abcd.substring(0).toString()).isEqualTo("ABCD");
|
||||
assertThat(abcd.substring(1).toString()).isEqualTo("BCD");
|
||||
assertThat(abcd.substring(2).toString()).isEqualTo("CD");
|
||||
assertThat(abcd.substring(3).toString()).isEqualTo("D");
|
||||
assertThat(abcd.substring(4).toString()).isEqualTo("");
|
||||
this.thrown.expect(IndexOutOfBoundsException.class);
|
||||
abcd.substring(5);
|
||||
}
|
||||
@@ -99,10 +97,10 @@ public class AsciiBytesTests {
|
||||
@Test
|
||||
public void substring() throws Exception {
|
||||
AsciiBytes abcd = new AsciiBytes(new byte[] { 65, 66, 67, 68 });
|
||||
assertThat(abcd.substring(0, 4).toString(), equalTo("ABCD"));
|
||||
assertThat(abcd.substring(1, 3).toString(), equalTo("BC"));
|
||||
assertThat(abcd.substring(3, 4).toString(), equalTo("D"));
|
||||
assertThat(abcd.substring(3, 3).toString(), equalTo(""));
|
||||
assertThat(abcd.substring(0, 4).toString()).isEqualTo("ABCD");
|
||||
assertThat(abcd.substring(1, 3).toString()).isEqualTo("BC");
|
||||
assertThat(abcd.substring(3, 4).toString()).isEqualTo("D");
|
||||
assertThat(abcd.substring(3, 3).toString()).isEqualTo("");
|
||||
this.thrown.expect(IndexOutOfBoundsException.class);
|
||||
abcd.substring(3, 5);
|
||||
}
|
||||
@@ -111,16 +109,16 @@ public class AsciiBytesTests {
|
||||
public void appendString() throws Exception {
|
||||
AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2);
|
||||
AsciiBytes appended = bc.append("D");
|
||||
assertThat(bc.toString(), equalTo("BC"));
|
||||
assertThat(appended.toString(), equalTo("BCD"));
|
||||
assertThat(bc.toString()).isEqualTo("BC");
|
||||
assertThat(appended.toString()).isEqualTo("BCD");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void appendBytes() throws Exception {
|
||||
AsciiBytes bc = new AsciiBytes(new byte[] { 65, 66, 67, 68 }, 1, 2);
|
||||
AsciiBytes appended = bc.append(new byte[] { 68 });
|
||||
assertThat(bc.toString(), equalTo("BC"));
|
||||
assertThat(appended.toString(), equalTo("BCD"));
|
||||
assertThat(bc.toString()).isEqualTo("BC");
|
||||
assertThat(appended.toString()).isEqualTo("BCD");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,28 +128,28 @@ public class AsciiBytesTests {
|
||||
AsciiBytes bc_substring = new AsciiBytes(new byte[] { 65, 66, 67, 68 })
|
||||
.substring(1, 3);
|
||||
AsciiBytes bc_string = new AsciiBytes("BC");
|
||||
assertThat(bc.hashCode(), equalTo(bc.hashCode()));
|
||||
assertThat(bc.hashCode(), equalTo(bc_substring.hashCode()));
|
||||
assertThat(bc.hashCode(), equalTo(bc_string.hashCode()));
|
||||
assertThat(bc, equalTo(bc));
|
||||
assertThat(bc, equalTo(bc_substring));
|
||||
assertThat(bc, equalTo(bc_string));
|
||||
assertThat(bc.hashCode(), not(equalTo(abcd.hashCode())));
|
||||
assertThat(bc, not(equalTo(abcd)));
|
||||
assertThat(bc.hashCode()).isEqualTo(bc.hashCode());
|
||||
assertThat(bc.hashCode()).isEqualTo(bc_substring.hashCode());
|
||||
assertThat(bc.hashCode()).isEqualTo(bc_string.hashCode());
|
||||
assertThat(bc).isEqualTo(bc);
|
||||
assertThat(bc).isEqualTo(bc_substring);
|
||||
assertThat(bc).isEqualTo(bc_string);
|
||||
assertThat(bc.hashCode()).isNotEqualTo(abcd.hashCode());
|
||||
assertThat(bc).isNotEqualTo(abcd);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeSameAsString() throws Exception {
|
||||
String s = "abcABC123xyz!";
|
||||
AsciiBytes a = new AsciiBytes(s);
|
||||
assertThat(s.hashCode(), equalTo(a.hashCode()));
|
||||
assertThat(s.hashCode()).isEqualTo(a.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCodeSameAsStringWithSpecial() throws Exception {
|
||||
String s = "special/\u00EB.dat";
|
||||
AsciiBytes a = new AsciiBytes(s);
|
||||
assertThat(s.hashCode(), equalTo(a.hashCode()));
|
||||
assertThat(s.hashCode()).isEqualTo(a.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -31,8 +31,7 @@ import org.springframework.boot.loader.TestJarCreator;
|
||||
import org.springframework.boot.loader.data.RandomAccessData;
|
||||
import org.springframework.boot.loader.data.RandomAccessDataFile;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
@@ -62,7 +61,7 @@ public class CentralDirectoryParserTests {
|
||||
|
||||
@Test
|
||||
public void visitsInOrder() throws Exception {
|
||||
CentralDirectoryVisitor visitor = mock(CentralDirectoryVisitor.class);
|
||||
CentralDirectoryVisitor visitor = mock(TestCentralDirectoryVisitor.class);
|
||||
CentralDirectoryParser parser = new CentralDirectoryParser();
|
||||
parser.addVisitor(visitor);
|
||||
parser.parse(this.jarData, false);
|
||||
@@ -81,17 +80,17 @@ public class CentralDirectoryParserTests {
|
||||
parser.addVisitor(collector);
|
||||
parser.parse(this.jarData, false);
|
||||
Iterator<CentralDirectoryFileHeader> headers = collector.getHeaders().iterator();
|
||||
assertThat(headers.next().getName().toString(), equalTo("META-INF/"));
|
||||
assertThat(headers.next().getName().toString(), equalTo("META-INF/MANIFEST.MF"));
|
||||
assertThat(headers.next().getName().toString(), equalTo("1.dat"));
|
||||
assertThat(headers.next().getName().toString(), equalTo("2.dat"));
|
||||
assertThat(headers.next().getName().toString(), equalTo("d/"));
|
||||
assertThat(headers.next().getName().toString(), equalTo("d/9.dat"));
|
||||
assertThat(headers.next().getName().toString(), equalTo("special/"));
|
||||
assertThat(headers.next().getName().toString(), equalTo("special/\u00EB.dat"));
|
||||
assertThat(headers.next().getName().toString(), equalTo("nested.jar"));
|
||||
assertThat(headers.next().getName().toString(), equalTo("another-nested.jar"));
|
||||
assertThat(headers.hasNext(), equalTo(false));
|
||||
assertThat(headers.next().getName().toString()).isEqualTo("META-INF/");
|
||||
assertThat(headers.next().getName().toString()).isEqualTo("META-INF/MANIFEST.MF");
|
||||
assertThat(headers.next().getName().toString()).isEqualTo("1.dat");
|
||||
assertThat(headers.next().getName().toString()).isEqualTo("2.dat");
|
||||
assertThat(headers.next().getName().toString()).isEqualTo("d/");
|
||||
assertThat(headers.next().getName().toString()).isEqualTo("d/9.dat");
|
||||
assertThat(headers.next().getName().toString()).isEqualTo("special/");
|
||||
assertThat(headers.next().getName().toString()).isEqualTo("special/\u00EB.dat");
|
||||
assertThat(headers.next().getName().toString()).isEqualTo("nested.jar");
|
||||
assertThat(headers.next().getName().toString()).isEqualTo("another-nested.jar");
|
||||
assertThat(headers.hasNext()).isFalse();
|
||||
}
|
||||
|
||||
private static class Collector implements CentralDirectoryVisitor {
|
||||
@@ -119,4 +118,8 @@ public class CentralDirectoryParserTests {
|
||||
|
||||
}
|
||||
|
||||
public interface TestCentralDirectoryVisitor extends CentralDirectoryVisitor {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -41,14 +41,7 @@ import org.springframework.boot.loader.data.RandomAccessDataFile;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -82,21 +75,21 @@ public class JarFileTests {
|
||||
// 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();
|
||||
assertThat(entries.nextElement().getName(), equalTo("META-INF/"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("META-INF/MANIFEST.MF"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("1.dat"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("2.dat"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("d/"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("d/9.dat"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("special/"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("special/\u00EB.dat"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("nested.jar"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("another-nested.jar"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/MANIFEST.MF");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("1.dat");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("2.dat");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("d/");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("d/9.dat");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("special/");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("special/\u00EB.dat");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("nested.jar");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("another-nested.jar");
|
||||
assertThat(entries.hasMoreElements()).isFalse();
|
||||
URL jarUrl = new URL("jar:" + this.rootJarFile.toURI() + "!/");
|
||||
URLClassLoader urlClassLoader = new URLClassLoader(new URL[] { jarUrl });
|
||||
assertThat(urlClassLoader.getResource("special/\u00EB.dat"), notNullValue());
|
||||
assertThat(urlClassLoader.getResource("d/9.dat"), notNullValue());
|
||||
assertThat(urlClassLoader.getResource("special/\u00EB.dat")).isNotNull();
|
||||
assertThat(urlClassLoader.getResource("d/9.dat")).isNotNull();
|
||||
jarFile.close();
|
||||
urlClassLoader.close();
|
||||
}
|
||||
@@ -104,79 +97,79 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void createFromFile() throws Exception {
|
||||
JarFile jarFile = new JarFile(this.rootJarFile);
|
||||
assertThat(jarFile.getName(), notNullValue(String.class));
|
||||
assertThat(jarFile.getName()).isNotNull();
|
||||
jarFile.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getManifest() throws Exception {
|
||||
assertThat(this.jarFile.getManifest().getMainAttributes().getValue("Built-By"),
|
||||
equalTo("j1"));
|
||||
assertThat(this.jarFile.getManifest().getMainAttributes().getValue("Built-By"))
|
||||
.isEqualTo("j1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public 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"), equalTo("j1"));
|
||||
assertThat(manifest.getMainAttributes().getValue("Built-By")).isEqualTo("j1");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getEntries() throws Exception {
|
||||
Enumeration<java.util.jar.JarEntry> entries = this.jarFile.entries();
|
||||
assertThat(entries.nextElement().getName(), equalTo("META-INF/"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("META-INF/MANIFEST.MF"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("1.dat"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("2.dat"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("d/"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("d/9.dat"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("special/"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("special/\u00EB.dat"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("nested.jar"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("another-nested.jar"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/MANIFEST.MF");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("1.dat");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("2.dat");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("d/");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("d/9.dat");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("special/");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("special/\u00EB.dat");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("nested.jar");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("another-nested.jar");
|
||||
assertThat(entries.hasMoreElements()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSpecialResourceViaClassLoader() throws Exception {
|
||||
URLClassLoader urlClassLoader = new URLClassLoader(
|
||||
new URL[] { this.jarFile.getUrl() });
|
||||
assertThat(urlClassLoader.getResource("special/\u00EB.dat"), notNullValue());
|
||||
assertThat(urlClassLoader.getResource("special/\u00EB.dat")).isNotNull();
|
||||
urlClassLoader.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getJarEntry() throws Exception {
|
||||
java.util.jar.JarEntry entry = this.jarFile.getJarEntry("1.dat");
|
||||
assertThat(entry, notNullValue(ZipEntry.class));
|
||||
assertThat(entry.getName(), equalTo("1.dat"));
|
||||
assertThat(entry).isNotNull();
|
||||
assertThat(entry.getName()).isEqualTo("1.dat");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getInputStream() throws Exception {
|
||||
InputStream inputStream = this.jarFile
|
||||
.getInputStream(this.jarFile.getEntry("1.dat"));
|
||||
assertThat(inputStream.available(), equalTo(1));
|
||||
assertThat(inputStream.read(), equalTo(1));
|
||||
assertThat(inputStream.available(), equalTo(0));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
assertThat(inputStream.available()).isEqualTo(1);
|
||||
assertThat(inputStream.read()).isEqualTo(1);
|
||||
assertThat(inputStream.available()).isEqualTo(0);
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getName() throws Exception {
|
||||
assertThat(this.jarFile.getName(), equalTo(this.rootJarFile.getPath()));
|
||||
assertThat(this.jarFile.getName()).isEqualTo(this.rootJarFile.getPath());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getSize() throws Exception {
|
||||
assertThat(this.jarFile.size(), equalTo((int) this.rootJarFile.length()));
|
||||
assertThat(this.jarFile.size()).isEqualTo((int) this.rootJarFile.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
public 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(),
|
||||
equalTo(jdkJarFile.getEntry("META-INF/MANIFEST.MF").getTime()));
|
||||
assertThat(this.jarFile.getEntry("META-INF/MANIFEST.MF").getTime())
|
||||
.isEqualTo(jdkJarFile.getEntry("META-INF/MANIFEST.MF").getTime());
|
||||
jdkJarFile.close();
|
||||
}
|
||||
|
||||
@@ -192,36 +185,36 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void getUrl() throws Exception {
|
||||
URL url = this.jarFile.getUrl();
|
||||
assertThat(url.toString(), equalTo("jar:" + this.rootJarFile.toURI() + "!/"));
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/");
|
||||
JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
|
||||
assertThat(jarURLConnection.getJarFile(), sameInstance(this.jarFile));
|
||||
assertThat(jarURLConnection.getJarEntry(), nullValue());
|
||||
assertThat(jarURLConnection.getContentLength(), greaterThan(1));
|
||||
assertThat(jarURLConnection.getContent(), sameInstance((Object) this.jarFile));
|
||||
assertThat(jarURLConnection.getContentType(), equalTo("x-java/jar"));
|
||||
assertThat(jarURLConnection.getJarFileURL().toURI(),
|
||||
equalTo(this.rootJarFile.toURI()));
|
||||
assertThat(jarURLConnection.getJarFile()).isSameAs(this.jarFile);
|
||||
assertThat(jarURLConnection.getJarEntry()).isNull();
|
||||
assertThat(jarURLConnection.getContentLength()).isGreaterThan(1);
|
||||
assertThat(jarURLConnection.getContent()).isSameAs(this.jarFile);
|
||||
assertThat(jarURLConnection.getContentType()).isEqualTo("x-java/jar");
|
||||
assertThat(jarURLConnection.getJarFileURL().toURI())
|
||||
.isEqualTo(this.rootJarFile.toURI());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createEntryUrl() throws Exception {
|
||||
URL url = new URL(this.jarFile.getUrl(), "1.dat");
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/1.dat"));
|
||||
assertThat(url.toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/1.dat");
|
||||
JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
|
||||
assertThat(jarURLConnection.getJarFile(), sameInstance(this.jarFile));
|
||||
assertThat(jarURLConnection.getJarEntry(),
|
||||
sameInstance(this.jarFile.getJarEntry("1.dat")));
|
||||
assertThat(jarURLConnection.getContentLength(), equalTo(1));
|
||||
assertThat(jarURLConnection.getContent(), instanceOf(InputStream.class));
|
||||
assertThat(jarURLConnection.getContentType(), equalTo("content/unknown"));
|
||||
assertThat(jarURLConnection.getJarFile()).isSameAs(this.jarFile);
|
||||
assertThat(jarURLConnection.getJarEntry())
|
||||
.isSameAs(this.jarFile.getJarEntry("1.dat"));
|
||||
assertThat(jarURLConnection.getContentLength()).isEqualTo(1);
|
||||
assertThat(jarURLConnection.getContent()).isInstanceOf(InputStream.class);
|
||||
assertThat(jarURLConnection.getContentType()).isEqualTo("content/unknown");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getMissingEntryUrl() throws Exception {
|
||||
URL url = new URL(this.jarFile.getUrl(), "missing.dat");
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/missing.dat"));
|
||||
assertThat(url.toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/missing.dat");
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
((JarURLConnection) url.openConnection()).getJarEntry();
|
||||
}
|
||||
@@ -239,8 +232,8 @@ public class JarFileTests {
|
||||
URL url = new URL(this.jarFile.getUrl(), "1.dat");
|
||||
url.openConnection();
|
||||
InputStream stream = url.openStream();
|
||||
assertThat(stream.read(), equalTo(1));
|
||||
assertThat(stream.read(), equalTo(-1));
|
||||
assertThat(stream.read()).isEqualTo(1);
|
||||
assertThat(stream.read()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -249,25 +242,25 @@ public class JarFileTests {
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
|
||||
Enumeration<java.util.jar.JarEntry> entries = nestedJarFile.entries();
|
||||
assertThat(entries.nextElement().getName(), equalTo("META-INF/"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("META-INF/MANIFEST.MF"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("3.dat"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("4.dat"));
|
||||
assertThat(entries.nextElement().getName(), equalTo("\u00E4.dat"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("META-INF/MANIFEST.MF");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("3.dat");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("4.dat");
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("\u00E4.dat");
|
||||
assertThat(entries.hasMoreElements()).isFalse();
|
||||
|
||||
InputStream inputStream = nestedJarFile
|
||||
.getInputStream(nestedJarFile.getEntry("3.dat"));
|
||||
assertThat(inputStream.read(), equalTo(3));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
assertThat(inputStream.read()).isEqualTo(3);
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
|
||||
URL url = nestedJarFile.getUrl();
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/"));
|
||||
assertThat(url.toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/");
|
||||
JarURLConnection conn = (JarURLConnection) url.openConnection();
|
||||
assertThat(conn.getJarFile(), sameInstance(nestedJarFile));
|
||||
assertThat(conn.getJarFileURL().toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar"));
|
||||
assertThat(conn.getJarFile()).isSameAs(nestedJarFile);
|
||||
assertThat(conn.getJarFileURL().toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -276,18 +269,18 @@ public class JarFileTests {
|
||||
.getNestedJarFile(this.jarFile.getEntry("d/"));
|
||||
|
||||
Enumeration<java.util.jar.JarEntry> entries = nestedJarFile.entries();
|
||||
assertThat(entries.nextElement().getName(), equalTo("9.dat"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
assertThat(entries.nextElement().getName()).isEqualTo("9.dat");
|
||||
assertThat(entries.hasMoreElements()).isFalse();
|
||||
|
||||
InputStream inputStream = nestedJarFile
|
||||
.getInputStream(nestedJarFile.getEntry("9.dat"));
|
||||
assertThat(inputStream.read(), equalTo(9));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
assertThat(inputStream.read()).isEqualTo(9);
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
|
||||
URL url = nestedJarFile.getUrl();
|
||||
assertThat(url.toString(), equalTo("jar:" + this.rootJarFile.toURI() + "!/d!/"));
|
||||
assertThat(((JarURLConnection) url.openConnection()).getJarFile(),
|
||||
sameInstance(nestedJarFile));
|
||||
assertThat(url.toString()).isEqualTo("jar:" + this.rootJarFile.toURI() + "!/d!/");
|
||||
assertThat(((JarURLConnection) url.openConnection()).getJarFile())
|
||||
.isSameAs(nestedJarFile);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -295,11 +288,11 @@ public class JarFileTests {
|
||||
JarFile nestedJarFile = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
URL url = nestedJarFile.getJarEntry("3.dat").getUrl();
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat"));
|
||||
assertThat(url.toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat");
|
||||
InputStream inputStream = url.openStream();
|
||||
assertThat(inputStream, notNullValue());
|
||||
assertThat(inputStream.read(), equalTo(3));
|
||||
assertThat(inputStream).isNotNull();
|
||||
assertThat(inputStream.read()).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -307,15 +300,15 @@ public class JarFileTests {
|
||||
JarFile.registerUrlProtocolHandler();
|
||||
String spec = "jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat";
|
||||
URL url = new URL(spec);
|
||||
assertThat(url.toString(), equalTo(spec));
|
||||
assertThat(url.toString()).isEqualTo(spec);
|
||||
InputStream inputStream = url.openStream();
|
||||
assertThat(inputStream, notNullValue());
|
||||
assertThat(inputStream.read(), equalTo(3));
|
||||
assertThat(inputStream).isNotNull();
|
||||
assertThat(inputStream.read()).isEqualTo(3);
|
||||
JarURLConnection connection = (JarURLConnection) url.openConnection();
|
||||
assertThat(connection.getURL().toString(), equalTo(spec));
|
||||
assertThat(connection.getJarFileURL().toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar"));
|
||||
assertThat(connection.getEntryName(), equalTo("3.dat"));
|
||||
assertThat(connection.getURL().toString()).isEqualTo(spec);
|
||||
assertThat(connection.getJarFileURL().toString())
|
||||
.isEqualTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar");
|
||||
assertThat(connection.getEntryName()).isEqualTo("3.dat");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -323,38 +316,37 @@ public class JarFileTests {
|
||||
JarFile.registerUrlProtocolHandler();
|
||||
String spec = "jar:" + this.rootJarFile.toURI() + "!/2.dat";
|
||||
URL url = new URL(spec);
|
||||
assertThat(url.toString(), equalTo(spec));
|
||||
assertThat(url.toString()).isEqualTo(spec);
|
||||
InputStream inputStream = url.openStream();
|
||||
assertThat(inputStream, notNullValue());
|
||||
assertThat(inputStream.read(), equalTo(2));
|
||||
assertThat(inputStream).isNotNull();
|
||||
assertThat(inputStream.read()).isEqualTo(2);
|
||||
JarURLConnection connection = (JarURLConnection) url.openConnection();
|
||||
assertThat(connection.getURL().toString(), equalTo(spec));
|
||||
assertThat(connection.getJarFileURL().toURI(), equalTo(this.rootJarFile.toURI()));
|
||||
assertThat(connection.getEntryName(), equalTo("2.dat"));
|
||||
assertThat(connection.getURL().toString()).isEqualTo(spec);
|
||||
assertThat(connection.getJarFileURL().toURI())
|
||||
.isEqualTo(this.rootJarFile.toURI());
|
||||
assertThat(connection.getEntryName()).isEqualTo("2.dat");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDirectoryInputStream() throws Exception {
|
||||
InputStream inputStream = this.jarFile
|
||||
.getInputStream(this.jarFile.getEntry("d/"));
|
||||
assertThat(inputStream, notNullValue());
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
assertThat(inputStream).isNotNull();
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDirectoryInputStreamWithoutSlash() throws Exception {
|
||||
InputStream inputStream = this.jarFile.getInputStream(this.jarFile.getEntry("d"));
|
||||
assertThat(inputStream, notNullValue());
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
assertThat(inputStream).isNotNull();
|
||||
assertThat(inputStream.read()).isEqualTo(-1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sensibleToString() throws Exception {
|
||||
assertThat(this.jarFile.toString(), equalTo(this.rootJarFile.getPath()));
|
||||
assertThat(
|
||||
this.jarFile.getNestedJarFile(this.jarFile.getEntry("nested.jar"))
|
||||
.toString(),
|
||||
equalTo(this.rootJarFile.getPath() + "!/nested.jar"));
|
||||
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
|
||||
@@ -367,7 +359,7 @@ public class JarFileTests {
|
||||
signedJarFile = entry;
|
||||
}
|
||||
}
|
||||
assertNotNull(signedJarFile);
|
||||
assertThat(signedJarFile).isNotNull();
|
||||
java.util.jar.JarFile jarFile = new JarFile(new File(signedJarFile));
|
||||
jarFile.getManifest();
|
||||
Enumeration<JarEntry> jarEntries = jarFile.entries();
|
||||
@@ -378,8 +370,7 @@ public class JarFileTests {
|
||||
inputStream.close();
|
||||
if (!jarEntry.getName().startsWith("META-INF") && !jarEntry.isDirectory()
|
||||
&& !jarEntry.getName().endsWith("TigerDigest.class")) {
|
||||
assertNotNull("Missing cert " + jarEntry.getName(),
|
||||
jarEntry.getCertificates());
|
||||
assertThat(jarEntry.getCertificates()).isNotNull();
|
||||
}
|
||||
}
|
||||
jarFile.close();
|
||||
|
||||
@@ -20,9 +20,11 @@ import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link SystemPropertyUtils}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
*/
|
||||
public class SystemPropertyUtilsTests {
|
||||
@@ -39,23 +41,25 @@ public class SystemPropertyUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testVanillaPlaceholder() {
|
||||
assertEquals("bar", SystemPropertyUtils.resolvePlaceholders("${foo}"));
|
||||
assertThat(SystemPropertyUtils.resolvePlaceholders("${foo}")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultValue() {
|
||||
assertEquals("foo", SystemPropertyUtils.resolvePlaceholders("${bar:foo}"));
|
||||
assertThat(SystemPropertyUtils.resolvePlaceholders("${bar:foo}"))
|
||||
.isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNestedPlaceholder() {
|
||||
assertEquals("foo",
|
||||
SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}"));
|
||||
assertThat(SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}"))
|
||||
.isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnvVar() {
|
||||
assertEquals(System.getenv("LANG"), SystemPropertyUtils.getProperty("lang"));
|
||||
assertThat(SystemPropertyUtils.getProperty("lang"))
|
||||
.isEqualTo(System.getenv("LANG"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user