Extracted simple MethodInvokingBean as alternative to (and base class for) MethodInvokingFactoryBean

Issue: SPR-11196
This commit is contained in:
Juergen Hoeller
2014-03-17 15:13:59 +01:00
parent a8577da30c
commit cf290ab42a
3 changed files with 185 additions and 122 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 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.
@@ -16,26 +16,27 @@
package org.springframework.beans.factory.config;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.junit.Test;
import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.beans.support.ArgumentConvertingMethodInvoker;
import org.springframework.util.MethodInvoker;
import static org.junit.Assert.*;
/**
* Unit tests for {@link MethodInvokingFactoryBean}.
* Unit tests for {@link MethodInvokingFactoryBean} and {@link MethodInvokingBean}.
*
* @author Colin Sampaleanu
* @author Juergen Hoeller
* @author Chris Beams
* @since 21.11.2003
*/
public final class MethodInvokingFactoryBeanTests {
public class MethodInvokingFactoryBeanTests {
@Test
public void testParameterValidation() throws Exception {
@@ -246,7 +247,7 @@ public final class MethodInvokingFactoryBeanTests {
mcfb = new MethodInvokingFactoryBean();
mcfb.setTargetClass(TestClass1.class);
mcfb.setTargetMethod("supertypes");
mcfb.setArguments(new Object[] {new Integer(1), new Object()});
mcfb.setArguments(new Object[] {1, new Object()});
try {
mcfb.afterPropertiesSet();
mcfb.getObject();
@@ -291,7 +292,7 @@ public final class MethodInvokingFactoryBeanTests {
ArgumentConvertingMethodInvoker methodInvoker = new ArgumentConvertingMethodInvoker();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArgument");
methodInvoker.setArguments(new Object[] {new Integer(5)});
methodInvoker.setArguments(new Object[] {5});
methodInvoker.prepare();
methodInvoker.invoke();
@@ -305,49 +306,44 @@ public final class MethodInvokingFactoryBeanTests {
@Test
public void testInvokeWithIntArguments() throws Exception {
ArgumentConvertingMethodInvoker methodInvoker = new ArgumentConvertingMethodInvoker();
MethodInvokingBean methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new Object[] {new Integer[] {new Integer(5), new Integer(10)}});
methodInvoker.prepare();
methodInvoker.invoke();
methodInvoker.setArguments(new Object[]{new Integer[] {5, 10}});
methodInvoker.afterPropertiesSet();
methodInvoker = new ArgumentConvertingMethodInvoker();
methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new Object[] {new String[] {"5", "10"}});
methodInvoker.prepare();
methodInvoker.invoke();
methodInvoker.setArguments(new Object[]{new String[]{"5", "10"}});
methodInvoker.afterPropertiesSet();
methodInvoker = new ArgumentConvertingMethodInvoker();
methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new Integer[] {new Integer(5), new Integer(10)});
methodInvoker.prepare();
methodInvoker.invoke();
methodInvoker.setArguments(new Object[]{new Integer[] {5, 10}});
methodInvoker.afterPropertiesSet();
methodInvoker = new ArgumentConvertingMethodInvoker();
methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new String[] {"5", "10"});
methodInvoker.prepare();
methodInvoker.invoke();
methodInvoker.setArguments(new String[]{"5", "10"});
methodInvoker.afterPropertiesSet();
methodInvoker = new ArgumentConvertingMethodInvoker();
methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new Object[] {new Integer(5), new Integer(10)});
methodInvoker.prepare();
methodInvoker.invoke();
methodInvoker.setArguments(new Object[]{new Integer[] {5, 10}});
methodInvoker.afterPropertiesSet();
methodInvoker = new ArgumentConvertingMethodInvoker();
methodInvoker = new MethodInvokingBean();
methodInvoker.setTargetClass(TestClass1.class);
methodInvoker.setTargetMethod("intArguments");
methodInvoker.setArguments(new Object[] {"5", "10"});
methodInvoker.prepare();
methodInvoker.invoke();
methodInvoker.setArguments(new Object[]{"5", "10"});
methodInvoker.afterPropertiesSet();
}
public static class TestClass1 {
public static int _staticField1;
@@ -395,5 +391,4 @@ public final class MethodInvokingFactoryBeanTests {
}
}
}