|
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; |
11 | 12 | import java.util.ArrayList; |
12 | 13 | import java.util.Collections; |
13 | 14 | import java.util.List; |
@@ -110,6 +111,32 @@ public void indexZero() { |
110 | 111 | emptyQueue.setIndex(0); |
111 | 112 | assertEquals(0, emptyQueue.getIndex()); |
112 | 113 | } |
| 114 | + |
| 115 | + @SuppressWarnings("unchecked") |
| 116 | + @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 | + */ |
| 127 | + nonEmptyQueue.setIndex(0); |
| 128 | + history = (List<PlayQueueItem>) Objects.requireNonNull( |
| 129 | + field.get(nonEmptyQueue) |
| 130 | + ); |
| 131 | + assertEquals(1, history.size()); |
| 132 | + |
| 133 | + // Index 3 != 0, so the second history element should be the item at streams[3] |
| 134 | + nonEmptyQueue.setIndex(3); |
| 135 | + history = (List<PlayQueueItem>) Objects.requireNonNull( |
| 136 | + field.get(nonEmptyQueue) |
| 137 | + ); |
| 138 | + assertEquals(nonEmptyQueue.getItem(3), history.get(1)); |
| 139 | + } |
113 | 140 | } |
114 | 141 |
|
115 | 142 | public static class GetItemTests { |
|
0 commit comments