From 945165a3c046fca826a77e1280d5ea2f89a2dae6 Mon Sep 17 00:00:00 2001 From: AudricV <74829229+AudricV@users.noreply.github.com> Date: Sun, 30 Apr 2023 17:39:46 +0200 Subject: [PATCH] [PeerTube] Don't return "No description" when there is no description for a channel or an account When a description is missing, no description should be returned, even the ones indicating there is no description. This behavior is represented by a null return instead. Also update PeertubeAccountExtractorTest to reflect these changes. --- .../peertube/extractors/PeertubeAccountExtractor.java | 8 +++----- .../peertube/extractors/PeertubeChannelExtractor.java | 8 +++----- .../peertube/PeertubeAccountExtractorTest.java | 11 ++++++++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeAccountExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeAccountExtractor.java index f63eca52f1..6a8c2dcf22 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeAccountExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeAccountExtractor.java @@ -21,6 +21,7 @@ import org.schabi.newpipe.extractor.utils.Utils; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.io.IOException; import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY; @@ -90,13 +91,10 @@ public long getSubscriberCount() throws ParsingException { return subscribersCount; } + @Nullable @Override public String getDescription() { - try { - return JsonUtils.getString(json, "description"); - } catch (final ParsingException e) { - return "No description"; - } + return json.getString("description"); } @Override diff --git a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeChannelExtractor.java b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeChannelExtractor.java index c5b7bf399d..f2a7b07e2d 100644 --- a/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeChannelExtractor.java +++ b/extractor/src/main/java/org/schabi/newpipe/extractor/services/peertube/extractors/PeertubeChannelExtractor.java @@ -19,6 +19,7 @@ import org.schabi.newpipe.extractor.utils.Utils; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.io.IOException; import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY; @@ -63,13 +64,10 @@ public long getSubscriberCount() { return json.getLong("followersCount"); } + @Nullable @Override public String getDescription() { - try { - return JsonUtils.getString(json, "description"); - } catch (final ParsingException e) { - return "No description"; - } + return json.getString("description"); } @Override diff --git a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountExtractorTest.java b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountExtractorTest.java index 4e4d142186..ec5bac31da 100644 --- a/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountExtractorTest.java +++ b/extractor/src/test/java/org/schabi/newpipe/extractor/services/peertube/PeertubeAccountExtractorTest.java @@ -10,10 +10,15 @@ import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest; import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeAccountExtractor; -import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.schabi.newpipe.extractor.ExtractorAsserts.assertIsSecureUrl; import static org.schabi.newpipe.extractor.ServiceList.PeerTube; -import static org.schabi.newpipe.extractor.services.DefaultTests.*; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestGetPageInNewExtractor; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestMoreItems; +import static org.schabi.newpipe.extractor.services.DefaultTests.defaultTestRelatedItems; /** * Test for {@link PeertubeAccountExtractor} @@ -82,7 +87,7 @@ public void testMoreRelatedItems() throws Exception { @Test public void testDescription() throws ParsingException { - assertNotNull(extractor.getDescription()); + assertNull(extractor.getDescription()); } @Test