TradingUtils { public static final String responseToString(HttpResponse response) throws IOException { HttpEntity entity = response.getEntity(); if ((response.getStatusLine().getStatusCode() == HttpStatus.SC_OK || response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED) && entity != null) { InputStream stream = entity.getContent(); String line; BufferedReader br = new BufferedReader(new InputStreamReader(stream)); StringBuilder strResp = new StringBuilder(); while ((line = br.readLine()) != null) { strResp.append(line); } IOUtils.closeQuietly(stream); IOUtils.closeQuietly(br); return strResp.toString(); } else { return StringUtils.EMPTY; } } private  TradingUtils(); static final String executingRequestMsg(HttpRequest request); static long toUnixTime(DateTime dateTime); static long toMillisFromNanos(long nanos); static String[] splitCcyPair(String instrument, String currencySeparator); static double calculateTakeProfitPrice(double tickSize, TradingSignal signal, double bidPrice,
			double askPrice, int pipsDesired); static final String responseToString(HttpResponse response); static final boolean isEmpty(Collection<?> collection); static final boolean isEmpty(Map<?, ?> map); static String[] splitInstrumentPair(String instrument); static final int getSign(String currencyInstrument, TradingSignal side, String currency); static void closeSilently(CloseableHttpClient httpClient); static void printErrorMsg(HttpResponse response); static String getResponse(HttpResponse response); static final int CCY_PAIR_LEN; static final int CCY_SEP_CHR_POS; }
@Test public void responseToStringTest() throws Exception { HttpResponse resp = mock(HttpResponse.class); HttpEntity entity = mock(HttpEntity.class); when(resp.getEntity()).thenReturn(entity); StatusLine statusLine = mock(StatusLine.class); when(resp.getStatusLine()).thenReturn(statusLine); when(statusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK); when(entity.getContent()).thenReturn(new FileInputStream("src/test/resources/foobar.txt")); assertEquals("hello world foo!!", TradingUtils.responseToString(resp)); }