я должен издеваться запрос к API, который возвращает ответ с JSON объекта Для этого я издеваться запрос GET, а также объект JSONнасмешливый ответ на HttpGet в Java
public class RestTest {
static JSONObject job;
static JSONArray portsArray;
static JSONArray routesArray;
static JSONObject routeObject;
private static final HttpClient client = mock(DefaultHttpClient.class);
private static final HttpGet get = mock(HttpGet.class);
private static final HttpResponse response = mock(CloseableHttpResponse.class);
private static HttpEntity entity = mock(HttpEntity.class);
@BeforeClass
public static void setup() throws ClientProtocolException, IOException, JSONException {
HttpGet getRoute = new HttpGet("api/to/access");
getRoute.setHeader("Content-type", "application/json");
JSONObject routesJson = new JSONObject();
routesJson.put("","");
when(response.getEntity()).thenReturn(entity);
when(response.getEntity().getContent().toString()).thenReturn(routesJson.toString());
when(client.execute(getRoutes)).thenReturn(response);
}
}
Это возвращает нуль указатель на when(response.getEntity().getContent().toString()).thenReturn(routesJson.toString());
Как я правильно издеваюсь над объектом JSON, поэтому, когда выполняется реальный запрос, он возвращает насмешливый JSON?
Я не могу установить entity.setContent()
, как показано в примерах, так как метода не существует.