Attempt to fix CI failures

Attempt to fix CI failures caused by timezone differences and different
JDK versions.

See gh-37668
This commit is contained in:
Phillip Webb 2023-10-03 20:29:33 -07:00
parent 560527945b
commit 42f50fa292
4 changed files with 15 additions and 21 deletions

View File

@ -352,7 +352,8 @@ class NestedJarFileTests {
assertThat(jar.stream().map((entry) -> entry.getName() + ":" + entry.getRealName())).containsExactly(
"META-INF/:META-INF/", "META-INF/MANIFEST.MF:META-INF/MANIFEST.MF",
"multi-release.dat:multi-release.dat",
"META-INF/versions/17/multi-release.dat:META-INF/versions/17/multi-release.dat");
"META-INF/versions/%1$d/multi-release.dat:META-INF/versions/%1$d/multi-release.dat"
.formatted(TestJar.MULTI_JAR_VERSION));
}
}
@ -361,7 +362,8 @@ class NestedJarFileTests {
try (NestedJarFile jar = new NestedJarFile(this.file, "multi-release.jar", Runtime.version())) {
assertThat(jar.versionedStream().map((entry) -> entry.getName() + ":" + entry.getRealName()))
.containsExactly("META-INF/:META-INF/", "META-INF/MANIFEST.MF:META-INF/MANIFEST.MF",
"multi-release.dat:META-INF/versions/17/multi-release.dat");
"multi-release.dat:META-INF/versions/%1$d/multi-release.dat"
.formatted(TestJar.MULTI_JAR_VERSION));
}
}

View File

@ -85,7 +85,7 @@ class ExplodedArchiveTests {
}
@Test
void getClassPathUrlsWhenNoPredicartesReturnsUrls() throws Exception {
void getClassPathUrlsWhenNoPredicatesReturnsUrls() throws Exception {
Set<URL> urls = this.archive.getClassPathUrls(Archive.ALL_ENTRIES);
URL[] expectedUrls = TestJar.expectedEntries().stream().map(this::toUrl).toArray(URL[]::new);
assertThat(urls).containsExactlyInAnyOrder(expectedUrls);
@ -123,7 +123,7 @@ class ExplodedArchiveTests {
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
File destination = new File(this.rootDirectory.getAbsolutePath() + File.separator + entry.getName());
File destination = new File(this.rootDirectory, entry.getName());
destination.getParentFile().mkdirs();
if (entry.isDirectory()) {
destination.mkdir();

View File

@ -35,22 +35,10 @@ import java.util.zip.ZipEntry;
*/
public abstract class TestJar {
public static final int MULTI_JAR_VERSION = Runtime.version().feature();
private static final int BASE_VERSION = 8;
private static final int RUNTIME_VERSION;
static {
int version;
try {
Object runtimeVersion = Runtime.class.getMethod("version").invoke(null);
version = (int) runtimeVersion.getClass().getMethod("major").invoke(runtimeVersion);
}
catch (Throwable ex) {
version = BASE_VERSION;
}
RUNTIME_VERSION = version;
}
public static void create(File file) throws Exception {
create(file, false);
}
@ -120,8 +108,9 @@ public abstract class TestJar {
writeManifest(jarOutputStream, "j2", multiRelease);
if (multiRelease) {
writeEntry(jarOutputStream, "multi-release.dat", BASE_VERSION);
writeEntry(jarOutputStream, String.format("META-INF/versions/%d/multi-release.dat", RUNTIME_VERSION),
RUNTIME_VERSION);
writeEntry(jarOutputStream,
String.format("META-INF/versions/%d/multi-release.dat", MULTI_JAR_VERSION),
MULTI_JAR_VERSION);
}
else {
writeEntry(jarOutputStream, "3.dat", 3);

View File

@ -16,6 +16,8 @@
package org.springframework.boot.loader.zip;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.zip.ZipEntry;
import org.junit.jupiter.api.Test;
@ -129,7 +131,8 @@ class ZipCentralDirectoryFileHeaderRecordTests {
record.copyTo(dataBlock, 0, entry);
assertThat(entry.getMethod()).isEqualTo(ZipEntry.DEFLATED);
assertThat(entry.getTimeLocal()).hasYear(2007);
assertThat(entry.getTime()).isEqualTo(1172356386000L);
ZonedDateTime expectedTime = ZonedDateTime.of(2007, 02, 24, 14, 33, 06, 0, ZoneId.systemDefault());
assertThat(entry.getTime()).isEqualTo(expectedTime.toEpochSecond() * 1000);
assertThat(entry.getCrc()).isEqualTo(0xFFFFFFFFL);
assertThat(entry.getCompressedSize()).isEqualTo(1);
assertThat(entry.getSize()).isEqualTo(2);