Skip to content

Commit 736cefe

Browse files
committed
Add tests for play queue items' equals()
1 parent fa8630d commit 736cefe

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.schabi.newpipe.player.playqueue;
2+
3+
import org.junit.Test;
4+
5+
import static org.junit.Assert.assertEquals;
6+
import static org.junit.Assert.assertNotEquals;
7+
8+
public class PlayQueueItemTest {
9+
10+
public static final String URL = "MY_URL";
11+
12+
@Test
13+
public void equalsMustNotBeOverloaded() {
14+
final PlayQueueItem a = PlayQueueTest.makeItemWithUrl(URL);
15+
final PlayQueueItem b = PlayQueueTest.makeItemWithUrl(URL);
16+
assertEquals(a, a);
17+
assertNotEquals(a, b); // they should compare different even if they have the same data
18+
}
19+
}

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import static org.junit.Assert.assertFalse;
1616
import static org.junit.Assert.assertNotEquals;
1717
import static org.junit.Assert.assertNull;
18+
import static org.junit.Assert.assertSame;
1819
import static org.junit.Assert.assertTrue;
1920
import static org.mockito.Mockito.doReturn;
2021
import static org.mockito.Mockito.spy;
@@ -148,6 +149,15 @@ public void outOfBounds() {
148149
assertNull(queue.getItem(-1));
149150
assertNull(queue.getItem(5));
150151
}
152+
153+
@Test
154+
public void itemsAreNotCloned() {
155+
final PlayQueueItem item = makeItemWithUrl("A url");
156+
final PlayQueue playQueue = makePlayQueue(0, Collections.singletonList(item));
157+
158+
// make sure that items are not cloned when added to the queue
159+
assertSame(playQueue.getItem(), item);
160+
}
151161
}
152162

153163
public static class EqualsTests {
@@ -162,6 +172,14 @@ public void sameStreams() {
162172
assertEquals(queue1, queue2);
163173
}
164174

175+
@Test
176+
public void sameStreamsDifferentIndex() {
177+
final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
178+
final PlayQueue queue1 = makePlayQueue(1, streams);
179+
final PlayQueue queue2 = makePlayQueue(4, streams);
180+
assertEquals(queue1, queue2);
181+
}
182+
165183
@Test
166184
public void sameSizeDifferentItems() {
167185
final List<PlayQueueItem> streams1 = Collections.nCopies(5, item1);

0 commit comments

Comments
 (0)