Java Mailing List Archive

http://www.gg3721.com/

Home » user.groovy »

Re: [groovy-user] Mocking Classes using Closures?

Andy Paramonov

2008-08-27

Replies: Find Java Web Hosting

Author LoginPost Reply

Doesn't your example work for you when Bar is class? What kind of error do
you get?


simonz wrote:
>
>
> ---- Java:
>
> class Bar {
>   public void bar() {
>     ...
>   }
> }
>
> class Foo {
>   public Bar bar;
>   public void foo() {
>     bar.bar();
>   }
> }
>
> ---- Groovy:
>
> def called = false;
> def bar = [ bar: { called = true; }] as Bar // Nice!
> new Foo(bar: bar).foo();
> assert called;
>
>

--
Sent from the groovy - user mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.