Merge branch '1.2.x'
This commit is contained in:
@@ -34,38 +34,39 @@ import static org.junit.Assert.assertTrue;
|
||||
public class InputArgumentsJavaAgentDetectorTests {
|
||||
|
||||
@Test
|
||||
public void nonAgentJarsDoNotProduceFalsePositives() throws MalformedURLException,
|
||||
IOException {
|
||||
public void nonAgentJarsDoNotProduceFalsePositives()
|
||||
throws MalformedURLException, IOException {
|
||||
InputArgumentsJavaAgentDetector detector = new InputArgumentsJavaAgentDetector(
|
||||
Arrays.asList("-javaagent:my-agent.jar"));
|
||||
assertFalse(detector.isJavaAgentJar(new File("something-else.jar")
|
||||
.getCanonicalFile().toURI().toURL()));
|
||||
assertFalse(detector.isJavaAgentJar(
|
||||
new File("something-else.jar").getCanonicalFile().toURI().toURL()));
|
||||
}
|
||||
|
||||
@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()));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
}
|
||||
|
||||
@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()));
|
||||
assertTrue(detector.isJavaAgentJar(
|
||||
new File("my-agent.jar").getCanonicalFile().toURI().toURL()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleJavaAgents() throws MalformedURLException, IOException {
|
||||
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()));
|
||||
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()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,44 +46,44 @@ 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"));
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
assertNull(getClass().getClassLoader()
|
||||
.getResource("c:\\Users\\user\\bar.properties"));
|
||||
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"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourceFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertNotNull(loader.getResource("demo/Application.java"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveResourcesFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRootPathFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertNotNull(loader.getResource(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolveRootResourcesFromArchive() throws Exception {
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(new URL[] { new URL(
|
||||
"jar:file:src/test/resources/jars/app.jar!/") }, getClass()
|
||||
.getClassLoader());
|
||||
LaunchedURLClassLoader loader = new LaunchedURLClassLoader(
|
||||
new URL[] { new URL("jar:file:src/test/resources/jars/app.jar!/") },
|
||||
getClass().getClassLoader());
|
||||
assertTrue(loader.getResources("").hasMoreElements());
|
||||
}
|
||||
|
||||
|
||||
@@ -80,7 +80,8 @@ public class PropertiesLauncherTests {
|
||||
System.setProperty("loader.config.name", "foo");
|
||||
PropertiesLauncher launcher = new PropertiesLauncher();
|
||||
assertEquals("my.Application", launcher.getMainClass());
|
||||
assertEquals("[etc/]", ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
assertEquals("[etc/]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,8 +96,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());
|
||||
assertEquals("[jars/]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -106,8 +107,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());
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -117,8 +118,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());
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
@@ -128,8 +129,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());
|
||||
assertEquals("[jars/app.jar]",
|
||||
ReflectionTestUtils.getField(launcher, "paths").toString());
|
||||
launcher.launch(new String[0]);
|
||||
waitFor("Hello World");
|
||||
}
|
||||
|
||||
@@ -65,10 +65,8 @@ public class WarLauncherTests {
|
||||
List<Archive> archives = launcher.getClassPathArchives();
|
||||
assertEquals(2, archives.size());
|
||||
|
||||
assertThat(
|
||||
getUrls(archives),
|
||||
hasItems(webInfClasses.toURI().toURL(), new URL("jar:"
|
||||
+ webInfLibFoo.toURI().toURL() + "!/")));
|
||||
assertThat(getUrls(archives), hasItems(webInfClasses.toURI().toURL(),
|
||||
new URL("jar:" + webInfLibFoo.toURI().toURL() + "!/")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,12 +78,10 @@ public class WarLauncherTests {
|
||||
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(getUrls(archives),
|
||||
hasItems(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 {
|
||||
@@ -100,8 +96,8 @@ public class WarLauncherTests {
|
||||
File warRoot = new File("target/archive.war");
|
||||
warRoot.delete();
|
||||
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(new FileOutputStream(
|
||||
warRoot));
|
||||
JarOutputStream jarOutputStream = new JarOutputStream(
|
||||
new FileOutputStream(warRoot));
|
||||
|
||||
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/"));
|
||||
jarOutputStream.putNextEntry(new JarEntry("WEB-INF/classes/"));
|
||||
|
||||
@@ -69,8 +69,8 @@ public class ExplodedArchiveTests {
|
||||
Enumeration<JarEntry> entries = jarFile.entries();
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry entry = entries.nextElement();
|
||||
File destination = new File(this.rootFolder.getAbsolutePath()
|
||||
+ File.separator + entry.getName());
|
||||
File destination = new File(
|
||||
this.rootFolder.getAbsolutePath() + File.separator + entry.getName());
|
||||
destination.getParentFile().mkdirs();
|
||||
if (entry.isDirectory()) {
|
||||
destination.mkdir();
|
||||
@@ -115,8 +115,8 @@ public class ExplodedArchiveTests {
|
||||
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(),
|
||||
equalTo("jar:" + this.rootFolder.toURI() + "nested.jar!/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,8 +125,8 @@ public class ExplodedArchiveTests {
|
||||
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(nested.getUrl().toString(),
|
||||
equalTo("file:" + this.rootFolder.toURI().getPath() + "d/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,7 +159,8 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveManifest() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"));
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"));
|
||||
assertNotNull(archive.getManifest());
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size(), equalTo(4));
|
||||
@@ -167,8 +168,8 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getNonRecursiveManifestEvenIfNonRecursive() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"), false);
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"),
|
||||
false);
|
||||
assertNotNull(archive.getManifest());
|
||||
Map<String, Archive.Entry> entries = getEntriesMap(archive);
|
||||
assertThat(entries.size(), equalTo(3));
|
||||
@@ -176,7 +177,8 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getResourceAsStream() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"));
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"));
|
||||
assertNotNull(archive.getManifest());
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml"));
|
||||
@@ -185,8 +187,8 @@ public class ExplodedArchiveTests {
|
||||
|
||||
@Test
|
||||
public void getResourceAsStreamNonRecursive() throws Exception {
|
||||
ExplodedArchive archive = new ExplodedArchive(
|
||||
new File("src/test/resources/root"), false);
|
||||
ExplodedArchive archive = new ExplodedArchive(new File("src/test/resources/root"),
|
||||
false);
|
||||
assertNotNull(archive.getManifest());
|
||||
URLClassLoader loader = new URLClassLoader(new URL[] { archive.getUrl() });
|
||||
assertNotNull(loader.getResourceAsStream("META-INF/spring/application.xml"));
|
||||
|
||||
@@ -85,8 +85,8 @@ public class JarFileArchiveTests {
|
||||
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(),
|
||||
equalTo("jar:" + this.rootJarFileUrl + "!/nested.jar!/"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -34,8 +34,8 @@ 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(FileCopyUtils.copyToByteArray(
|
||||
data.getInputStream(ResourceAccess.PER_READ)), equalTo(bytes));
|
||||
assertThat(data.getSize(), equalTo((long) bytes.length));
|
||||
}
|
||||
|
||||
@@ -44,8 +44,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(
|
||||
FileCopyUtils
|
||||
.copyToByteArray(data.getInputStream(ResourceAccess.PER_READ)),
|
||||
equalTo(new byte[] { 2, 3 }));
|
||||
assertThat(data.getSize(), equalTo(2L));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ import static org.junit.Assert.assertThat;
|
||||
public class RandomAccessDataFileTests {
|
||||
|
||||
private static final byte[] BYTES;
|
||||
|
||||
static {
|
||||
BYTES = new byte[256];
|
||||
for (int i = 0; i < BYTES.length; i++) {
|
||||
@@ -212,7 +213,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(),
|
||||
equalTo(-1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -152,8 +152,8 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getInputStream() throws Exception {
|
||||
InputStream inputStream = this.jarFile.getInputStream(this.jarFile
|
||||
.getEntry("1.dat"));
|
||||
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));
|
||||
@@ -180,8 +180,8 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void close() throws Exception {
|
||||
RandomAccessDataFile randomAccessDataFile = spy(new RandomAccessDataFile(
|
||||
this.rootJarFile, 1));
|
||||
RandomAccessDataFile randomAccessDataFile = spy(
|
||||
new RandomAccessDataFile(this.rootJarFile, 1));
|
||||
JarFile jarFile = new JarFile(randomAccessDataFile);
|
||||
jarFile.close();
|
||||
verify(randomAccessDataFile).close();
|
||||
@@ -204,7 +204,8 @@ public class JarFileTests {
|
||||
@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(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/1.dat"));
|
||||
JarURLConnection jarURLConnection = (JarURLConnection) url.openConnection();
|
||||
assertThat(jarURLConnection.getJarFile(), sameInstance(this.jarFile));
|
||||
assertThat(jarURLConnection.getJarEntry(),
|
||||
@@ -217,8 +218,8 @@ public class JarFileTests {
|
||||
@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(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/missing.dat"));
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
((JarURLConnection) url.openConnection()).getJarEntry();
|
||||
}
|
||||
@@ -242,8 +243,8 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getNestedJarFile() throws Exception {
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile
|
||||
.getEntry("nested.jar"));
|
||||
JarFile nestedJarFile = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
|
||||
Enumeration<java.util.jar.JarEntry> entries = nestedJarFile.entries();
|
||||
assertThat(entries.nextElement().getName(), equalTo("META-INF/"));
|
||||
@@ -253,14 +254,14 @@ public class JarFileTests {
|
||||
assertThat(entries.nextElement().getName(), equalTo("\u00E4.dat"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
|
||||
InputStream inputStream = nestedJarFile.getInputStream(nestedJarFile
|
||||
.getEntry("3.dat"));
|
||||
InputStream inputStream = nestedJarFile
|
||||
.getInputStream(nestedJarFile.getEntry("3.dat"));
|
||||
assertThat(inputStream.read(), equalTo(3));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
|
||||
URL url = nestedJarFile.getUrl();
|
||||
assertThat(url.toString(), equalTo("jar:" + this.rootJarFile.toURI()
|
||||
+ "!/nested.jar!/"));
|
||||
assertThat(url.toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/"));
|
||||
JarURLConnection conn = (JarURLConnection) url.openConnection();
|
||||
assertThat(conn.getJarFile(), sameInstance(nestedJarFile));
|
||||
assertThat(conn.getJarFileURL().toString(),
|
||||
@@ -276,8 +277,8 @@ public class JarFileTests {
|
||||
assertThat(entries.nextElement().getName(), equalTo("9.dat"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
|
||||
InputStream inputStream = nestedJarFile.getInputStream(nestedJarFile
|
||||
.getEntry("9.dat"));
|
||||
InputStream inputStream = nestedJarFile
|
||||
.getInputStream(nestedJarFile.getEntry("9.dat"));
|
||||
assertThat(inputStream.read(), equalTo(9));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
|
||||
@@ -289,11 +290,11 @@ public class JarFileTests {
|
||||
|
||||
@Test
|
||||
public void getNestJarEntryUrl() throws Exception {
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile
|
||||
.getEntry("nested.jar"));
|
||||
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(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar!/3.dat"));
|
||||
InputStream inputStream = url.openStream();
|
||||
assertThat(inputStream, notNullValue());
|
||||
assertThat(inputStream.read(), equalTo(3));
|
||||
@@ -310,8 +311,8 @@ public class JarFileTests {
|
||||
assertThat(inputStream.read(), equalTo(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.getJarFileURL().toString(),
|
||||
equalTo("jar:" + this.rootJarFile.toURI() + "!/nested.jar"));
|
||||
assertThat(connection.getEntryName(), equalTo("3.dat"));
|
||||
}
|
||||
|
||||
@@ -360,8 +361,8 @@ public class JarFileTests {
|
||||
assertThat(entries.nextElement().getName(), equalTo("x.dat"));
|
||||
assertThat(entries.hasMoreElements(), equalTo(false));
|
||||
|
||||
InputStream inputStream = filteredJarFile.getInputStream(filteredJarFile
|
||||
.getEntry("x.dat"));
|
||||
InputStream inputStream = filteredJarFile
|
||||
.getInputStream(filteredJarFile.getEntry("x.dat"));
|
||||
assertThat(inputStream.read(), equalTo(1));
|
||||
assertThat(inputStream.read(), equalTo(-1));
|
||||
}
|
||||
@@ -369,8 +370,10 @@ public class JarFileTests {
|
||||
@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.getNestedJarFile(this.jarFile.getEntry("nested.jar"))
|
||||
.toString(),
|
||||
equalTo(this.rootJarFile.getPath() + "!/nested.jar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -418,8 +421,8 @@ public class JarFileTests {
|
||||
@Test
|
||||
public void cannotLoadMissingJar() throws Exception {
|
||||
// relates to gh-1070
|
||||
JarFile nestedJarFile = this.jarFile.getNestedJarFile(this.jarFile
|
||||
.getEntry("nested.jar"));
|
||||
JarFile nestedJarFile = this.jarFile
|
||||
.getNestedJarFile(this.jarFile.getEntry("nested.jar"));
|
||||
URL nestedUrl = nestedJarFile.getUrl();
|
||||
URL url = new URL(nestedUrl, nestedJarFile.getUrl() + "missing.jar!/3.dat");
|
||||
this.thrown.expect(FileNotFoundException.class);
|
||||
|
||||
@@ -49,7 +49,8 @@ public class SystemPropertyUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testNestedPlaceholder() {
|
||||
assertEquals("foo", SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}"));
|
||||
assertEquals("foo",
|
||||
SystemPropertyUtils.resolvePlaceholders("${bar:${spam:foo}}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user