Skip to content

Commit 015982b

Browse files
litetexAudricV
authored andcommitted
Extended Tests for ListHelper#getSortedStreamVideosList
* Fixed expected and actual results. They were reversed... * Added new method ``getSortedStreamVideosListWithPreferVideoOnlyStreamsTest``
1 parent a1c5c94 commit 015982b

1 file changed

Lines changed: 55 additions & 6 deletions

File tree

app/src/test/java/org/schabi/newpipe/util/ListHelperTest.java

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import java.util.List;
1111

1212
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertFalse;
14+
import static org.junit.Assert.assertTrue;
1315

1416
public class ListHelperTest {
1517
private static final String BEST_RESOLUTION_KEY = "best_resolution";
@@ -52,9 +54,9 @@ public void getSortedStreamVideosListTest() {
5254
List<String> expected = Arrays.asList("144p", "240p", "360p", "480p", "720p", "720p60",
5355
"1080p", "1080p60", "1440p60", "2160p", "2160p60");
5456

55-
assertEquals(result.size(), expected.size());
57+
assertEquals(expected.size(), result.size());
5658
for (int i = 0; i < result.size(); i++) {
57-
assertEquals(result.get(i).resolution, expected.get(i));
59+
assertEquals(expected.get(i), result.get(i).resolution);
5860
}
5961

6062
////////////////////
@@ -65,9 +67,56 @@ public void getSortedStreamVideosListTest() {
6567
VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, false, false);
6668
expected = Arrays.asList("2160p60", "2160p", "1440p60", "1080p60", "1080p", "720p60",
6769
"720p", "480p", "360p", "240p", "144p");
68-
assertEquals(result.size(), expected.size());
70+
assertEquals(expected.size(), result.size());
6971
for (int i = 0; i < result.size(); i++) {
70-
assertEquals(result.get(i).resolution, expected.get(i));
72+
assertEquals(expected.get(i), result.get(i).resolution);
73+
}
74+
}
75+
76+
@Test
77+
public void getSortedStreamVideosListWithPreferVideoOnlyStreamsTest() {
78+
List<VideoStream> result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
79+
null, VIDEO_ONLY_STREAMS_TEST_LIST, true, true);
80+
81+
List<String> expected =
82+
Arrays.asList("720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
83+
84+
assertEquals(expected.size(), result.size());
85+
for (int i = 0; i < result.size(); i++) {
86+
assertEquals(expected.get(i), result.get(i).resolution);
87+
assertTrue(result.get(i).isVideoOnly);
88+
}
89+
90+
//////////////////////////////////////////////////////////
91+
// No video only streams -> should return mixed streams //
92+
//////////////////////////////////////////////////////////
93+
94+
result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
95+
VIDEO_STREAMS_TEST_LIST, null, false, true);
96+
expected = Arrays.asList("720p", "480p", "360p", "240p", "144p");
97+
assertEquals(expected.size(), result.size());
98+
for (int i = 0; i < result.size(); i++) {
99+
assertEquals(expected.get(i), result.get(i).resolution);
100+
assertFalse(result.get(i).isVideoOnly);
101+
}
102+
103+
/////////////////////////////////////////////////////////////////
104+
// Both types of streams -> should return correct one streams //
105+
/////////////////////////////////////////////////////////////////
106+
107+
result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
108+
VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, true, true);
109+
expected = Arrays.asList("144p", "240p", "360p", "480p", "720p", "720p60",
110+
"1080p", "1080p60", "1440p60", "2160p", "2160p60");
111+
final List<String> expectedVideoOnly =
112+
Arrays.asList("720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
113+
114+
assertEquals(expected.size(), result.size());
115+
for (int i = 0; i < result.size(); i++) {
116+
assertEquals(expected.get(i), result.get(i).resolution);
117+
assertEquals(
118+
expectedVideoOnly.contains(result.get(i).resolution),
119+
result.get(i).isVideoOnly);
71120
}
72121
}
73122

@@ -81,9 +130,9 @@ public void getSortedStreamVideosExceptHighResolutionsTest() {
81130
false, VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, false, false);
82131
final List<String> expected = Arrays.asList(
83132
"1080p60", "1080p", "720p60", "720p", "480p", "360p", "240p", "144p");
84-
assertEquals(result.size(), expected.size());
133+
assertEquals(expected.size(), result.size());
85134
for (int i = 0; i < result.size(); i++) {
86-
assertEquals(result.get(i).resolution, expected.get(i));
135+
assertEquals(expected.get(i), result.get(i).resolution);
87136
}
88137
}
89138

0 commit comments

Comments
 (0)