@Test public void validateArgsMismatchContent() throws NoSuchMethodException { BiConsumer<Method, String> validateBasics = (method, s) -> { s = s.toLowerCase(); assertTrue(s.contains(method.getName().toLowerCase())); assertTrue(s.contains(method.getReturnType().getSimpleName().toLowerCase())); assertTrue(s.contains(String.valueOf(method.getParameterCount()))); }; Method voidReturn = ReflTestClass.class.getMethod("methodWithLotsOfParams", int.class, int.class, int.class, int.class, int.class, int.class, int.class); String voidReturnDescriptor = ReflectionUtil.getArgMismatchString(voidReturn); validateBasics.accept(voidReturn, voidReturnDescriptor); assertTrue(voidReturnDescriptor.toLowerCase().contains("void")); Method getSubClass = ReflTestClass.class.getMethod("getSubClass"); String getterDescriptor = ReflectionUtil.getArgMismatchString(getSubClass); validateBasics.accept(getSubClass, getterDescriptor); assertTrue(getterDescriptor.toLowerCase().contains(" a ")); Method getSomeNumbers = ReflTestClass.class.getMethod("getSomeNumbers"); String someNumbersDescriptor = ReflectionUtil.getArgMismatchString(getSomeNumbers); validateBasics.accept(getSomeNumbers, someNumbersDescriptor); assertTrue(someNumbersDescriptor.toLowerCase().contains(" an ")); }
public static @NotNull String getArgMismatchString(Method method) { final String methodName = method.getName(); final Class<?> returnType = method.getReturnType(); final String returnTypeName = returnType.getSimpleName(); String returnInfo; if (returnType.equals(Void.TYPE)) { returnInfo = "returns void."; } else if (startsWithVowel.test(returnTypeName)) { returnInfo = "returns an " + returnTypeName; } else { returnInfo = "returns a " + returnTypeName; } return "Method " + methodName + " requires " + method.getParameterCount() + " args and " + returnInfo + "\n" + ReflectionUtil.getFormattedMethodSignature(method); }
ReflectionUtil { public static @NotNull String getArgMismatchString(Method method) { final String methodName = method.getName(); final Class<?> returnType = method.getReturnType(); final String returnTypeName = returnType.getSimpleName(); String returnInfo; if (returnType.equals(Void.TYPE)) { returnInfo = "returns void."; } else if (startsWithVowel.test(returnTypeName)) { returnInfo = "returns an " + returnTypeName; } else { returnInfo = "returns a " + returnTypeName; } return "Method " + methodName + " requires " + method.getParameterCount() + " args and " + returnInfo + "\n" + ReflectionUtil.getFormattedMethodSignature(method); } }
ReflectionUtil { public static @NotNull String getArgMismatchString(Method method) { final String methodName = method.getName(); final Class<?> returnType = method.getReturnType(); final String returnTypeName = returnType.getSimpleName(); String returnInfo; if (returnType.equals(Void.TYPE)) { returnInfo = "returns void."; } else if (startsWithVowel.test(returnTypeName)) { returnInfo = "returns an " + returnTypeName; } else { returnInfo = "returns a " + returnTypeName; } return "Method " + methodName + " requires " + method.getParameterCount() + " args and " + returnInfo + "\n" + ReflectionUtil.getFormattedMethodSignature(method); }  }
ReflectionUtil { public static @NotNull String getArgMismatchString(Method method) { final String methodName = method.getName(); final Class<?> returnType = method.getReturnType(); final String returnTypeName = returnType.getSimpleName(); String returnInfo; if (returnType.equals(Void.TYPE)) { returnInfo = "returns void."; } else if (startsWithVowel.test(returnTypeName)) { returnInfo = "returns an " + returnTypeName; } else { returnInfo = "returns a " + returnTypeName; } return "Method " + methodName + " requires " + method.getParameterCount() + " args and " + returnInfo + "\n" + ReflectionUtil.getFormattedMethodSignature(method); }  static @NotNull List<String> getArgsForMethod(@NotNull List<String> args, @NotNull Method method); static @NotNull String getFormattedMethodSignature(Method method); static @NotNull String getMethodId(Method method); static @NotNull String getArgMismatchString(Method method); }
ReflectionUtil { public static @NotNull String getArgMismatchString(Method method) { final String methodName = method.getName(); final Class<?> returnType = method.getReturnType(); final String returnTypeName = returnType.getSimpleName(); String returnInfo; if (returnType.equals(Void.TYPE)) { returnInfo = "returns void."; } else if (startsWithVowel.test(returnTypeName)) { returnInfo = "returns an " + returnTypeName; } else { returnInfo = "returns a " + returnTypeName; } return "Method " + methodName + " requires " + method.getParameterCount() + " args and " + returnInfo + "\n" + ReflectionUtil.getFormattedMethodSignature(method); }  static @NotNull List<String> getArgsForMethod(@NotNull List<String> args, @NotNull Method method); static @NotNull String getFormattedMethodSignature(Method method); static @NotNull String getMethodId(Method method); static @NotNull String getArgMismatchString(Method method);  }