Do not invoke AotTestExecutionListener for @DisabledInAotMode tests
Closes gh-33589
This commit is contained in:
parent
602ac903ff
commit
5cc4d0a2ca
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -370,7 +370,7 @@ public class TestContextAotGenerator {
|
|||
registerDeclaredConstructors(testContextBootstrapper.getClass()); // @BootstrapWith
|
||||
testContextBootstrapper.getTestExecutionListeners().forEach(listener -> {
|
||||
registerDeclaredConstructors(listener.getClass()); // @TestExecutionListeners
|
||||
if (listener instanceof AotTestExecutionListener aotListener) {
|
||||
if (!isDisabledInAotMode.test(testClass) && listener instanceof AotTestExecutionListener aotListener) {
|
||||
aotListener.processAheadOfTime(this.runtimeHints, testClass, getClass().getClassLoader());
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
* Copyright 2002-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -19,26 +19,33 @@ package org.springframework.test.context.aot.samples.basic;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.aot.AotDetector;
|
||||
import org.springframework.aot.hint.RuntimeHints;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.TestExecutionListeners;
|
||||
import org.springframework.test.context.aot.AotTestExecutionListener;
|
||||
import org.springframework.test.context.aot.DisabledInAotMode;
|
||||
import org.springframework.test.context.aot.TestContextAotGenerator;
|
||||
import org.springframework.test.context.aot.samples.basic.DisabledInAotProcessingTests.BrokenAotTestExecutionListener;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.test.context.TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS;
|
||||
|
||||
/**
|
||||
* {@code @DisabledInAotMode} test class which verifies that the application context
|
||||
* for the test class is skipped during AOT processing.
|
||||
* for the test class is skipped during AOT processing and that an
|
||||
* {@link AotTestExecutionListener} is also not invoked.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 6.1
|
||||
*/
|
||||
@SpringJUnitConfig
|
||||
@DisabledInAotMode
|
||||
@TestExecutionListeners(listeners = BrokenAotTestExecutionListener.class, mergeMode = MERGE_WITH_DEFAULTS)
|
||||
public class DisabledInAotProcessingTests {
|
||||
|
||||
@Test
|
||||
|
@ -64,4 +71,12 @@ public class DisabledInAotProcessingTests {
|
|||
}
|
||||
}
|
||||
|
||||
static class BrokenAotTestExecutionListener implements AotTestExecutionListener {
|
||||
|
||||
@Override
|
||||
public void processAheadOfTime(RuntimeHints runtimeHints, Class<?> testClass, ClassLoader classLoader) {
|
||||
throw new UnsupportedOperationException("Broken AotTestExecutionListener");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue