From bf8e8798d9e12f46ceeb3fa5bd029bb8ad0f9236 Mon Sep 17 00:00:00 2001 From: Zhiheng Xu Date: Sat, 22 May 2021 12:45:09 -0400 Subject: [PATCH] Add test for setIndex --- .../player/playqueue/PlayQueueTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/src/test/java/org/schabi/newpipe/player/playqueue/PlayQueueTest.java b/app/src/test/java/org/schabi/newpipe/player/playqueue/PlayQueueTest.java index d9b6c5f18..0211b5efc 100644 --- a/app/src/test/java/org/schabi/newpipe/player/playqueue/PlayQueueTest.java +++ b/app/src/test/java/org/schabi/newpipe/player/playqueue/PlayQueueTest.java @@ -8,6 +8,7 @@ import org.junit.runner.RunWith; import org.schabi.newpipe.extractor.stream.StreamInfoItem; import org.schabi.newpipe.extractor.stream.StreamType; +import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -110,6 +111,32 @@ public class PlayQueueTest { emptyQueue.setIndex(0); assertEquals(0, emptyQueue.getIndex()); } + + @SuppressWarnings("unchecked") + @Test + public void addToHistory() throws NoSuchFieldException, IllegalAccessException { + final Field field; + field = PlayQueue.class.getDeclaredField("history"); + field.setAccessible(true); + List history; + + /* + history's size is currently 1. 0 is the also the current index, so history should not + be affected. + */ + nonEmptyQueue.setIndex(0); + history = (List) Objects.requireNonNull( + field.get(nonEmptyQueue) + ); + assertEquals(1, history.size()); + + // Index 3 != 0, so the second history element should be the item at streams[3] + nonEmptyQueue.setIndex(3); + history = (List) Objects.requireNonNull( + field.get(nonEmptyQueue) + ); + assertEquals(nonEmptyQueue.getItem(3), history.get(1)); + } } public static class GetItemTests {