Skip to content

Commit ecf8467

Browse files
author
Steve Riesenberg
committed
Fix tests on JDK 21
Issue gh-12790 Issue gh-13811
1 parent d48b869 commit ecf8467

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

core/src/test/java/org/springframework/security/core/JavaVersionTests.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,8 @@
2020
import java.io.InputStream;
2121

2222
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.condition.EnabledOnJre;
24+
import org.junit.jupiter.api.condition.JRE;
2325

2426
import static org.assertj.core.api.Assertions.assertThat;
2527

@@ -31,20 +33,29 @@ public class JavaVersionTests {
3133

3234
private static final int JDK17_CLASS_VERSION = 61;
3335

36+
private static final int JDK21_CLASS_VERSION = 65;
37+
38+
@Test
39+
@EnabledOnJre(JRE.JAVA_17)
40+
public void authenticationWhenJdk17ThenCorrectJdkCompatibility() throws Exception {
41+
assertClassVersion(Authentication.class, JDK17_CLASS_VERSION);
42+
}
43+
3444
@Test
35-
public void authenticationCorrectJdkCompatibility() throws Exception {
36-
assertClassVersion(Authentication.class);
45+
@EnabledOnJre(JRE.JAVA_21)
46+
public void authenticationWhenJdk21ThenCorrectJdkCompatibility() throws Exception {
47+
assertClassVersion(Authentication.class, JDK21_CLASS_VERSION);
3748
}
3849

39-
private void assertClassVersion(Class<?> clazz) throws Exception {
50+
private void assertClassVersion(Class<?> clazz, int classVersion) throws Exception {
4051
String classResourceName = clazz.getName().replaceAll("\\.", "/") + ".class";
4152
try (InputStream input = Thread.currentThread().getContextClassLoader()
4253
.getResourceAsStream(classResourceName)) {
4354
DataInputStream data = new DataInputStream(input);
4455
data.readInt();
4556
data.readShort(); // minor
4657
int major = data.readShort();
47-
assertThat(major).isEqualTo(JDK17_CLASS_VERSION);
58+
assertThat(major).isEqualTo(classVersion);
4859
}
4960
}
5061

web/src/test/java/org/springframework/security/web/util/TextEscapeUtilsTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -62,7 +62,7 @@ public void validSurrogatePairIsAccepted() {
6262

6363
@Test
6464
public void undefinedSurrogatePairIsIgnored() {
65-
assertThat(TextEscapeUtils.escapeEntities("abc\uD888\uDC00a")).isEqualTo("abca");
65+
assertThat(TextEscapeUtils.escapeEntities("abc\uDBFF\uDFFFa")).isEqualTo("abca");
6666
}
6767

6868
}

0 commit comments

Comments
 (0)