dhamini-poornachandra / mockito

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

NullpointerException after when(); MockitoException #432

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi all,
to achieve the mock "anzeige" returning an Optional, I was programming it like 
this:

when(anzeige.wähleAus(anyList())).thenReturn(Optional.<Arbeitsschein> 
absent());

This works but the test sporadically fails with

1. a NullPointerException, because the mock returns null instead of absent
2. sometimes with a MockitoException that tells me that I'm trying to stub 
method foo() for return although it has return type void:
'foo' is a *void method* and it *cannot* be stubbed with a *return value*!

The last point is not true, because I'm stubbing wähleAus() and not foo(). 

But wähleAus() and foo() are both called from a different thread that is 
started during setUp. 
It is assured that wähleAus() is called after the mock is programmed by when().

Do you know what my problem could be?

Thanks a lot in advance,
please let me know if you need some further information.

Cheers,

Stephan

Original issue reported on code.google.com by s.luec...@gmail.com on 29 Apr 2013 at 2:44

GoogleCodeExporter commented 8 years ago
Hi Stephan, this shouldn't be a problem with Mockito, but without more code 
sample I cannot point you to the problem.
You definitely should ask the mailing list (mockito@googlegroups.com) instead 
of filling an issue, this is the proper place to discuss such matter.

Also not everyone speaks german. And as an advice I would avoid diacritic marks 
like umlaut in class or member identifiers.

HTH

Brice

Original comment by brice.du...@gmail.com on 29 Apr 2013 at 3:54

GoogleCodeExporter commented 8 years ago

Original comment by brice.du...@gmail.com on 29 Apr 2013 at 3:54

GoogleCodeExporter commented 8 years ago
Hi Brice, 

thanks a lot for your immediate reply.  

I decided to create this issue because although I did not stub method foo(), 
Mockito told me that I did. 

So this seemed to me being a problem of Mockito.  

If you're sure that this is no problem of Mockito, please close this issue. 

Otherwise we could wait some days until I get some feedback from the mailing 
list. 

Thanks again for your help, 

cheers,  

Stephan

Original comment by s.luec...@gmail.com on 30 Apr 2013 at 8:04

GoogleCodeExporter commented 8 years ago
Fair enough ;)

Original comment by brice.du...@gmail.com on 30 Apr 2013 at 10:40

GoogleCodeExporter commented 8 years ago
On the mailing list, analysis revealed, that stubbing was realized after mock 
is being used by some other threads.

The stubbing and the use of the mock appears to be in 2 distinct threads. So it 
might be possible to do something about it.

But volunteers are needed.

Original comment by brice.du...@gmail.com on 26 May 2013 at 2:15