gstackoverflow
gstackoverflow

Reputation: 36976

Mockito tries to invoke method when I set behaviour for it

I have following code line:

when(htmlEmailSpy.setFrom(anyString())).thenReturn(null);

Following code executes real htmlEmailSpy.setFrom(...) but it throws exception.

@Spy
HtmlEmail htmlEmailSpy = new HtmlEmail();

What do I wrong?

my aim - set new behaviour to spy object.

Upvotes: 0

Views: 299

Answers (1)

gstackoverflow
gstackoverflow

Reputation: 36976

I have resolved problem:

doReturn(null).when(htmlEmailSpy).setFrom(anyString());

took from: Mockito: Trying to spy on method is calling the original method

Upvotes: 2

Related Questions