Export to GitHub

mockito - issue #444

Mocking behaviour on two mocks at the same time causes exception, but message is unclear.


Posted on Jul 19, 2013 by Grumpy Rhino

What steps will reproduce the problem? calling: when(foo.bar()).thenReturn(createMockReturning("something"))

where createMockReturning is defined as: public Something createMockReturning(final String value) { final Something mockSomething = mock(Something.class); when(something.value()).thenReturn(value); return mockSomething; }

The exception thrown if you try and do this hints that there is unfinished stubbing (i.e. you haven't coded the thenReturn); or that the method/class was final. This isn't the situation here, instead you've just tried recording two mocks at the same time. This isn't entirely clear unless you know how the internals of the recording occurs.

Mockito 1.9.0

It would be good to just add this as another hint, e.g. "Hint 3: are you trying to mock behaviour on two mocks at the same time?"

Comment #1

Posted on Dec 4, 2013 by Happy Horse

(No comment was entered for this change.)

Comment #2

Posted on Dec 4, 2013 by Happy Horse

Thx for the idea, you could also make a pull request ;)

Comment #3

Posted on Feb 23, 2014 by Grumpy Rhino

Hi, I just checked the latest sources, this doesn't look fixed even though this is marked as fixed? Should I create a pull request for this still?

Comment #4

Posted on Aug 16, 2014 by Massive Monkey

(No comment was entered for this change.)

Comment #5

Posted on Aug 24, 2014 by Massive Monkey

(No comment was entered for this change.)

Comment #6

Posted on Aug 24, 2014 by Massive Monkey

(No comment was entered for this change.)

Comment #7

Posted on Aug 24, 2014 by Massive Monkey

(No comment was entered for this change.)

Status: New

Labels:
Type-Defect Priority-Medium