dhamini-poornachandra / mockito

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

UnfinishedStubbingException - add "thenReturn(mock(...))" example #344

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

1. when(m.foo()).thenReturn(mock(Foo.class));

This correctly results in UnfinishedStubbingException. The message is pretty 
helpful, except it does not call out this case and it can consume a lot of time 
to figure out what is actually wrong:

E.g. thenReturn() may be missing.
Examples of correct stubbing:
    when(mock.isOk()).thenReturn(true);
    when(mock.isOk()).thenThrow(exception);
    doThrow(exception).when(mock).someVoidMethod();
Hints:
 1. missing thenReturn()
 2. you are trying to stub a final method, you naughty developer!

What is the expected output? What do you see instead?

E.g. thenReturn() may be missing.
Examples of correct stubbing:
    when(mock.isOk()).thenReturn(true);
    when(mock.isOk()).thenThrow(exception);
    doThrow(exception).when(mock).someVoidMethod();
Hints:
 1. missing thenReturn()
 2. thenReturn(mock(...))   <-- I suggest to add this
 3. you are trying to stub a final method, you naughty developer!

What version of the product are you using? On what operating system?
1.9.0, Red Hat Linux 5

Original issue reported on code.google.com by kamot...@gmail.com on 27 May 2012 at 3:04

GoogleCodeExporter commented 8 years ago
Alternatively, we could stop detecting unfinished stubbing at mock().

Thanks for reporting!

Original comment by szcze...@gmail.com on 27 May 2012 at 9:25

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 29 May 2012 at 8:17