Skip to content

Commit bf8e879

Browse files
committed
Add test for setIndex
1 parent 08949ee commit bf8e879

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

app/src/test/java/org/schabi/newpipe/player/playqueue/PlayQueueTest.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
99
import org.schabi.newpipe.extractor.stream.StreamType;
1010

11+
import java.lang.reflect.Field;
1112
import java.util.ArrayList;
1213
import java.util.Collections;
1314
import java.util.List;
@@ -110,6 +111,32 @@ public void indexZero() {
110111
emptyQueue.setIndex(0);
111112
assertEquals(0, emptyQueue.getIndex());
112113
}
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+
}
113140
}
114141

115142
public static class GetItemTests {

0 commit comments

Comments
 (0)