@Test public void stopTcpDump() throws Exception { Socket tcpDumpSocket = Mockito.mock(Socket.class); OutputStream out = Mockito.mock(OutputStream.class); Mockito.doReturn(tcpDumpSocket).when(androidImpl).getLocalSocket(); Mockito.doReturn(out).when(tcpDumpSocket).getOutputStream(); Mockito.doNothing().when(tcpDumpSocket).close(); Mockito.doNothing().when(out).close(); IDevice device = mock(IDevice.class); boolean res = androidImpl.stopTcpDump(device); assertTrue(res == true); }
@Override public boolean stopTcpDump(IDevice device) { try(Socket emulatorSocket = getLocalSocket(); OutputStream out = emulatorSocket.getOutputStream()) { if (out != null) { out.write("STOP".getBytes("ASCII")); out.flush(); } return true; } catch (UnknownHostException e) { LOGGER.error(e.getMessage()); } catch (IOException e) { LOGGER.error(e.getMessage()); } return false; }
AndroidImpl implements IAndroid { @Override public boolean stopTcpDump(IDevice device) { try(Socket emulatorSocket = getLocalSocket(); OutputStream out = emulatorSocket.getOutputStream()) { if (out != null) { out.write("STOP".getBytes("ASCII")); out.flush(); } return true; } catch (UnknownHostException e) { LOGGER.error(e.getMessage()); } catch (IOException e) { LOGGER.error(e.getMessage()); } return false; } }
AndroidImpl implements IAndroid { @Override public boolean stopTcpDump(IDevice device) { try(Socket emulatorSocket = getLocalSocket(); OutputStream out = emulatorSocket.getOutputStream()) { if (out != null) { out.write("STOP".getBytes("ASCII")); out.flush(); } return true; } catch (UnknownHostException e) { LOGGER.error(e.getMessage()); } catch (IOException e) { LOGGER.error(e.getMessage()); } return false; }  }
AndroidImpl implements IAndroid { @Override public boolean stopTcpDump(IDevice device) { try(Socket emulatorSocket = getLocalSocket(); OutputStream out = emulatorSocket.getOutputStream()) { if (out != null) { out.write("STOP".getBytes("ASCII")); out.flush(); } return true; } catch (UnknownHostException e) { LOGGER.error(e.getMessage()); } catch (IOException e) { LOGGER.error(e.getMessage()); } return false; }  boolean setExecutePermission(IDevice device, String remotePath); @Override boolean isEmulator(IDevice device); ShellOutputReceiver getShellOutput(); ShellCommandCheckSDCardOutputReceiver getOutputReturn(); @Override boolean pushFile(IDevice emulator, String local, String remote); @Override DeviceState getState(IDevice device); @Override boolean isSDCardAttached(IDevice device); @Override boolean isSDCardEnoughSpace(IDevice device, long kbs); @Override boolean pullTraceFilesFromEmulator(IDevice device, String remoteFilepath, String localFilename); @Override boolean pullTraceFilesFromDevice(IDevice device, String remoteFilepath, String localFilename); @Override boolean makeAROTraceDirectory(IDevice device, String traceName); @Override boolean makeDirectory(IDevice device, String dirpath); @Override String getProperty(IDevice device, String property); @Override SyncService getSyncService(IDevice device); @Override boolean removeEmulatorData(IDevice device, String deviceTracePath); @Override boolean stopTcpDump(IDevice device); Socket getLocalSocket(); @Override boolean checkTcpDumpRunning(IDevice device); @Override boolean startTcpDump(IDevice device, boolean seLinuxEnforced, String traceFolderName); @Override boolean isTraceRunning(); @Override String[] getShellReturn(IDevice device, String arocmd); @Override boolean checkPackageExist(IDevice device, String fullpackageName); @Override boolean runApkInDevice(IDevice device, String cmd); @Override boolean runVpnApkInDevice(IDevice device); }
AndroidImpl implements IAndroid { @Override public boolean stopTcpDump(IDevice device) { try(Socket emulatorSocket = getLocalSocket(); OutputStream out = emulatorSocket.getOutputStream()) { if (out != null) { out.write("STOP".getBytes("ASCII")); out.flush(); } return true; } catch (UnknownHostException e) { LOGGER.error(e.getMessage()); } catch (IOException e) { LOGGER.error(e.getMessage()); } return false; }  boolean setExecutePermission(IDevice device, String remotePath); @Override boolean isEmulator(IDevice device); ShellOutputReceiver getShellOutput(); ShellCommandCheckSDCardOutputReceiver getOutputReturn(); @Override boolean pushFile(IDevice emulator, String local, String remote); @Override DeviceState getState(IDevice device); @Override boolean isSDCardAttached(IDevice device); @Override boolean isSDCardEnoughSpace(IDevice device, long kbs); @Override boolean pullTraceFilesFromEmulator(IDevice device, String remoteFilepath, String localFilename); @Override boolean pullTraceFilesFromDevice(IDevice device, String remoteFilepath, String localFilename); @Override boolean makeAROTraceDirectory(IDevice device, String traceName); @Override boolean makeDirectory(IDevice device, String dirpath); @Override String getProperty(IDevice device, String property); @Override SyncService getSyncService(IDevice device); @Override boolean removeEmulatorData(IDevice device, String deviceTracePath); @Override boolean stopTcpDump(IDevice device); Socket getLocalSocket(); @Override boolean checkTcpDumpRunning(IDevice device); @Override boolean startTcpDump(IDevice device, boolean seLinuxEnforced, String traceFolderName); @Override boolean isTraceRunning(); @Override String[] getShellReturn(IDevice device, String arocmd); @Override boolean checkPackageExist(IDevice device, String fullpackageName); @Override boolean runApkInDevice(IDevice device, String cmd); @Override boolean runVpnApkInDevice(IDevice device);  }