@Test public void runTest_resIsNoErrResultTypeIsFail() { Mockito.when(tracedata.getFilter()).thenReturn(analysisFilter); Mockito.when(timeRange.getBeginTime()).thenReturn(0.0); Mockito.when(timeRange.getEndTime()).thenReturn(100.0); Mockito.when(traceResult.getCameraActiveDuration()).thenReturn(10.0); Mockito.when(traceResult.getBluetoothActiveDuration()).thenReturn(10.0); Mockito.when(traceResult.getGpsActiveDuration()).thenReturn(10.0); Mockito.when(traceResult.getTraceResultType()).thenReturn(TraceResultType.TRACE_DIRECTORY); Mockito.when((TraceDirectoryResult) tracedata.getTraceresult()).thenReturn(traceResult); Mockito.when(analysisFilter.getTimeRange()).thenReturn(timeRange); acPrphlImpl = (AccessingPeripheralImpl) context.getBean("accessingPeripheral"); AbstractBestPracticeResult testResult = acPrphlImpl.runTest(tracedata); assertEquals(BPResultType.NO_DATA, testResult.getResultType()); }
@Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { AccessingPeripheralResult result = new AccessingPeripheralResult(); AbstractTraceResult traceResult = tracedata.getTraceresult(); TraceDirectoryResult trresult = null; if (traceResult != null && traceResult instanceof TraceDirectoryResult) { trresult = (TraceDirectoryResult) traceResult; } if (trresult != null && isPeripheralDataAvailable(trresult)) { double activeGPSRatio = 0.0; double activeBluetoothRatio = 0.0; double activeCameraRatio = 0.0; double gpsActiveDuration = 0.0; double bluetoothActiveDuration = 0.0; double cameraActiveDuration = 0.0; double duration = 0.0; boolean accessingPeripherals = true; TimeRange timeRange = null; if (tracedata.getFilter() != null) { timeRange = tracedata.getFilter().getTimeRange(); } if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) { gpsActiveDuration = trresult.getGpsActiveDuration(); bluetoothActiveDuration = trresult.getBluetoothActiveDuration(); cameraActiveDuration = trresult.getCameraActiveDuration(); } if (timeRange != null) { duration = timeRange.getEndTime() - timeRange.getBeginTime(); } else { duration = tracedata.getTraceresult().getTraceDuration(); } activeGPSRatio = (gpsActiveDuration * 100) / duration; activeBluetoothRatio = (bluetoothActiveDuration * 100) / duration; activeCameraRatio = (cameraActiveDuration * 100) / duration; result.setActiveBluetoothRatio(activeBluetoothRatio); result.setActiveCameraRatio(activeCameraRatio); result.setActiveGPSRatio(activeGPSRatio); result.setActiveBluetoothDuration(bluetoothActiveDuration); result.setActiveCameraDuration(cameraActiveDuration); result.setActiveGPSDuration(gpsActiveDuration); if (activeGPSRatio > PERIPHERAL_ACTIVE_LIMIT || activeBluetoothRatio > PERIPHERAL_ACTIVE_LIMIT || activeCameraRatio > PERIPHERAL_ACTIVE_LIMIT) { accessingPeripherals = false; } String cameraPer = "0"; NumberFormat nfor = NumberFormat.getIntegerInstance(); if (cameraActiveDuration != 0.0) { if (activeCameraRatio < 1.0) { cameraPer = Util.percentageFormat(activeCameraRatio); } else { cameraPer = nfor.format(activeCameraRatio); } } String key = ""; if (accessingPeripherals) { result.setResultType(BPResultType.PASS); key = this.textResultPass; } else { result.setResultType(BPResultType.WARNING); key = this.textResults; } String text = MessageFormat.format(key, activeGPSRatio, activeBluetoothRatio, cameraPer); result.setResultText(text); } else { result.setResultText(noData); result.setResultType(BPResultType.NO_DATA); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllBTDesc(exportAllBTDesc); result.setExportAllCamDesc(exportAllCamDesc); result.setExportAllGPSDesc(exportAllGPSDesc); return result; }
AccessingPeripheralImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { AccessingPeripheralResult result = new AccessingPeripheralResult(); AbstractTraceResult traceResult = tracedata.getTraceresult(); TraceDirectoryResult trresult = null; if (traceResult != null && traceResult instanceof TraceDirectoryResult) { trresult = (TraceDirectoryResult) traceResult; } if (trresult != null && isPeripheralDataAvailable(trresult)) { double activeGPSRatio = 0.0; double activeBluetoothRatio = 0.0; double activeCameraRatio = 0.0; double gpsActiveDuration = 0.0; double bluetoothActiveDuration = 0.0; double cameraActiveDuration = 0.0; double duration = 0.0; boolean accessingPeripherals = true; TimeRange timeRange = null; if (tracedata.getFilter() != null) { timeRange = tracedata.getFilter().getTimeRange(); } if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) { gpsActiveDuration = trresult.getGpsActiveDuration(); bluetoothActiveDuration = trresult.getBluetoothActiveDuration(); cameraActiveDuration = trresult.getCameraActiveDuration(); } if (timeRange != null) { duration = timeRange.getEndTime() - timeRange.getBeginTime(); } else { duration = tracedata.getTraceresult().getTraceDuration(); } activeGPSRatio = (gpsActiveDuration * 100) / duration; activeBluetoothRatio = (bluetoothActiveDuration * 100) / duration; activeCameraRatio = (cameraActiveDuration * 100) / duration; result.setActiveBluetoothRatio(activeBluetoothRatio); result.setActiveCameraRatio(activeCameraRatio); result.setActiveGPSRatio(activeGPSRatio); result.setActiveBluetoothDuration(bluetoothActiveDuration); result.setActiveCameraDuration(cameraActiveDuration); result.setActiveGPSDuration(gpsActiveDuration); if (activeGPSRatio > PERIPHERAL_ACTIVE_LIMIT || activeBluetoothRatio > PERIPHERAL_ACTIVE_LIMIT || activeCameraRatio > PERIPHERAL_ACTIVE_LIMIT) { accessingPeripherals = false; } String cameraPer = "0"; NumberFormat nfor = NumberFormat.getIntegerInstance(); if (cameraActiveDuration != 0.0) { if (activeCameraRatio < 1.0) { cameraPer = Util.percentageFormat(activeCameraRatio); } else { cameraPer = nfor.format(activeCameraRatio); } } String key = ""; if (accessingPeripherals) { result.setResultType(BPResultType.PASS); key = this.textResultPass; } else { result.setResultType(BPResultType.WARNING); key = this.textResults; } String text = MessageFormat.format(key, activeGPSRatio, activeBluetoothRatio, cameraPer); result.setResultText(text); } else { result.setResultText(noData); result.setResultType(BPResultType.NO_DATA); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllBTDesc(exportAllBTDesc); result.setExportAllCamDesc(exportAllCamDesc); result.setExportAllGPSDesc(exportAllGPSDesc); return result; } }
AccessingPeripheralImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { AccessingPeripheralResult result = new AccessingPeripheralResult(); AbstractTraceResult traceResult = tracedata.getTraceresult(); TraceDirectoryResult trresult = null; if (traceResult != null && traceResult instanceof TraceDirectoryResult) { trresult = (TraceDirectoryResult) traceResult; } if (trresult != null && isPeripheralDataAvailable(trresult)) { double activeGPSRatio = 0.0; double activeBluetoothRatio = 0.0; double activeCameraRatio = 0.0; double gpsActiveDuration = 0.0; double bluetoothActiveDuration = 0.0; double cameraActiveDuration = 0.0; double duration = 0.0; boolean accessingPeripherals = true; TimeRange timeRange = null; if (tracedata.getFilter() != null) { timeRange = tracedata.getFilter().getTimeRange(); } if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) { gpsActiveDuration = trresult.getGpsActiveDuration(); bluetoothActiveDuration = trresult.getBluetoothActiveDuration(); cameraActiveDuration = trresult.getCameraActiveDuration(); } if (timeRange != null) { duration = timeRange.getEndTime() - timeRange.getBeginTime(); } else { duration = tracedata.getTraceresult().getTraceDuration(); } activeGPSRatio = (gpsActiveDuration * 100) / duration; activeBluetoothRatio = (bluetoothActiveDuration * 100) / duration; activeCameraRatio = (cameraActiveDuration * 100) / duration; result.setActiveBluetoothRatio(activeBluetoothRatio); result.setActiveCameraRatio(activeCameraRatio); result.setActiveGPSRatio(activeGPSRatio); result.setActiveBluetoothDuration(bluetoothActiveDuration); result.setActiveCameraDuration(cameraActiveDuration); result.setActiveGPSDuration(gpsActiveDuration); if (activeGPSRatio > PERIPHERAL_ACTIVE_LIMIT || activeBluetoothRatio > PERIPHERAL_ACTIVE_LIMIT || activeCameraRatio > PERIPHERAL_ACTIVE_LIMIT) { accessingPeripherals = false; } String cameraPer = "0"; NumberFormat nfor = NumberFormat.getIntegerInstance(); if (cameraActiveDuration != 0.0) { if (activeCameraRatio < 1.0) { cameraPer = Util.percentageFormat(activeCameraRatio); } else { cameraPer = nfor.format(activeCameraRatio); } } String key = ""; if (accessingPeripherals) { result.setResultType(BPResultType.PASS); key = this.textResultPass; } else { result.setResultType(BPResultType.WARNING); key = this.textResults; } String text = MessageFormat.format(key, activeGPSRatio, activeBluetoothRatio, cameraPer); result.setResultText(text); } else { result.setResultText(noData); result.setResultType(BPResultType.NO_DATA); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllBTDesc(exportAllBTDesc); result.setExportAllCamDesc(exportAllCamDesc); result.setExportAllGPSDesc(exportAllGPSDesc); return result; }  }
AccessingPeripheralImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { AccessingPeripheralResult result = new AccessingPeripheralResult(); AbstractTraceResult traceResult = tracedata.getTraceresult(); TraceDirectoryResult trresult = null; if (traceResult != null && traceResult instanceof TraceDirectoryResult) { trresult = (TraceDirectoryResult) traceResult; } if (trresult != null && isPeripheralDataAvailable(trresult)) { double activeGPSRatio = 0.0; double activeBluetoothRatio = 0.0; double activeCameraRatio = 0.0; double gpsActiveDuration = 0.0; double bluetoothActiveDuration = 0.0; double cameraActiveDuration = 0.0; double duration = 0.0; boolean accessingPeripherals = true; TimeRange timeRange = null; if (tracedata.getFilter() != null) { timeRange = tracedata.getFilter().getTimeRange(); } if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) { gpsActiveDuration = trresult.getGpsActiveDuration(); bluetoothActiveDuration = trresult.getBluetoothActiveDuration(); cameraActiveDuration = trresult.getCameraActiveDuration(); } if (timeRange != null) { duration = timeRange.getEndTime() - timeRange.getBeginTime(); } else { duration = tracedata.getTraceresult().getTraceDuration(); } activeGPSRatio = (gpsActiveDuration * 100) / duration; activeBluetoothRatio = (bluetoothActiveDuration * 100) / duration; activeCameraRatio = (cameraActiveDuration * 100) / duration; result.setActiveBluetoothRatio(activeBluetoothRatio); result.setActiveCameraRatio(activeCameraRatio); result.setActiveGPSRatio(activeGPSRatio); result.setActiveBluetoothDuration(bluetoothActiveDuration); result.setActiveCameraDuration(cameraActiveDuration); result.setActiveGPSDuration(gpsActiveDuration); if (activeGPSRatio > PERIPHERAL_ACTIVE_LIMIT || activeBluetoothRatio > PERIPHERAL_ACTIVE_LIMIT || activeCameraRatio > PERIPHERAL_ACTIVE_LIMIT) { accessingPeripherals = false; } String cameraPer = "0"; NumberFormat nfor = NumberFormat.getIntegerInstance(); if (cameraActiveDuration != 0.0) { if (activeCameraRatio < 1.0) { cameraPer = Util.percentageFormat(activeCameraRatio); } else { cameraPer = nfor.format(activeCameraRatio); } } String key = ""; if (accessingPeripherals) { result.setResultType(BPResultType.PASS); key = this.textResultPass; } else { result.setResultType(BPResultType.WARNING); key = this.textResults; } String text = MessageFormat.format(key, activeGPSRatio, activeBluetoothRatio, cameraPer); result.setResultText(text); } else { result.setResultText(noData); result.setResultType(BPResultType.NO_DATA); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllBTDesc(exportAllBTDesc); result.setExportAllCamDesc(exportAllCamDesc); result.setExportAllGPSDesc(exportAllGPSDesc); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata); }
AccessingPeripheralImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { AccessingPeripheralResult result = new AccessingPeripheralResult(); AbstractTraceResult traceResult = tracedata.getTraceresult(); TraceDirectoryResult trresult = null; if (traceResult != null && traceResult instanceof TraceDirectoryResult) { trresult = (TraceDirectoryResult) traceResult; } if (trresult != null && isPeripheralDataAvailable(trresult)) { double activeGPSRatio = 0.0; double activeBluetoothRatio = 0.0; double activeCameraRatio = 0.0; double gpsActiveDuration = 0.0; double bluetoothActiveDuration = 0.0; double cameraActiveDuration = 0.0; double duration = 0.0; boolean accessingPeripherals = true; TimeRange timeRange = null; if (tracedata.getFilter() != null) { timeRange = tracedata.getFilter().getTimeRange(); } if (tracedata.getTraceresult().getTraceResultType() == TraceResultType.TRACE_DIRECTORY) { gpsActiveDuration = trresult.getGpsActiveDuration(); bluetoothActiveDuration = trresult.getBluetoothActiveDuration(); cameraActiveDuration = trresult.getCameraActiveDuration(); } if (timeRange != null) { duration = timeRange.getEndTime() - timeRange.getBeginTime(); } else { duration = tracedata.getTraceresult().getTraceDuration(); } activeGPSRatio = (gpsActiveDuration * 100) / duration; activeBluetoothRatio = (bluetoothActiveDuration * 100) / duration; activeCameraRatio = (cameraActiveDuration * 100) / duration; result.setActiveBluetoothRatio(activeBluetoothRatio); result.setActiveCameraRatio(activeCameraRatio); result.setActiveGPSRatio(activeGPSRatio); result.setActiveBluetoothDuration(bluetoothActiveDuration); result.setActiveCameraDuration(cameraActiveDuration); result.setActiveGPSDuration(gpsActiveDuration); if (activeGPSRatio > PERIPHERAL_ACTIVE_LIMIT || activeBluetoothRatio > PERIPHERAL_ACTIVE_LIMIT || activeCameraRatio > PERIPHERAL_ACTIVE_LIMIT) { accessingPeripherals = false; } String cameraPer = "0"; NumberFormat nfor = NumberFormat.getIntegerInstance(); if (cameraActiveDuration != 0.0) { if (activeCameraRatio < 1.0) { cameraPer = Util.percentageFormat(activeCameraRatio); } else { cameraPer = nfor.format(activeCameraRatio); } } String key = ""; if (accessingPeripherals) { result.setResultType(BPResultType.PASS); key = this.textResultPass; } else { result.setResultType(BPResultType.WARNING); key = this.textResults; } String text = MessageFormat.format(key, activeGPSRatio, activeBluetoothRatio, cameraPer); result.setResultText(text); } else { result.setResultText(noData); result.setResultType(BPResultType.NO_DATA); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllBTDesc(exportAllBTDesc); result.setExportAllCamDesc(exportAllCamDesc); result.setExportAllGPSDesc(exportAllGPSDesc); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata);  }