Mockito and mock webservicetemplate

235 Views Asked by At

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?

1

There are 1 best solutions below

0
Petar Bivolarski On

I see that you are mocking the same method marshalSendAndReceive in both cases.

It appears therefore that the response is always responseB, because the code that is returning responseB is invoked last.

Is the method overloaded using different types of parameters, or do TypeA and TypeB share the same parent class?