Java Code Examples for org.springframework.util.MethodInvoker#setTargetClass()

The following examples show how to use org.springframework.util.MethodInvoker#setTargetClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReflectionUtils.java    From embedded-database-spring-test with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static <T> T invokeStaticMethod(Class<?> targetClass, String name, Object... args) {
    Assert.notNull(targetClass, "Target class must not be null");
    Assert.hasText(name, "Method name must not be empty");

    try {
        MethodInvoker methodInvoker = new MethodInvoker();
        methodInvoker.setTargetClass(targetClass);
        methodInvoker.setTargetMethod(name);
        methodInvoker.setArguments(args);
        methodInvoker.prepare();
        return (T) methodInvoker.invoke();
    } catch (Exception ex) {
        org.springframework.util.ReflectionUtils.handleReflectionException(ex);
        throw new IllegalStateException("Should never get here");
    }
}
 
Example 2
Source File: MethodInvokingFactoryBeanTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testInvokeWithNullArgument() throws Exception {
	MethodInvoker methodInvoker = new MethodInvoker();
	methodInvoker.setTargetClass(TestClass1.class);
	methodInvoker.setTargetMethod("nullArgument");
	methodInvoker.setArguments(new Object[] {null});
	methodInvoker.prepare();
	methodInvoker.invoke();
}
 
Example 3
Source File: MethodInvokingFactoryBeanTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testInvokeWithNullArgument() throws Exception {
	MethodInvoker methodInvoker = new MethodInvoker();
	methodInvoker.setTargetClass(TestClass1.class);
	methodInvoker.setTargetMethod("nullArgument");
	methodInvoker.setArguments(new Object[] {null});
	methodInvoker.prepare();
	methodInvoker.invoke();
}
 
Example 4
Source File: MethodInvokingFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvokeWithNullArgument() throws Exception {
	MethodInvoker methodInvoker = new MethodInvoker();
	methodInvoker.setTargetClass(TestClass1.class);
	methodInvoker.setTargetMethod("nullArgument");
	methodInvoker.setArguments(new Object[] {null});
	methodInvoker.prepare();
	methodInvoker.invoke();
}