[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.
This commit is contained in:
AudricV 2023-04-30 17:39:46 +02:00
parent d61dc27406
commit 945165a3c0
No known key found for this signature in database
GPG Key ID: DA92EC7905614198
3 changed files with 14 additions and 13 deletions

View File

@ -21,6 +21,7 @@ import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Utils; import org.schabi.newpipe.extractor.utils.Utils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY; import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY;
@ -90,13 +91,10 @@ public class PeertubeAccountExtractor extends ChannelExtractor {
return subscribersCount; return subscribersCount;
} }
@Nullable
@Override @Override
public String getDescription() { public String getDescription() {
try { return json.getString("description");
return JsonUtils.getString(json, "description");
} catch (final ParsingException e) {
return "No description";
}
} }
@Override @Override

View File

@ -19,6 +19,7 @@ import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Utils; import org.schabi.newpipe.extractor.utils.Utils;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY; import static org.schabi.newpipe.extractor.services.peertube.PeertubeParsingHelper.COUNT_KEY;
@ -63,13 +64,10 @@ public class PeertubeChannelExtractor extends ChannelExtractor {
return json.getLong("followersCount"); return json.getLong("followersCount");
} }
@Nullable
@Override @Override
public String getDescription() { public String getDescription() {
try { return json.getString("description");
return JsonUtils.getString(json, "description");
} catch (final ParsingException e) {
return "No description";
}
} }
@Override @Override

View File

@ -10,10 +10,15 @@ import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest; import org.schabi.newpipe.extractor.services.BaseChannelExtractorTest;
import org.schabi.newpipe.extractor.services.peertube.extractors.PeertubeAccountExtractor; 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.ExtractorAsserts.assertIsSecureUrl;
import static org.schabi.newpipe.extractor.ServiceList.PeerTube; 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} * Test for {@link PeertubeAccountExtractor}
@ -82,7 +87,7 @@ public class PeertubeAccountExtractorTest {
@Test @Test
public void testDescription() throws ParsingException { public void testDescription() throws ParsingException {
assertNotNull(extractor.getDescription()); assertNull(extractor.getDescription());
} }
@Test @Test