22
33import me .chanjar .weixin .cp .bean .article .MpnewsArticle ;
44import me .chanjar .weixin .cp .bean .article .NewArticle ;
5- import org .testng .annotations .* ;
5+ import org .testng .annotations .Test ;
66
7- import static org .testng .Assert .*;
7+ import static org .assertj .core .api .Assertions .assertThat ;
8+ import static org .testng .Assert .assertEquals ;
89
910@ Test
1011public class WxCpMessageTest {
1112
1213 public void testTextBuild () {
1314 WxCpMessage reply = WxCpMessage .TEXT ().toUser ("OPENID" ).content ("sfsfdsdf" ).build ();
14- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" text\" ,\" text\" :{\" content\" :\" sfsfdsdf\" },\" safe\" :\" 0\" }" );
15+ assertThat (reply .toJson ())
16+ .isEqualTo ("{\" touser\" :\" OPENID\" ,\" msgtype\" :\" text\" ,\" text\" :{\" content\" :\" sfsfdsdf\" },\" safe\" :\" 0\" }" );
1517 }
1618
1719 public void testTextCardBuild () {
1820 WxCpMessage reply = WxCpMessage .TEXTCARD ().toUser ("OPENID" )
1921 .title ("领奖通知" )
20- .description ( "<div class=\" gray\" >2016年9月26日</div> <div class=\" normal\" >恭喜你抽中iPhone 7一台,领奖码:xxxx</div><div class=\" highlight\" >请于2016年10月10日前联系行政同事领取</div>" )
21- .url ("http://www.qq.com" ).build ();
22- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" textcard\" ,\" textcard\" :{\" title\" :\" 领奖通知\" ,\" description\" :\" <div class=\\ \" gray\\ \" >2016年9月26日</div> <div class=\\ \" normal\\ \" >恭喜你抽中iPhone 7一台,领奖码:xxxx</div><div class=\\ \" highlight\\ \" >请于2016年10月10日前联系行政同事领取</div>\" ,\" url\" :\" http://www.qq.com\" },\" safe\" :\" 0\" }" );
22+ .description ("<div class=\" gray\" >2016年9月26日</div> <div class=\" normal\" >恭喜你抽中iPhone 7一台,领奖码:xxxx</div><div class=\" highlight\" >请于2016年10月10日前联系行政同事领取</div>" )
23+ .url ("http://www.qq.com" )
24+ .btnTxt ("更多" )
25+ .build ();
26+ assertThat (reply .toJson ())
27+ .isEqualTo ("{\" touser\" :\" OPENID\" ,\" msgtype\" :\" textcard\" ,\" textcard\" :{\" title\" :\" 领奖通知\" ,\" description\" :\" <div class=\\ \" gray\\ \" >2016年9月26日</div> <div class=\\ \" normal\\ \" >恭喜你抽中iPhone 7一台,领奖码:xxxx</div><div class=\\ \" highlight\\ \" >请于2016年10月10日前联系行政同事领取</div>\" ,\" url\" :\" http://www.qq.com\" ,\" btntxt\" :\" 更多\" },\" safe\" :\" 0\" }" );
2328 }
2429
2530 public void testImageBuild () {
2631 WxCpMessage reply = WxCpMessage .IMAGE ().toUser ("OPENID" ).mediaId ("MEDIA_ID" ).build ();
27- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" image\" ,\" image\" :{\" media_id\" :\" MEDIA_ID\" },\" safe\" :\" 0\" }" );
32+ assertThat (reply .toJson ())
33+ .isEqualTo ("{\" touser\" :\" OPENID\" ,\" msgtype\" :\" image\" ,\" image\" :{\" media_id\" :\" MEDIA_ID\" },\" safe\" :\" 0\" }" );
2834 }
2935
3036 public void testVoiceBuild () {
3137 WxCpMessage reply = WxCpMessage .VOICE ().toUser ("OPENID" ).mediaId ("MEDIA_ID" ).build ();
32- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" voice\" ,\" voice\" :{\" media_id\" :\" MEDIA_ID\" },\" safe\" :\" 0\" }" );
38+ assertThat (reply .toJson ())
39+ .isEqualTo ("{\" touser\" :\" OPENID\" ,\" msgtype\" :\" voice\" ,\" voice\" :{\" media_id\" :\" MEDIA_ID\" },\" safe\" :\" 0\" }" );
3340 }
3441
3542 public void testVideoBuild () {
3643 WxCpMessage reply = WxCpMessage .VIDEO ().toUser ("OPENID" ).title ("TITLE" ).mediaId ("MEDIA_ID" ).thumbMediaId ("MEDIA_ID" ).description ("DESCRIPTION" ).build ();
37- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" video\" ,\" safe\" :\" 0\" ,\" video\" :{\" media_id\" :\" MEDIA_ID\" ,\" thumb_media_id\" :\" MEDIA_ID\" ,\" title\" :\" TITLE\" ,\" description\" :\" DESCRIPTION\" }}" );
44+ assertThat (reply .toJson ())
45+ .isEqualTo ("{\" touser\" :\" OPENID\" ,\" msgtype\" :\" video\" ,\" safe\" :\" 0\" ,\" video\" :{\" media_id\" :\" MEDIA_ID\" ,\" thumb_media_id\" :\" MEDIA_ID\" ,\" title\" :\" TITLE\" ,\" description\" :\" DESCRIPTION\" }}" );
3846 }
3947
4048 public void testNewsBuild () {
@@ -52,7 +60,8 @@ public void testNewsBuild() {
5260
5361 WxCpMessage reply = WxCpMessage .NEWS ().toUser ("OPENID" ).addArticle (article1 ).addArticle (article2 ).build ();
5462
55- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" news\" ,\" safe\" :\" 0\" ,\" news\" :{\" articles\" :[{\" title\" :\" Happy Day\" ,\" description\" :\" Is Really A Happy Day\" ,\" url\" :\" URL\" ,\" picurl\" :\" PIC_URL\" },{\" title\" :\" Happy Day\" ,\" description\" :\" Is Really A Happy Day\" ,\" url\" :\" URL\" ,\" picurl\" :\" PIC_URL\" }]}}" );
63+ assertThat (reply .toJson ())
64+ .isEqualTo ( "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" news\" ,\" safe\" :\" 0\" ,\" news\" :{\" articles\" :[{\" title\" :\" Happy Day\" ,\" description\" :\" Is Really A Happy Day\" ,\" url\" :\" URL\" ,\" picurl\" :\" PIC_URL\" },{\" title\" :\" Happy Day\" ,\" description\" :\" Is Really A Happy Day\" ,\" url\" :\" URL\" ,\" picurl\" :\" PIC_URL\" }]}}" );
5665 }
5766
5867 public void testMpnewsBuild_with_articles () {
@@ -78,14 +87,15 @@ public void testMpnewsBuild_with_articles() {
7887
7988 WxCpMessage reply = WxCpMessage .MPNEWS ().toUser ("OPENID" ).addArticle (article1 , article2 ).build ();
8089
81- assertEquals (reply .toJson (), "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" mpnews\" ,\" safe\" :\" 0\" ,\" mpnews\" :{\" articles\" :[{\" title\" :\" Happy Day\" ,\" thumb_media_id\" :\" thumb\" ,\" author\" :\" aaaaaa\" ,\" content_source_url\" :\" nice url\" ,\" content\" :\" hahaha\" ,\" digest\" :\" digest\" ,\" show_cover_pic\" :\" heihei\" },{\" title\" :\" Happy Day\" ,\" thumb_media_id\" :\" thumb\" ,\" author\" :\" aaaaaa\" ,\" content_source_url\" :\" nice url\" ,\" content\" :\" hahaha\" ,\" digest\" :\" digest\" ,\" show_cover_pic\" :\" heihei\" }]}}" );
90+ assertThat (reply .toJson ())
91+ .isEqualTo ( "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" mpnews\" ,\" safe\" :\" 0\" ,\" mpnews\" :{\" articles\" :[{\" title\" :\" Happy Day\" ,\" thumb_media_id\" :\" thumb\" ,\" author\" :\" aaaaaa\" ,\" content_source_url\" :\" nice url\" ,\" content\" :\" hahaha\" ,\" digest\" :\" digest\" ,\" show_cover_pic\" :\" heihei\" },{\" title\" :\" Happy Day\" ,\" thumb_media_id\" :\" thumb\" ,\" author\" :\" aaaaaa\" ,\" content_source_url\" :\" nice url\" ,\" content\" :\" hahaha\" ,\" digest\" :\" digest\" ,\" show_cover_pic\" :\" heihei\" }]}}" );
8292 }
8393
8494 public void testMpnewsBuild_with_media_id () {
8595 WxCpMessage reply = WxCpMessage .MPNEWS ().toUser ("OPENID" ).mediaId ("mmm" ).build ();
8696
87- assertEquals (reply .toJson (),
88- "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" mpnews\" ,\" safe\" :\" 0\" ,\" mpnews\" :{\" media_id\" :\" mmm\" }}" );
97+ assertThat (reply .toJson ())
98+ . isEqualTo ( "{\" touser\" :\" OPENID\" ,\" msgtype\" :\" mpnews\" ,\" safe\" :\" 0\" ,\" mpnews\" :{\" media_id\" :\" mmm\" }}" );
8999 }
90100
91101}
0 commit comments