@Test public void getBestMediaFileUrl_withZeroDimension_shouldReturnMediaFileUrl() throws Exception { final VastXmlManager.MediaXmlManager mediaXmlManager = initializeMediaXmlManagerMock(0, 250, "video/mp4", "video_url"); final String bestMediaFileUrl = subject.getBestMediaFileUrl(Arrays.asList(mediaXmlManager)); assertThat(bestMediaFileUrl).isEqualTo("video_url"); }
String getBestMediaFileUrl(final List<VastXmlManager.MediaXmlManager> managers) { final List<VastXmlManager.MediaXmlManager> mediaXmlManagers = new ArrayList<VastXmlManager.MediaXmlManager>(managers); double bestMediaFitness = Double.POSITIVE_INFINITY; String bestMediaFileUrl = null; final Iterator<VastXmlManager.MediaXmlManager> xmlManagerIterator = mediaXmlManagers.iterator(); while (xmlManagerIterator.hasNext()) { final VastXmlManager.MediaXmlManager mediaXmlManager = xmlManagerIterator.next(); final String mediaType = mediaXmlManager.getType(); final String mediaUrl = mediaXmlManager.getMediaUrl(); if (!VIDEO_MIME_TYPES.contains(mediaType) || mediaUrl == null) { xmlManagerIterator.remove(); continue; } final Integer mediaWidth = mediaXmlManager.getWidth(); final Integer mediaHeight = mediaXmlManager.getHeight(); if (mediaWidth == null || mediaWidth <= 0 || mediaHeight == null || mediaHeight <= 0) { continue; } final double mediaFitness = calculateFitness(mediaWidth, mediaHeight); if (mediaFitness < bestMediaFitness) { bestMediaFitness = mediaFitness; bestMediaFileUrl = mediaUrl; } } if (bestMediaFileUrl == null && !mediaXmlManagers.isEmpty()) { bestMediaFileUrl = mediaXmlManagers.get(0).getMediaUrl(); } return bestMediaFileUrl; }
VastManager implements VastXmlManagerAggregatorListener { String getBestMediaFileUrl(final List<VastXmlManager.MediaXmlManager> managers) { final List<VastXmlManager.MediaXmlManager> mediaXmlManagers = new ArrayList<VastXmlManager.MediaXmlManager>(managers); double bestMediaFitness = Double.POSITIVE_INFINITY; String bestMediaFileUrl = null; final Iterator<VastXmlManager.MediaXmlManager> xmlManagerIterator = mediaXmlManagers.iterator(); while (xmlManagerIterator.hasNext()) { final VastXmlManager.MediaXmlManager mediaXmlManager = xmlManagerIterator.next(); final String mediaType = mediaXmlManager.getType(); final String mediaUrl = mediaXmlManager.getMediaUrl(); if (!VIDEO_MIME_TYPES.contains(mediaType) || mediaUrl == null) { xmlManagerIterator.remove(); continue; } final Integer mediaWidth = mediaXmlManager.getWidth(); final Integer mediaHeight = mediaXmlManager.getHeight(); if (mediaWidth == null || mediaWidth <= 0 || mediaHeight == null || mediaHeight <= 0) { continue; } final double mediaFitness = calculateFitness(mediaWidth, mediaHeight); if (mediaFitness < bestMediaFitness) { bestMediaFitness = mediaFitness; bestMediaFileUrl = mediaUrl; } } if (bestMediaFileUrl == null && !mediaXmlManagers.isEmpty()) { bestMediaFileUrl = mediaXmlManagers.get(0).getMediaUrl(); } return bestMediaFileUrl; } }
VastManager implements VastXmlManagerAggregatorListener { String getBestMediaFileUrl(final List<VastXmlManager.MediaXmlManager> managers) { final List<VastXmlManager.MediaXmlManager> mediaXmlManagers = new ArrayList<VastXmlManager.MediaXmlManager>(managers); double bestMediaFitness = Double.POSITIVE_INFINITY; String bestMediaFileUrl = null; final Iterator<VastXmlManager.MediaXmlManager> xmlManagerIterator = mediaXmlManagers.iterator(); while (xmlManagerIterator.hasNext()) { final VastXmlManager.MediaXmlManager mediaXmlManager = xmlManagerIterator.next(); final String mediaType = mediaXmlManager.getType(); final String mediaUrl = mediaXmlManager.getMediaUrl(); if (!VIDEO_MIME_TYPES.contains(mediaType) || mediaUrl == null) { xmlManagerIterator.remove(); continue; } final Integer mediaWidth = mediaXmlManager.getWidth(); final Integer mediaHeight = mediaXmlManager.getHeight(); if (mediaWidth == null || mediaWidth <= 0 || mediaHeight == null || mediaHeight <= 0) { continue; } final double mediaFitness = calculateFitness(mediaWidth, mediaHeight); if (mediaFitness < bestMediaFitness) { bestMediaFitness = mediaFitness; bestMediaFileUrl = mediaUrl; } } if (bestMediaFileUrl == null && !mediaXmlManagers.isEmpty()) { bestMediaFileUrl = mediaXmlManagers.get(0).getMediaUrl(); } return bestMediaFileUrl; } VastManager(final Context context); }
VastManager implements VastXmlManagerAggregatorListener { String getBestMediaFileUrl(final List<VastXmlManager.MediaXmlManager> managers) { final List<VastXmlManager.MediaXmlManager> mediaXmlManagers = new ArrayList<VastXmlManager.MediaXmlManager>(managers); double bestMediaFitness = Double.POSITIVE_INFINITY; String bestMediaFileUrl = null; final Iterator<VastXmlManager.MediaXmlManager> xmlManagerIterator = mediaXmlManagers.iterator(); while (xmlManagerIterator.hasNext()) { final VastXmlManager.MediaXmlManager mediaXmlManager = xmlManagerIterator.next(); final String mediaType = mediaXmlManager.getType(); final String mediaUrl = mediaXmlManager.getMediaUrl(); if (!VIDEO_MIME_TYPES.contains(mediaType) || mediaUrl == null) { xmlManagerIterator.remove(); continue; } final Integer mediaWidth = mediaXmlManager.getWidth(); final Integer mediaHeight = mediaXmlManager.getHeight(); if (mediaWidth == null || mediaWidth <= 0 || mediaHeight == null || mediaHeight <= 0) { continue; } final double mediaFitness = calculateFitness(mediaWidth, mediaHeight); if (mediaFitness < bestMediaFitness) { bestMediaFitness = mediaFitness; bestMediaFileUrl = mediaUrl; } } if (bestMediaFileUrl == null && !mediaXmlManagers.isEmpty()) { bestMediaFileUrl = mediaXmlManagers.get(0).getMediaUrl(); } return bestMediaFileUrl; } VastManager(final Context context); void prepareVastVideoConfiguration(final String vastXml, final VastManagerListener vastManagerListener); void cancel(); @Override void onAggregationComplete(final List<VastXmlManager> vastXmlManagers); }
VastManager implements VastXmlManagerAggregatorListener { String getBestMediaFileUrl(final List<VastXmlManager.MediaXmlManager> managers) { final List<VastXmlManager.MediaXmlManager> mediaXmlManagers = new ArrayList<VastXmlManager.MediaXmlManager>(managers); double bestMediaFitness = Double.POSITIVE_INFINITY; String bestMediaFileUrl = null; final Iterator<VastXmlManager.MediaXmlManager> xmlManagerIterator = mediaXmlManagers.iterator(); while (xmlManagerIterator.hasNext()) { final VastXmlManager.MediaXmlManager mediaXmlManager = xmlManagerIterator.next(); final String mediaType = mediaXmlManager.getType(); final String mediaUrl = mediaXmlManager.getMediaUrl(); if (!VIDEO_MIME_TYPES.contains(mediaType) || mediaUrl == null) { xmlManagerIterator.remove(); continue; } final Integer mediaWidth = mediaXmlManager.getWidth(); final Integer mediaHeight = mediaXmlManager.getHeight(); if (mediaWidth == null || mediaWidth <= 0 || mediaHeight == null || mediaHeight <= 0) { continue; } final double mediaFitness = calculateFitness(mediaWidth, mediaHeight); if (mediaFitness < bestMediaFitness) { bestMediaFitness = mediaFitness; bestMediaFileUrl = mediaUrl; } } if (bestMediaFileUrl == null && !mediaXmlManagers.isEmpty()) { bestMediaFileUrl = mediaXmlManagers.get(0).getMediaUrl(); } return bestMediaFileUrl; } VastManager(final Context context); void prepareVastVideoConfiguration(final String vastXml, final VastManagerListener vastManagerListener); void cancel(); @Override void onAggregationComplete(final List<VastXmlManager> vastXmlManagers);  }