Add tests for play queue items' equals()

This commit is contained in:
Stypox 2021-07-21 18:22:17 +02:00
parent fa8630ddae
commit 736cefed5a
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
2 changed files with 37 additions and 0 deletions

View File

@ -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
}
}

View File

@ -15,6 +15,7 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
@ -148,6 +149,15 @@ public class PlayQueueTest {
assertNull(queue.getItem(-1)); assertNull(queue.getItem(-1));
assertNull(queue.getItem(5)); 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 { public static class EqualsTests {
@ -162,6 +172,14 @@ public class PlayQueueTest {
assertEquals(queue1, queue2); assertEquals(queue1, queue2);
} }
@Test
public void sameStreamsDifferentIndex() {
final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
final PlayQueue queue1 = makePlayQueue(1, streams);
final PlayQueue queue2 = makePlayQueue(4, streams);
assertEquals(queue1, queue2);
}
@Test @Test
public void sameSizeDifferentItems() { public void sameSizeDifferentItems() {
final List<PlayQueueItem> streams1 = Collections.nCopies(5, item1); final List<PlayQueueItem> streams1 = Collections.nCopies(5, item1);