@@ -182,18 +182,17 @@ boolean createUnitTest(Class<?> _clazz) throws IOException {
182182 }
183183
184184 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 ())
188187 .filter (c -> Modifier .isStatic (c .getModifiers ()))
189188 .map (Class ::getDeclaredMethods )
190189 .filter (arr -> arr .length > 0 )
191190 .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 )))
195192 .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
197196 .min (Comparator .comparingInt (Method ::getModifiers )
198197 // prioritize non-void return types
199198 .thenComparing ((m1 , m2 ) -> Integer .compare (m1 .getReturnType () == void .class ? -1 : 1 , m2 .getReturnType () == void .class ? -1 : 1 )))
0 commit comments