@Test public void run() throws IOException { String aMessage = "helloFromRun"; InputStream stream = new ByteArrayInputStream(aMessage.getBytes()); externalProcessReader = new ExternalProcessReaderImpl(); externalProcessReader.setInputStream(stream); subscriber = Mockito.mock(IExternalProcessReaderSubscriber.class); externalProcessReader.addSubscriber(subscriber); Mockito.doAnswer(new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { String method = invocation.getMethod().getName(); Object[] args = invocation.getArguments(); if (method.equals("newMessage")) { if (args[0] != null) { ExternalProcessReaderImplTest.message += (String) args[0]; } } return null; } }).when(subscriber).newMessage(Mockito.anyString()); externalProcessReader.run(); externalProcessReader.setStop(); assertTrue(ExternalProcessReaderImplTest.message.equals(aMessage)); }
@Override public void run() { String line = null; try { InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); while (!willStop) { line = bufferedReader.readLine(); if (line == null) { break; } else { line = line.trim(); if (line.length() > 0) { out(line); } } } } catch (IOException exception) { out("Error: " + exception.getMessage()); } notifyExit(); }
ExternalProcessReaderImpl implements Runnable, IExternalProcessReader { @Override public void run() { String line = null; try { InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); while (!willStop) { line = bufferedReader.readLine(); if (line == null) { break; } else { line = line.trim(); if (line.length() > 0) { out(line); } } } } catch (IOException exception) { out("Error: " + exception.getMessage()); } notifyExit(); } }
ExternalProcessReaderImpl implements Runnable, IExternalProcessReader { @Override public void run() { String line = null; try { InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); while (!willStop) { line = bufferedReader.readLine(); if (line == null) { break; } else { line = line.trim(); if (line.length() > 0) { out(line); } } } } catch (IOException exception) { out("Error: " + exception.getMessage()); } notifyExit(); }  }
ExternalProcessReaderImpl implements Runnable, IExternalProcessReader { @Override public void run() { String line = null; try { InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); while (!willStop) { line = bufferedReader.readLine(); if (line == null) { break; } else { line = line.trim(); if (line.length() > 0) { out(line); } } } } catch (IOException exception) { out("Error: " + exception.getMessage()); } notifyExit(); }  @Override void setInputStream(InputStream stream); @Override void addSubscriber(IExternalProcessReaderSubscriber subscriber); @Override void setStop(); @Override void out(String message); @Override void removeSubscriber(IExternalProcessReaderSubscriber sub); @Override void run(); }
ExternalProcessReaderImpl implements Runnable, IExternalProcessReader { @Override public void run() { String line = null; try { InputStreamReader inputStreamReader = new InputStreamReader(inputStream); BufferedReader bufferedReader = new BufferedReader(inputStreamReader); while (!willStop) { line = bufferedReader.readLine(); if (line == null) { break; } else { line = line.trim(); if (line.length() > 0) { out(line); } } } } catch (IOException exception) { out("Error: " + exception.getMessage()); } notifyExit(); }  @Override void setInputStream(InputStream stream); @Override void addSubscriber(IExternalProcessReaderSubscriber subscriber); @Override void setStop(); @Override void out(String message); @Override void removeSubscriber(IExternalProcessReaderSubscriber sub); @Override void run();  }