How to generate Java method reference using Groovy for testing purposes

I am using Groovy with JUnit to test Java code.

I need to test the foo() method, which takes a java.util.function.Function value

 public void foo(Function<Foo,Bar> func){ return null; } 

In my normal code, I call foo , passing the method bar reference of the bar ie method.

 foo(mybar::bar) 

How can I test this feature in Groovy elegantly?

Using:

 mybar.&bar 

gives a groovy.lang.Closure<...> , which is incompatible with java.util.function.Function .

How else can I achieve this?

+5
source share
1 answer

Confirm the final Function attempt, for example:

 foo(mybar.&bar as Function) 
+5
source

Source: https://habr.com/ru/post/1261790/


All Articles