I use mockito 3 as follow:
Mockito.when(webServiceTemplate.marshalSendAndReceive(Mockito.anyString(),
ArgumentMatchers.<JAXBElement<TypeA>>any()))
.thenReturn(responseA);
Mockito.when(webServiceTemplate.marshalSendAndReceive(Mockito.anyString(),
ArgumentMatchers.<JAXBElement<TypeB>>any()))
.thenReturn(responseB);
The problem is that mockito returns always the responseB.
Where is the problem?
I see that you are mocking the same method
marshalSendAndReceivein both cases.It appears therefore that the response is always
responseB, because the code that is returningresponseBis invoked last.Is the method overloaded using different types of parameters, or do
TypeAandTypeBshare the same parent class?