Skip to content

Commit

Permalink
Add tests for play queue items' equals()
Browse files Browse the repository at this point in the history
  • Loading branch information
Stypox committed Jul 21, 2021
1 parent fa8630d commit 736cefe
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -148,6 +149,15 @@ public void outOfBounds() {
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 {
Expand All @@ -162,6 +172,14 @@ public void sameStreams() {
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);
Expand Down

0 comments on commit 736cefe

Please sign in to comment.