Good day. I'm writing simple test with API calls where Retrofit takes place.
The test looks like this
mockWebServer.enqueue(new MockResponse()
.setResponseCode(200)
.setBody("{\"initial\":\"合理咯\"," +
" \"translation\":\"sometranlsation\"}"));
PinyTranslationRequest pinyTranslationRequest = new PinyTranslationRequest();
ArrayList<String> inputString = new ArrayList<>();
inputString.add("合理咯");
pinyTranslationRequest.locale = CHINESSE_LANGUAGE_COUNTRY_CODE;
pinyTranslationRequest.inputStrings = inputString;
Call<PinyinTranslationResponse> responseCall = backendServerAPI.getPinyinTranslation(pinyTranslationRequest);
Response<PinyinTranslationResponse> pinyinTranslationResponseResponse = responseCall.execute();
assertEquals("he li ge", pinyinTranslationResponseResponse.body().translation);
Here the assertion fails becausetranslation
variable is null so I've checked the full response which looks as follows:
Response{protocol=h2, code=200, message=, url=https://xxxx.xxx}
As you can see message
is empty but whereas it shall not as I've set the body for the MockResponse
.
Any clues what am I doing wrong?
Aucun commentaire:
Enregistrer un commentaire