Add tests for play queue items' equals()
This commit is contained in:
parent
fa8630ddae
commit
736cefed5a
|
@ -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
|
||||
}
|
||||
}
|
|
@ -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<PlayQueueItem> 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<PlayQueueItem> streams1 = Collections.nCopies(5, item1);
|
||||
|
|
Loading…
Reference in New Issue