|
8 | 8 | import org.schabi.newpipe.extractor.stream.StreamInfoItem; |
9 | 9 | import org.schabi.newpipe.extractor.stream.StreamType; |
10 | 10 |
|
11 | | -import java.lang.reflect.Field; |
12 | 11 | import java.util.ArrayList; |
13 | 12 | import java.util.Collections; |
14 | 13 | import java.util.List; |
15 | 14 | import java.util.Objects; |
16 | 15 |
|
17 | 16 | import static org.junit.Assert.assertEquals; |
| 17 | +import static org.junit.Assert.assertFalse; |
18 | 18 | import static org.junit.Assert.assertNotEquals; |
19 | 19 | import static org.junit.Assert.assertNull; |
| 20 | +import static org.junit.Assert.assertTrue; |
20 | 21 | import static org.mockito.Mockito.doReturn; |
21 | | -import static org.mockito.Mockito.mock; |
22 | 22 | import static org.mockito.Mockito.spy; |
23 | 23 |
|
24 | 24 | @SuppressWarnings("checkstyle:HideUtilityClassConstructor") |
@@ -53,9 +53,11 @@ public static class SetIndexTests { |
53 | 53 |
|
54 | 54 | @Before |
55 | 55 | public void setup() { |
56 | | - nonEmptyQueue = spy(makePlayQueue( |
57 | | - 0, Collections.nCopies(SIZE, mock(PlayQueueItem.class)) |
58 | | - )); |
| 56 | + final List<PlayQueueItem> streams = new ArrayList<>(5); |
| 57 | + for (int i = 0; i < 5; ++i) { |
| 58 | + streams.add(makeItemWithUrl("URL_" + i)); |
| 59 | + } |
| 60 | + nonEmptyQueue = spy(makePlayQueue(0, streams)); |
59 | 61 | emptyQueue = spy(makePlayQueue(0, new ArrayList<>())); |
60 | 62 | } |
61 | 63 |
|
@@ -112,30 +114,14 @@ public void indexZero() { |
112 | 114 | assertEquals(0, emptyQueue.getIndex()); |
113 | 115 | } |
114 | 116 |
|
115 | | - @SuppressWarnings("unchecked") |
116 | 117 | @Test |
117 | | - public void addToHistory() throws NoSuchFieldException, IllegalAccessException { |
118 | | - final Field field; |
119 | | - field = PlayQueue.class.getDeclaredField("history"); |
120 | | - field.setAccessible(true); |
121 | | - List<PlayQueueItem> history; |
122 | | - |
123 | | - /* |
124 | | - history's size is currently 1. 0 is the also the current index, so history should not |
125 | | - be affected. |
126 | | - */ |
| 118 | + public void addToHistory() { |
127 | 119 | nonEmptyQueue.setIndex(0); |
128 | | - history = (List<PlayQueueItem>) Objects.requireNonNull( |
129 | | - field.get(nonEmptyQueue) |
130 | | - ); |
131 | | - assertEquals(1, history.size()); |
| 120 | + assertFalse(nonEmptyQueue.previous()); |
132 | 121 |
|
133 | | - // Index 3 != 0, so the second history element should be the item at streams[3] |
134 | 122 | nonEmptyQueue.setIndex(3); |
135 | | - history = (List<PlayQueueItem>) Objects.requireNonNull( |
136 | | - field.get(nonEmptyQueue) |
137 | | - ); |
138 | | - assertEquals(nonEmptyQueue.getItem(3), history.get(1)); |
| 123 | + assertTrue(nonEmptyQueue.previous()); |
| 124 | + assertEquals("URL_0", Objects.requireNonNull(nonEmptyQueue.getItem()).getUrl()); |
139 | 125 | } |
140 | 126 | } |
141 | 127 |
|
|
0 commit comments