HttpResponseHandler { public TrackerResponse handleResponse(InputStream in, Charset charset) { try (BEParser parser = new BEParser(in)) { return handleResponse(parser, charset); } catch (Exception e) { return TrackerResponse.exceptional(e); } } HttpResponseHandler(); TrackerResponse handleResponse(InputStream in, Charset charset); TrackerResponse handleResponse(byte[] bytes, Charset charset);  }
@Test public void handleResponse_Success1() throws Exception { TrackerResponse trackerResponse = responseHandler.handleResponse( HttpResponseHandlerTest.class.getResourceAsStream("tracker_response_success1"), defaultCharset); assertNotNull(trackerResponse); assertTrue(trackerResponse.isSuccess()); assertEquals(3591, trackerResponse.getInterval()); assertEquals(3591, trackerResponse.getMinInterval()); assertHasPeers(trackerResponse.getPeers().iterator(), createPeer(null, new byte[]{77,(byte)245,113,10}, 13933), createPeer(null, new byte[]{37,17,49,(byte)228}, 6881), createPeer(null, new byte[]{(byte)178, (byte)215,98,37}, 16881), createPeer(null, new byte[]{46,(byte)167,127,46}, 44264), createPeer(null, new byte[]{91,(byte)247,(byte)233,(byte)253}, 6881), createPeer(null, new byte[]{(byte)176,117,(byte)218,(byte)136}, 39638), createPeer(null, new byte[]{37, (byte)190,(byte)197,(byte)178}, 62354), createPeer(null, new byte[]{77,105,(byte)190,5}, 15418), createPeer(null, new byte[]{(byte)176,99,67,43}, 28391)); }
@Test public void handleResponse_Failure1() { TrackerResponse trackerResponse = responseHandler.handleResponse( HttpResponseHandlerTest.class.getResourceAsStream("tracker_response_failure1"), defaultCharset); assertNotNull(trackerResponse); assertFalse(trackerResponse.isSuccess()); assertFalse(trackerResponse.getError().isPresent()); assertEquals("Invalid info_hash (0 - )", trackerResponse.getErrorMessage()); }