From ae6d09c6e85578c301f789b7c7e113a5204cf0fc Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 1 Jul 2018 15:14:09 -0400 Subject: [PATCH] Added some unit tests for DeviantartRipper --- .../ripme/ripper/rippers/DeviantartRipper.java | 8 +++----- .../ripme/tst/ripper/rippers/DeviantartRipperTest.java | 10 ++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java index a3428ae6..8d9f3da2 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/DeviantartRipper.java @@ -190,13 +190,11 @@ public class DeviantartRipper extends AbstractJSONRipper { return null; } - private String getGalleryID(Document doc) { + public String getGalleryID(Document doc) { for (Element el : doc.select("input[name=set]")) { try { String galleryID = el.attr("value"); - if (galleryID.length() == 8) { - return galleryID; - } + return galleryID; } catch (NullPointerException e) { continue; } @@ -205,7 +203,7 @@ public class DeviantartRipper extends AbstractJSONRipper { return null; } - private String getUsername(Document doc) { + public String getUsername(Document doc) { return doc.select("meta[property=og:title]").attr("content").replaceAll("'s DeviantArt gallery", ""); } diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/DeviantartRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/DeviantartRipperTest.java index f68d1db5..52b6bc59 100644 --- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/DeviantartRipperTest.java +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/DeviantartRipperTest.java @@ -4,6 +4,8 @@ import java.io.IOException; import java.net.URL; import com.rarchives.ripme.ripper.rippers.DeviantartRipper; +import com.rarchives.ripme.utils.Http; +import org.jsoup.nodes.Document; public class DeviantartRipperTest extends RippersTest { public void testDeviantartAlbum() throws IOException { @@ -22,4 +24,12 @@ public class DeviantartRipperTest extends RippersTest { DeviantartRipper ripper = new DeviantartRipper(url); assertEquals("airgee", ripper.getGID(url)); } + + public void testGetGalleryIDAndUsername() throws IOException { + URL url = new URL("https://www.deviantart.com/airgee/gallery/"); + DeviantartRipper ripper = new DeviantartRipper(url); + Document doc = Http.url(url).get(); + assertEquals("airgee", ripper.getUsername(doc)); + assertEquals("714589", ripper.getGalleryID(doc)); + } }