Add runtime hint test for inherited destroy methods
This commit ensures that init/destroy methods that are provided as default methods from interfaces are properly covered by runtime hints at runtime. Closes gh-29246
This commit is contained in:
parent
b374824319
commit
fe6589d5af
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2022 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.
|
||||||
|
|
@ -18,6 +18,7 @@ package org.springframework.context.generator;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
|
import jakarta.annotation.PreDestroy;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import org.springframework.aot.hint.RuntimeHints;
|
import org.springframework.aot.hint.RuntimeHints;
|
||||||
|
|
@ -80,6 +81,14 @@ class ApplicationContextAotGeneratorRuntimeHintsTests {
|
||||||
compile(context, (hints, invocations) -> assertThat(invocations).match(hints));
|
compile(context, (hints, invocations) -> assertThat(invocations).match(hints));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void generateApplicationContextWithInheritedDestroyMethods() {
|
||||||
|
GenericApplicationContext context = new AnnotationConfigApplicationContext();
|
||||||
|
RootBeanDefinition beanDefinition = new RootBeanDefinition(InheritedDestroy.class);
|
||||||
|
context.registerBeanDefinition("initDestroyComponent", beanDefinition);
|
||||||
|
compile(context, (hints, invocations) -> assertThat(invocations).match(hints));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||||
private void compile(GenericApplicationContext applicationContext, BiConsumer<RuntimeHints, RuntimeHintsInvocations> initializationResult) {
|
private void compile(GenericApplicationContext applicationContext, BiConsumer<RuntimeHints, RuntimeHintsInvocations> initializationResult) {
|
||||||
ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator();
|
ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator();
|
||||||
|
|
@ -98,4 +107,17 @@ class ApplicationContextAotGeneratorRuntimeHintsTests {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface Destroyable {
|
||||||
|
|
||||||
|
@PreDestroy
|
||||||
|
default void destroy() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class InheritedDestroy implements Destroyable {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue