View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.commons.lang3.function;
19  
20  import java.io.IOException;
21  import java.lang.reflect.Method;
22  
23  import org.apache.commons.lang3.AbstractLangTest;
24  import org.apache.commons.lang3.exception.CustomCheckedException;
25  import org.apache.commons.lang3.exception.CustomUncheckedException;
26  
27  class MethodFixtures extends AbstractLangTest {
28  
29      static MethodFixtures INSTANCE = new MethodFixtures();
30  
31      static Method getDeclaredMethod(final String name, final Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
32          return MethodFixtures.class.getDeclaredMethod(name, parameterTypes);
33      }
34  
35      static Method getMethodForGetString() throws NoSuchMethodException, SecurityException {
36          return getDeclaredMethod("getString");
37      }
38  
39      static Method getMethodForGetString1Arg() throws NoSuchMethodException, SecurityException {
40          return getDeclaredMethod("getString1Arg", String.class);
41      }
42  
43      static Method getMethodForGetString1ArgChecked() throws NoSuchMethodException, SecurityException {
44          return getDeclaredMethod("getString1ArgChecked", String.class);
45      }
46  
47      static Method getMethodForGetString1ArgThrowsChecked() throws NoSuchMethodException, SecurityException {
48          return getDeclaredMethod("getString1ArgThrowsChecked", String.class);
49      }
50  
51      static Method getMethodForGetString1ArgThrowsUnchecked() throws NoSuchMethodException, SecurityException {
52          return getDeclaredMethod("getString1ArgThrowsUnchecked", String.class);
53      }
54  
55      static Method getMethodForGetString2Arg() throws NoSuchMethodException, SecurityException {
56          return getDeclaredMethod("getString2Args", String.class, String.class);
57      }
58  
59      static Method getMethodForGetStringChecked() throws NoSuchMethodException, SecurityException {
60          return getDeclaredMethod("getStringChecked");
61      }
62  
63      static Method getMethodForGetStringsVarArg() throws NoSuchMethodException, SecurityException {
64          return getDeclaredMethod("getStringArrayVarStringArgs", String[].class);
65      }
66  
67      static Method getMethodForGetStringThrowsChecked() throws NoSuchMethodException, SecurityException {
68          return getDeclaredMethod("getStringThrowsChecked");
69      }
70  
71      static Method getMethodForGetStringThrowsUnchecked() throws NoSuchMethodException, SecurityException {
72          return getDeclaredMethod("getStringThrowsUnchecked");
73      }
74  
75      static Method getMethodForGetStringVarStringArgs() throws NoSuchMethodException, SecurityException {
76          return getDeclaredMethod("geStringtVarStringArgs", String[].class);
77      }
78  
79      static Method getMethodForSetString1Arg() throws NoSuchMethodException, SecurityException {
80          return getDeclaredMethod("setValue1", String.class);
81      }
82  
83      static Method getMethodForSetString1ArgThrows() throws NoSuchMethodException, SecurityException {
84          return getDeclaredMethod("setValue1Throws", String.class);
85      }
86  
87      static Method getMethodForSetString1ArgThrowsChecked() throws NoSuchMethodException, SecurityException {
88          return getDeclaredMethod("setValue1ThrowsChecked", String.class);
89      }
90  
91      static Method getMethodForSetString1ArgThrowsUnchecked() throws NoSuchMethodException, SecurityException {
92          return getDeclaredMethod("setValue1ThrowsUnchecked", String.class);
93      }
94  
95      static Method getMethodForSetString2Args() throws NoSuchMethodException, SecurityException {
96          return getDeclaredMethod("setValue1And2", String.class, String.class);
97      }
98  
99      static Method getMethodForSetStringsVarArg() throws NoSuchMethodException, SecurityException {
100         return getDeclaredMethod("setValueArray", String[].class);
101     }
102 
103     static Method getMethodForStaticGetString() throws NoSuchMethodException, SecurityException {
104         return getDeclaredMethod("staticGetString");
105     }
106 
107     static Method getMethodForVoidMethod() throws NoSuchMethodException, SecurityException {
108         return getDeclaredMethod("voidMethod");
109     }
110 
111     public static String staticGetString() {
112         return "Static.ABC";
113     }
114 
115     private String value1;
116 
117     private String value2;
118 
119     private String[] valueArray;
120 
121     public String geStringtVarStringArgs(final String... strings) {
122         return "XYZ";
123     }
124 
125     @AnnotationTestFixture
126     public String getString() {
127         return "ABC";
128     }
129 
130     public String getString1Arg(final String value) {
131         return value;
132     }
133 
134     @SuppressWarnings("unused") // IOException is declared but never thrown.
135     public String getString1ArgChecked(final String value) throws IOException {
136         return value;
137     }
138 
139     public String getString1ArgThrowsChecked(final String value) throws CustomCheckedException {
140         throw new CustomCheckedException("getString1ArgThrowsChecked");
141     }
142 
143     public String getString1ArgThrowsUnchecked(final String value) {
144         throw new CustomUncheckedException("getString1ArgThrowsUnchecked");
145     }
146 
147     @AnnotationTestFixture
148     public String getString2() {
149         return "EFG";
150     }
151 
152     public String getString2Args(final String value1, final String value2) {
153         return value1 + value2;
154     }
155 
156     public String[] getStringArrayVarStringArgs(final String... strings) {
157         return strings;
158     }
159 
160     public String getStringChecked() throws Exception {
161         return "ABC";
162     }
163 
164     public String getStringThrowsChecked() throws CustomCheckedException {
165         throw new CustomCheckedException("getStringThrowsChecked");
166     }
167 
168     public String getStringThrowsUnchecked() {
169         throw new CustomUncheckedException("getStringThrowsUnchecked");
170     }
171 
172     String getValue1() {
173         return value1;
174     }
175 
176     String getValue2() {
177         return value2;
178     }
179 
180     String[] getValueArray() {
181         return valueArray;
182     }
183 
184     void setValue1(final String value1) throws Exception {
185         this.value1 = value1;
186     }
187 
188     void setValue1And2(final String value1, final String value2) throws Exception {
189         this.value1 = value1;
190         this.value2 = value2;
191     }
192 
193     void setValue1ThrowsChecked(final String value1) throws CustomCheckedException {
194         throw new CustomCheckedException("setValue1ThrowsChecked");
195     }
196 
197     void setValue1ThrowsUnchecked(final String value1) {
198         throw new CustomUncheckedException("setValue1ThrowsUnchecked");
199     }
200 
201     void setValue2(final String value2) {
202         this.value2 = value2;
203     }
204 
205     void setValueArray(final String... values) throws Exception {
206         this.valueArray = values;
207     }
208 
209     public void voidMethod() {
210         // noop
211     }
212 
213 }