Browse Source

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
pull/31837/head
Sam Brannen 2 years ago
parent
commit
8d4deca2a6
  1. 33
      spring-context/src/test/java/org/springframework/beans/factory/xml/XmlBeanFactoryTests.java
  2. 9
      spring-context/src/test/resources/org/springframework/beans/factory/xml/XmlBeanFactoryTests-delegationOverrides.xml

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

@ -22,8 +22,13 @@ import java.io.InputStream; @@ -22,8 +22,13 @@ import java.io.InputStream;
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.ITestBean; @@ -56,6 +61,8 @@ import org.springframework.beans.testfixture.beans.ITestBean;
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 @@ class XmlBeanFactoryTests { @@ -1336,6 +1343,15 @@ class XmlBeanFactoryTests {
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 @@ class XmlBeanFactoryTests { @@ -1891,3 +1907,20 @@ class XmlBeanFactoryTests {
}
}
interface EchoService {
String[] echo(Object... objects);
}
class ReverseArrayMethodReplacer implements MethodReplacer {
@Override
public Object reimplement(Object obj, Method method, Object[] args) {
List<String> list = Arrays.stream((Object[]) args[0])
.map(Object::toString)
.collect(Collectors.toCollection(ArrayList::new));
Collections.reverse(list);
return list.toArray(String[]::new);
}
}

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

@ -36,12 +36,21 @@ @@ -36,12 +36,21 @@
<bean id="replaceVoidMethod" parent="someParent"
class="org.springframework.beans.factory.xml.OverrideOneMethodSubclass">
</bean>
<bean id="replaceEchoMethod" class="org.springframework.beans.factory.xml.EchoService">
<!--
This method is not overloaded, so we don't need to specify any arg types
-->
<replaced-method name="echo" replacer="reverseArrayReplacer" />
</bean>
<bean id="reverseReplacer"
class="org.springframework.beans.factory.xml.ReverseMethodReplacer"/>
<bean id="reverseArrayReplacer"
class="org.springframework.beans.factory.xml.ReverseArrayMethodReplacer"/>
<bean id="fixedReplacer"
class="org.springframework.beans.factory.xml.FixedMethodReplacer"/>

Loading…
Cancel
Save