Skip to content

Commit 57532c6

Browse files
committed
Fix tests regarding Native Image baseline on JDKs < 25
See gh-47433
1 parent 2890bd8 commit 57532c6

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

core/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1661,13 +1661,13 @@ public AbandonedRunException(@Nullable ConfigurableApplicationContext applicatio
16611661
/**
16621662
* Exception which is thrown if GraalVM's native-image requirements aren't met.
16631663
*/
1664-
private static final class NativeImageRequirementsNotMetException extends RuntimeException {
1664+
static final class NativeImageRequirementsNotMetException extends RuntimeException {
16651665

16661666
/**
16671667
* Creates a new {@link NativeImageRequirementsNotMetException} instance.
16681668
* @param message the message
16691669
*/
1670-
private NativeImageRequirementsNotMetException(String message) {
1670+
NativeImageRequirementsNotMetException(String message) {
16711671
super(message);
16721672
}
16731673

core/spring-boot/src/test/java/org/springframework/boot/SpringApplicationTests.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import org.junit.jupiter.api.AfterEach;
3838
import org.junit.jupiter.api.BeforeEach;
3939
import org.junit.jupiter.api.Test;
40+
import org.junit.jupiter.api.condition.EnabledForJreRange;
41+
import org.junit.jupiter.api.condition.JRE;
4042
import org.junit.jupiter.api.extension.ExtendWith;
4143
import org.mockito.ArgumentMatcher;
4244
import org.mockito.ArgumentMatchers;
@@ -57,6 +59,7 @@
5759
import org.springframework.beans.factory.support.BeanNameGenerator;
5860
import org.springframework.beans.factory.support.DefaultBeanNameGenerator;
5961
import org.springframework.boot.Banner.Mode;
62+
import org.springframework.boot.SpringApplication.NativeImageRequirementsNotMetException;
6063
import org.springframework.boot.availability.AvailabilityChangeEvent;
6164
import org.springframework.boot.availability.AvailabilityState;
6265
import org.springframework.boot.availability.LivenessState;
@@ -744,6 +747,24 @@ void failureOnTheJvmLogsApplicationRunFailed(CapturedOutput output) {
744747

745748
@Test
746749
@ForkedClassPath
750+
@EnabledForJreRange(max = JRE.JAVA_24)
751+
void nativeImageShouldCheckForJava25() {
752+
System.setProperty("org.graalvm.nativeimage.imagecode", "true");
753+
try {
754+
SpringApplication application = new SpringApplication();
755+
application.setWebApplicationType(WebApplicationType.NONE);
756+
assertThatExceptionOfType(NativeImageRequirementsNotMetException.class).isThrownBy(application::run)
757+
.withMessage(
758+
"Native Image requirements not met, please upgrade it. Native Image must support at least Java 25");
759+
}
760+
finally {
761+
System.clearProperty("org.graalvm.nativeimage.imagecode");
762+
}
763+
}
764+
765+
@Test
766+
@ForkedClassPath
767+
@EnabledForJreRange(min = JRE.JAVA_25)
747768
void failureInANativeImageWritesFailureToSystemOut(CapturedOutput output) {
748769
System.setProperty("org.graalvm.nativeimage.imagecode", "true");
749770
try {

0 commit comments

Comments
 (0)