mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-10-01 06:49:42 +00:00
Fix tests regarding Native Image baseline on JDKs < 25
See gh-47433
This commit is contained in:
@@ -1661,13 +1661,13 @@ public class SpringApplication {
|
||||
/**
|
||||
* Exception which is thrown if GraalVM's native-image requirements aren't met.
|
||||
*/
|
||||
private static final class NativeImageRequirementsNotMetException extends RuntimeException {
|
||||
static final class NativeImageRequirementsNotMetException extends RuntimeException {
|
||||
|
||||
/**
|
||||
* Creates a new {@link NativeImageRequirementsNotMetException} instance.
|
||||
* @param message the message
|
||||
*/
|
||||
private NativeImageRequirementsNotMetException(String message) {
|
||||
NativeImageRequirementsNotMetException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,8 @@ import org.jspecify.annotations.Nullable;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledForJreRange;
|
||||
import org.junit.jupiter.api.condition.JRE;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.ArgumentMatchers;
|
||||
@@ -57,6 +59,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||
import org.springframework.beans.factory.support.BeanNameGenerator;
|
||||
import org.springframework.beans.factory.support.DefaultBeanNameGenerator;
|
||||
import org.springframework.boot.Banner.Mode;
|
||||
import org.springframework.boot.SpringApplication.NativeImageRequirementsNotMetException;
|
||||
import org.springframework.boot.availability.AvailabilityChangeEvent;
|
||||
import org.springframework.boot.availability.AvailabilityState;
|
||||
import org.springframework.boot.availability.LivenessState;
|
||||
@@ -744,6 +747,24 @@ class SpringApplicationTests {
|
||||
|
||||
@Test
|
||||
@ForkedClassPath
|
||||
@EnabledForJreRange(max = JRE.JAVA_24)
|
||||
void nativeImageShouldCheckForJava25() {
|
||||
System.setProperty("org.graalvm.nativeimage.imagecode", "true");
|
||||
try {
|
||||
SpringApplication application = new SpringApplication();
|
||||
application.setWebApplicationType(WebApplicationType.NONE);
|
||||
assertThatExceptionOfType(NativeImageRequirementsNotMetException.class).isThrownBy(application::run)
|
||||
.withMessage(
|
||||
"Native Image requirements not met, please upgrade it. Native Image must support at least Java 25");
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("org.graalvm.nativeimage.imagecode");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ForkedClassPath
|
||||
@EnabledForJreRange(min = JRE.JAVA_25)
|
||||
void failureInANativeImageWritesFailureToSystemOut(CapturedOutput output) {
|
||||
System.setProperty("org.graalvm.nativeimage.imagecode", "true");
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user