### Question:
BackgroundRpcListener implements RpcListener { @Override public void start(InputStream inputStream) { Objects.requireNonNull(inputStream, "inputStream may not be null"); if (listener != null) { log.info("Already listening, ignoring"); return; } listener = executorService.submit(() -> { try { log.info("Started listening on stream"); listenForMessages(inputStream); } catch (IOException e) { log.error("Listening to messages failed!", e); throw new RuntimeException(e); } }); } BackgroundRpcListener(ExecutorService executorService, ObjectMapper responseObjectMapper); @Override void start(InputStream inputStream); @Override void stop(); @Override void listenForResponse(int id, ResponseCallback callback); @Override void listenForNotifications(NotificationCallback callback); @Override void listenForRequests(RequestCallback callback); static final Logger log; }### Answer:
@Test public void testStart() throws IOException { prepareSequentialExecutorService(); given(objectMapper.reader()).willReturn(objectReader); given(objectReader.readTree(inputStream)).willReturn(JsonNodeFactory.instance.arrayNode(), (JsonNode) null); backgroundRpcListener.start(inputStream); }
@Test(expected = RuntimeException.class) public void exceptionOnStartIsThrown() { prepareSequentialExecutorService(); given(objectMapper.reader()).willThrow(new IOException()); backgroundRpcListener.start(inputStream); }