Skip to content

Commit

Permalink
issue #467: correct JSON mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
bhecquet committed Jan 18, 2022
1 parent e19863e commit 3d9189a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 11 additions & 0 deletions core/src/test/java/com/seleniumtests/ConnectorsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,18 @@ public String answer(InvocationOnMock invocation) {
when(jsonResponse.getBody()).thenReturn(json);
when(jsonResponse.getStatusText()).thenReturn("TEXT");
try {
// check data is compatible with JSON
for (Object d: replyData) {
if (((String)d).isEmpty()) {
d = "{}";
}
new JSONObject((String)d);
}


// JSONObject jsonReply = new JSONObject((String)replyData);
// when(json.getObject()).thenReturn(jsonReply);

when(json.getObject()).then(new Answer<JSONObject>() {
private int count = -1;

Expand All @@ -253,6 +262,8 @@ public JSONObject answer(InvocationOnMock invocation) {
pageList.add(jsonResponse);

} catch (JSONException e) {}


} else if (replyData.get(0) instanceof File) {
when(streamResponse.getStatus()).thenReturn(statusCode);
when(streamResponse.getStatusText()).thenReturn("TEXT");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
Expand Down

0 comments on commit 3d9189a

Please sign in to comment.