|
1 | 1 | package org.schabi.newpipe.player.playqueue; |
2 | 2 |
|
3 | 3 | import org.junit.Before; |
| 4 | +import org.junit.BeforeClass; |
4 | 5 | import org.junit.Test; |
5 | 6 | import org.junit.experimental.runners.Enclosed; |
6 | 7 | import org.junit.runner.RunWith; |
|
10 | 11 | import java.util.ArrayList; |
11 | 12 | import java.util.Collections; |
12 | 13 | import java.util.List; |
| 14 | +import java.util.Objects; |
13 | 15 |
|
14 | 16 | import static org.junit.Assert.assertEquals; |
15 | 17 | import static org.junit.Assert.assertNotEquals; |
@@ -110,6 +112,34 @@ public void indexZero() { |
110 | 112 | } |
111 | 113 | } |
112 | 114 |
|
| 115 | + public static class GetItemTests { |
| 116 | + private static List<PlayQueueItem> streams; |
| 117 | + private PlayQueue queue; |
| 118 | + |
| 119 | + @BeforeClass |
| 120 | + public static void init() { |
| 121 | + streams = new ArrayList<>(Collections.nCopies(5, makeItemWithUrl("OTHER_URL"))); |
| 122 | + streams.set(3, makeItemWithUrl("TARGET_URL")); |
| 123 | + } |
| 124 | + |
| 125 | + @Before |
| 126 | + public void setup() { |
| 127 | + queue = mockPlayQueue(0, streams); |
| 128 | + } |
| 129 | + |
| 130 | + @Test |
| 131 | + public void inBounds() { |
| 132 | + assertEquals("TARGET_URL", Objects.requireNonNull(queue.getItem(3)).getUrl()); |
| 133 | + assertEquals("OTHER_URL", Objects.requireNonNull(queue.getItem(1)).getUrl()); |
| 134 | + } |
| 135 | + |
| 136 | + @Test |
| 137 | + public void outOfBounds() { |
| 138 | + assertNull(queue.getItem(-1)); |
| 139 | + assertNull(queue.getItem(5)); |
| 140 | + } |
| 141 | + } |
| 142 | + |
113 | 143 | public static class EqualsTests { |
114 | 144 | private final PlayQueueItem item1 = makeItemWithUrl("URL_1"); |
115 | 145 | private final PlayQueueItem item2 = makeItemWithUrl("URL_2"); |
|
0 commit comments