How can I use local Json File as response body in MockWebServer? Thank you!
Asked
Active
Viewed 3,145 times
1 Answers
2
You can stream the json file to a byte array. Using org.apache.commons.io.IOUtils to save time, then pass this as a String to a new MockResponse body.
InputStream jsonStream = MyClass.class.getClassLoader().getResourceAsStream("file.json");
byte[] jsonBytes = IOUtils.toByteArray(jsonStream);
mockWebServer.enqueue(new MockResponse().setBody(new String(jsonBytes)));

mhutti1
- 65
- 8