@Test public void getBestCompanionAd_withIncompatibleMediaType_shouldReturnNull() throws Exception { final VastXmlManager.ImageCompanionAdXmlManager companionXmlManager = initializeCompanionXmlManagerMock(300, 250, "image/rubbish", "image_url"); final VastCompanionAd bestCompanionAd = subject.getBestCompanionAd(Arrays.asList(companionXmlManager)); assertThat(bestCompanionAd).isNull(); }
VastCompanionAd getBestCompanionAd(final List<VastXmlManager.ImageCompanionAdXmlManager> managers) { final List<VastXmlManager.ImageCompanionAdXmlManager> companionXmlManagers = new ArrayList<VastXmlManager.ImageCompanionAdXmlManager>(managers); double bestCompanionFitness = Double.POSITIVE_INFINITY; VastXmlManager.ImageCompanionAdXmlManager bestCompanionXmlManager = null; final Iterator<VastXmlManager.ImageCompanionAdXmlManager> xmlManagerIterator = companionXmlManagers.iterator(); while (xmlManagerIterator.hasNext()) { final VastXmlManager.ImageCompanionAdXmlManager companionXmlManager = xmlManagerIterator.next(); final String imageType = companionXmlManager.getType(); final String imageUrl = companionXmlManager.getImageUrl(); if (!COMPANION_IMAGE_MIME_TYPES.contains(imageType) || imageUrl == null) { xmlManagerIterator.remove(); continue; } final Integer imageWidth = companionXmlManager.getWidth(); final Integer imageHeight = companionXmlManager.getHeight(); if (imageWidth == null || imageWidth <= 0 || imageHeight == null || imageHeight <= 0) { continue; } final double companionFitness = calculateFitness(imageWidth, imageHeight); if (companionFitness < bestCompanionFitness) { bestCompanionFitness = companionFitness; bestCompanionXmlManager = companionXmlManager; } } if (bestCompanionXmlManager == null && !companionXmlManagers.isEmpty()) { bestCompanionXmlManager = companionXmlManagers.get(0); } if (bestCompanionXmlManager != null) { return new VastCompanionAd( bestCompanionXmlManager.getWidth(), bestCompanionXmlManager.getHeight(), bestCompanionXmlManager.getImageUrl(), bestCompanionXmlManager.getClickThroughUrl(), new ArrayList<String>(bestCompanionXmlManager.getClickTrackers()) ); } return null; }
VastManager implements VastXmlManagerAggregatorListener { VastCompanionAd getBestCompanionAd(final List<VastXmlManager.ImageCompanionAdXmlManager> managers) { final List<VastXmlManager.ImageCompanionAdXmlManager> companionXmlManagers = new ArrayList<VastXmlManager.ImageCompanionAdXmlManager>(managers); double bestCompanionFitness = Double.POSITIVE_INFINITY; VastXmlManager.ImageCompanionAdXmlManager bestCompanionXmlManager = null; final Iterator<VastXmlManager.ImageCompanionAdXmlManager> xmlManagerIterator = companionXmlManagers.iterator(); while (xmlManagerIterator.hasNext()) { final VastXmlManager.ImageCompanionAdXmlManager companionXmlManager = xmlManagerIterator.next(); final String imageType = companionXmlManager.getType(); final String imageUrl = companionXmlManager.getImageUrl(); if (!COMPANION_IMAGE_MIME_TYPES.contains(imageType) || imageUrl == null) { xmlManagerIterator.remove(); continue; } final Integer imageWidth = companionXmlManager.getWidth(); final Integer imageHeight = companionXmlManager.getHeight(); if (imageWidth == null || imageWidth <= 0 || imageHeight == null || imageHeight <= 0) { continue; } final double companionFitness = calculateFitness(imageWidth, imageHeight); if (companionFitness < bestCompanionFitness) { bestCompanionFitness = companionFitness; bestCompanionXmlManager = companionXmlManager; } } if (bestCompanionXmlManager == null && !companionXmlManagers.isEmpty()) { bestCompanionXmlManager = companionXmlManagers.get(0); } if (bestCompanionXmlManager != null) { return new VastCompanionAd( bestCompanionXmlManager.getWidth(), bestCompanionXmlManager.getHeight(), bestCompanionXmlManager.getImageUrl(), bestCompanionXmlManager.getClickThroughUrl(), new ArrayList<String>(bestCompanionXmlManager.getClickTrackers()) ); } return null; } }
VastManager implements VastXmlManagerAggregatorListener { VastCompanionAd getBestCompanionAd(final List<VastXmlManager.ImageCompanionAdXmlManager> managers) { final List<VastXmlManager.ImageCompanionAdXmlManager> companionXmlManagers = new ArrayList<VastXmlManager.ImageCompanionAdXmlManager>(managers); double bestCompanionFitness = Double.POSITIVE_INFINITY; VastXmlManager.ImageCompanionAdXmlManager bestCompanionXmlManager = null; final Iterator<VastXmlManager.ImageCompanionAdXmlManager> xmlManagerIterator = companionXmlManagers.iterator(); while (xmlManagerIterator.hasNext()) { final VastXmlManager.ImageCompanionAdXmlManager companionXmlManager = xmlManagerIterator.next(); final String imageType = companionXmlManager.getType(); final String imageUrl = companionXmlManager.getImageUrl(); if (!COMPANION_IMAGE_MIME_TYPES.contains(imageType) || imageUrl == null) { xmlManagerIterator.remove(); continue; } final Integer imageWidth = companionXmlManager.getWidth(); final Integer imageHeight = companionXmlManager.getHeight(); if (imageWidth == null || imageWidth <= 0 || imageHeight == null || imageHeight <= 0) { continue; } final double companionFitness = calculateFitness(imageWidth, imageHeight); if (companionFitness < bestCompanionFitness) { bestCompanionFitness = companionFitness; bestCompanionXmlManager = companionXmlManager; } } if (bestCompanionXmlManager == null && !companionXmlManagers.isEmpty()) { bestCompanionXmlManager = companionXmlManagers.get(0); } if (bestCompanionXmlManager != null) { return new VastCompanionAd( bestCompanionXmlManager.getWidth(), bestCompanionXmlManager.getHeight(), bestCompanionXmlManager.getImageUrl(), bestCompanionXmlManager.getClickThroughUrl(), new ArrayList<String>(bestCompanionXmlManager.getClickTrackers()) ); } return null; } VastManager(final Context context); }
VastManager implements VastXmlManagerAggregatorListener { VastCompanionAd getBestCompanionAd(final List<VastXmlManager.ImageCompanionAdXmlManager> managers) { final List<VastXmlManager.ImageCompanionAdXmlManager> companionXmlManagers = new ArrayList<VastXmlManager.ImageCompanionAdXmlManager>(managers); double bestCompanionFitness = Double.POSITIVE_INFINITY; VastXmlManager.ImageCompanionAdXmlManager bestCompanionXmlManager = null; final Iterator<VastXmlManager.ImageCompanionAdXmlManager> xmlManagerIterator = companionXmlManagers.iterator(); while (xmlManagerIterator.hasNext()) { final VastXmlManager.ImageCompanionAdXmlManager companionXmlManager = xmlManagerIterator.next(); final String imageType = companionXmlManager.getType(); final String imageUrl = companionXmlManager.getImageUrl(); if (!COMPANION_IMAGE_MIME_TYPES.contains(imageType) || imageUrl == null) { xmlManagerIterator.remove(); continue; } final Integer imageWidth = companionXmlManager.getWidth(); final Integer imageHeight = companionXmlManager.getHeight(); if (imageWidth == null || imageWidth <= 0 || imageHeight == null || imageHeight <= 0) { continue; } final double companionFitness = calculateFitness(imageWidth, imageHeight); if (companionFitness < bestCompanionFitness) { bestCompanionFitness = companionFitness; bestCompanionXmlManager = companionXmlManager; } } if (bestCompanionXmlManager == null && !companionXmlManagers.isEmpty()) { bestCompanionXmlManager = companionXmlManagers.get(0); } if (bestCompanionXmlManager != null) { return new VastCompanionAd( bestCompanionXmlManager.getWidth(), bestCompanionXmlManager.getHeight(), bestCompanionXmlManager.getImageUrl(), bestCompanionXmlManager.getClickThroughUrl(), new ArrayList<String>(bestCompanionXmlManager.getClickTrackers()) ); } return null; } VastManager(final Context context); void prepareVastVideoConfiguration(final String vastXml, final VastManagerListener vastManagerListener); void cancel(); @Override void onAggregationComplete(final List<VastXmlManager> vastXmlManagers); }
VastManager implements VastXmlManagerAggregatorListener { VastCompanionAd getBestCompanionAd(final List<VastXmlManager.ImageCompanionAdXmlManager> managers) { final List<VastXmlManager.ImageCompanionAdXmlManager> companionXmlManagers = new ArrayList<VastXmlManager.ImageCompanionAdXmlManager>(managers); double bestCompanionFitness = Double.POSITIVE_INFINITY; VastXmlManager.ImageCompanionAdXmlManager bestCompanionXmlManager = null; final Iterator<VastXmlManager.ImageCompanionAdXmlManager> xmlManagerIterator = companionXmlManagers.iterator(); while (xmlManagerIterator.hasNext()) { final VastXmlManager.ImageCompanionAdXmlManager companionXmlManager = xmlManagerIterator.next(); final String imageType = companionXmlManager.getType(); final String imageUrl = companionXmlManager.getImageUrl(); if (!COMPANION_IMAGE_MIME_TYPES.contains(imageType) || imageUrl == null) { xmlManagerIterator.remove(); continue; } final Integer imageWidth = companionXmlManager.getWidth(); final Integer imageHeight = companionXmlManager.getHeight(); if (imageWidth == null || imageWidth <= 0 || imageHeight == null || imageHeight <= 0) { continue; } final double companionFitness = calculateFitness(imageWidth, imageHeight); if (companionFitness < bestCompanionFitness) { bestCompanionFitness = companionFitness; bestCompanionXmlManager = companionXmlManager; } } if (bestCompanionXmlManager == null && !companionXmlManagers.isEmpty()) { bestCompanionXmlManager = companionXmlManagers.get(0); } if (bestCompanionXmlManager != null) { return new VastCompanionAd( bestCompanionXmlManager.getWidth(), bestCompanionXmlManager.getHeight(), bestCompanionXmlManager.getImageUrl(), bestCompanionXmlManager.getClickThroughUrl(), new ArrayList<String>(bestCompanionXmlManager.getClickTrackers()) ); } return null; } VastManager(final Context context); void prepareVastVideoConfiguration(final String vastXml, final VastManagerListener vastManagerListener); void cancel(); @Override void onAggregationComplete(final List<VastXmlManager> vastXmlManagers);  }