-
Notifications
You must be signed in to change notification settings - Fork 299
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#32 Added unit tests for OldNovelContentParser and UserInfo
- Loading branch information
Showing
11 changed files
with
154 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...ibrary/app/src/androidTest/java/org/mewx/wenku8/global/api/OldNovelContentParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
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"; | ||
|
||
@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 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); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...d/LightNovelLibrary/app/src/androidTest/java/org/mewx/wenku8/global/api/UserInfoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.