I am writing test for an Activity which makes several consecutive calls to server. My MockWebServer mixes sequence of responses.e.g. When I make two consecutive requests request1 and request2 it sometimes returns request2's Json in response to request1 and request1's Json in response to request2. How can I specify which response MockWebServer has to return to specified request?
server.enqueue(new MockResponse()
.setResponseCode(200)
.setBody(readFromFile("response1 path"));
server.enqueue(new MockResponse()
.setResponseCode(200)
.setBody(readFromFile("response2 path"));
In documentation it is said "Enqueue scripts response to be returned to a request made in sequence. The first request is served by the first enqueued response; the second request by the second enqueued response; and so on."
This sequence doesn't work in case of parallel requests.