Playlist { public String next() { if (isEmpty()) { return ""; } else { this.counter--; this.index++; return this.counter == -1 ? "" : this.segments[this.index % this.segmentCount]; } } Playlist(String[] segments, int iterations); String current(); boolean isOngoing(); boolean isEmpty(); String next(); void rewind();  }
@Test public void testPlaylistWithSingleIteration() { final String[] segments = new String[] { "a", "b", "c" }; final int iterations = 1; final Playlist playlist = new Playlist(segments, iterations); String segmentA = playlist.next(); String segmentB = playlist.next(); String segmentC = playlist.next(); String segmentD = playlist.next(); assertEquals(segments[0], segmentA); assertEquals(segments[1], segmentB); assertEquals(segments[2], segmentC); assertEquals("", segmentD); }
@Test public void testPlaylistWithMultipleIterations() { final String[] segments = new String[] { "a", "b" }; final int iterations = 2; final Playlist playlist = new Playlist(segments, iterations); String segmentA = playlist.next(); String segmentB = playlist.next(); String segmentC = playlist.next(); String segmentD = playlist.next(); String segmentE = playlist.next(); assertEquals(segments[0], segmentA); assertEquals(segments[1], segmentB); assertEquals(segments[0], segmentC); assertEquals(segments[1], segmentD); assertEquals("", segmentE); }