ssacher-tgm / mockito

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

'void' method not allowed here - better message #180

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
there is something what I don't understand:
I've got a mock-object:

private Session session;

which I initialize in the setUp-method:

session = mock(Session)

It's an Hibernate Session (org.hibernate.Session)
When I try to set a "when(...)" with matchers I'll receive an error
"'void' method not allowed here":

when(session.load(anyObject(),anyString())).thenReturn(a)

the same happens when I change the Matchers to:

when(session.load(any(A.class),eq("123"))).thenReturn(a);

I had a look on anyObject(), anyString() etc. they're all "non-void-
methods".
Also the session.load(...,...) isn't a "void-method".

Everything works great when I remove the matchers:
when(session.load(A.class, "123").thenReturn(a)

Original issue reported on code.google.com by szcze...@gmail.com on 17 Mar 2010 at 12:36

GoogleCodeExporter commented 8 years ago
Make the exception message better:

'someMethod' is a *void method* and it *cannot* be stubbed with a *return 
value*!
Voids are usually stubbed with Throwables:
    doThrow(exception).when(mock).someVoidMethod();
If the method you are trying to stub is *overloaded* then make sure you are 
calling
the right overloaded version.

Original comment by szcze...@gmail.com on 17 Mar 2010 at 1:02

GoogleCodeExporter commented 8 years ago
fixed some time ago

Original comment by szcze...@gmail.com on 24 May 2010 at 5:32

GoogleCodeExporter commented 8 years ago

Original comment by szcze...@gmail.com on 24 May 2010 at 7:58