Skip to content

Commit b885d2a

Browse files
committed
#111 的unit test code
1 parent 913f49e commit b885d2a

File tree

2 files changed

+65
-3
lines changed

2 files changed

+65
-3
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxMenu.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,14 @@ public static WxMenu fromJson(String json) {
3636
public static WxMenu fromJson(InputStream is) {
3737
return WxGsonBuilder.create().fromJson(new InputStreamReader(is), WxMenu.class);
3838
}
39-
39+
40+
@Override
41+
public String toString() {
42+
return "WxMenu{" +
43+
"buttons=" + buttons +
44+
'}';
45+
}
46+
4047
public static class WxMenuButton {
4148

4249
private String type;
@@ -85,7 +92,17 @@ public List<WxMenuButton> getSubButtons() {
8592
public void setSubButtons(List<WxMenuButton> subButtons) {
8693
this.subButtons = subButtons;
8794
}
88-
95+
96+
@Override
97+
public String toString() {
98+
return "WxMenuButton{" +
99+
"type='" + type + '\'' +
100+
", name='" + name + '\'' +
101+
", key='" + key + '\'' +
102+
", url='" + url + '\'' +
103+
", subButtons=" + subButtons +
104+
'}';
105+
}
89106
}
90107

91108
}

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMenuAPITest.java

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,54 @@ public class WxMpMenuAPITest {
2424

2525
@Test(dataProvider = "menu")
2626
public void testCreateMenu(WxMenu wxMenu) throws WxErrorException {
27+
System.out.println(wxMenu.toJson());
2728
wxService.menuCreate(wxMenu);
2829
}
29-
30+
31+
@Test
32+
public void testCreateMenu2() throws WxErrorException {
33+
String a = "{\n"
34+
+ " \"menu\": {\n"
35+
+ " \"button\": [\n"
36+
+ " {\n"
37+
+ " \"type\": \"click\",\n"
38+
+ " \"name\": \"今日歌曲\",\n"
39+
+ " \"key\": \"V1001_TODAY_MUSIC\"\n"
40+
+ " },\n"
41+
+ " {\n"
42+
+ " \"type\": \"click\",\n"
43+
+ " \"name\": \"歌手简介\",\n"
44+
+ " \"key\": \"V1001_TODAY_SINGER\"\n"
45+
+ " },\n"
46+
+ " {\n"
47+
+ " \"name\": \"菜单\",\n"
48+
+ " \"sub_button\": [\n"
49+
+ " {\n"
50+
+ " \"type\": \"view\",\n"
51+
+ " \"name\": \"搜索\",\n"
52+
+ " \"url\": \"http://www.soso.com/\"\n"
53+
+ " },\n"
54+
+ " {\n"
55+
+ " \"type\": \"view\",\n"
56+
+ " \"name\": \"视频\",\n"
57+
+ " \"url\": \"http://v.qq.com/\"\n"
58+
+ " },\n"
59+
+ " {\n"
60+
+ " \"type\": \"click\",\n"
61+
+ " \"name\": \"赞一下我们\",\n"
62+
+ " \"key\": \"V1001_GOOD\"\n"
63+
+ " }\n"
64+
+ " ]\n"
65+
+ " }\n"
66+
+ " ]\n"
67+
+ " }\n"
68+
+ "}";
69+
70+
WxMenu menu = WxMenu.fromJson(a);
71+
System.out.println(menu.toJson());
72+
wxService.menuCreate(menu);
73+
}
74+
3075
@Test(dependsOnMethods = { "testCreateMenu"})
3176
public void testGetMenu() throws WxErrorException {
3277
Assert.assertNotNull(wxService.menuGet());

0 commit comments

Comments
 (0)