简体   繁体   中英

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.

I have resolved problem:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM