@SuppressWarnings("unused") @Test public void executeCmdsTest() throws IOException{ Runtime runtime = Mockito.mock(Runtime.class); process = Mockito.mock(Process.class); OutputStream out = Mockito.mock(ByteArrayOutputStream.class); boolean done = true; String cmd2 = "echo Hello"; String cmd1 = "ls -la"; Mockito.when(runtime.exec(cmd1)).thenReturn(process); Mockito.when(process.getOutputStream()).thenReturn(out); Mockito.doNothing().when(out).write(cmd2.getBytes()); Mockito.doNothing().when(out).flush(); boolean result = lldbProcessRunner.executeCmds(cmd1, cmd2); boolean result2 = lldbProcessRunner.executeCmds(cmd1, cmd2); }
@Override public boolean executeCmds(String cmd1, String cmd2){ OutputStream out; boolean done = false; try { if(lldbProcess != null){ out = lldbProcess.getOutputStream(); out.write(cmd1.getBytes()); out.write(cmd2.getBytes()); out.flush(); out.close(); }else{ lldbProcess = procfactory.create(cmd1); out = lldbProcess.getOutputStream(); out.write(cmd2.getBytes()); out.flush(); } done = true; } catch (IOException e1) { LOG.error("Executing cmds on attached lldb process has failed"); } return done; }
LLDBProcessRunnerImpl implements ILLDBProcessRunner { @Override public boolean executeCmds(String cmd1, String cmd2){ OutputStream out; boolean done = false; try { if(lldbProcess != null){ out = lldbProcess.getOutputStream(); out.write(cmd1.getBytes()); out.write(cmd2.getBytes()); out.flush(); out.close(); }else{ lldbProcess = procfactory.create(cmd1); out = lldbProcess.getOutputStream(); out.write(cmd2.getBytes()); out.flush(); } done = true; } catch (IOException e1) { LOG.error("Executing cmds on attached lldb process has failed"); } return done; } }
LLDBProcessRunnerImpl implements ILLDBProcessRunner { @Override public boolean executeCmds(String cmd1, String cmd2){ OutputStream out; boolean done = false; try { if(lldbProcess != null){ out = lldbProcess.getOutputStream(); out.write(cmd1.getBytes()); out.write(cmd2.getBytes()); out.flush(); out.close(); }else{ lldbProcess = procfactory.create(cmd1); out = lldbProcess.getOutputStream(); out.write(cmd2.getBytes()); out.flush(); } done = true; } catch (IOException e1) { LOG.error("Executing cmds on attached lldb process has failed"); } return done; }  }
LLDBProcessRunnerImpl implements ILLDBProcessRunner { @Override public boolean executeCmds(String cmd1, String cmd2){ OutputStream out; boolean done = false; try { if(lldbProcess != null){ out = lldbProcess.getOutputStream(); out.write(cmd1.getBytes()); out.write(cmd2.getBytes()); out.flush(); out.close(); }else{ lldbProcess = procfactory.create(cmd1); out = lldbProcess.getOutputStream(); out.write(cmd2.getBytes()); out.flush(); } done = true; } catch (IOException e1) { LOG.error("Executing cmds on attached lldb process has failed"); } return done; }  @Autowired void setProcessFactory(IProcessFactory factory); @Override boolean executeCmds(String cmd1, String cmd2); }
LLDBProcessRunnerImpl implements ILLDBProcessRunner { @Override public boolean executeCmds(String cmd1, String cmd2){ OutputStream out; boolean done = false; try { if(lldbProcess != null){ out = lldbProcess.getOutputStream(); out.write(cmd1.getBytes()); out.write(cmd2.getBytes()); out.flush(); out.close(); }else{ lldbProcess = procfactory.create(cmd1); out = lldbProcess.getOutputStream(); out.write(cmd2.getBytes()); out.flush(); } done = true; } catch (IOException e1) { LOG.error("Executing cmds on attached lldb process has failed"); } return done; }  @Autowired void setProcessFactory(IProcessFactory factory); @Override boolean executeCmds(String cmd1, String cmd2);  }