@@ -182,18 +182,17 @@ boolean createUnitTest(Class<?> _clazz) throws IOException {
182
182
}
183
183
184
184
Method findTestMethod (Class <?> _clazz ) {
185
- Method [] methods = _clazz .getDeclaredMethods ();
186
- if (methods .length == 0 ) {
187
- methods = Arrays .stream (_clazz .getDeclaredClasses ())
185
+ List <Method > list = Arrays .stream (_clazz .getDeclaredMethods ().length > 0 ? _clazz .getDeclaredMethods () :
186
+ Arrays .stream (_clazz .getDeclaredClasses ())
188
187
.filter (c -> Modifier .isStatic (c .getModifiers ()))
189
188
.map (Class ::getDeclaredMethods )
190
189
.filter (arr -> arr .length > 0 )
191
190
.findFirst ().orElseThrow (
192
- () -> new LeetcodeRuntimeException ("No non-static methods found in inner classes of " + _clazz ));
193
- }
194
- return Arrays .stream (methods )
191
+ () -> new LeetcodeRuntimeException ("No non-static methods found in inner classes of " + _clazz )))
195
192
.filter (m -> !Modifier .isStatic (m .getModifiers ()))
196
- .filter (m -> !Modifier .isPrivate (m .getModifiers ()))
193
+ .filter (m -> !Modifier .isPrivate (m .getModifiers ())).collect (Collectors .toCollection (ArrayList ::new ));
194
+ return IntStream .rangeClosed (1 , list .size ())
195
+ .mapToObj (i -> list .get (list .size () - i )) // establish order of methods in source code
197
196
.min (Comparator .comparingInt (Method ::getModifiers )
198
197
// prioritize non-void return types
199
198
.thenComparing ((m1 , m2 ) -> Integer .compare (m1 .getReturnType () == void .class ? -1 : 1 , m2 .getReturnType () == void .class ? -1 : 1 )))
0 commit comments