Hi,

thanks to both of you - I think everyone helped me. As I am already
using Spring, I can really define the needed bean in my separate test
context configuration - maybe very easy with the help of JavaConfig:
http://static.springsource.org/spring-javaconfig/docs/1.0.0.m3/reference/html/quick-start.html#d0e511
I hope I will be able to configure my Mockito stubs there without the
need of creating real implementations. If it doesn't work, I will create
a separate factory class that delivers the needed stubs. This is indeed
a feature Spring supports via XML configuration, too.

Maybe I will create a small separate Wiki entry when I get the things
running, although a separate "injection" feature within the
MockRoundtrip would be a cool thing, too.

Kind regards,
Marcus


Richard Hauswald schrieb:
> I don't know how to do this in spring, but in guice you can create a
> so called provider that creates a instance of the interface. this
> instance can also be mock created by Mockito. Maybe its called factory
> method or factory in spring.
>
> On Sat, Nov 21, 2009 at 12:05 PM, Iwao AVE! <[email protected]> wrote:
>   
>> Doesn't it require a concrete implementation of the service interface?
>>
>> on 09/11/21 16:31 Richard Hauswald said the following:
>>     
>>> how about using a different DI configuration for testing?
>>>
>>> On Sat, Nov 21, 2009 at 3:24 AM, Iwao AVE!<[email protected]>  wrote:
>>>       
>>>> Hi Marcus,
>>>>
>>>> Here's how I did in my recent project.
>>>> In a @BeforeMethod of my base test class, spring's application
>>>> context is created with mocks and added to MockServletContext.
>>>>
>>>> @BeforeMethod
>>>> public void setupSpringContext() {
>>>>   GenericWebApplicationContext springContext =
>>>>     new GenericWebApplicationContext();
>>>>   context.setAttribute(
>>>>     WebApplicationContext
>>>>       .ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE,
>>>>     springContext);
>>>>
>>>>   yourService = mock(YourService.class);
>>>>   prepareSpringBean("yourService", bureauService);
>>>>   personService = mock(AnotherService.class);
>>>>   anotherSpringBean("anotherService", personService);
>>>>   scripService = mock(ScripService.class);
>>>>   ...
>>>> }
>>>>
>>>> protected void prepareSpringBean(String name, Object bean) {
>>>>   GenericWebApplicationContext springContext =
>>>>     (GenericWebApplicationContext)context
>>>>       .getAttribute(WebApplicationContext
>>>>         .ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
>>>>   springContext.getBeanFactory()
>>>>     .registerSingleton(name, bean);
>>>> }
>>>>
>>>> --
>>>> And in each test class, mocks are configured before creating a
>>>> MockRoundtrip.
>>>>
>>>> @Test
>>>> public void testSomething() throws Exception {
>>>>   // define behavior of services used in the test.
>>>>   when(yourService.doServiceMethod())
>>>>     .thenReturn(x);
>>>>
>>>>   trip = new MockRoundtrip(context,
>>>>     OneOfYourActionBean.class);
>>>>   // add parameters
>>>>   trip.execute();
>>>>
>>>>   // assertions
>>>> }
>>>>
>>>> --
>>>> It's a little bit annoying that I have to prepare all the spring
>>>> beans manually.
>>>> If you find a easier way to do this, please let me know.
>>>>
>>>> Hope this helps,
>>>> Iwao
>>>>
>>>>
>>>> on 09/11/21 6:19 M.C.S. said the following:
>>>>         
>>>>> Hi all,
>>>>>
>>>>> until now I used MockRoundtrip for testing my ActionBeans. This went
>>>>> fine although my beans usually had some Spring-injected services. But as
>>>>> long as they were valid Spring beans, every worked fine.
>>>>>
>>>>> Now while developing, I don't always have a concrete implementation of
>>>>> the services that I am planning to be injected in the ActionBeans, so I
>>>>> want the bean use a stub (created by Mockito) instead of a real class.
>>>>> But that seems to be a problem: I see no way to get the stub in the
>>>>> ActionBean because it is created on trip.execute().
>>>>>
>>>>> Any idea how I can use my stub in the ActionBean when using MockRoundtrip?
>>>>>
>>>>> Kind regards,
>>>>> Marcus
>>>>>           
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
>> trial. Simplify your report design, integration and deployment - and focus on
>> what you do best, core application coding. Discover what's new with
>> Crystal Reports now.  http://p.sf.net/sfu/bobj-july
>> _______________________________________________
>> Stripes-users mailing list
>> [email protected]
>> https://lists.sourceforge.net/lists/listinfo/stripes-users
>>
>>     
>
>
>
>   


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Stripes-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-users

Reply via email to