Merge branch '2.0.x' into 2.1.x
Closes gh-17078
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -170,8 +170,7 @@ public class DefaultLaunchScriptTests {
|
||||
public void expandVariables() throws Exception {
|
||||
File file = this.temporaryFolder.newFile();
|
||||
FileCopyUtils.copy("h{{a}}ll{{b}}".getBytes(), file);
|
||||
DefaultLaunchScript script = new DefaultLaunchScript(file,
|
||||
createProperties("a:e", "b:o"));
|
||||
DefaultLaunchScript script = new DefaultLaunchScript(file, createProperties("a:e", "b:o"));
|
||||
String content = new String(script.toByteArray());
|
||||
assertThat(content).isEqualTo("hello");
|
||||
}
|
||||
@@ -180,8 +179,7 @@ public class DefaultLaunchScriptTests {
|
||||
public void expandVariablesMultiLine() throws Exception {
|
||||
File file = this.temporaryFolder.newFile();
|
||||
FileCopyUtils.copy("h{{a}}l\nl{{b}}".getBytes(), file);
|
||||
DefaultLaunchScript script = new DefaultLaunchScript(file,
|
||||
createProperties("a:e", "b:o"));
|
||||
DefaultLaunchScript script = new DefaultLaunchScript(file, createProperties("a:e", "b:o"));
|
||||
String content = new String(script.toByteArray());
|
||||
assertThat(content).isEqualTo("hel\nlo");
|
||||
}
|
||||
@@ -208,8 +206,7 @@ public class DefaultLaunchScriptTests {
|
||||
public void expandVariablesWithDefaultsOverride() throws Exception {
|
||||
File file = this.temporaryFolder.newFile();
|
||||
FileCopyUtils.copy("h{{a:e}}ll{{b:o}}".getBytes(), file);
|
||||
DefaultLaunchScript script = new DefaultLaunchScript(file,
|
||||
createProperties("a:a"));
|
||||
DefaultLaunchScript script = new DefaultLaunchScript(file, createProperties("a:a"));
|
||||
String content = new String(script.toByteArray());
|
||||
assertThat(content).isEqualTo("hallo");
|
||||
}
|
||||
@@ -224,8 +221,7 @@ public class DefaultLaunchScriptTests {
|
||||
}
|
||||
|
||||
private void assertThatPlaceholderCanBeReplaced(String placeholder) throws Exception {
|
||||
DefaultLaunchScript script = new DefaultLaunchScript(null,
|
||||
createProperties(placeholder + ":__test__"));
|
||||
DefaultLaunchScript script = new DefaultLaunchScript(null, createProperties(placeholder + ":__test__"));
|
||||
String content = new String(script.toByteArray());
|
||||
assertThat(content).contains("__test__");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,8 +60,7 @@ public class FileUtilsTests {
|
||||
File file = new File(this.outputDirectory, "logback.xml");
|
||||
file.createNewFile();
|
||||
new File(this.originDirectory, "logback.xml").createNewFile();
|
||||
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
|
||||
this.originDirectory);
|
||||
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
|
||||
assertThat(file.exists()).isFalse();
|
||||
}
|
||||
|
||||
@@ -72,8 +71,7 @@ public class FileUtilsTests {
|
||||
File file = new File(this.outputDirectory, "sub/logback.xml");
|
||||
file.createNewFile();
|
||||
new File(this.originDirectory, "sub/logback.xml").createNewFile();
|
||||
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
|
||||
this.originDirectory);
|
||||
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
|
||||
assertThat(file.exists()).isFalse();
|
||||
}
|
||||
|
||||
@@ -84,8 +82,7 @@ public class FileUtilsTests {
|
||||
File file = new File(this.outputDirectory, "sub/logback.xml");
|
||||
file.createNewFile();
|
||||
new File(this.originDirectory, "sub/different.xml").createNewFile();
|
||||
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
|
||||
this.originDirectory);
|
||||
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
|
||||
assertThat(file.exists()).isTrue();
|
||||
}
|
||||
|
||||
@@ -94,8 +91,7 @@ public class FileUtilsTests {
|
||||
File file = new File(this.outputDirectory, "logback.xml");
|
||||
file.createNewFile();
|
||||
new File(this.originDirectory, "different.xml").createNewFile();
|
||||
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory,
|
||||
this.originDirectory);
|
||||
FileUtils.removeDuplicatesFromOutputDirectory(this.outputDirectory, this.originDirectory);
|
||||
assertThat(file.exists()).isTrue();
|
||||
}
|
||||
|
||||
@@ -105,8 +101,7 @@ public class FileUtilsTests {
|
||||
try (OutputStream outputStream = new FileOutputStream(file)) {
|
||||
outputStream.write(new byte[] { 1, 2, 3 });
|
||||
}
|
||||
assertThat(FileUtils.sha1Hash(file))
|
||||
.isEqualTo("7037807198c22a7d2b0807371d763779a84fdfcf");
|
||||
assertThat(FileUtils.sha1Hash(file)).isEqualTo("7037807198c22a7d2b0807371d763779a84fdfcf");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,8 +36,7 @@ public class LayoutsTests {
|
||||
assertThat(Layouts.forFile(new File("test.jar"))).isInstanceOf(Layouts.Jar.class);
|
||||
assertThat(Layouts.forFile(new File("test.JAR"))).isInstanceOf(Layouts.Jar.class);
|
||||
assertThat(Layouts.forFile(new File("test.jAr"))).isInstanceOf(Layouts.Jar.class);
|
||||
assertThat(Layouts.forFile(new File("te.st.jar")))
|
||||
.isInstanceOf(Layouts.Jar.class);
|
||||
assertThat(Layouts.forFile(new File("te.st.jar"))).isInstanceOf(Layouts.Jar.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -45,41 +44,31 @@ public class LayoutsTests {
|
||||
assertThat(Layouts.forFile(new File("test.war"))).isInstanceOf(Layouts.War.class);
|
||||
assertThat(Layouts.forFile(new File("test.WAR"))).isInstanceOf(Layouts.War.class);
|
||||
assertThat(Layouts.forFile(new File("test.wAr"))).isInstanceOf(Layouts.War.class);
|
||||
assertThat(Layouts.forFile(new File("te.st.war")))
|
||||
.isInstanceOf(Layouts.War.class);
|
||||
assertThat(Layouts.forFile(new File("te.st.war"))).isInstanceOf(Layouts.War.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unknownFile() {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> Layouts.forFile(new File("test.txt")))
|
||||
assertThatIllegalStateException().isThrownBy(() -> Layouts.forFile(new File("test.txt")))
|
||||
.withMessageContaining("Unable to deduce layout for 'test.txt'");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarLayout() {
|
||||
Layout layout = new Layouts.Jar();
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE))
|
||||
.isEqualTo("BOOT-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM))
|
||||
.isEqualTo("BOOT-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED))
|
||||
.isEqualTo("BOOT-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME))
|
||||
.isEqualTo("BOOT-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE)).isEqualTo("BOOT-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM)).isEqualTo("BOOT-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED)).isEqualTo("BOOT-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME)).isEqualTo("BOOT-INF/lib/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void warLayout() {
|
||||
Layout layout = new Layouts.War();
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE))
|
||||
.isEqualTo("WEB-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM))
|
||||
.isEqualTo("WEB-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED))
|
||||
.isEqualTo("WEB-INF/lib-provided/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME))
|
||||
.isEqualTo("WEB-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.COMPILE)).isEqualTo("WEB-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.CUSTOM)).isEqualTo("WEB-INF/lib/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.PROVIDED)).isEqualTo("WEB-INF/lib-provided/");
|
||||
assertThat(layout.getLibraryDestination("lib.jar", LibraryScope.RUNTIME)).isEqualTo("WEB-INF/lib/");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -81,18 +81,16 @@ public class MainClassFinderTests {
|
||||
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> MainClassFinder
|
||||
.findSingleMainClass(this.testJarFile.getJarFile(), ""))
|
||||
.withMessageContaining("Unable to find a single main class "
|
||||
+ "from the following candidates [a.B, a.b.c.E]");
|
||||
.isThrownBy(() -> MainClassFinder.findSingleMainClass(this.testJarFile.getJarFile(), ""))
|
||||
.withMessageContaining(
|
||||
"Unable to find a single main class " + "from the following candidates [a.B, a.b.c.E]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findSingleJarSearchPrefersAnnotatedMainClass() throws Exception {
|
||||
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/c/E.class", AnnotatedClassWithMainMethod.class);
|
||||
String mainClass = MainClassFinder.findSingleMainClass(
|
||||
this.testJarFile.getJarFile(), "",
|
||||
String mainClass = MainClassFinder.findSingleMainClass(this.testJarFile.getJarFile(), "",
|
||||
"org.springframework.boot.loader.tools.sample.SomeApplication");
|
||||
assertThat(mainClass).isEqualTo("a.b.c.E");
|
||||
}
|
||||
@@ -101,8 +99,7 @@ public class MainClassFinderTests {
|
||||
public void findMainClassInJarSubLocation() throws Exception {
|
||||
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
|
||||
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(),
|
||||
"a/");
|
||||
String actual = MainClassFinder.findMainClass(this.testJarFile.getJarFile(), "a/");
|
||||
assertThat(actual).isEqualTo("B");
|
||||
|
||||
}
|
||||
@@ -137,18 +134,16 @@ public class MainClassFinderTests {
|
||||
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/c/E.class", ClassWithMainMethod.class);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> MainClassFinder
|
||||
.findSingleMainClass(this.testJarFile.getJarSource()))
|
||||
.withMessageContaining("Unable to find a single main class "
|
||||
+ "from the following candidates [a.B, a.b.c.E]");
|
||||
.isThrownBy(() -> MainClassFinder.findSingleMainClass(this.testJarFile.getJarSource()))
|
||||
.withMessageContaining(
|
||||
"Unable to find a single main class " + "from the following candidates [a.B, a.b.c.E]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findSingleFolderSearchPrefersAnnotatedMainClass() throws Exception {
|
||||
this.testJarFile.addClass("a/B.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("a/b/c/E.class", AnnotatedClassWithMainMethod.class);
|
||||
String mainClass = MainClassFinder.findSingleMainClass(
|
||||
this.testJarFile.getJarSource(),
|
||||
String mainClass = MainClassFinder.findSingleMainClass(this.testJarFile.getJarSource(),
|
||||
"org.springframework.boot.loader.tools.sample.SomeApplication");
|
||||
assertThat(mainClass).isEqualTo("a.b.c.E");
|
||||
}
|
||||
|
||||
@@ -96,14 +96,12 @@ public class RepackagerTests {
|
||||
|
||||
@Test
|
||||
public void missingSource() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new Repackager(new File("missing")));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Repackager(new File("missing")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void directorySource() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> new Repackager(this.temporaryFolder.getRoot()));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> new Repackager(this.temporaryFolder.getRoot()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,8 +114,7 @@ public class RepackagerTests {
|
||||
Manifest actualManifest = getManifest(file);
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo("org.springframework.boot.loader.JarLauncher");
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
|
||||
.isEqualTo("a.b.C");
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
|
||||
assertThat(hasLauncherClasses(file)).isTrue();
|
||||
}
|
||||
|
||||
@@ -134,8 +131,7 @@ public class RepackagerTests {
|
||||
Manifest actualManifest = getManifest(file);
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo("org.springframework.boot.loader.JarLauncher");
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
|
||||
.isEqualTo("a.b.C");
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
|
||||
assertThat(hasLauncherClasses(file)).isTrue();
|
||||
}
|
||||
|
||||
@@ -148,8 +144,7 @@ public class RepackagerTests {
|
||||
Manifest actualManifest = getManifest(file);
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo("org.springframework.boot.loader.JarLauncher");
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
|
||||
.isEqualTo("a.b.C");
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
|
||||
assertThat(hasLauncherClasses(file)).isTrue();
|
||||
}
|
||||
|
||||
@@ -163,8 +158,7 @@ public class RepackagerTests {
|
||||
Manifest actualManifest = getManifest(file);
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo("org.springframework.boot.loader.JarLauncher");
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Start-Class"))
|
||||
.isEqualTo("a.b.C");
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Start-Class")).isEqualTo("a.b.C");
|
||||
assertThat(hasLauncherClasses(file)).isTrue();
|
||||
}
|
||||
|
||||
@@ -174,17 +168,15 @@ public class RepackagerTests {
|
||||
this.testJarFile.addClass("a/b/D.class", ClassWithMainMethod.class);
|
||||
File file = this.testJarFile.getFile();
|
||||
Repackager repackager = new Repackager(file);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> repackager.repackage(NO_LIBRARIES))
|
||||
.withMessageContaining("Unable to find a single main class "
|
||||
+ "from the following candidates [a.b.C, a.b.D]");
|
||||
assertThatIllegalStateException().isThrownBy(() -> repackager.repackage(NO_LIBRARIES)).withMessageContaining(
|
||||
"Unable to find a single main class " + "from the following candidates [a.b.C, a.b.D]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noMainClass() throws Exception {
|
||||
this.testJarFile.addClass("a/b/C.class", ClassWithoutMainMethod.class);
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
() -> new Repackager(this.testJarFile.getFile()).repackage(NO_LIBRARIES))
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> new Repackager(this.testJarFile.getFile()).repackage(NO_LIBRARIES))
|
||||
.withMessageContaining("Unable to find main class");
|
||||
}
|
||||
|
||||
@@ -196,8 +188,7 @@ public class RepackagerTests {
|
||||
repackager.setLayout(new Layouts.None());
|
||||
repackager.repackage(file, NO_LIBRARIES);
|
||||
Manifest actualManifest = getManifest(file);
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo("a.b.C");
|
||||
assertThat(actualManifest.getMainAttributes().getValue("Main-Class")).isEqualTo("a.b.C");
|
||||
assertThat(hasLauncherClasses(file)).isFalse();
|
||||
}
|
||||
|
||||
@@ -230,8 +221,7 @@ public class RepackagerTests {
|
||||
Repackager repackager = new Repackager(file);
|
||||
repackager.setBackupSource(false);
|
||||
repackager.repackage(NO_LIBRARIES);
|
||||
assertThat(new File(file.getParent(), file.getName() + ".original"))
|
||||
.doesNotExist();
|
||||
assertThat(new File(file.getParent(), file.getName() + ".original")).doesNotExist();
|
||||
assertThat(hasLauncherClasses(file)).isTrue();
|
||||
}
|
||||
|
||||
@@ -242,8 +232,7 @@ public class RepackagerTests {
|
||||
File dest = this.temporaryFolder.newFile("different.jar");
|
||||
Repackager repackager = new Repackager(source);
|
||||
repackager.repackage(dest, NO_LIBRARIES);
|
||||
assertThat(new File(source.getParent(), source.getName() + ".original"))
|
||||
.doesNotExist();
|
||||
assertThat(new File(source.getParent(), source.getName() + ".original")).doesNotExist();
|
||||
assertThat(hasLauncherClasses(source)).isFalse();
|
||||
assertThat(hasLauncherClasses(dest)).isTrue();
|
||||
}
|
||||
@@ -252,8 +241,7 @@ public class RepackagerTests {
|
||||
public void nullDestination() throws Exception {
|
||||
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
|
||||
Repackager repackager = new Repackager(this.testJarFile.getFile());
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> repackager.repackage(null, NO_LIBRARIES))
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> repackager.repackage(null, NO_LIBRARIES))
|
||||
.withMessageContaining("Invalid destination");
|
||||
}
|
||||
|
||||
@@ -261,8 +249,8 @@ public class RepackagerTests {
|
||||
public void destinationIsDirectory() throws Exception {
|
||||
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
|
||||
Repackager repackager = new Repackager(this.testJarFile.getFile());
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
() -> repackager.repackage(this.temporaryFolder.getRoot(), NO_LIBRARIES))
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> repackager.repackage(this.temporaryFolder.getRoot(), NO_LIBRARIES))
|
||||
.withMessageContaining("Invalid destination");
|
||||
}
|
||||
|
||||
@@ -281,8 +269,7 @@ public class RepackagerTests {
|
||||
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
|
||||
File file = this.testJarFile.getFile();
|
||||
Repackager repackager = new Repackager(file);
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> repackager.repackage(file, null))
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> repackager.repackage(file, null))
|
||||
.withMessageContaining("Libraries must not be null");
|
||||
}
|
||||
|
||||
@@ -295,8 +282,7 @@ public class RepackagerTests {
|
||||
File libNonJarFile = this.temporaryFolder.newFile();
|
||||
FileCopyUtils.copy(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, libNonJarFile);
|
||||
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addFile("BOOT-INF/lib/" + libJarFileToUnpack.getName(),
|
||||
libJarFileToUnpack);
|
||||
this.testJarFile.addFile("BOOT-INF/lib/" + libJarFileToUnpack.getName(), libJarFileToUnpack);
|
||||
File file = this.testJarFile.getFile();
|
||||
libJarFile.setLastModified(JAN_1_1980);
|
||||
Repackager repackager = new Repackager(file);
|
||||
@@ -306,8 +292,7 @@ public class RepackagerTests {
|
||||
callback.library(new Library(libNonJarFile, LibraryScope.COMPILE));
|
||||
});
|
||||
assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFile.getName())).isTrue();
|
||||
assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFileToUnpack.getName()))
|
||||
.isTrue();
|
||||
assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFileToUnpack.getName())).isTrue();
|
||||
assertThat(hasEntry(file, "BOOT-INF/lib/" + libNonJarFile.getName())).isFalse();
|
||||
JarEntry entry = getEntry(file, "BOOT-INF/lib/" + libJarFile.getName());
|
||||
assertThat(entry.getTime()).isEqualTo(JAN_1_1985);
|
||||
@@ -324,13 +309,10 @@ public class RepackagerTests {
|
||||
this.testJarFile.addClass("a/b/C.class", ClassWithMainMethod.class);
|
||||
File file = this.testJarFile.getFile();
|
||||
Repackager repackager = new Repackager(file);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> repackager.repackage((callback) -> {
|
||||
callback.library(
|
||||
new Library(libJarFile, LibraryScope.COMPILE, false));
|
||||
callback.library(
|
||||
new Library(libJarFile, LibraryScope.COMPILE, false));
|
||||
})).withMessageContaining("Duplicate library");
|
||||
assertThatIllegalStateException().isThrownBy(() -> repackager.repackage((callback) -> {
|
||||
callback.library(new Library(libJarFile, LibraryScope.COMPILE, false));
|
||||
callback.library(new Library(libJarFile, LibraryScope.COMPILE, false));
|
||||
})).withMessageContaining("Duplicate library");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -345,16 +327,12 @@ public class RepackagerTests {
|
||||
LibraryScope scope = mock(LibraryScope.class);
|
||||
given(layout.getLauncherClassName()).willReturn("testLauncher");
|
||||
given(layout.getLibraryDestination(anyString(), eq(scope))).willReturn("test/");
|
||||
given(layout.getLibraryDestination(anyString(), eq(LibraryScope.COMPILE)))
|
||||
.willReturn("test-lib/");
|
||||
given(layout.getLibraryDestination(anyString(), eq(LibraryScope.COMPILE))).willReturn("test-lib/");
|
||||
repackager.setLayout(layout);
|
||||
repackager.repackage(
|
||||
(callback) -> callback.library(new Library(libJarFile, scope)));
|
||||
repackager.repackage((callback) -> callback.library(new Library(libJarFile, scope)));
|
||||
assertThat(hasEntry(file, "test/" + libJarFile.getName())).isTrue();
|
||||
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib"))
|
||||
.isEqualTo("test-lib/");
|
||||
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo("testLauncher");
|
||||
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib")).isEqualTo("test-lib/");
|
||||
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class")).isEqualTo("testLauncher");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -369,12 +347,9 @@ public class RepackagerTests {
|
||||
LibraryScope scope = mock(LibraryScope.class);
|
||||
given(layout.getLauncherClassName()).willReturn("testLauncher");
|
||||
repackager.setLayout(layout);
|
||||
repackager.repackage(
|
||||
(callback) -> callback.library(new Library(libJarFile, scope)));
|
||||
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib"))
|
||||
.isNull();
|
||||
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class"))
|
||||
.isEqualTo("testLauncher");
|
||||
repackager.repackage((callback) -> callback.library(new Library(libJarFile, scope)));
|
||||
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib")).isNull();
|
||||
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class")).isEqualTo("testLauncher");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -384,8 +359,7 @@ public class RepackagerTests {
|
||||
Repackager repackager = new Repackager(file);
|
||||
repackager.repackage(NO_LIBRARIES);
|
||||
Manifest actualManifest = getManifest(file);
|
||||
assertThat(actualManifest.getMainAttributes())
|
||||
.containsKey(new Attributes.Name("Spring-Boot-Version"));
|
||||
assertThat(actualManifest.getMainAttributes()).containsKey(new Attributes.Name("Spring-Boot-Version"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -395,24 +369,23 @@ public class RepackagerTests {
|
||||
Repackager repackager = new Repackager(file);
|
||||
repackager.repackage(NO_LIBRARIES);
|
||||
Manifest actualManifest = getManifest(file);
|
||||
assertThat(actualManifest.getMainAttributes())
|
||||
.containsEntry(new Attributes.Name("Spring-Boot-Lib"), "BOOT-INF/lib/");
|
||||
assertThat(actualManifest.getMainAttributes()).containsEntry(
|
||||
new Attributes.Name("Spring-Boot-Classes"), "BOOT-INF/classes/");
|
||||
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Lib"),
|
||||
"BOOT-INF/lib/");
|
||||
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Classes"),
|
||||
"BOOT-INF/classes/");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void executableWarLayoutAttributes() throws Exception {
|
||||
this.testJarFile.addClass("WEB-INF/classes/a/b/C.class",
|
||||
ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("WEB-INF/classes/a/b/C.class", ClassWithMainMethod.class);
|
||||
File file = this.testJarFile.getFile("war");
|
||||
Repackager repackager = new Repackager(file);
|
||||
repackager.repackage(NO_LIBRARIES);
|
||||
Manifest actualManifest = getManifest(file);
|
||||
assertThat(actualManifest.getMainAttributes())
|
||||
.containsEntry(new Attributes.Name("Spring-Boot-Lib"), "WEB-INF/lib/");
|
||||
assertThat(actualManifest.getMainAttributes()).containsEntry(
|
||||
new Attributes.Name("Spring-Boot-Classes"), "WEB-INF/classes/");
|
||||
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Lib"),
|
||||
"WEB-INF/lib/");
|
||||
assertThat(actualManifest.getMainAttributes()).containsEntry(new Attributes.Name("Spring-Boot-Classes"),
|
||||
"WEB-INF/classes/");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -432,15 +405,11 @@ public class RepackagerTests {
|
||||
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
|
||||
File file = this.testJarFile.getFile();
|
||||
Repackager repackager = new Repackager(file);
|
||||
repackager.repackage((callback) -> callback
|
||||
.library(new Library(nestedFile, LibraryScope.COMPILE)));
|
||||
repackager.repackage((callback) -> callback.library(new Library(nestedFile, LibraryScope.COMPILE)));
|
||||
|
||||
try (JarFile jarFile = new JarFile(file)) {
|
||||
assertThat(
|
||||
jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getMethod())
|
||||
.isEqualTo(ZipEntry.STORED);
|
||||
assertThat(jarFile.getEntry("BOOT-INF/classes/test/nested.jar").getMethod())
|
||||
.isEqualTo(ZipEntry.STORED);
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getMethod()).isEqualTo(ZipEntry.STORED);
|
||||
assertThat(jarFile.getEntry("BOOT-INF/classes/test/nested.jar").getMethod()).isEqualTo(ZipEntry.STORED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -457,8 +426,7 @@ public class RepackagerTests {
|
||||
assertThat(hasLauncherClasses(source)).isFalse();
|
||||
assertThat(hasLauncherClasses(dest)).isTrue();
|
||||
try {
|
||||
assertThat(Files.getPosixFilePermissions(dest.toPath()))
|
||||
.contains(PosixFilePermission.OWNER_EXECUTE);
|
||||
assertThat(Files.getPosixFilePermissions(dest.toPath())).contains(PosixFilePermission.OWNER_EXECUTE);
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
// Probably running the test on Windows
|
||||
@@ -466,8 +434,7 @@ public class RepackagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unpackLibrariesTakePrecedenceOverExistingSourceEntries()
|
||||
throws Exception {
|
||||
public void unpackLibrariesTakePrecedenceOverExistingSourceEntries() throws Exception {
|
||||
TestJarFile nested = new TestJarFile(this.temporaryFolder);
|
||||
nested.addClass("a/b/C.class", ClassWithoutMainMethod.class);
|
||||
File nestedFile = nested.getFile();
|
||||
@@ -476,21 +443,18 @@ public class RepackagerTests {
|
||||
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
|
||||
File file = this.testJarFile.getFile();
|
||||
Repackager repackager = new Repackager(file);
|
||||
repackager.repackage((callback) -> callback
|
||||
.library(new Library(nestedFile, LibraryScope.COMPILE, true)));
|
||||
repackager.repackage((callback) -> callback.library(new Library(nestedFile, LibraryScope.COMPILE, true)));
|
||||
try (JarFile jarFile = new JarFile(file)) {
|
||||
assertThat(jarFile.getEntry(name).getComment()).startsWith("UNPACK:");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void existingSourceEntriesTakePrecedenceOverStandardLibraries()
|
||||
throws Exception {
|
||||
public void existingSourceEntriesTakePrecedenceOverStandardLibraries() throws Exception {
|
||||
TestJarFile nested = new TestJarFile(this.temporaryFolder);
|
||||
nested.addClass("a/b/C.class", ClassWithoutMainMethod.class);
|
||||
File nestedFile = nested.getFile();
|
||||
this.testJarFile.addFile("BOOT-INF/lib/" + nestedFile.getName(),
|
||||
nested.getFile());
|
||||
this.testJarFile.addFile("BOOT-INF/lib/" + nestedFile.getName(), nested.getFile());
|
||||
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
|
||||
File file = this.testJarFile.getFile();
|
||||
Repackager repackager = new Repackager(file);
|
||||
@@ -502,16 +466,14 @@ public class RepackagerTests {
|
||||
callback.library(new Library(nestedFile, LibraryScope.COMPILE));
|
||||
});
|
||||
try (JarFile jarFile = new JarFile(file)) {
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getSize())
|
||||
.isEqualTo(sourceLength);
|
||||
assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getSize()).isEqualTo(sourceLength);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfIndexListIsRemovedFromRepackagedJar() throws Exception {
|
||||
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addFile("META-INF/INDEX.LIST",
|
||||
this.temporaryFolder.newFile("INDEX.LIST"));
|
||||
this.testJarFile.addFile("META-INF/INDEX.LIST", this.temporaryFolder.newFile("INDEX.LIST"));
|
||||
File source = this.testJarFile.getFile();
|
||||
File dest = this.temporaryFolder.newFile("dest.jar");
|
||||
Repackager repackager = new Repackager(source);
|
||||
@@ -545,11 +507,9 @@ public class RepackagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metaInfAopXmlIsMovedBeneathBootInfClassesWhenRepackaged()
|
||||
throws Exception {
|
||||
public void metaInfAopXmlIsMovedBeneathBootInfClassesWhenRepackaged() throws Exception {
|
||||
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addFile("META-INF/aop.xml",
|
||||
this.temporaryFolder.newFile("aop.xml"));
|
||||
this.testJarFile.addFile("META-INF/aop.xml", this.temporaryFolder.newFile("aop.xml"));
|
||||
File source = this.testJarFile.getFile();
|
||||
File dest = this.temporaryFolder.newFile("dest.jar");
|
||||
Repackager repackager = new Repackager(source);
|
||||
@@ -578,10 +538,8 @@ public class RepackagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loaderIsWrittenFirstThenApplicationClassesThenLibraries()
|
||||
throws IOException {
|
||||
this.testJarFile.addClass("com/example/Application.class",
|
||||
ClassWithMainMethod.class);
|
||||
public void loaderIsWrittenFirstThenApplicationClassesThenLibraries() throws IOException {
|
||||
this.testJarFile.addClass("com/example/Application.class", ClassWithMainMethod.class);
|
||||
File source = this.testJarFile.getFile();
|
||||
File dest = this.temporaryFolder.newFile("dest.jar");
|
||||
File libraryOne = createLibrary();
|
||||
@@ -593,31 +551,23 @@ public class RepackagerTests {
|
||||
callback.library(new Library(libraryTwo, LibraryScope.COMPILE, true));
|
||||
callback.library(new Library(libraryThree, LibraryScope.COMPILE, false));
|
||||
});
|
||||
assertThat(getEntryNames(dest)).containsSubsequence(
|
||||
"org/springframework/boot/loader/",
|
||||
"BOOT-INF/classes/com/example/Application.class",
|
||||
"BOOT-INF/lib/" + libraryOne.getName(),
|
||||
"BOOT-INF/lib/" + libraryTwo.getName(),
|
||||
"BOOT-INF/lib/" + libraryThree.getName());
|
||||
assertThat(getEntryNames(dest)).containsSubsequence("org/springframework/boot/loader/",
|
||||
"BOOT-INF/classes/com/example/Application.class", "BOOT-INF/lib/" + libraryOne.getName(),
|
||||
"BOOT-INF/lib/" + libraryTwo.getName(), "BOOT-INF/lib/" + libraryThree.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void existingEntryThatMatchesUnpackLibraryIsMarkedForUnpack()
|
||||
throws IOException {
|
||||
public void existingEntryThatMatchesUnpackLibraryIsMarkedForUnpack() throws IOException {
|
||||
File library = createLibrary();
|
||||
this.testJarFile.addClass("WEB-INF/classes/com/example/Application.class",
|
||||
ClassWithMainMethod.class);
|
||||
this.testJarFile.addClass("WEB-INF/classes/com/example/Application.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addFile("WEB-INF/lib/" + library.getName(), library);
|
||||
File source = this.testJarFile.getFile("war");
|
||||
File dest = this.temporaryFolder.newFile("dest.war");
|
||||
Repackager repackager = new Repackager(source);
|
||||
repackager.setLayout(new Layouts.War());
|
||||
repackager.repackage(dest, (callback) -> callback
|
||||
.library(new Library(library, LibraryScope.COMPILE, true)));
|
||||
assertThat(getEntryNames(dest)).containsSubsequence(
|
||||
"org/springframework/boot/loader/",
|
||||
"WEB-INF/classes/com/example/Application.class",
|
||||
"WEB-INF/lib/" + library.getName());
|
||||
repackager.repackage(dest, (callback) -> callback.library(new Library(library, LibraryScope.COMPILE, true)));
|
||||
assertThat(getEntryNames(dest)).containsSubsequence("org/springframework/boot/loader/",
|
||||
"WEB-INF/classes/com/example/Application.class", "WEB-INF/lib/" + library.getName());
|
||||
JarEntry unpackLibrary = getEntry(dest, "WEB-INF/lib/" + library.getName());
|
||||
assertThat(unpackLibrary.getComment()).startsWith("UNPACK:");
|
||||
}
|
||||
@@ -633,15 +583,13 @@ public class RepackagerTests {
|
||||
Layout layout = mock(Layout.class);
|
||||
LibraryScope scope = mock(LibraryScope.class);
|
||||
repackager.setLayout(layout);
|
||||
repackager.repackage(
|
||||
(callback) -> callback.library(new Library(libJarFile, scope)));
|
||||
assertThat(getEntryNames(file)).containsExactly("META-INF/",
|
||||
"META-INF/MANIFEST.MF", "a/", "a/b/", "a/b/C.class");
|
||||
repackager.repackage((callback) -> callback.library(new Library(libJarFile, scope)));
|
||||
assertThat(getEntryNames(file)).containsExactly("META-INF/", "META-INF/MANIFEST.MF", "a/", "a/b/",
|
||||
"a/b/C.class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void jarThatUsesCustomCompressionConfigurationCanBeRepackaged()
|
||||
throws IOException {
|
||||
public void jarThatUsesCustomCompressionConfigurationCanBeRepackaged() throws IOException {
|
||||
File source = this.temporaryFolder.newFile("source.jar");
|
||||
ZipOutputStream output = new ZipOutputStream(new FileOutputStream(source)) {
|
||||
{
|
||||
@@ -676,26 +624,22 @@ public class RepackagerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinModuleMetadataMovesBeneathBootInfClassesWhenRepackaged()
|
||||
throws Exception {
|
||||
public void kotlinModuleMetadataMovesBeneathBootInfClassesWhenRepackaged() throws Exception {
|
||||
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
|
||||
this.testJarFile.addFile("META-INF/test.kotlin_module",
|
||||
this.temporaryFolder.newFile("test.kotlin_module"));
|
||||
this.testJarFile.addFile("META-INF/test.kotlin_module", this.temporaryFolder.newFile("test.kotlin_module"));
|
||||
File source = this.testJarFile.getFile();
|
||||
File dest = this.temporaryFolder.newFile("dest.jar");
|
||||
Repackager repackager = new Repackager(source);
|
||||
repackager.repackage(dest, NO_LIBRARIES);
|
||||
try (JarFile jarFile = new JarFile(dest)) {
|
||||
assertThat(jarFile.getEntry("META-INF/test.kotlin_module")).isNull();
|
||||
assertThat(jarFile.getEntry("BOOT-INF/classes/META-INF/test.kotlin_module"))
|
||||
.isNotNull();
|
||||
assertThat(jarFile.getEntry("BOOT-INF/classes/META-INF/test.kotlin_module")).isNotNull();
|
||||
}
|
||||
}
|
||||
|
||||
private File createLibrary() throws IOException {
|
||||
TestJarFile library = new TestJarFile(this.temporaryFolder);
|
||||
library.addClass("com/example/library/Library.class",
|
||||
ClassWithoutMainMethod.class);
|
||||
library.addClass("com/example/library/Library.class", ClassWithoutMainMethod.class);
|
||||
return library.getFile();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,12 +55,11 @@ public class TestJarFile {
|
||||
addClass(filename, classToCopy, null);
|
||||
}
|
||||
|
||||
public void addClass(String filename, Class<?> classToCopy, Long time)
|
||||
throws IOException {
|
||||
public void addClass(String filename, Class<?> classToCopy, Long time) throws IOException {
|
||||
File file = getFilePath(filename);
|
||||
file.getParentFile().mkdirs();
|
||||
InputStream inputStream = getClass().getResourceAsStream(
|
||||
"/" + classToCopy.getName().replace('.', '/') + ".class");
|
||||
InputStream inputStream = getClass()
|
||||
.getResourceAsStream("/" + classToCopy.getName().replace('.', '/') + ".class");
|
||||
copyToFile(inputStream, file);
|
||||
if (time != null) {
|
||||
file.setLastModified(time);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,8 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class ZipHeaderPeekInputStreamTests {
|
||||
|
||||
@Test
|
||||
public void hasZipHeaderReturnsTrueWhenStreamStartsWithZipHeader()
|
||||
throws IOException {
|
||||
public void hasZipHeaderReturnsTrueWhenStreamStartsWithZipHeader() throws IOException {
|
||||
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
|
||||
new ByteArrayInputStream(new byte[] { 0x50, 0x4b, 0x03, 0x04, 5, 6 }))) {
|
||||
assertThat(in.hasZipHeader()).isTrue();
|
||||
@@ -42,8 +41,7 @@ public class ZipHeaderPeekInputStreamTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasZipHeaderReturnsFalseWhenStreamDoesNotStartWithZipHeader()
|
||||
throws IOException {
|
||||
public void hasZipHeaderReturnsFalseWhenStreamDoesNotStartWithZipHeader() throws IOException {
|
||||
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
|
||||
new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }))) {
|
||||
assertThat(in.hasZipHeader()).isFalse();
|
||||
@@ -88,8 +86,7 @@ public class ZipHeaderPeekInputStreamTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOfSomeOfTheHeaderThenMoreThanEntireStreamReadsToEndOfStream()
|
||||
throws IOException {
|
||||
public void readOfSomeOfTheHeaderThenMoreThanEntireStreamReadsToEndOfStream() throws IOException {
|
||||
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
|
||||
new ByteArrayInputStream(new byte[] { 0, 1, 2, 3, 4, 5 }))) {
|
||||
byte[] bytes = new byte[8];
|
||||
@@ -101,10 +98,8 @@ public class ZipHeaderPeekInputStreamTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readMoreThanEntireStreamWhenStreamLengthIsLessThanZipHeaderLength()
|
||||
throws IOException {
|
||||
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
|
||||
new ByteArrayInputStream(new byte[] { 10 }))) {
|
||||
public void readMoreThanEntireStreamWhenStreamLengthIsLessThanZipHeaderLength() throws IOException {
|
||||
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[] { 10 }))) {
|
||||
byte[] bytes = new byte[8];
|
||||
assertThat(in.read(bytes)).isEqualTo(1);
|
||||
assertThat(bytes).containsExactly(10, 0, 0, 0, 0, 0, 0, 0);
|
||||
@@ -112,8 +107,7 @@ public class ZipHeaderPeekInputStreamTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readMoreThanEntireStreamWhenStreamLengthIsSameAsHeaderLength()
|
||||
throws IOException {
|
||||
public void readMoreThanEntireStreamWhenStreamLengthIsSameAsHeaderLength() throws IOException {
|
||||
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
|
||||
new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }))) {
|
||||
byte[] bytes = new byte[8];
|
||||
@@ -124,8 +118,7 @@ public class ZipHeaderPeekInputStreamTests {
|
||||
|
||||
@Test
|
||||
public void readMoreThanEntireStreamWhenStreamLengthIsZero() throws IOException {
|
||||
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(
|
||||
new ByteArrayInputStream(new byte[0]))) {
|
||||
try (ZipHeaderPeekInputStream in = new ZipHeaderPeekInputStream(new ByteArrayInputStream(new byte[0]))) {
|
||||
byte[] bytes = new byte[8];
|
||||
assertThat(in.read(bytes)).isEqualTo(-1);
|
||||
assertThat(bytes).containsExactly(0, 0, 0, 0, 0, 0, 0, 0);
|
||||
|
||||
Reference in New Issue
Block a user