mirror of
				https://github.com/spring-projects/spring-security.git
				synced 2025-10-30 22:28:46 +00:00 
			
		
		
		
	Fix tests on JDK 21
Issue gh-12790 Issue gh-13811
This commit is contained in:
		
							parent
							
								
									d48b8697bd
								
							
						
					
					
						commit
						ecf8467cac
					
				| @ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
|  * Copyright 2002-2021 the original author or authors. |  * Copyright 2002-2023 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
| @ -20,6 +20,8 @@ import java.io.DataInputStream; | |||||||
| import java.io.InputStream; | import java.io.InputStream; | ||||||
| 
 | 
 | ||||||
| import org.junit.jupiter.api.Test; | import org.junit.jupiter.api.Test; | ||||||
|  | import org.junit.jupiter.api.condition.EnabledOnJre; | ||||||
|  | import org.junit.jupiter.api.condition.JRE; | ||||||
| 
 | 
 | ||||||
| import static org.assertj.core.api.Assertions.assertThat; | import static org.assertj.core.api.Assertions.assertThat; | ||||||
| 
 | 
 | ||||||
| @ -31,12 +33,21 @@ public class JavaVersionTests { | |||||||
| 
 | 
 | ||||||
| 	private static final int JDK17_CLASS_VERSION = 61; | 	private static final int JDK17_CLASS_VERSION = 61; | ||||||
| 
 | 
 | ||||||
|  | 	private static final int JDK21_CLASS_VERSION = 65; | ||||||
|  | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void authenticationCorrectJdkCompatibility() throws Exception { | 	@EnabledOnJre(JRE.JAVA_17) | ||||||
| 		assertClassVersion(Authentication.class); | 	public void authenticationWhenJdk17ThenCorrectJdkCompatibility() throws Exception { | ||||||
|  | 		assertClassVersion(Authentication.class, JDK17_CLASS_VERSION); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	private void assertClassVersion(Class<?> clazz) throws Exception { | 	@Test | ||||||
|  | 	@EnabledOnJre(JRE.JAVA_21) | ||||||
|  | 	public void authenticationWhenJdk21ThenCorrectJdkCompatibility() throws Exception { | ||||||
|  | 		assertClassVersion(Authentication.class, JDK21_CLASS_VERSION); | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	private void assertClassVersion(Class<?> clazz, int classVersion) throws Exception { | ||||||
| 		String classResourceName = clazz.getName().replaceAll("\\.", "/") + ".class"; | 		String classResourceName = clazz.getName().replaceAll("\\.", "/") + ".class"; | ||||||
| 		try (InputStream input = Thread.currentThread().getContextClassLoader() | 		try (InputStream input = Thread.currentThread().getContextClassLoader() | ||||||
| 				.getResourceAsStream(classResourceName)) { | 				.getResourceAsStream(classResourceName)) { | ||||||
| @ -44,7 +55,7 @@ public class JavaVersionTests { | |||||||
| 			data.readInt(); | 			data.readInt(); | ||||||
| 			data.readShort(); // minor | 			data.readShort(); // minor | ||||||
| 			int major = data.readShort(); | 			int major = data.readShort(); | ||||||
| 			assertThat(major).isEqualTo(JDK17_CLASS_VERSION); | 			assertThat(major).isEqualTo(classVersion); | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1,5 +1,5 @@ | |||||||
| /* | /* | ||||||
|  * Copyright 2002-2016 the original author or authors. |  * Copyright 2002-2023 the original author or authors. | ||||||
|  * |  * | ||||||
|  * Licensed under the Apache License, Version 2.0 (the "License"); |  * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||
|  * you may not use this file except in compliance with the License. |  * you may not use this file except in compliance with the License. | ||||||
| @ -62,7 +62,7 @@ public class TextEscapeUtilsTests { | |||||||
| 
 | 
 | ||||||
| 	@Test | 	@Test | ||||||
| 	public void undefinedSurrogatePairIsIgnored() { | 	public void undefinedSurrogatePairIsIgnored() { | ||||||
| 		assertThat(TextEscapeUtils.escapeEntities("abc\uD888\uDC00a")).isEqualTo("abca"); | 		assertThat(TextEscapeUtils.escapeEntities("abc\uDBFF\uDFFFa")).isEqualTo("abca"); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user