Mock call to external web service with Mockito in Java [closed]

1

Having this code:

private ConsultaCiudadanoStub clienteConsultaCiudadanoWS;

clienteGestionColectivosWS = new GestionColectivosWsStub();

clienteGestionColectivosWS._getServiceClient().getOptions().setTo(new org.apache.axis2.addressing.EndpointReference(Inicializacion.getUrlWsGestionColectivos()));

How can I mock a call to clientGestionColectivosWS, being this an external web service, with Mockito in a test with Java?

    
asked by David Baños 01.03.2017 в 10:11
source

1 answer

1

the way to use Mockito is quite easy. You just have to create a mock of the kind you want:

clienteGestionColectivosWS = Mockito.mock(GestionColectivosWsStub.class);

If you wanted to have a certain behavior, for example, to return a specific object when you make a call, you would have to use when and do something similar to this: when(clienteGestionColectivosWS.METODO(PARAMETROS)).thenReturn(OBJETO_DE_VUELTA);

I hope that this will help you to start. If not, you can always pull the documentation ( link ).

    
answered by 01.03.2017 в 11:51