From 8d4deca2a658d8ea456a18ecce8a7418373030c4 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Wed, 13 Dec 2023 15:00:44 +0100 Subject: [PATCH] Introduce test for XML replaced-method element without explicit arg-type This commit introduces an integration test for the regression fixed in the previous commit (cd64e6676c). Closes gh-31826 --- .../factory/xml/XmlBeanFactoryTests.java | 33 +++++++++++++++++++ ...mlBeanFactoryTests-delegationOverrides.xml | 9 +++++ 2 files changed, 42 insertions(+) diff --git a/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java b/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java index 795e1694d3cd..42106fcf1611 100644 --- a/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java +++ b/spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java @@ -22,8 +22,13 @@ import java.io.InputStreamReader; import java.io.StringWriter; import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import org.apache.commons.logging.LogFactory; import org.junit.jupiter.api.Test; @@ -56,6 +61,8 @@ import org.springframework.beans.testfixture.beans.IndexedTestBean; import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.beans.testfixture.beans.factory.DummyFactory; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.FileSystemResource; import org.springframework.core.io.UrlResource; @@ -1336,6 +1343,15 @@ void replaceMethodOverrideWithSetterInjection() { assertThat(dos.lastArg).isEqualTo(s2); } + @Test // gh-31826 + void replaceNonOverloadedInterfaceMethodWithoutSpecifyingExplicitArgTypes() { + try (ConfigurableApplicationContext context = + new ClassPathXmlApplicationContext(DELEGATION_OVERRIDES_CONTEXT.getPath())) { + EchoService echoService = context.getBean(EchoService.class); + assertThat(echoService.echo("foo", "bar")).containsExactly("bar", "foo"); + } + } + @Test void lookupOverrideOneMethodWithConstructorInjection() { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); @@ -1891,3 +1907,20 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw } } + +interface EchoService { + + String[] echo(Object... objects); +} + +class ReverseArrayMethodReplacer implements MethodReplacer { + + @Override + public Object reimplement(Object obj, Method method, Object[] args) { + List list = Arrays.stream((Object[]) args[0]) + .map(Object::toString) + .collect(Collectors.toCollection(ArrayList::new)); + Collections.reverse(list); + return list.toArray(String[]::new); + } +} diff --git a/spring-context/src/test/resources/org/springframework/beans/factory/xml/XmlBeanFactoryTests-delegationOverrides.xml b/spring-context/src/test/resources/org/springframework/beans/factory/xml/XmlBeanFactoryTests-delegationOverrides.xml index 175408a2cb39..208fdf7b8f3c 100644 --- a/spring-context/src/test/resources/org/springframework/beans/factory/xml/XmlBeanFactoryTests-delegationOverrides.xml +++ b/spring-context/src/test/resources/org/springframework/beans/factory/xml/XmlBeanFactoryTests-delegationOverrides.xml @@ -36,12 +36,21 @@ + + + + + +