Browse Source

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
pull/30243/head
Brian Clozel 2 years ago
parent
commit
fe6589d5af
  1. 24
      spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java

24
spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java

@ -1,5 +1,5 @@ @@ -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");
* you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.springframework.context.generator; @@ -18,6 +18,7 @@ package org.springframework.context.generator;
import java.util.function.BiConsumer;
import jakarta.annotation.PreDestroy;
import org.junit.jupiter.api.Test;
import org.springframework.aot.hint.RuntimeHints;
@ -80,6 +81,14 @@ class ApplicationContextAotGeneratorRuntimeHintsTests { @@ -80,6 +81,14 @@ class ApplicationContextAotGeneratorRuntimeHintsTests {
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" })
private void compile(GenericApplicationContext applicationContext, BiConsumer<RuntimeHints, RuntimeHintsInvocations> initializationResult) {
ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator();
@ -98,4 +107,17 @@ class ApplicationContextAotGeneratorRuntimeHintsTests { @@ -98,4 +107,17 @@ class ApplicationContextAotGeneratorRuntimeHintsTests {
});
}
public interface Destroyable {
@PreDestroy
default void destroy() {
}
}
public static class InheritedDestroy implements Destroyable {
}
}

Loading…
Cancel
Save