JSONPOSTResponseProcessor implements ResponseProcessor<Integer> { @Override public Integer process(Connection.Response response) { int statusCode = 0; try { statusCode = response.statusCode(); return Optional.ofNullable(new JsonParser().parse(response.body())) .map(e -> e.isJsonObject() ? e.getAsJsonObject() : null) .map(e -> e.get("status")) .map(JsonElement::getAsInt) .orElse(0); } catch (JsonParseException ignore) { return statusCode; } }  @Override Integer process(Connection.Response response);  }
@Test public void processEmptyResponse() throws Exception { Connection.Response response = new ResponseMock(""); assertTrue(0 == processor.process(response)); }
@Test public void processValidResponse() throws Exception { Connection.Response response = new ResponseMock("{\"status\":200}"); assertTrue(HttpURLConnection.HTTP_OK == processor.process(response)); }