diff --git a/app/src/test/java/org/schabi/newpipe/player/playqueue/PlayQueueItemTest.java b/app/src/test/java/org/schabi/newpipe/player/playqueue/PlayQueueItemTest.java new file mode 100644 index 000000000..d10d33f7e --- /dev/null +++ b/app/src/test/java/org/schabi/newpipe/player/playqueue/PlayQueueItemTest.java @@ -0,0 +1,19 @@ +package org.schabi.newpipe.player.playqueue; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +public class PlayQueueItemTest { + + public static final String URL = "MY_URL"; + + @Test + public void equalsMustNotBeOverloaded() { + final PlayQueueItem a = PlayQueueTest.makeItemWithUrl(URL); + final PlayQueueItem b = PlayQueueTest.makeItemWithUrl(URL); + assertEquals(a, a); + assertNotEquals(a, b); // they should compare different even if they have the same data + } +} 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 43e090900..f92863eab 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 @@ -15,6 +15,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.spy; @@ -148,6 +149,15 @@ public class PlayQueueTest { assertNull(queue.getItem(-1)); assertNull(queue.getItem(5)); } + + @Test + public void itemsAreNotCloned() { + final PlayQueueItem item = makeItemWithUrl("A url"); + final PlayQueue playQueue = makePlayQueue(0, Collections.singletonList(item)); + + // make sure that items are not cloned when added to the queue + assertSame(playQueue.getItem(), item); + } } public static class EqualsTests { @@ -162,6 +172,14 @@ public class PlayQueueTest { assertEquals(queue1, queue2); } + @Test + public void sameStreamsDifferentIndex() { + final List streams = Collections.nCopies(5, item1); + final PlayQueue queue1 = makePlayQueue(1, streams); + final PlayQueue queue2 = makePlayQueue(4, streams); + assertEquals(queue1, queue2); + } + @Test public void sameSizeDifferentItems() { final List streams1 = Collections.nCopies(5, item1);