Example #1
0
  /**
   * Asserts that arguments can be resolved from lambda expressions for simple functional
   * interfaces.
   */
  public void shouldResolveArguments() {
    Predicate<String> predicate = str -> true;
    Function<String, Integer> fn = str -> Integer.valueOf(str);
    Supplier<String> supplier = () -> "test";
    Consumer<String> consumer = s -> {};

    assertEquals(
        TypeResolver.resolveRawArgument(Predicate.class, predicate.getClass()), String.class);
    assertEquals(
        TypeResolver.resolveRawArguments(Function.class, fn.getClass()),
        new Class<?>[] {String.class, Integer.class});
    assertEquals(
        TypeResolver.resolveRawArgument(Supplier.class, supplier.getClass()), String.class);
    assertEquals(
        TypeResolver.resolveRawArgument(Consumer.class, consumer.getClass()), String.class);
  }
Example #2
0
 private <T, R> void handlePassedFunction(Function<T, R> fn) {
   Class<?>[] typeArgs = TypeResolver.resolveRawArguments(Function.class, fn.getClass());
   assertEquals(typeArgs[0], UUID.class);
   assertEquals(typeArgs[1], String.class);
 }