@Ignore @Test public void stopCollector(){ String[] str1 = {}; Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(str1); String[] str2 = {"some ip "}; Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(str2); try { Mockito.doNothing().when(fileManager).saveFile(Mockito.any(InputStream.class), Mockito.anyString()); } catch (IOException IOExp) { IOExp.printStackTrace(); } Mockito.doNothing().when(videoCapture).stopRecording(); Mockito.when(android.removeEmulatorData(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(true); StatusResult sResult= null; SyncService sycService = null; try { Mockito.when(device.getSyncService()).thenReturn(sycService); } catch (TimeoutException e1) { e1.printStackTrace(); } catch (AdbCommandRejectedException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } sResult = nonRootedAndroidCollector.stopCollector(); assertEquals(411, sResult.getError().getCode()); sycService = Mockito.mock(SyncService.class); try { Mockito.when(device.getSyncService()).thenReturn(sycService); } catch (TimeoutException e1) { e1.printStackTrace(); } catch (AdbCommandRejectedException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } try { Mockito.doNothing().when(sycService).pullFile(Mockito.anyString(), Mockito.anyString(), Mockito.any(ISyncProgressMonitor.class)); } catch (SyncException e) { e.printStackTrace(); } catch (TimeoutException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } sResult = nonRootedAndroidCollector.stopCollector(); assertTrue(sResult.isSuccess()); Hashtable<String, Object> extranalParams = new Hashtable<String, Object>(); Mockito.when(fileManager.directoryExistAndNotEmpty(Mockito.anyString())).thenReturn(false); Mockito.doNothing().when(fileManager).mkDir(Mockito.anyString()); Mockito.when(fileManager.directoryExist(Mockito.anyString())).thenReturn(true); IDevice aDevice1 = Mockito.mock(IDevice.class); Mockito.when(aDevice1.getSerialNumber()).thenReturn("device1"); IDevice[] devices = {aDevice1}; try { Mockito.when(adbService.getConnectedDevices()).thenReturn(devices); } catch (Exception exp) { exp.printStackTrace(); } Mockito.when(fileManager.fileExist(Mockito.anyString())).thenReturn(true); Mockito.when(android.runApkInDevice(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(true); String[] str3 = {"some ip ", "tun0: ip 10. some"}; Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(str3); try { Mockito.doNothing().when(videoCapture).init(Mockito.any(IDevice.class), Mockito.anyString()); Mockito.doNothing().when(videoCapture).addSubscriber(Mockito.any(IVideoImageSubscriber.class)); Mockito.doNothing().when(threadExecutor).execute(Mockito.any(IVideoCapture.class)); } catch (IOException e) { e.printStackTrace(); } nonRootedAndroidCollector.stopRunning(); Mockito.when(android.getShellReturn(Mockito.any(IDevice.class), Mockito.anyString())).thenReturn(noVpnCon).thenReturn(vpnActive); sResult = nonRootedAndroidCollector.startCollector(true, "test", VideoOption.LREZ, false, "device1", extranalParams, null); assertTrue(sResult.isSuccess()); Date aDate = new Date(); Mockito.when(videoCapture.getVideoStartTime()).thenReturn(aDate); sResult = nonRootedAndroidCollector.stopCollector(); assertEquals(411, sResult.getError().getCode()); }
@Override public StatusResult stopCollector() { StatusResult result = new StatusResult(); if (!stopAllServices()) { LOG.error("Cannot stop all services, please check services in device Settings->Apps->Running"); } if (!forceStopProcess()) { LOG.error("Cannot force stop VPN Collector"); } if (isAndroidVersionNougatOrHigher(device) == true) cpuTraceCollector.stopCpuTraceCapture(this.device); if (isVideo()) { LOG.debug("stopping video capture"); this.stopCaptureVideo(); } if(this.attnrScriptRun){ attnr.stopAtenuationScript(this.device); } LOG.debug("pulling trace to local dir"); new LogcatCollector(adbService, device.getSerialNumber()).collectLogcat(localTraceFolder, "Logcat.log"); result = pullTrace(this.mDataDeviceCollectortraceFileNames); if(result.isSuccess()) { try { metaDataHelper.initMetaData(localTraceFolder, traceDesc, traceType, targetedApp, appProducer); } catch (Exception e) { e.printStackTrace(); } } GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents( GoogleAnalyticsUtil.getAnalyticsEvents().getNonRootedCollector(), GoogleAnalyticsUtil.getAnalyticsEvents().getEndTrace()); running = false; return result; }
NorootedAndroidCollectorImpl implements IDataCollector, IVideoImageSubscriber { @Override public StatusResult stopCollector() { StatusResult result = new StatusResult(); if (!stopAllServices()) { LOG.error("Cannot stop all services, please check services in device Settings->Apps->Running"); } if (!forceStopProcess()) { LOG.error("Cannot force stop VPN Collector"); } if (isAndroidVersionNougatOrHigher(device) == true) cpuTraceCollector.stopCpuTraceCapture(this.device); if (isVideo()) { LOG.debug("stopping video capture"); this.stopCaptureVideo(); } if(this.attnrScriptRun){ attnr.stopAtenuationScript(this.device); } LOG.debug("pulling trace to local dir"); new LogcatCollector(adbService, device.getSerialNumber()).collectLogcat(localTraceFolder, "Logcat.log"); result = pullTrace(this.mDataDeviceCollectortraceFileNames); if(result.isSuccess()) { try { metaDataHelper.initMetaData(localTraceFolder, traceDesc, traceType, targetedApp, appProducer); } catch (Exception e) { e.printStackTrace(); } } GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents( GoogleAnalyticsUtil.getAnalyticsEvents().getNonRootedCollector(), GoogleAnalyticsUtil.getAnalyticsEvents().getEndTrace()); running = false; return result; } }
NorootedAndroidCollectorImpl implements IDataCollector, IVideoImageSubscriber { @Override public StatusResult stopCollector() { StatusResult result = new StatusResult(); if (!stopAllServices()) { LOG.error("Cannot stop all services, please check services in device Settings->Apps->Running"); } if (!forceStopProcess()) { LOG.error("Cannot force stop VPN Collector"); } if (isAndroidVersionNougatOrHigher(device) == true) cpuTraceCollector.stopCpuTraceCapture(this.device); if (isVideo()) { LOG.debug("stopping video capture"); this.stopCaptureVideo(); } if(this.attnrScriptRun){ attnr.stopAtenuationScript(this.device); } LOG.debug("pulling trace to local dir"); new LogcatCollector(adbService, device.getSerialNumber()).collectLogcat(localTraceFolder, "Logcat.log"); result = pullTrace(this.mDataDeviceCollectortraceFileNames); if(result.isSuccess()) { try { metaDataHelper.initMetaData(localTraceFolder, traceDesc, traceType, targetedApp, appProducer); } catch (Exception e) { e.printStackTrace(); } } GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents( GoogleAnalyticsUtil.getAnalyticsEvents().getNonRootedCollector(), GoogleAnalyticsUtil.getAnalyticsEvents().getEndTrace()); running = false; return result; }  }
NorootedAndroidCollectorImpl implements IDataCollector, IVideoImageSubscriber { @Override public StatusResult stopCollector() { StatusResult result = new StatusResult(); if (!stopAllServices()) { LOG.error("Cannot stop all services, please check services in device Settings->Apps->Running"); } if (!forceStopProcess()) { LOG.error("Cannot force stop VPN Collector"); } if (isAndroidVersionNougatOrHigher(device) == true) cpuTraceCollector.stopCpuTraceCapture(this.device); if (isVideo()) { LOG.debug("stopping video capture"); this.stopCaptureVideo(); } if(this.attnrScriptRun){ attnr.stopAtenuationScript(this.device); } LOG.debug("pulling trace to local dir"); new LogcatCollector(adbService, device.getSerialNumber()).collectLogcat(localTraceFolder, "Logcat.log"); result = pullTrace(this.mDataDeviceCollectortraceFileNames); if(result.isSuccess()) { try { metaDataHelper.initMetaData(localTraceFolder, traceDesc, traceType, targetedApp, appProducer); } catch (Exception e) { e.printStackTrace(); } } GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents( GoogleAnalyticsUtil.getAnalyticsEvents().getNonRootedCollector(), GoogleAnalyticsUtil.getAnalyticsEvents().getEndTrace()); running = false; return result; }  @Autowired void setMetaDataHelper(IMetaDataHelper metaDataHelper); @Autowired void setAndroid(IAndroid android); @Autowired void setExternalProcessRunner(IExternalProcessRunner runner); @Autowired void setFileManager(IFileManager filemanager); void setDevice(IDevice aDevice); @Autowired void setAdbService(IAdbService adbservice); @Autowired void setVideoCapture(IVideoCapture videocapture); @Autowired void setThreadExecutor(IThreadExecutor thread); @Autowired void setFileExtactor(IReadWriteFileExtractor extractor); @Override String getName(); @Override void addDeviceStatusSubscriber(IDeviceStatus subscriber); @Override void addVideoImageSubscriber(IVideoImageSubscriber subscriber); @Override void receiveImage(BufferedImage videoimage); @Override int getMajorVersion(); @Override String getMinorVersion(); @Override DataCollectorType getType(); @Override boolean isRunning(); void stopRunning(); @Override String[] getLog(); @Override StatusResult startCollector(boolean isCommandLine, String tracepath, VideoOption videoOption_deprecated,
			String password); @Override StatusResult startCollector(boolean isCommandLine, String folderToSaveTrace,
			VideoOption videoOption_deprecated, boolean isLiveViewVideo, String deviceId,
			Hashtable<String, Object> extraParams, String password); void cleanARO(); @Override boolean isTrafficCaptureRunning(int milliSeconds); boolean isVpnActivated(); @Override StatusResult stopCollector(); @Override void timeOutShutdown(); @Override void haltCollectorInDevice(); @Override String getPassword(); @Override boolean setPassword(String requestPassword); @Override String[] getDeviceSerialNumber(StatusResult status); @Override IAroDevice[] getDevices(StatusResult status); @Override boolean isDeviceDataPulled(); }
NorootedAndroidCollectorImpl implements IDataCollector, IVideoImageSubscriber { @Override public StatusResult stopCollector() { StatusResult result = new StatusResult(); if (!stopAllServices()) { LOG.error("Cannot stop all services, please check services in device Settings->Apps->Running"); } if (!forceStopProcess()) { LOG.error("Cannot force stop VPN Collector"); } if (isAndroidVersionNougatOrHigher(device) == true) cpuTraceCollector.stopCpuTraceCapture(this.device); if (isVideo()) { LOG.debug("stopping video capture"); this.stopCaptureVideo(); } if(this.attnrScriptRun){ attnr.stopAtenuationScript(this.device); } LOG.debug("pulling trace to local dir"); new LogcatCollector(adbService, device.getSerialNumber()).collectLogcat(localTraceFolder, "Logcat.log"); result = pullTrace(this.mDataDeviceCollectortraceFileNames); if(result.isSuccess()) { try { metaDataHelper.initMetaData(localTraceFolder, traceDesc, traceType, targetedApp, appProducer); } catch (Exception e) { e.printStackTrace(); } } GoogleAnalyticsUtil.getGoogleAnalyticsInstance().sendAnalyticsEvents( GoogleAnalyticsUtil.getAnalyticsEvents().getNonRootedCollector(), GoogleAnalyticsUtil.getAnalyticsEvents().getEndTrace()); running = false; return result; }  @Autowired void setMetaDataHelper(IMetaDataHelper metaDataHelper); @Autowired void setAndroid(IAndroid android); @Autowired void setExternalProcessRunner(IExternalProcessRunner runner); @Autowired void setFileManager(IFileManager filemanager); void setDevice(IDevice aDevice); @Autowired void setAdbService(IAdbService adbservice); @Autowired void setVideoCapture(IVideoCapture videocapture); @Autowired void setThreadExecutor(IThreadExecutor thread); @Autowired void setFileExtactor(IReadWriteFileExtractor extractor); @Override String getName(); @Override void addDeviceStatusSubscriber(IDeviceStatus subscriber); @Override void addVideoImageSubscriber(IVideoImageSubscriber subscriber); @Override void receiveImage(BufferedImage videoimage); @Override int getMajorVersion(); @Override String getMinorVersion(); @Override DataCollectorType getType(); @Override boolean isRunning(); void stopRunning(); @Override String[] getLog(); @Override StatusResult startCollector(boolean isCommandLine, String tracepath, VideoOption videoOption_deprecated,
			String password); @Override StatusResult startCollector(boolean isCommandLine, String folderToSaveTrace,
			VideoOption videoOption_deprecated, boolean isLiveViewVideo, String deviceId,
			Hashtable<String, Object> extraParams, String password); void cleanARO(); @Override boolean isTrafficCaptureRunning(int milliSeconds); boolean isVpnActivated(); @Override StatusResult stopCollector(); @Override void timeOutShutdown(); @Override void haltCollectorInDevice(); @Override String getPassword(); @Override boolean setPassword(String requestPassword); @Override String[] getDeviceSerialNumber(StatusResult status); @Override IAroDevice[] getDevices(StatusResult status); @Override boolean isDeviceDataPulled();  }