VastXmlManager { @NonNull List<VastFractionalProgressTracker> getFractionalProgressTrackers() { List<VastFractionalProgressTracker> percentTrackers = new ArrayList<VastFractionalProgressTracker>(); addQuartileTrackerWithFraction(percentTrackers, getVideoTrackerByAttribute(FIRST_QUARTILE), FIRST_QUARTER_MARKER); addQuartileTrackerWithFraction(percentTrackers, getVideoTrackerByAttribute(MIDPOINT), MID_POINT_MARKER); addQuartileTrackerWithFraction(percentTrackers, getVideoTrackerByAttribute(THIRD_QUARTILE), THIRD_QUARTER_MARKER); final List<Node> progressNodes = XmlUtils.getNodesWithElementAndAttribute(mVastDoc, VIDEO_TRACKER, EVENT, PROGRESS); for (Node progressNode : progressNodes) { final String offsetString = XmlUtils.getAttributeValue(progressNode, OFFSET).trim(); if (Strings.isPercentageTracker(offsetString)) { String trackingUrl = XmlUtils.getNodeValue(progressNode).trim(); try { float trackingFraction = Float.parseFloat(offsetString.replace("%", "")) / 100f; percentTrackers.add(new VastFractionalProgressTracker(trackingUrl, trackingFraction)); } catch (NumberFormatException e) { MoPubLog.d(String.format("Failed to parse VAST progress tracker %s", offsetString)); } } } Collections.sort(percentTrackers); return percentTrackers; }    }
@Test public void getFractionalTrackers_shouldReturnCorrectValues() { List<VastFractionalProgressTracker> trackers = mXmlManager.getFractionalProgressTrackers(); assertThat(trackers.size()).isEqualTo(7); VastFractionalProgressTracker tracker0 = trackers.get(0); assertThat(tracker0.trackingFraction()).isEqualTo(0.13f); assertThat(tracker0.getTrackingUrl()).isEqualTo("http: VastFractionalProgressTracker tracker1 = trackers.get(1); assertThat(tracker1.trackingFraction()).isEqualTo(0.25f); assertThat(tracker1.getTrackingUrl()).isEqualTo("http: VastFractionalProgressTracker tracker2 = trackers.get(2); assertThat(tracker2.trackingFraction()).isEqualTo(0.25f); assertThat(tracker2.getTrackingUrl()).isEqualTo("http: VastFractionalProgressTracker tracker3 = trackers.get(3); assertThat(tracker3.trackingFraction()).isEqualTo(0.5f); assertThat(tracker3.getTrackingUrl()).isEqualTo("http: VastFractionalProgressTracker tracker4 = trackers.get(4); assertThat(tracker4.trackingFraction()).isEqualTo(0.5f); assertThat(tracker4.getTrackingUrl()).isEqualTo("http: VastFractionalProgressTracker tracker5 = trackers.get(5); assertThat(tracker5.trackingFraction()).isEqualTo(0.75f); assertThat(tracker5.getTrackingUrl()).isEqualTo("http: VastFractionalProgressTracker tracker6 = trackers.get(6); assertThat(tracker6.trackingFraction()).isEqualTo(0.75f); assertThat(tracker6.getTrackingUrl()).isEqualTo("http: }