Skip to content

Commit

Permalink
#32 Merge branch 'master' into v1.6 (mainly the unit tests)
Browse files Browse the repository at this point in the history
  • Loading branch information
MewX committed Nov 3, 2018
2 parents 233bd54 + 78ab7c4 commit 8b7ec6b
Show file tree
Hide file tree
Showing 34 changed files with 1,070 additions and 802 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ before_install:
- android-wait-for-emulator
- adb shell input keyevent 82 &

script: ./gradlew build connectedCheck coveralls
script: ./gradlew assembleAlpha connectedAlphaDebugAndroidTest coveralls

6 changes: 3 additions & 3 deletions studio-android/LightNovelLibrary/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'junit:junit:4.12'
androidTestImplementation 'org.mockito:mockito-core:1.10.19'
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestImplementation 'org.mockito:mockito-core:2.19.0'
androidTestImplementation 'com.linkedin.dexmaker:dexmaker:2.19.1'
androidTestImplementation 'com.linkedin.dexmaker:dexmaker-mockito:2.19.1'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-all:1.10.19'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.mewx.wenku8.global.api;

import org.junit.Test;

import static org.junit.Assert.*;

public class NovelItemInfoUpdateTest {

@Test
public void convertFromMeta() {
final String META_XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<metadata>\n" +
"<data name=\"Title\" aid=\"1306\"><![CDATA[向森之魔物献上花束(向森林的魔兽少女献花)]]></data>\n" +
"<data name=\"Author\" value=\"小木君人\"/>\n" +
"<data name=\"DayHitsCount\" value=\"26\"/>\n" +
"<data name=\"TotalHitsCount\" value=\"43984\"/>\n" +
"<data name=\"PushCount\" value=\"1735\"/>\n" +
"<data name=\"FavCount\" value=\"848\"/>\n" +
"<data name=\"PressId\" value=\"小学馆\" sid=\"10\"/>\n" +
"<data name=\"BookStatus\" value=\"已完成\"/>\n" +
"<data name=\"BookLength\" value=\"105985\"/>\n" +
"<data name=\"LastUpdate\" value=\"2012-11-02\"/>\n" +
"<data name=\"LatestSection\" cid=\"41897\"><![CDATA[第一卷 插图]]></data>\n" +
"</metadata>";
NovelItemMeta meta = Wenku8Parser.parseNovelFullMeta(META_XML);
assertNotNull(meta);

NovelItemInfoUpdate info = NovelItemInfoUpdate.convertFromMeta(meta);
assertEquals("向森之魔物献上花束(向森林的魔兽少女献花)", info.title);
assertEquals(1306, info.aid);
assertEquals("小木君人", info.author);
assertEquals("已完成", info.status);
assertEquals("2012-11-02", info.update);
assertEquals("第一卷 插图", info.latest_chapter);
}

@Test
public void parseNovelItemInfoUpdate() {
final String XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<metadata>\n" +
"<data name=\"Title\" aid=\"1305\"><![CDATA[绝对双刃absolute duo]]></data>\n" +
"<data name=\"Author\" value=\"柊★巧\"/>\n" +
"<data name=\"BookStatus\" value=\"连载中\"/>\n" +
"<data name=\"LastUpdate\" value=\"2014-10-01\"/>\n" +
"<data\n" +
"name=\"IntroPreview\"><![CDATA[  「焰牙」——那是藉由超化之后的精神力将自身灵...]]></data>\n" +
"</metadata>";
NovelItemInfoUpdate info = NovelItemInfoUpdate.parse(XML);
assertNotNull(info);

assertEquals("绝对双刃absolute duo", info.title);
assertEquals(1305, info.aid);
assertEquals("柊★巧", info.author);
assertEquals("连载中", info.status);
assertEquals("2014-10-01", info.update);
assertEquals("「焰牙」——那是藉由超化之后的精神力将自身灵...", info.intro_short);
}

@Test
public void parseNovelItemInfoUpdateInvalid() {
NovelItemInfoUpdate info = NovelItemInfoUpdate.parse("1234");
assertNull(info);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.mewx.wenku8.global.api;

import org.junit.Test;

import java.util.List;

import static org.junit.Assert.*;

public class NovelListWithInfoParserTest {
private static final String XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<result>\n" +
"<page num='166'/>\n" +
"\n" +
"<item aid='1034'>\n" +
"<data name='Title'><![CDATA[恶魔高校DxD(High School DxD)]]></data>\n" +
"<data name='TotalHitsCount' value='2316361'/>\n" +
"<data name='PushCount' value='153422'/>\n" +
"<data name='FavCount' value='14416'/>\n" +
"<data name='Author' value='xxx1'/>\n" +
"<data name='BookStatus' value='xxx2'/>\n" +
"<data name='LastUpdate' value='xxx3'/>\n" +
"<data name='IntroPreview' value='xxx4'/>\n" +
"</item>\n" +
"\n" +
"<item aid='1035'>\n" +
"<data name='Title'><![CDATA[High School DxD]]></data>\n" +
"<data name='TotalHitsCount' value='1234'/>\n" +
"<data name='PushCount' value='4567'/>\n" +
"<data name='FavCount' value='789'/>\n" +
"<data name='Author' value='yyy1'/>\n" +
"<data name='BookStatus' value='yyy2'/>\n" +
"<data name='LastUpdate' value='yyy3'/>\n" +
"<data name='IntroPreview' value='yyy4'/>\n" +
"</item>\n" +
"\n" +
"</result>";

@Test
public void getNovelListWithInfoPageNumInvalid() {
assertEquals(0, NovelListWithInfoParser.getNovelListWithInfoPageNum("1234"));
}

@Test
public void getNovelListWithInfoPageNum() {
assertEquals(166, NovelListWithInfoParser.getNovelListWithInfoPageNum(XML));
}


@Test
public void getNovelListWithInfoInvalid() {
List<NovelListWithInfoParser.NovelListWithInfo> list = NovelListWithInfoParser.getNovelListWithInfo("1234");
assertTrue(list.isEmpty());
}

@Test
public void getNovelListWithInfo() {
List<NovelListWithInfoParser.NovelListWithInfo> list = NovelListWithInfoParser.getNovelListWithInfo(XML);
assertEquals(2, list.size());

NovelListWithInfoParser.NovelListWithInfo info = list.get(0);
assertEquals(1034, info.aid);
assertEquals(14416, info.fav);
assertEquals(2316361, info.hit);
assertEquals(153422, info.push);
assertEquals("恶魔高校DxD(High School DxD)", info.name);

info = list.get(1);
assertEquals(1035, info.aid);
assertEquals(789, info.fav);
assertEquals(1234, info.hit);
assertEquals(4567, info.push);
assertEquals("High School DxD", info.name);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package org.mewx.wenku8.global.api;

import org.junit.Test;

import java.util.List;

import static org.mewx.wenku8.global.api.OldNovelContentParser.NovelContentType.*;

import static org.junit.Assert.assertEquals;

public class OldNovelContentParserTest {
private static final String NOVEL_CONTENT = "line 1\r\n" +
" <!--image-->http://bbbbb.com/pictures/1/1339/90903/107724.jpg<!--image--> \r\n" +
" line 2 \r\n\r\n" +
"<!--image-->http://bbbbb.com/pictures/1/1339/90903/107725.jpg<!--image-->\r\n" +
"line 3\r\n";

private static final String NOVEL_CONTENt_BROKEN_IMAGE = "line 1\r\n" +
" <!--image-->http://bbbbb.com/pictures/1/1339/90903/107724.jpg<!--image--> \r\n" +
" line 2 \r\n\r\n" +
" <!--image-->http://bbbbb.com/pictures/1/1339/90903/107725.jpg \r\n" +
"line 3\r\n";

@Test
public void parseNovelContent() {
List<OldNovelContentParser.NovelContent> contents = OldNovelContentParser.parseNovelContent(NOVEL_CONTENT, null);
assertEquals(5, contents.size());

OldNovelContentParser.NovelContent tempContent = contents.get(0);
assertEquals(TEXT, tempContent.type);
assertEquals("line 1", tempContent.content);

tempContent = contents.get(1);
assertEquals(IMAGE, tempContent.type);
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107724.jpg", tempContent.content);

tempContent = contents.get(2);
assertEquals(TEXT, tempContent.type);
assertEquals("line 2", tempContent.content);

tempContent = contents.get(3);
assertEquals(IMAGE, tempContent.type);
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107725.jpg", tempContent.content);

tempContent = contents.get(4);
assertEquals(TEXT, tempContent.type);
assertEquals("line 3", tempContent.content);
}

@Test
public void parseNovelContentWithIncompleteImageTag() {
List<OldNovelContentParser.NovelContent> contents = OldNovelContentParser.parseNovelContent(NOVEL_CONTENt_BROKEN_IMAGE, null);
assertEquals(5, contents.size());

OldNovelContentParser.NovelContent tempContent = contents.get(0);
assertEquals(TEXT, tempContent.type);
assertEquals("line 1", tempContent.content);

tempContent = contents.get(1);
assertEquals(IMAGE, tempContent.type);
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107724.jpg", tempContent.content);

tempContent = contents.get(2);
assertEquals(TEXT, tempContent.type);
assertEquals("line 2", tempContent.content);

tempContent = contents.get(3);
assertEquals(TEXT, tempContent.type);
assertEquals("<!--image-->http://bbbbb.com/pictures/1/1339/90903/107725.jpg", tempContent.content);

tempContent = contents.get(4);
assertEquals(TEXT, tempContent.type);
assertEquals("line 3", tempContent.content);
}

@Test
public void novelContentParser_onlyImage() {
List<OldNovelContentParser.NovelContent> contents = OldNovelContentParser.NovelContentParser_onlyImage(NOVEL_CONTENT);
assertEquals(2, contents.size());

OldNovelContentParser.NovelContent tempContent = contents.get(0);
assertEquals(IMAGE, tempContent.type);
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107724.jpg", tempContent.content);

tempContent = contents.get(1);
assertEquals(IMAGE, tempContent.type);
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107725.jpg", tempContent.content);
}

@Test
public void novelContentParser_onlyImageBroken() {
List<OldNovelContentParser.NovelContent> contents = OldNovelContentParser.NovelContentParser_onlyImage(NOVEL_CONTENt_BROKEN_IMAGE);
assertEquals(1, contents.size());

OldNovelContentParser.NovelContent tempContent = contents.get(0);
assertEquals(IMAGE, tempContent.type);
assertEquals("http://bbbbb.com/pictures/1/1339/90903/107724.jpg", tempContent.content);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.mewx.wenku8.global.api;

import android.support.test.filters.SmallTest;

import org.junit.Test;

import static org.junit.Assert.*;

@SmallTest
public class UserInfoTest {
private static final String USER_INFO_XML = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<metadata>\n" +
"<item name=\"uname\"><![CDATA[apptest]]></item>\n" +
"<item name=\"nickname\"><![CDATA[apptest nick]]></item>\n" +
"<item name=\"score\">100</item>\n" +
"<item name=\"experience\">10</item>\n" +
"<item name=\"rank\"><![CDATA[新手上路]]></item>\n" +
"</metadata>";

@Test
public void parseUserInfo() {
UserInfo ui = UserInfo.parseUserInfo(USER_INFO_XML);
assertNotNull(ui);
assertEquals("apptest", ui.username);
assertEquals("apptest nick", ui.nickyname);
assertEquals(10, ui.experience);
assertEquals(100, ui.score);
assertEquals("新手上路", ui.rank);
}

@Test
public void parseInvalidUserInfo() {
UserInfo ui = UserInfo.parseUserInfo("adfsdfasdfasdf");
assertNull(ui);
}
}
Loading

0 comments on commit 8b7ec6b

Please sign in to comment.