Skip to content
Permalink
Browse files

Consistent handling of null array for arguments

Issue: SPR-16075
  • Loading branch information...
jhoeller committed Oct 16, 2017
1 parent 3890d4c commit c29b6f5b5565f8103faa288f3708cb9c736d7ee7
@@ -51,7 +51,7 @@
private String staticMethod;

@Nullable
private Object[] arguments = new Object[0];
private Object[] arguments;

/** The method we will call */
@Nullable
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -49,26 +49,36 @@ public void plainMethodInvoker() throws Exception {
Integer i = (Integer) mi.invoke();
assertEquals(1, i.intValue());

// defensive check: singleton, non-static should work with null array
tc1 = new TestClass1();
mi = new MethodInvoker();
mi.setTargetObject(tc1);
mi.setTargetMethod("method1");
mi.setArguments((Object[]) null);
mi.prepare();
i = (Integer) mi.invoke();
assertEquals(1, i.intValue());

// sanity check: check that argument count matching works
mi = new MethodInvoker();
mi.setTargetClass(TestClass1.class);
mi.setTargetMethod("supertypes");
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello"});
mi.setArguments(new ArrayList<>(), new ArrayList<>(), "hello");
mi.prepare();
assertEquals("hello", mi.invoke());

mi = new MethodInvoker();
mi.setTargetClass(TestClass1.class);
mi.setTargetMethod("supertypes2");
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello", "bogus"});
mi.setArguments(new ArrayList<>(), new ArrayList<>(), "hello", "bogus");
mi.prepare();
assertEquals("hello", mi.invoke());

// Sanity check: check that argument conversion doesn't work with plain MethodInvoker
mi = new MethodInvoker();
mi.setTargetClass(TestClass1.class);
mi.setTargetMethod("supertypes2");
mi.setArguments(new Object[] {new ArrayList<>(), new ArrayList<>(), "hello", Boolean.TRUE});
mi.setArguments(new ArrayList<>(), new ArrayList<>(), "hello", Boolean.TRUE);

exception.expect(NoSuchMethodException.class);
mi.prepare();
@@ -79,7 +89,7 @@ public void stringWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet");
methodInvoker.setArguments(new Object[] {"no match"});
methodInvoker.setArguments("no match");

exception.expect(NoSuchMethodException.class);
methodInvoker.prepare();
@@ -90,7 +100,7 @@ public void purchaserWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet");
methodInvoker.setArguments(new Object[] {new Purchaser()});
methodInvoker.setArguments(new Purchaser());
methodInvoker.prepare();
String greeting = (String) methodInvoker.invoke();
assertEquals("purchaser: hello", greeting);
@@ -101,7 +111,7 @@ public void shopperWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet");
methodInvoker.setArguments(new Object[] {new Shopper()});
methodInvoker.setArguments(new Shopper());
methodInvoker.prepare();
String greeting = (String) methodInvoker.invoke();
assertEquals("purchaser: may I help you?", greeting);
@@ -112,7 +122,7 @@ public void salesmanWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet");
methodInvoker.setArguments(new Object[] {new Salesman()});
methodInvoker.setArguments(new Salesman());
methodInvoker.prepare();
String greeting = (String) methodInvoker.invoke();
assertEquals("greetable: how are sales?", greeting);
@@ -123,7 +133,7 @@ public void customerWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet");
methodInvoker.setArguments(new Object[] {new Customer()});
methodInvoker.setArguments(new Customer());
methodInvoker.prepare();
String greeting = (String) methodInvoker.invoke();
assertEquals("customer: good day", greeting);
@@ -134,7 +144,7 @@ public void regularWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet");
methodInvoker.setArguments(new Object[] {new Regular("Kotter")});
methodInvoker.setArguments(new Regular("Kotter"));
methodInvoker.prepare();
String greeting = (String) methodInvoker.invoke();
assertEquals("regular: welcome back Kotter", greeting);
@@ -145,7 +155,7 @@ public void vipWithMethodInvoker() throws Exception {
MethodInvoker methodInvoker = new MethodInvoker();
methodInvoker.setTargetObject(new Greeter());
methodInvoker.setTargetMethod("greet");
methodInvoker.setArguments(new Object[] {new VIP("Fonzie")});
methodInvoker.setArguments(new VIP("Fonzie"));
methodInvoker.prepare();
String greeting = (String) methodInvoker.invoke();
assertEquals("regular: whassup dude?", greeting);

0 comments on commit c29b6f5

Please sign in to comment.
You can’t perform that action at this time.