Grails Gmock partial mock example
Posted by admin - 21/10/11 at 01:10:52 pmclass Foo { def methodFoo(String param){ return "methodFoo" } } ... class Bar { def foo def methodBar(String param){ return foo.methodFoo(param) + methodBarSecond(param); } def methodBarSecond(String param){ return "methodBarSecond" } } ... import static org.hamcrest.Matchers.any @WithGmock class BarTests { @Test public void checkMethodBar(){ def result = "my other result" def mockFoo = mock(Foo) mockFoo.testMethod(any(String)).returns(result) Bar bar = new Bar() bar.foo = mockFoo mock(bar).methodBarSecond(any(String)).returns(result) play { assertEquals (result * 2, bar.methodBar()) } } }
October 21, 2011 | In Grails | No Comments
No Comments yet »
RSS feed for comments on this post.
Leave a comment
Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds.
Valid XHTML and CSS.