Issue
I am actually trying to do below: My service class
@Service
public class serviceclass{
@Autowired
MessageReplyingSender rclass;
public void doMethod(){
Object o = rlcass.something("hey","hey",null,1000);
}
}
public interface MessageReplyingSender {
public <T> Object something(String sendertopic,T message,Map<String, Object> headers, long replyTimeout)
throws Exception;
}
Test Class:
@RunWith(MockitoJUnitRunner.class)
public class testclass{
@InjectMocks
private serviceclass sclass;
@Mock
MessageReplyingSender rclass;
public void test throws Exception{
Mockito.verify(rclass).something(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyLong());
Mockito.when(rclass.something(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.anyLong())).thenReturn("gh");
sclass.doMethod();
}
}
This gives me wanted by not invoked,actually there were Zero interactions with this mock. Any idea what am i doing wrong??
Solution
You're verifying that rclass#something
is called. But that's not happening because you forgot to trigger it with serviceclass#doMethod
Answered By - Nicolas Garcia
Answer Checked By - David Marino (JavaFixing Volunteer)