Skip to content

Commit 67e0310

Browse files
committed
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 (76bc9cf). See gh-31826 Closes gh-31828 (cherry picked from commit 8d4deca)
1 parent 76bc9cf commit 67e0310

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java

+33
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@
2222
import java.io.InputStreamReader;
2323
import java.io.StringWriter;
2424
import java.lang.reflect.Method;
25+
import java.util.ArrayList;
26+
import java.util.Arrays;
27+
import java.util.Collections;
28+
import java.util.List;
2529
import java.util.Map;
2630
import java.util.concurrent.atomic.AtomicInteger;
31+
import java.util.stream.Collectors;
2732

2833
import org.apache.commons.logging.LogFactory;
2934
import org.junit.jupiter.api.Test;
@@ -56,6 +61,8 @@
5661
import org.springframework.beans.testfixture.beans.IndexedTestBean;
5762
import org.springframework.beans.testfixture.beans.TestBean;
5863
import org.springframework.beans.testfixture.beans.factory.DummyFactory;
64+
import org.springframework.context.ConfigurableApplicationContext;
65+
import org.springframework.context.support.ClassPathXmlApplicationContext;
5966
import org.springframework.core.io.ClassPathResource;
6067
import org.springframework.core.io.FileSystemResource;
6168
import org.springframework.core.io.UrlResource;
@@ -1336,6 +1343,15 @@ void replaceMethodOverrideWithSetterInjection() {
13361343
assertThat(dos.lastArg).isEqualTo(s2);
13371344
}
13381345

1346+
@Test // gh-31826
1347+
void replaceNonOverloadedInterfaceMethodWithoutSpecifyingExplicitArgTypes() {
1348+
try (ConfigurableApplicationContext context =
1349+
new ClassPathXmlApplicationContext(DELEGATION_OVERRIDES_CONTEXT.getPath())) {
1350+
EchoService echoService = context.getBean(EchoService.class);
1351+
assertThat(echoService.echo("foo", "bar")).containsExactly("bar", "foo");
1352+
}
1353+
}
1354+
13391355
@Test
13401356
void lookupOverrideOneMethodWithConstructorInjection() {
13411357
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
@@ -1891,3 +1907,20 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
18911907
}
18921908

18931909
}
1910+
1911+
interface EchoService {
1912+
1913+
String[] echo(Object... objects);
1914+
}
1915+
1916+
class ReverseArrayMethodReplacer implements MethodReplacer {
1917+
1918+
@Override
1919+
public Object reimplement(Object obj, Method method, Object[] args) {
1920+
List<String> list = Arrays.stream((Object[]) args[0])
1921+
.map(Object::toString)
1922+
.collect(Collectors.toCollection(ArrayList::new));
1923+
Collections.reverse(list);
1924+
return list.toArray(String[]::new);
1925+
}
1926+
}

spring-context/src/test/resources/org/springframework/beans/factory/xml/XmlBeanFactoryTests-delegationOverrides.xml

+9
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,21 @@
3636

3737
<bean id="replaceVoidMethod" parent="someParent"
3838
class="org.springframework.beans.factory.xml.OverrideOneMethodSubclass">
39+
</bean>
3940

41+
<bean id="replaceEchoMethod" class="org.springframework.beans.factory.xml.EchoService">
42+
<!--
43+
This method is not overloaded, so we don't need to specify any arg types
44+
-->
45+
<replaced-method name="echo" replacer="reverseArrayReplacer" />
4046
</bean>
4147

4248
<bean id="reverseReplacer"
4349
class="org.springframework.beans.factory.xml.ReverseMethodReplacer"/>
4450

51+
<bean id="reverseArrayReplacer"
52+
class="org.springframework.beans.factory.xml.ReverseArrayMethodReplacer"/>
53+
4554
<bean id="fixedReplacer"
4655
class="org.springframework.beans.factory.xml.FixedMethodReplacer"/>
4756

0 commit comments

Comments
 (0)