### Question:
GetTransactionByIdSolidityServlet extends RateLimiterServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) { try { PostParams params = PostParams.getPostParams(request); BytesMessage.Builder build = BytesMessage.newBuilder(); JsonFormat.merge(params.getParams(), build, params.isVisible()); fillResponse(build.build().getValue(), params.isVisible(), response); } catch (Exception e) { logger.debug("Exception: {}", e.getMessage()); try { response.getWriter().println(e.getMessage()); } catch (IOException ioe) { logger.debug("IOException: {}", ioe.getMessage()); } } }    }### Answer:
@Test public void doPostTest() throws IOException { final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); System.setOut(new PrintStream(outContent)); String href = "http: httpUrlStreamHandler.addConnection(new URL(href), httpUrlConnection); httpUrlConnection.setRequestMethod("POST"); httpUrlConnection.setRequestProperty("Content-Type", "application/json"); httpUrlConnection.setRequestProperty("Connection", "Keep-Alive"); httpUrlConnection.setUseCaches(false); httpUrlConnection.setDoOutput(true); String postData = "{\"value\": \"309b6fa3d01353e46f57dd8a8f27611f98e392b50d035cef21" + "3f2c55225a8bd2\"}"; httpUrlConnection.setRequestProperty("Content-Length", "" + postData.length()); when(httpUrlConnection.getOutputStream()).thenReturn(outContent); OutputStreamWriter out = new OutputStreamWriter(httpUrlConnection.getOutputStream(), StandardCharsets.UTF_8); out.write(postData); out.flush(); out.close(); PrintWriter writer = new PrintWriter("temp.txt"); when(response.getWriter()).thenReturn(writer); getTransactionByIdSolidityServlet.doPost(request, response); String line; StringBuilder result = new StringBuilder(); byte[] buffer = new byte[1024]; ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buffer); when(httpUrlConnection.getInputStream()).thenReturn(byteArrayInputStream); BufferedReader in = new BufferedReader(new InputStreamReader(httpUrlConnection.getInputStream(), StandardCharsets.UTF_8)); while ((line = in.readLine()) != null) { result.append(line).append("\n"); } in.close(); writer.flush(); FileInputStream fileInputStream = new FileInputStream("temp.txt"); InputStreamReader inputStreamReader = new InputStreamReader(fileInputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); StringBuffer sb = new StringBuffer(); String text = null; while ((text = bufferedReader.readLine()) != null) { sb.append(text); } Assert.assertTrue(sb.toString().contains("null")); httpUrlConnection.disconnect(); }