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
Grails bean factory + method with parameters
Posted by admin - 20/10/11 at 11:10:14 pmclass MyObjectFactory { static final int TYPE_ONE = 1 static final int TYPE_TWO = 2 def produce(int type){ if (type == TYPE_ONE){ return ... // type one } if (type == TYPE_TWO){ return ... // type two } throw new IllegalArgumentException() } } ... beans { myObjectFactoryBean(MyObjectFactory) myObjectBean(myObjectFactoryBean:'produce'){bean-> bean.constructorArgs = [MyObjectFactory.TYPE_ONE ] } }
October 20, 2011 | In Grails | No Comments
Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds.
Valid XHTML and CSS.