#111 的unit test code

This commit is contained in:
Daniel Qian 2015-03-20 14:59:59 +08:00
parent 913f49e470
commit b885d2a1a9
2 changed files with 65 additions and 3 deletions

View File

@ -36,7 +36,14 @@ public class WxMenu implements Serializable {
public static WxMenu fromJson(InputStream is) { public static WxMenu fromJson(InputStream is) {
return WxGsonBuilder.create().fromJson(new InputStreamReader(is), WxMenu.class); return WxGsonBuilder.create().fromJson(new InputStreamReader(is), WxMenu.class);
} }
@Override
public String toString() {
return "WxMenu{" +
"buttons=" + buttons +
'}';
}
public static class WxMenuButton { public static class WxMenuButton {
private String type; private String type;
@ -85,7 +92,17 @@ public class WxMenu implements Serializable {
public void setSubButtons(List<WxMenuButton> subButtons) { public void setSubButtons(List<WxMenuButton> subButtons) {
this.subButtons = subButtons; this.subButtons = subButtons;
} }
@Override
public String toString() {
return "WxMenuButton{" +
"type='" + type + '\'' +
", name='" + name + '\'' +
", key='" + key + '\'' +
", url='" + url + '\'' +
", subButtons=" + subButtons +
'}';
}
} }
} }

View File

@ -24,9 +24,54 @@ public class WxMpMenuAPITest {
@Test(dataProvider = "menu") @Test(dataProvider = "menu")
public void testCreateMenu(WxMenu wxMenu) throws WxErrorException { public void testCreateMenu(WxMenu wxMenu) throws WxErrorException {
System.out.println(wxMenu.toJson());
wxService.menuCreate(wxMenu); wxService.menuCreate(wxMenu);
} }
@Test
public void testCreateMenu2() throws WxErrorException {
String a = "{\n"
+ " \"menu\": {\n"
+ " \"button\": [\n"
+ " {\n"
+ " \"type\": \"click\",\n"
+ " \"name\": \"今日歌曲\",\n"
+ " \"key\": \"V1001_TODAY_MUSIC\"\n"
+ " },\n"
+ " {\n"
+ " \"type\": \"click\",\n"
+ " \"name\": \"歌手简介\",\n"
+ " \"key\": \"V1001_TODAY_SINGER\"\n"
+ " },\n"
+ " {\n"
+ " \"name\": \"菜单\",\n"
+ " \"sub_button\": [\n"
+ " {\n"
+ " \"type\": \"view\",\n"
+ " \"name\": \"搜索\",\n"
+ " \"url\": \"http://www.soso.com/\"\n"
+ " },\n"
+ " {\n"
+ " \"type\": \"view\",\n"
+ " \"name\": \"视频\",\n"
+ " \"url\": \"http://v.qq.com/\"\n"
+ " },\n"
+ " {\n"
+ " \"type\": \"click\",\n"
+ " \"name\": \"赞一下我们\",\n"
+ " \"key\": \"V1001_GOOD\"\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ " ]\n"
+ " }\n"
+ "}";
WxMenu menu = WxMenu.fromJson(a);
System.out.println(menu.toJson());
wxService.menuCreate(menu);
}
@Test(dependsOnMethods = { "testCreateMenu"}) @Test(dependsOnMethods = { "testCreateMenu"})
public void testGetMenu() throws WxErrorException { public void testGetMenu() throws WxErrorException {
Assert.assertNotNull(wxService.menuGet()); Assert.assertNotNull(wxService.menuGet());