mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-04-11 01:11:22 +00:00
Improve code style to be more consistent
This commit is contained in:
@@ -7,6 +7,7 @@ import org.schabi.newpipe.extractor.subscription.SubscriptionItem;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -19,9 +20,11 @@ import static org.junit.Assert.fail;
|
||||
public class ImportExportJsonHelperTest {
|
||||
@Test
|
||||
public void testEmptySource() throws Exception {
|
||||
String emptySource = "{\"app_version\":\"0.11.6\",\"app_version_int\": 47,\"subscriptions\":[]}";
|
||||
String emptySource =
|
||||
"{\"app_version\":\"0.11.6\",\"app_version_int\": 47,\"subscriptions\":[]}";
|
||||
|
||||
List<SubscriptionItem> items = ImportExportJsonHelper.readFrom(new ByteArrayInputStream(emptySource.getBytes("UTF-8")), null);
|
||||
List<SubscriptionItem> items = ImportExportJsonHelper.readFrom(new ByteArrayInputStream(
|
||||
emptySource.getBytes(StandardCharsets.UTF_8)), null);
|
||||
assertTrue(items.isEmpty());
|
||||
}
|
||||
|
||||
@@ -36,7 +39,7 @@ public class ImportExportJsonHelperTest {
|
||||
for (String invalidContent : invalidList) {
|
||||
try {
|
||||
if (invalidContent != null) {
|
||||
byte[] bytes = invalidContent.getBytes("UTF-8");
|
||||
byte[] bytes = invalidContent.getBytes(StandardCharsets.UTF_8);
|
||||
ImportExportJsonHelper.readFrom((new ByteArrayInputStream(bytes)), null);
|
||||
} else {
|
||||
ImportExportJsonHelper.readFrom(null, null);
|
||||
@@ -44,8 +47,10 @@ public class ImportExportJsonHelperTest {
|
||||
|
||||
fail("didn't throw exception");
|
||||
} catch (Exception e) {
|
||||
boolean isExpectedException = e instanceof SubscriptionExtractor.InvalidSourceException;
|
||||
assertTrue("\"" + e.getClass().getSimpleName() + "\" is not the expected exception", isExpectedException);
|
||||
boolean isExpectedException = e
|
||||
instanceof SubscriptionExtractor.InvalidSourceException;
|
||||
assertTrue("\"" + e.getClass().getSimpleName()
|
||||
+ "\" is not the expected exception", isExpectedException);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,9 +75,9 @@ public class ImportExportJsonHelperTest {
|
||||
final SubscriptionItem item1 = itemsFromFile.get(i);
|
||||
final SubscriptionItem item2 = itemsSecondRead.get(i);
|
||||
|
||||
final boolean equals = item1.getServiceId() == item2.getServiceId() &&
|
||||
item1.getUrl().equals(item2.getUrl()) &&
|
||||
item1.getName().equals(item2.getName());
|
||||
final boolean equals = item1.getServiceId() == item2.getServiceId()
|
||||
&& item1.getUrl().equals(item2.getUrl())
|
||||
&& item1.getName().equals(item2.getName());
|
||||
|
||||
if (!equals) {
|
||||
fail("The list of items were different from each other");
|
||||
@@ -81,8 +86,10 @@ public class ImportExportJsonHelperTest {
|
||||
}
|
||||
|
||||
private List<SubscriptionItem> readFromFile() throws Exception {
|
||||
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream("import_export_test.json");
|
||||
final List<SubscriptionItem> itemsFromFile = ImportExportJsonHelper.readFrom(inputStream, null);
|
||||
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(
|
||||
"import_export_test.json");
|
||||
final List<SubscriptionItem> itemsFromFile = ImportExportJsonHelper.readFrom(
|
||||
inputStream, null);
|
||||
|
||||
if (itemsFromFile == null || itemsFromFile.isEmpty()) {
|
||||
fail("ImportExportJsonHelper.readFrom(input) returned a null or empty list");
|
||||
@@ -91,7 +98,7 @@ public class ImportExportJsonHelperTest {
|
||||
return itemsFromFile;
|
||||
}
|
||||
|
||||
private String testWriteTo(List<SubscriptionItem> itemsFromFile) throws Exception {
|
||||
private String testWriteTo(final List<SubscriptionItem> itemsFromFile) throws Exception {
|
||||
final ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ImportExportJsonHelper.writeTo(itemsFromFile, out, null);
|
||||
final String jsonOut = out.toString("UTF-8");
|
||||
@@ -103,9 +110,11 @@ public class ImportExportJsonHelperTest {
|
||||
return jsonOut;
|
||||
}
|
||||
|
||||
private List<SubscriptionItem> readFromWriteTo(String jsonOut) throws Exception {
|
||||
final ByteArrayInputStream inputStream = new ByteArrayInputStream(jsonOut.getBytes("UTF-8"));
|
||||
final List<SubscriptionItem> secondReadItems = ImportExportJsonHelper.readFrom(inputStream, null);
|
||||
private List<SubscriptionItem> readFromWriteTo(final String jsonOut) throws Exception {
|
||||
final ByteArrayInputStream inputStream = new ByteArrayInputStream(
|
||||
jsonOut.getBytes(StandardCharsets.UTF_8));
|
||||
final List<SubscriptionItem> secondReadItems = ImportExportJsonHelper.readFrom(
|
||||
inputStream, null);
|
||||
|
||||
if (secondReadItems == null || secondReadItems.isEmpty()) {
|
||||
fail("second call to readFrom returned an empty list");
|
||||
@@ -113,4 +122,4 @@ public class ImportExportJsonHelperTest {
|
||||
|
||||
return secondReadItems;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ErrorActivity}
|
||||
* Unit tests for {@link ErrorActivity}.
|
||||
*/
|
||||
public class ErrorActivityTest {
|
||||
@Test
|
||||
@@ -32,7 +32,4 @@ public class ErrorActivityTest {
|
||||
returnActivity = ErrorActivity.getReturnActivity(VideoDetailFragment.class);
|
||||
assertEquals(MainActivity.class, returnActivity);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,4 @@ public class TabTest {
|
||||
assertTrue("Id was already used: " + type.getTabId(), added);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,10 +36,9 @@ public class TabsJsonHelperTest {
|
||||
@Test
|
||||
public void testInvalidIdRead() throws TabsJsonHelper.InvalidJsonException {
|
||||
final int blankTabId = Tab.Type.BLANK.getTabId();
|
||||
final String emptyTabsJson = "{\"" + JSON_TABS_ARRAY_KEY + "\":[" +
|
||||
"{\"" + JSON_TAB_ID_KEY + "\":" + blankTabId + "}," +
|
||||
"{\"" + JSON_TAB_ID_KEY + "\":" + 12345678 + "}" +
|
||||
"]}";
|
||||
final String emptyTabsJson = "{\"" + JSON_TABS_ARRAY_KEY + "\":["
|
||||
+ "{\"" + JSON_TAB_ID_KEY + "\":" + blankTabId + "},"
|
||||
+ "{\"" + JSON_TAB_ID_KEY + "\":" + 12345678 + "}" + "]}";
|
||||
final List<Tab> items = TabsJsonHelper.getTabsFromJson(emptyTabsJson);
|
||||
|
||||
assertEquals("Should ignore the tab with invalid id", 1, items.size());
|
||||
@@ -61,7 +60,8 @@ public class TabsJsonHelperTest {
|
||||
fail("didn't throw exception");
|
||||
} catch (Exception e) {
|
||||
boolean isExpectedException = e instanceof TabsJsonHelper.InvalidJsonException;
|
||||
assertTrue("\"" + e.getClass().getSimpleName() + "\" is not the expected exception", isExpectedException);
|
||||
assertTrue("\"" + e.getClass().getSimpleName()
|
||||
+ "\" is not the expected exception", isExpectedException);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,7 +77,7 @@ public class TabsJsonHelperTest {
|
||||
assertTrue(isTabsArrayEmpty(returnedJson));
|
||||
}
|
||||
|
||||
private boolean isTabsArrayEmpty(String returnedJson) throws JsonParserException {
|
||||
private boolean isTabsArrayEmpty(final String returnedJson) throws JsonParserException {
|
||||
JsonObject jsonObject = JsonParser.object().from(returnedJson);
|
||||
assertTrue(jsonObject.containsKey(JSON_TABS_ARRAY_KEY));
|
||||
return jsonObject.getArray(JSON_TABS_ARRAY_KEY).size() == 0;
|
||||
@@ -89,10 +89,12 @@ public class TabsJsonHelperTest {
|
||||
final Tab.BlankTab blankTab = new Tab.BlankTab();
|
||||
final Tab.DefaultKioskTab defaultKioskTab = new Tab.DefaultKioskTab();
|
||||
final Tab.SubscriptionsTab subscriptionsTab = new Tab.SubscriptionsTab();
|
||||
final Tab.ChannelTab channelTab = new Tab.ChannelTab(666, "https://example.org", "testName");
|
||||
final Tab.ChannelTab channelTab = new Tab.ChannelTab(
|
||||
666, "https://example.org", "testName");
|
||||
final Tab.KioskTab kioskTab = new Tab.KioskTab(123, "trending_key");
|
||||
|
||||
final List<Tab> tabs = Arrays.asList(blankTab, defaultKioskTab, subscriptionsTab, channelTab, kioskTab);
|
||||
final List<Tab> tabs = Arrays.asList(
|
||||
blankTab, defaultKioskTab, subscriptionsTab, channelTab, kioskTab);
|
||||
final String returnedJson = TabsJsonHelper.getJsonToSave(tabs);
|
||||
|
||||
// Reading
|
||||
@@ -102,24 +104,30 @@ public class TabsJsonHelperTest {
|
||||
|
||||
assertEquals(tabs.size(), tabsFromArray.size());
|
||||
|
||||
final Tab.BlankTab blankTabFromReturnedJson = requireNonNull((Tab.BlankTab) Tab.from(((JsonObject) tabsFromArray.get(0))));
|
||||
final Tab.BlankTab blankTabFromReturnedJson = requireNonNull((Tab.BlankTab) Tab.from(
|
||||
(JsonObject) tabsFromArray.get(0)));
|
||||
assertEquals(blankTab.getTabId(), blankTabFromReturnedJson.getTabId());
|
||||
|
||||
final Tab.DefaultKioskTab defaultKioskTabFromReturnedJson = requireNonNull((Tab.DefaultKioskTab) Tab.from(((JsonObject) tabsFromArray.get(1))));
|
||||
final Tab.DefaultKioskTab defaultKioskTabFromReturnedJson = requireNonNull(
|
||||
(Tab.DefaultKioskTab) Tab.from((JsonObject) tabsFromArray.get(1)));
|
||||
assertEquals(defaultKioskTab.getTabId(), defaultKioskTabFromReturnedJson.getTabId());
|
||||
|
||||
final Tab.SubscriptionsTab subscriptionsTabFromReturnedJson = requireNonNull((Tab.SubscriptionsTab) Tab.from(((JsonObject) tabsFromArray.get(2))));
|
||||
final Tab.SubscriptionsTab subscriptionsTabFromReturnedJson = requireNonNull(
|
||||
(Tab.SubscriptionsTab) Tab.from((JsonObject) tabsFromArray.get(2)));
|
||||
assertEquals(subscriptionsTab.getTabId(), subscriptionsTabFromReturnedJson.getTabId());
|
||||
|
||||
final Tab.ChannelTab channelTabFromReturnedJson = requireNonNull((Tab.ChannelTab) Tab.from(((JsonObject) tabsFromArray.get(3))));
|
||||
final Tab.ChannelTab channelTabFromReturnedJson = requireNonNull((Tab.ChannelTab) Tab.from(
|
||||
(JsonObject) tabsFromArray.get(3)));
|
||||
assertEquals(channelTab.getTabId(), channelTabFromReturnedJson.getTabId());
|
||||
assertEquals(channelTab.getChannelServiceId(), channelTabFromReturnedJson.getChannelServiceId());
|
||||
assertEquals(channelTab.getChannelServiceId(),
|
||||
channelTabFromReturnedJson.getChannelServiceId());
|
||||
assertEquals(channelTab.getChannelUrl(), channelTabFromReturnedJson.getChannelUrl());
|
||||
assertEquals(channelTab.getChannelName(), channelTabFromReturnedJson.getChannelName());
|
||||
|
||||
final Tab.KioskTab kioskTabFromReturnedJson = requireNonNull((Tab.KioskTab) Tab.from(((JsonObject) tabsFromArray.get(4))));
|
||||
final Tab.KioskTab kioskTabFromReturnedJson = requireNonNull((Tab.KioskTab) Tab.from(
|
||||
(JsonObject) tabsFromArray.get(4)));
|
||||
assertEquals(kioskTab.getTabId(), kioskTabFromReturnedJson.getTabId());
|
||||
assertEquals(kioskTab.getKioskServiceId(), kioskTabFromReturnedJson.getKioskServiceId());
|
||||
assertEquals(kioskTab.getKioskId(), kioskTabFromReturnedJson.getKioskId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ListHelperTest {
|
||||
private static final String BEST_RESOLUTION_KEY = "best_resolution";
|
||||
private static final List<AudioStream> audioStreamsTestList = Arrays.asList(
|
||||
private static final List<AudioStream> AUDIO_STREAMS_TEST_LIST = Arrays.asList(
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 128),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192),
|
||||
new AudioStream("", MediaFormat.MP3, /**/ 64),
|
||||
@@ -25,7 +25,7 @@ public class ListHelperTest {
|
||||
new AudioStream("", MediaFormat.MP3, /**/ 192),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 320));
|
||||
|
||||
private static final List<VideoStream> videoStreamsTestList = Arrays.asList(
|
||||
private static final List<VideoStream> VIDEO_STREAMS_TEST_LIST = Arrays.asList(
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "720p"),
|
||||
new VideoStream("", MediaFormat.v3GPP, /**/ "240p"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "480p"),
|
||||
@@ -33,7 +33,7 @@ public class ListHelperTest {
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "360p"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "360p"));
|
||||
|
||||
private static final List<VideoStream> videoOnlyStreamsTestList = Arrays.asList(
|
||||
private static final List<VideoStream> VIDEO_ONLY_STREAMS_TEST_LIST = Arrays.asList(
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "720p", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "720p", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "2160p", true),
|
||||
@@ -46,10 +46,16 @@ public class ListHelperTest {
|
||||
|
||||
@Test
|
||||
public void getSortedStreamVideosListTest() {
|
||||
List<VideoStream> result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true, videoStreamsTestList, videoOnlyStreamsTestList, true);
|
||||
List<VideoStream> result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
|
||||
VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, true);
|
||||
|
||||
List<String> expected = Arrays.asList("144p", "240p", "360p", "480p", "720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
|
||||
//for (VideoStream videoStream : result) System.out.println(videoStream.resolution + " > " + MediaFormat.getSuffixById(videoStream.format) + " > " + videoStream.isVideoOnly);
|
||||
List<String> expected = Arrays.asList("144p", "240p", "360p", "480p", "720p", "720p60",
|
||||
"1080p", "1080p60", "1440p60", "2160p", "2160p60");
|
||||
// for (VideoStream videoStream : result) {
|
||||
// System.out.println(videoStream.resolution + " > "
|
||||
// + MediaFormat.getSuffixById(videoStream.format) + " > "
|
||||
// + videoStream.isVideoOnly);
|
||||
// }
|
||||
|
||||
assertEquals(result.size(), expected.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
@@ -60,10 +66,14 @@ public class ListHelperTest {
|
||||
// Reverse Order //
|
||||
//////////////////
|
||||
|
||||
result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true, videoStreamsTestList, videoOnlyStreamsTestList, false);
|
||||
expected = Arrays.asList("2160p60", "2160p", "1440p60", "1080p60", "1080p", "720p60", "720p", "480p", "360p", "240p", "144p");
|
||||
result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
|
||||
VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, false);
|
||||
expected = Arrays.asList("2160p60", "2160p", "1440p60", "1080p60", "1080p", "720p60",
|
||||
"720p", "480p", "360p", "240p", "144p");
|
||||
assertEquals(result.size(), expected.size());
|
||||
for (int i = 0; i < result.size(); i++) assertEquals(result.get(i).resolution, expected.get(i));
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertEquals(result.get(i).resolution, expected.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,10 +82,14 @@ public class ListHelperTest {
|
||||
// Don't show Higher resolutions //
|
||||
//////////////////////////////////
|
||||
|
||||
List<VideoStream> result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, false, videoStreamsTestList, videoOnlyStreamsTestList, false);
|
||||
List<String> expected = Arrays.asList("1080p60", "1080p", "720p60", "720p", "480p", "360p", "240p", "144p");
|
||||
List<VideoStream> result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4,
|
||||
false, VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, false);
|
||||
List<String> expected = Arrays.asList(
|
||||
"1080p60", "1080p", "720p60", "720p", "480p", "360p", "240p", "144p");
|
||||
assertEquals(result.size(), expected.size());
|
||||
for (int i = 0; i < result.size(); i++) assertEquals(result.get(i).resolution, expected.get(i));
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertEquals(result.get(i).resolution, expected.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,57 +103,68 @@ public class ListHelperTest {
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "144p"),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "360p"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "360p"));
|
||||
VideoStream result = testList.get(ListHelper.getDefaultResolutionIndex("720p", BEST_RESOLUTION_KEY, MediaFormat.MPEG_4, testList));
|
||||
VideoStream result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"720p", BEST_RESOLUTION_KEY, MediaFormat.MPEG_4, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals(MediaFormat.MPEG_4, result.getFormat());
|
||||
|
||||
// Have resolution and the format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("480p", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"480p", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("480p", result.resolution);
|
||||
assertEquals(MediaFormat.WEBM, result.getFormat());
|
||||
|
||||
// Have resolution but not the format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("480p", BEST_RESOLUTION_KEY, MediaFormat.MPEG_4, testList));
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"480p", BEST_RESOLUTION_KEY, MediaFormat.MPEG_4, testList));
|
||||
assertEquals("480p", result.resolution);
|
||||
assertEquals(MediaFormat.WEBM, result.getFormat());
|
||||
|
||||
// Have resolution and the format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("240p", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"240p", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("240p", result.resolution);
|
||||
assertEquals(MediaFormat.WEBM, result.getFormat());
|
||||
|
||||
// The best resolution
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(BEST_RESOLUTION_KEY, BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
BEST_RESOLUTION_KEY, BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals(MediaFormat.MPEG_4, result.getFormat());
|
||||
|
||||
// Doesn't have the 60fps variant and format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("720p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"720p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals(MediaFormat.MPEG_4, result.getFormat());
|
||||
|
||||
// Doesn't have the 60fps variant
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("480p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"480p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("480p", result.resolution);
|
||||
assertEquals(MediaFormat.WEBM, result.getFormat());
|
||||
|
||||
// Doesn't have the resolution, will return the best one
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex("2160p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"2160p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals(MediaFormat.MPEG_4, result.getFormat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHighestQualityAudioFormatTest() {
|
||||
AudioStream stream = audioStreamsTestList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.M4A, audioStreamsTestList));
|
||||
AudioStream stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getHighestQualityAudioIndex(
|
||||
MediaFormat.M4A, AUDIO_STREAMS_TEST_LIST));
|
||||
assertEquals(320, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.M4A, stream.getFormat());
|
||||
|
||||
stream = audioStreamsTestList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.WEBMA, audioStreamsTestList));
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getHighestQualityAudioIndex(
|
||||
MediaFormat.WEBMA, AUDIO_STREAMS_TEST_LIST));
|
||||
assertEquals(320, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.WEBMA, stream.getFormat());
|
||||
|
||||
stream = audioStreamsTestList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, audioStreamsTestList));
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getHighestQualityAudioIndex(
|
||||
MediaFormat.MP3, AUDIO_STREAMS_TEST_LIST));
|
||||
assertEquals(192, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.MP3, stream.getFormat());
|
||||
}
|
||||
@@ -154,8 +179,10 @@ public class ListHelperTest {
|
||||
List<AudioStream> testList = Arrays.asList(
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 128),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192));
|
||||
// List doesn't contains this format, it should fallback to the highest bitrate audio no matter what format it is
|
||||
AudioStream stream = testList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, testList));
|
||||
// List doesn't contains this format
|
||||
// It should fallback to the highest bitrate audio no matter what format it is
|
||||
AudioStream stream = testList.get(ListHelper.getHighestQualityAudioIndex(
|
||||
MediaFormat.MP3, testList));
|
||||
assertEquals(192, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.WEBMA, stream.getFormat());
|
||||
|
||||
@@ -193,15 +220,18 @@ public class ListHelperTest {
|
||||
|
||||
@Test
|
||||
public void getLowestQualityAudioFormatTest() {
|
||||
AudioStream stream = audioStreamsTestList.get(ListHelper.getMostCompactAudioIndex(MediaFormat.M4A, audioStreamsTestList));
|
||||
AudioStream stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getMostCompactAudioIndex(
|
||||
MediaFormat.M4A, AUDIO_STREAMS_TEST_LIST));
|
||||
assertEquals(128, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.M4A, stream.getFormat());
|
||||
|
||||
stream = audioStreamsTestList.get(ListHelper.getMostCompactAudioIndex(MediaFormat.WEBMA, audioStreamsTestList));
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getMostCompactAudioIndex(
|
||||
MediaFormat.WEBMA, AUDIO_STREAMS_TEST_LIST));
|
||||
assertEquals(64, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.WEBMA, stream.getFormat());
|
||||
|
||||
stream = audioStreamsTestList.get(ListHelper.getMostCompactAudioIndex(MediaFormat.MP3, audioStreamsTestList));
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getMostCompactAudioIndex(
|
||||
MediaFormat.MP3, AUDIO_STREAMS_TEST_LIST));
|
||||
assertEquals(64, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.MP3, stream.getFormat());
|
||||
}
|
||||
@@ -216,8 +246,10 @@ public class ListHelperTest {
|
||||
List<AudioStream> testList = new ArrayList<>(Arrays.asList(
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 128),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192)));
|
||||
// List doesn't contains this format, it should fallback to the most compact audio no matter what format it is.
|
||||
AudioStream stream = testList.get(ListHelper.getMostCompactAudioIndex(MediaFormat.MP3, testList));
|
||||
// List doesn't contains this format
|
||||
// It should fallback to the most compact audio no matter what format it is.
|
||||
AudioStream stream = testList.get(ListHelper.getMostCompactAudioIndex(
|
||||
MediaFormat.MP3, testList));
|
||||
assertEquals(128, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.M4A, stream.getFormat());
|
||||
|
||||
@@ -238,7 +270,8 @@ public class ListHelperTest {
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 192),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192),
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 192)));
|
||||
// List doesn't contains this format, it should fallback to the most compact audio no matter what format it is.
|
||||
// List doesn't contain this format
|
||||
// It should fallback to the most compact audio no matter what format it is.
|
||||
stream = testList.get(ListHelper.getMostCompactAudioIndex(MediaFormat.MP3, testList));
|
||||
assertEquals(192, stream.average_bitrate);
|
||||
assertEquals(MediaFormat.WEBMA, stream.getFormat());
|
||||
@@ -298,4 +331,4 @@ public class ListHelperTest {
|
||||
// Can't find a match
|
||||
assertEquals(-1, ListHelper.getVideoStreamIndex("100p", null, testList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,17 @@
|
||||
package org.schabi.newpipe.util;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class QuadraticSliderStrategyTest {
|
||||
private final static int STEP = 100;
|
||||
private final static float DELTA = 1f / (float) STEP;
|
||||
private static final int STEP = 100;
|
||||
private static final float DELTA = 1f / (float) STEP;
|
||||
|
||||
private final SliderStrategy.Quadratic standard =
|
||||
new SliderStrategy.Quadratic(0f, 100f, 50f, STEP);
|
||||
|
||||
@Test
|
||||
public void testLeftBound() {
|
||||
assertEquals(standard.progressOf(0), 0);
|
||||
|
||||
Reference in New Issue
Block a user