title: How to generate a Java method reference using Groovy for testing purposes
body: <p>I'm using <code>Groovy</code> with <code>JUnit</code> to test my <code>Java</code> code.</p>
  
  <p>I need to test a method <code>foo()</code> which takes in a <code>java.util.function.Function</code></p>
  
  <pre><code>public void foo(Function&lt;Foo,Bar&gt; func){
      return null; 
  }
  </code></pre>
  
  <p>In my normal code I call <code>foo</code> by passing in a method reference of a method <code>bar</code> ie.</p>
  
  <pre><code>foo(mybar::bar)
  </code></pre>
  
  <p>How can I test this function in <code>Groovy</code> elegantly?</p>
  
  <p>Using:</p>
  
  <pre><code>mybar.&amp;bar
  </code></pre>
  
  <p>yields a <code>groovy.lang.Closure&lt;...&gt;</code> which is not compatible with <code>java.util.function.Function</code>.</p>
  
  <p>How else can I achieve this?</p>