cloud1105 / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

nested stubbing - UnfinishedStubbingException when using a mocked object inside another mock #430

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Stub a call to return a list of objects which themselves are mocks
2. use one api which returns a mocked object as a parameter in thenReturn()
3. gives UnfinishedStubbingException

What is the expected output? What do you see instead?
Mocks should get created without issues. But getting exception

What version of the product are you using? On what operating system?
mockito 1.9.5 Windows 7

Please provide any additional information below.
I have seen https://code.google.com/p/mockito/issues/detail?id=53
and https://code.google.com/p/mockito/issues/detail?id=191

I am able to do https://code.google.com/p/mockito/issues/detail?id=191#c1
but not the below

Foo getFoo(){
    Foo foo = mock(Foo.class);
    when(..).thenReturn(..);
    return foo;
}

Bar getBar(){
    Bar bar = mock(Bar.class);
    when(bar.getFoo).thenReturn(getFoo());
    return bar;
}

Original issue reported on code.google.com by rajq...@gmail.com on 19 Apr 2013 at 8:40

GoogleCodeExporter commented 8 years ago
>>What steps will reproduce the problem?
2. use one api which returns a mocked object as a parameter in thenReturn() of 
another

Original comment by rajq...@gmail.com on 19 Apr 2013 at 8:41

GoogleCodeExporter commented 8 years ago
Hi,

This way of doing mocks is not supported. You need to write the stubs one at a 
time.

It might be possible to extend the stubbing support, do you want to contribute ?

Cheers,
Brice

Original comment by brice.du...@gmail.com on 19 Apr 2013 at 11:29

GoogleCodeExporter commented 8 years ago
Hi,

Would have been a good to have feature which will reuse the code. Let me see 
the src. Thanks for asking :-)

Rajesh

Original comment by rajq...@gmail.com on 19 Apr 2013 at 1:23

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 29 Apr 2013 at 4:08