import android.app.Application; import com.github.catvod.spider.Glod; import com.github.catvod.spider.Init; import com.github.catvod.spider.Introduce; import com.github.catvod.utils.Json; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import org.junit.Assert; import org.junit.runner.RunWith; import org.robolectric.RobolectricTestRunner; import org.robolectric.RuntimeEnvironment; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @RunWith(RobolectricTestRunner.class) public class IntroduceTest { // @Mock private Application mockContext; private Introduce spider; @org.junit.Before public void setUp() throws Exception { mockContext = RuntimeEnvironment.application; Init.init(mockContext); spider = new Introduce(); spider.init(mockContext, "https://www.czzy.site/"); } @org.junit.Test public void homeContent() throws Exception { String content = spider.homeContent(true); JsonObject map = Json.safeObject(content); Gson gson = new GsonBuilder().setPrettyPrinting().create(); System.out.println("homeContent--" + gson.toJson(map)); //Assert.assertFalse(map.getAsJsonArray("list").isEmpty()); } @org.junit.Test public void homeVideoContent() throws Exception { String content = spider.homeVideoContent(); JsonObject map = Json.safeObject(content); Gson gson = new GsonBuilder().setPrettyPrinting().create(); System.out.println("homeVideoContent--" + gson.toJson(map)); //Assert.assertFalse(map.getAsJsonArray("list").isEmpty()); } @org.junit.Test public void categoryContent() throws Exception { String content = spider.categoryContent("2", "2", true, new HashMap<>()); JsonObject map = Json.safeObject(content); Gson gson = new GsonBuilder().setPrettyPrinting().create(); System.out.println("categoryContent--" + gson.toJson(map)); Assert.assertFalse(map.getAsJsonArray("list").isEmpty()); } @org.junit.Test public void detailContent() throws Exception { String content = spider.detailContent(Arrays.asList("UCToken")); JsonObject map = Json.safeObject(content); Gson gson = new GsonBuilder().setPrettyPrinting().create(); System.out.println("detailContent--" + gson.toJson(map)); Assert.assertFalse(map.getAsJsonArray("list").isEmpty()); } @org.junit.Test public void playerContent() throws Exception { String froms = "glod"; String urls = "1$/vod/play/126164/sid/1057548#2$/vod/play/126164/sid/1057549#3$/vod/play/126164/sid/1057735#4$/vod/play/126164/sid/1057683"; for (int i = 0; i < urls.split("\\$\\$\\$").length; i++) { String content = spider.playerContent(froms.split("\\$\\$\\$")[i], urls.split("\\$\\$\\$")[i].split("#")[0].split("\\$")[1], new ArrayList<>()); JsonObject map = Json.safeObject(content); Gson gson = new GsonBuilder().setPrettyPrinting().create(); System.out.println("playerContent--" + gson.toJson(map)); Assert.assertFalse(map.getAsJsonPrimitive("url").getAsString().isEmpty()); } } @org.junit.Test public void searchContent() throws Exception { String content = spider.searchContent("红", false); JsonObject map = Json.safeObject(content); Gson gson = new GsonBuilder().setPrettyPrinting().create(); System.out.println("searchContent--" + gson.toJson(map)); Assert.assertFalse(map.getAsJsonArray("list").isEmpty()); } }