public static Method getApplyMethod(ScalarFn scalarFn) {
    Class<? extends ScalarFn> clazz = scalarFn.getClass();
    Collection<Method> matches =
        ReflectHelpers.declaredMethodsWithAnnotation(
            ScalarFn.ApplyMethod.class, clazz, ScalarFn.class);

    if (matches.isEmpty()) {
      throw new IllegalArgumentException(
          String.format(
              "No method annotated with @%s found in class %s.",
              ScalarFn.ApplyMethod.class.getSimpleName(), clazz.getName()));
    }

    // If we have at least one match, then either it should be the only match
    // or it should be an extension of the other matches (which came from parent
    // classes).
    Method first = matches.iterator().next();
    for (Method other : matches) {
      if (!first.getName().equals(other.getName())
          || !Arrays.equals(first.getParameterTypes(), other.getParameterTypes())) {
        throw new IllegalArgumentException(
            String.format(
                "Found multiple methods annotated with @%s. [%s] and [%s]",
                ScalarFn.ApplyMethod.class.getSimpleName(),
                ReflectHelpers.formatMethod(first),
                ReflectHelpers.formatMethod(other)));
      }
    }

    // Method must be public.
    if ((first.getModifiers() & Modifier.PUBLIC) == 0) {
      throw new IllegalArgumentException(
          String.format("Method %s is not public.", ReflectHelpers.formatMethod(first)));
    }

    return first;
  }
@Test
  public void testDifferentMethodNameThrowsIllegalArgumentException() {
    thrown.expect(instanceOf(IllegalArgumentException.class));
    thrown.expectMessage("Found multiple methods annotated with @ApplyMethod.");
    ScalarFnReflector.getApplyMethod(new IncrementFnDifferentMethodName());
  }