From fe6589d5afdc049a9f136a039e6ddf0f7325c171 Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Thu, 30 Mar 2023 14:42:19 +0200 Subject: [PATCH] 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 --- ...nContextAotGeneratorRuntimeHintsTests.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java b/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java index a570748108f..311b63b1a71 100644 --- a/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java +++ b/spring-context/src/test/java/org/springframework/context/generator/ApplicationContextAotGeneratorRuntimeHintsTests.java @@ -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; 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 { 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 initializationResult) { ApplicationContextAotGenerator generator = new ApplicationContextAotGenerator(); @@ -98,4 +107,17 @@ class ApplicationContextAotGeneratorRuntimeHintsTests { }); } + public interface Destroyable { + + @PreDestroy + default void destroy() { + + } + + } + + public static class InheritedDestroy implements Destroyable { + + } + }