Skip to content

Commit 882b235

Browse files
committed
Test PlayQueue equals
1 parent 4cd1f20 commit 882b235

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package org.schabi.newpipe.player.playqueue;
2+
3+
import org.junit.Before;
4+
import org.junit.Test;
5+
import org.junit.experimental.runners.Enclosed;
6+
import org.junit.runner.RunWith;
7+
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
8+
import org.schabi.newpipe.extractor.stream.StreamType;
9+
10+
import java.util.Collections;
11+
import java.util.List;
12+
13+
import static org.junit.Assert.assertEquals;
14+
import static org.junit.Assert.assertNotEquals;
15+
16+
@SuppressWarnings("checkstyle:HideUtilityClassConstructor")
17+
@RunWith(Enclosed.class)
18+
public class PlayQueueTest {
19+
public static PlayQueue mockPlayQueue(final int index, final List<PlayQueueItem> streams) {
20+
// I tried using Mockito, but it didn't work for some reason
21+
return new PlayQueue(index, streams) {
22+
@Override
23+
public boolean isComplete() {
24+
throw new UnsupportedOperationException();
25+
}
26+
27+
@Override
28+
public void fetch() {
29+
throw new UnsupportedOperationException();
30+
}
31+
};
32+
}
33+
34+
public static class EqualsTests {
35+
private PlayQueueItem item1;
36+
private PlayQueueItem item2;
37+
38+
@Before
39+
public void setup() {
40+
final String url1 = "www.website1.com";
41+
final String url2 = "www.website2.com";
42+
final StreamInfoItem info1 = new StreamInfoItem(
43+
0, url1, "", StreamType.VIDEO_STREAM
44+
);
45+
final StreamInfoItem info2 = new StreamInfoItem(
46+
0, url2, "", StreamType.VIDEO_STREAM
47+
);
48+
item1 = new PlayQueueItem(info1);
49+
item2 = new PlayQueueItem(info2);
50+
}
51+
52+
@Test
53+
public void sameStreams() {
54+
final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
55+
final PlayQueue queue1 = mockPlayQueue(0, streams);
56+
final PlayQueue queue2 = mockPlayQueue(0, streams);
57+
assertEquals(queue1, queue2);
58+
}
59+
60+
@Test
61+
public void sameSizeDifferentItems() {
62+
final List<PlayQueueItem> streams1 = Collections.nCopies(5, item1);
63+
final List<PlayQueueItem> streams2 = Collections.nCopies(5, item2);
64+
final PlayQueue queue1 = mockPlayQueue(0, streams1);
65+
final PlayQueue queue2 = mockPlayQueue(0, streams2);
66+
assertNotEquals(queue1, queue2);
67+
}
68+
69+
@Test
70+
public void differentSizeStreams() {
71+
final List<PlayQueueItem> streams1 = Collections.nCopies(5, item1);
72+
final List<PlayQueueItem> streams2 = Collections.nCopies(6, item2);
73+
final PlayQueue queue1 = mockPlayQueue(0, streams1);
74+
final PlayQueue queue2 = mockPlayQueue(0, streams2);
75+
assertNotEquals(queue1, queue2);
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)