1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 import org.junit.jupiter.api.AfterEach;
27 import org.junit.jupiter.api.BeforeEach;
28
29 class MethodFixtures extends AbstractLangTest {
30
31 static MethodFixtures INSTANCE = new MethodFixtures();
32
33 static Method getDeclaredMethod(final String name, final Class<?>... parameterTypes) throws NoSuchMethodException, SecurityException {
34 return MethodFixtures.class.getDeclaredMethod(name, parameterTypes);
35 }
36
37 static Method getMethodForGetString() throws NoSuchMethodException, SecurityException {
38 return getDeclaredMethod("getString");
39 }
40
41 static Method getMethodForGetString1Arg() throws NoSuchMethodException, SecurityException {
42 return getDeclaredMethod("getString1Arg", String.class);
43 }
44
45 static Method getMethodForGetString1ArgChecked() throws NoSuchMethodException, SecurityException {
46 return getDeclaredMethod("getString1ArgChecked", String.class);
47 }
48
49 static Method getMethodForGetString1ArgThrowsChecked() throws NoSuchMethodException, SecurityException {
50 return getDeclaredMethod("getString1ArgThrowsChecked", String.class);
51 }
52
53 static Method getMethodForGetString1ArgThrowsUnchecked() throws NoSuchMethodException, SecurityException {
54 return getDeclaredMethod("getString1ArgThrowsUnchecked", String.class);
55 }
56
57 static Method getMethodForGetString2Arg() throws NoSuchMethodException, SecurityException {
58 return getDeclaredMethod("getString2Args", String.class, String.class);
59 }
60
61 static Method getMethodForGetStringChecked() throws NoSuchMethodException, SecurityException {
62 return getDeclaredMethod("getStringChecked");
63 }
64
65 static Method getMethodForGetStringsVarArg() throws NoSuchMethodException, SecurityException {
66 return getDeclaredMethod("getStringArrayVarStringArgs", String[].class);
67 }
68
69 static Method getMethodForGetStringThrowsChecked() throws NoSuchMethodException, SecurityException {
70 return getDeclaredMethod("getStringThrowsChecked");
71 }
72
73 static Method getMethodForGetStringThrowsUnchecked() throws NoSuchMethodException, SecurityException {
74 return getDeclaredMethod("getStringThrowsUnchecked");
75 }
76
77 static Method getMethodForGetStringVarStringArgs() throws NoSuchMethodException, SecurityException {
78 return getDeclaredMethod("geStringtVarStringArgs", String[].class);
79 }
80
81 static Method getMethodForSetString1Arg() throws NoSuchMethodException, SecurityException {
82 return getDeclaredMethod("setValue1", String.class);
83 }
84
85 static Method getMethodForSetString1ArgThrows() throws NoSuchMethodException, SecurityException {
86 return getDeclaredMethod("setValue1Throws", String.class);
87 }
88
89 static Method getMethodForSetString1ArgThrowsChecked() throws NoSuchMethodException, SecurityException {
90 return getDeclaredMethod("setValue1ThrowsChecked", String.class);
91 }
92
93 static Method getMethodForSetString1ArgThrowsUnchecked() throws NoSuchMethodException, SecurityException {
94 return getDeclaredMethod("setValue1ThrowsUnchecked", String.class);
95 }
96
97 static Method getMethodForSetString2Args() throws NoSuchMethodException, SecurityException {
98 return getDeclaredMethod("setValue1And2", String.class, String.class);
99 }
100
101 static Method getMethodForSetStringsVarArg() throws NoSuchMethodException, SecurityException {
102 return getDeclaredMethod("setValueArray", String[].class);
103 }
104
105 static Method getMethodForStaticGetString() throws NoSuchMethodException, SecurityException {
106 return getDeclaredMethod("staticGetString");
107 }
108
109 static Method getMethodForVoidMethod() throws NoSuchMethodException, SecurityException {
110 return getDeclaredMethod("voidMethod");
111 }
112
113 public static String staticGetString() {
114 return "Static.ABC";
115 }
116
117 private String value1;
118
119 private String value2;
120
121 private String[] valueArray;
122
123 @BeforeEach
124 @AfterEach
125 public void clear() {
126 value1 = null;
127 value1 = null;
128 valueArray = null;
129 }
130
131 public String geStringtVarStringArgs(final String... strings) {
132 return "XYZ";
133 }
134
135 @AnnotationTestFixture
136 public String getString() {
137 return "ABC";
138 }
139
140 public String getString1Arg(final String value) {
141 return value;
142 }
143
144 @SuppressWarnings("unused")
145 public String getString1ArgChecked(final String value) throws IOException {
146 return value;
147 }
148
149 public String getString1ArgThrowsChecked(final String value) throws CustomCheckedException {
150 throw new CustomCheckedException("getString1ArgThrowsChecked");
151 }
152
153 public String getString1ArgThrowsUnchecked(final String value) {
154 throw new CustomUncheckedException("getString1ArgThrowsUnchecked");
155 }
156
157 @AnnotationTestFixture
158 public String getString2() {
159 return "EFG";
160 }
161
162 public String getString2Args(final String value1, final String value2) {
163 return value1 + value2;
164 }
165
166 public String[] getStringArrayVarStringArgs(final String... strings) {
167 return strings;
168 }
169
170 public String getStringChecked() throws Exception {
171 return "ABC";
172 }
173
174 public String getStringThrowsChecked() throws CustomCheckedException {
175 throw new CustomCheckedException("getStringThrowsChecked");
176 }
177
178 public String getStringThrowsUnchecked() {
179 throw new CustomUncheckedException("getStringThrowsUnchecked");
180 }
181
182 String getValue1() {
183 return value1;
184 }
185
186 String getValue2() {
187 return value2;
188 }
189
190 String[] getValueArray() {
191 return valueArray;
192 }
193
194 void setValue1(final String value1) throws Exception {
195 this.value1 = value1;
196 }
197
198 void setValue1And2(final String value1, final String value2) throws Exception {
199 this.value1 = value1;
200 this.value2 = value2;
201 }
202
203 void setValue1ThrowsChecked(final String value1) throws CustomCheckedException {
204 throw new CustomCheckedException("setValue1ThrowsChecked");
205 }
206
207 void setValue1ThrowsUnchecked(final String value1) {
208 throw new CustomUncheckedException("setValue1ThrowsUnchecked");
209 }
210
211 void setValue2(final String value2) {
212 this.value2 = value2;
213 }
214
215 void setValueArray(final String... values) throws Exception {
216 this.valueArray = values;
217 }
218
219 public void voidMethod() {
220
221 }
222
223 }