@Test public void runTest_resIsPass(){ Mockito.when(httpRequestInfo01.getDirection()).thenReturn(HttpDirection.RESPONSE); Mockito.when(httpRequestInfo01.getContentType()).thenReturn("abc"); Mockito.when(httpRequestInfo01.getContentLength()).thenReturn(6145); Mockito.when(httpRequestInfo02.getDirection()).thenReturn(HttpDirection.REQUEST); Mockito.when(httpRequestInfo03.getDirection()).thenReturn(HttpDirection.RESPONSE); Mockito.when(httpRequestInfo04.getDirection()).thenReturn(HttpDirection.RESPONSE); List<HttpRequestResponseInfo> value = new ArrayList<HttpRequestResponseInfo>(); value.add(httpRequestInfo01); value.add(httpRequestInfo02); value.add(httpRequestInfo03); value.add(httpRequestInfo04); Mockito.when(session01.getRequestResponseInfo()).thenReturn(value); List<Session> sessionList = new ArrayList<Session>(); Mockito.when(session01.getDomainName()).thenReturn("www.google.com"); sessionList.add(session01); Mockito.when(tracedata.getSessionlist()).thenReturn(sessionList); AbstractBestPracticeResult testResult = spriteImageImpl.runTest(tracedata); assertEquals(BPResultType.PASS,testResult.getResultType() ); }
@Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { SpriteImageResult result = new SpriteImageResult(); List<SpriteImageEntry> analysisResults = new ArrayList<SpriteImageEntry>(); for(Session session:tracedata.getSessionlist()){ double lastTimeStamp = 0.0; HttpRequestResponseInfo lastReqRessInfo = null; HttpRequestResponseInfo secondReqRessInfo = null; boolean thirdOccurrenceTriggered = false; for(HttpRequestResponseInfo req:session.getRequestResponseInfo()){ if(req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getFirstDataPacket() != null && req.getContentType().contains("image/") && req.getContentLength() < IMAGE_SIZE_LIMIT){ PacketInfo pktInfo = req.getFirstDataPacket(); if (lastTimeStamp == 0.0) { lastTimeStamp = pktInfo.getTimeStamp(); lastReqRessInfo = req; continue; } else{ if ((pktInfo.getTimeStamp() - lastTimeStamp) <= 5.0) { if (!thirdOccurrenceTriggered) { secondReqRessInfo = req; thirdOccurrenceTriggered = true; continue; } else { analysisResults.add(new SpriteImageEntry(lastReqRessInfo)); analysisResults.add(new SpriteImageEntry(secondReqRessInfo)); analysisResults.add(new SpriteImageEntry(req)); lastTimeStamp = 0.0; lastReqRessInfo = null; secondReqRessInfo = null; thirdOccurrenceTriggered = false; } } lastTimeStamp = pktInfo.getTimeStamp(); lastReqRessInfo = req; secondReqRessInfo = null; thirdOccurrenceTriggered = false; } } } } result.setAnalysisResults(analysisResults); String text = ""; if(analysisResults.isEmpty()){ result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, analysisResults.size()); result.setResultText(text); }else{ result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), analysisResults.size()); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllNumberOfSpriteFiles(exportAllNumberOfSpriteFiles); return result; }
SpriteImageImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { SpriteImageResult result = new SpriteImageResult(); List<SpriteImageEntry> analysisResults = new ArrayList<SpriteImageEntry>(); for(Session session:tracedata.getSessionlist()){ double lastTimeStamp = 0.0; HttpRequestResponseInfo lastReqRessInfo = null; HttpRequestResponseInfo secondReqRessInfo = null; boolean thirdOccurrenceTriggered = false; for(HttpRequestResponseInfo req:session.getRequestResponseInfo()){ if(req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getFirstDataPacket() != null && req.getContentType().contains("image/") && req.getContentLength() < IMAGE_SIZE_LIMIT){ PacketInfo pktInfo = req.getFirstDataPacket(); if (lastTimeStamp == 0.0) { lastTimeStamp = pktInfo.getTimeStamp(); lastReqRessInfo = req; continue; } else{ if ((pktInfo.getTimeStamp() - lastTimeStamp) <= 5.0) { if (!thirdOccurrenceTriggered) { secondReqRessInfo = req; thirdOccurrenceTriggered = true; continue; } else { analysisResults.add(new SpriteImageEntry(lastReqRessInfo)); analysisResults.add(new SpriteImageEntry(secondReqRessInfo)); analysisResults.add(new SpriteImageEntry(req)); lastTimeStamp = 0.0; lastReqRessInfo = null; secondReqRessInfo = null; thirdOccurrenceTriggered = false; } } lastTimeStamp = pktInfo.getTimeStamp(); lastReqRessInfo = req; secondReqRessInfo = null; thirdOccurrenceTriggered = false; } } } } result.setAnalysisResults(analysisResults); String text = ""; if(analysisResults.isEmpty()){ result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, analysisResults.size()); result.setResultText(text); }else{ result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), analysisResults.size()); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllNumberOfSpriteFiles(exportAllNumberOfSpriteFiles); return result; } }
SpriteImageImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { SpriteImageResult result = new SpriteImageResult(); List<SpriteImageEntry> analysisResults = new ArrayList<SpriteImageEntry>(); for(Session session:tracedata.getSessionlist()){ double lastTimeStamp = 0.0; HttpRequestResponseInfo lastReqRessInfo = null; HttpRequestResponseInfo secondReqRessInfo = null; boolean thirdOccurrenceTriggered = false; for(HttpRequestResponseInfo req:session.getRequestResponseInfo()){ if(req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getFirstDataPacket() != null && req.getContentType().contains("image/") && req.getContentLength() < IMAGE_SIZE_LIMIT){ PacketInfo pktInfo = req.getFirstDataPacket(); if (lastTimeStamp == 0.0) { lastTimeStamp = pktInfo.getTimeStamp(); lastReqRessInfo = req; continue; } else{ if ((pktInfo.getTimeStamp() - lastTimeStamp) <= 5.0) { if (!thirdOccurrenceTriggered) { secondReqRessInfo = req; thirdOccurrenceTriggered = true; continue; } else { analysisResults.add(new SpriteImageEntry(lastReqRessInfo)); analysisResults.add(new SpriteImageEntry(secondReqRessInfo)); analysisResults.add(new SpriteImageEntry(req)); lastTimeStamp = 0.0; lastReqRessInfo = null; secondReqRessInfo = null; thirdOccurrenceTriggered = false; } } lastTimeStamp = pktInfo.getTimeStamp(); lastReqRessInfo = req; secondReqRessInfo = null; thirdOccurrenceTriggered = false; } } } } result.setAnalysisResults(analysisResults); String text = ""; if(analysisResults.isEmpty()){ result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, analysisResults.size()); result.setResultText(text); }else{ result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), analysisResults.size()); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllNumberOfSpriteFiles(exportAllNumberOfSpriteFiles); return result; }  }
SpriteImageImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { SpriteImageResult result = new SpriteImageResult(); List<SpriteImageEntry> analysisResults = new ArrayList<SpriteImageEntry>(); for(Session session:tracedata.getSessionlist()){ double lastTimeStamp = 0.0; HttpRequestResponseInfo lastReqRessInfo = null; HttpRequestResponseInfo secondReqRessInfo = null; boolean thirdOccurrenceTriggered = false; for(HttpRequestResponseInfo req:session.getRequestResponseInfo()){ if(req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getFirstDataPacket() != null && req.getContentType().contains("image/") && req.getContentLength() < IMAGE_SIZE_LIMIT){ PacketInfo pktInfo = req.getFirstDataPacket(); if (lastTimeStamp == 0.0) { lastTimeStamp = pktInfo.getTimeStamp(); lastReqRessInfo = req; continue; } else{ if ((pktInfo.getTimeStamp() - lastTimeStamp) <= 5.0) { if (!thirdOccurrenceTriggered) { secondReqRessInfo = req; thirdOccurrenceTriggered = true; continue; } else { analysisResults.add(new SpriteImageEntry(lastReqRessInfo)); analysisResults.add(new SpriteImageEntry(secondReqRessInfo)); analysisResults.add(new SpriteImageEntry(req)); lastTimeStamp = 0.0; lastReqRessInfo = null; secondReqRessInfo = null; thirdOccurrenceTriggered = false; } } lastTimeStamp = pktInfo.getTimeStamp(); lastReqRessInfo = req; secondReqRessInfo = null; thirdOccurrenceTriggered = false; } } } } result.setAnalysisResults(analysisResults); String text = ""; if(analysisResults.isEmpty()){ result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, analysisResults.size()); result.setResultText(text); }else{ result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), analysisResults.size()); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllNumberOfSpriteFiles(exportAllNumberOfSpriteFiles); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata); }
SpriteImageImpl implements IBestPractice { @Override public AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata) { SpriteImageResult result = new SpriteImageResult(); List<SpriteImageEntry> analysisResults = new ArrayList<SpriteImageEntry>(); for(Session session:tracedata.getSessionlist()){ double lastTimeStamp = 0.0; HttpRequestResponseInfo lastReqRessInfo = null; HttpRequestResponseInfo secondReqRessInfo = null; boolean thirdOccurrenceTriggered = false; for(HttpRequestResponseInfo req:session.getRequestResponseInfo()){ if(req.getDirection() == HttpDirection.RESPONSE && req.getContentType() != null && req.getFirstDataPacket() != null && req.getContentType().contains("image/") && req.getContentLength() < IMAGE_SIZE_LIMIT){ PacketInfo pktInfo = req.getFirstDataPacket(); if (lastTimeStamp == 0.0) { lastTimeStamp = pktInfo.getTimeStamp(); lastReqRessInfo = req; continue; } else{ if ((pktInfo.getTimeStamp() - lastTimeStamp) <= 5.0) { if (!thirdOccurrenceTriggered) { secondReqRessInfo = req; thirdOccurrenceTriggered = true; continue; } else { analysisResults.add(new SpriteImageEntry(lastReqRessInfo)); analysisResults.add(new SpriteImageEntry(secondReqRessInfo)); analysisResults.add(new SpriteImageEntry(req)); lastTimeStamp = 0.0; lastReqRessInfo = null; secondReqRessInfo = null; thirdOccurrenceTriggered = false; } } lastTimeStamp = pktInfo.getTimeStamp(); lastReqRessInfo = req; secondReqRessInfo = null; thirdOccurrenceTriggered = false; } } } } result.setAnalysisResults(analysisResults); String text = ""; if(analysisResults.isEmpty()){ result.setResultType(BPResultType.PASS); text = MessageFormat.format(textResultPass, analysisResults.size()); result.setResultText(text); }else{ result.setResultType(BPResultType.FAIL); text = MessageFormat.format(textResults, ApplicationConfig.getInstance().getAppShortName(), analysisResults.size()); result.setResultText(text); } result.setAboutText(aboutText); result.setDetailTitle(detailTitle); result.setLearnMoreUrl(learnMoreUrl); result.setOverviewTitle(overviewTitle); result.setExportAllNumberOfSpriteFiles(exportAllNumberOfSpriteFiles); return result; }  @Override AbstractBestPracticeResult runTest(PacketAnalyzerResult tracedata);  }