View Javadoc
1   /**
2    * Copyright 2005-2016 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.uif;
17  
18  import org.junit.Assert;
19  import org.junit.Test;
20  import org.kuali.rice.krad.uif.component.MethodInvokerConfig;
21  
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  /**
26   * This class MethodInvokerConfig
27   *
28   * @author Kuali Rice Team (rice.collab@kuali.org)
29   */
30  public class MethodInvokerConfigTest {
31  
32      @Test
33      public void testGetArgumentsTypes() {
34          // if arguments are not set, will select first match
35          checkGetArgumentTypes(TestMethodClass.class, "retrieveTestObject", 0, 1);
36  
37          checkGetArgumentTypes(TestMethodClass.class, "retrieveTestObject", 1, 1);
38          checkGetArgumentTypes(TestMethodClass.class, "retrieveTestObject", 2, 2);
39      }
40  
41      protected void checkGetArgumentTypes(Class targetClass, String methodName, int argumentTypeSize, int expectedSize) {
42          MethodInvokerConfig methodInvokerConfig = new MethodInvokerConfig();
43          methodInvokerConfig.setTargetClass(targetClass);
44          methodInvokerConfig.setTargetMethod(methodName);
45          methodInvokerConfig.setArguments(new Object[argumentTypeSize]);
46  
47          Class[] classes = methodInvokerConfig.getArgumentTypes();
48          Assert.assertEquals("Should return " + argumentTypeSize + " classes", expectedSize, classes.length);
49      }
50  
51      private class TestMethodClass {
52  
53          public List<Object> retrieveTestObject(String term1) {
54              return new ArrayList<Object>();
55          }
56  
57          public List<Object> retrieveTestObject(String term1, String term2) {
58              return new ArrayList<Object>();
59          }
60  
61      }
62  
63  }