/** * Asserts that arguments can be resolved from method references for simple functional interfaces. */ public void shouldResolveArgumentsFromMethodRefs() { Baz baz = new Baz(); Predicate<String> p1 = baz::evaluate; Predicate<String> p2 = Baz::eval; BiPredicate<Baz, String> p3 = Baz::evaluate; Comparator<String> c = String::compareToIgnoreCase; assertEquals(TypeResolver.resolveRawArgument(Predicate.class, p1.getClass()), String.class); assertEquals(TypeResolver.resolveRawArgument(Predicate.class, p2.getClass()), String.class); assertEquals( TypeResolver.resolveRawArguments(BiPredicate.class, p3.getClass()), new Class<?>[] {Baz.class, String.class}); assertEquals(TypeResolver.resolveRawArgument(Comparator.class, c.getClass()), String.class); }
/** * 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); }