import android.app.Application; import com.github.catvod.spider.Init; import com.github.catvod.spider.Jianpian; import com.github.catvod.spider.NCat; 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.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; import java.util.ArrayList; import java.util.Arrays; @RunWith(MockitoJUnitRunner.class) public class NCatTest { @Mock private Application mockContext; private NCat spider; @org.junit.Before public void setUp() throws Exception { Init.init(mockContext); spider = new NCat(); spider.init(mockContext, ""); } @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("1", "2", true, null); 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("232824.html")); 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 = "FF线路$$$蓝光3$$$蓝光9$$$蓝光9-1$$$蓝光1$$$蓝光9-2$$$蓝光1-1$$$蓝光1-2$$$蓝光7"; String urls = "国语$232824-4-648287.html#粤语$232824-4-730937.html$$$HD国语$232824-2-558076.html#HD粤语$232824-2-573419.html$$$正片$232824-36-395120.html$$$正片$232824-36-395138.html$$$TC$232824-27-504728.html$$$抢先版$232824-36-377043.html$$$粤语中字$232824-27-547751.html$$$国语中字$232824-27-547772.html$$$正片$232824-33-393805.html"; for (int i = 0; i < urls.split("\\$\\$\\$").length; i++) { String content = spider.playerContent(froms.split("\\$\\$\\$")[i], urls.split("\\$\\$\\$")[i].split("\\$")[1].split("#")[0], 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()); } }