Skip to content

Commit bc5f249

Browse files
author
Javen
committed
Adding tests.
1 parent 657ec2c commit bc5f249

File tree

5 files changed

+137
-89
lines changed

5 files changed

+137
-89
lines changed

src/cn/jpush/api/JPushClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
* The overall entrance of JPush API library.
1111
*/
1212
public class JPushClient {
13-
private PushClient _pushClient;
14-
private ReportClient _reportClient;
13+
private final PushClient _pushClient;
14+
private final ReportClient _reportClient;
1515

1616
/**
1717
* Create a JPush Client.

src/cn/jpush/api/common/BaseResult.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package cn.jpush.api.common;
22

3-
import cn.jpush.api.common.ResponseWrapper.ErrorContent;
3+
import cn.jpush.api.common.ResponseWrapper.ErrorObject;
44

55
import com.google.gson.Gson;
66
import com.google.gson.GsonBuilder;
@@ -15,15 +15,15 @@ public abstract class BaseResult {
1515

1616
public ResponseWrapper responseResult;
1717

18-
protected ErrorContent getErrorObject() {
18+
protected ErrorObject getErrorObject() {
1919
if (null != responseResult) {
2020
return responseResult.error;
2121
}
2222
return null;
2323
}
2424

2525
public int getErrorCode() {
26-
ErrorContent eo = getErrorObject();
26+
ErrorObject eo = getErrorObject();
2727
if (null != eo) {
2828
return eo.error.code;
2929
}
@@ -36,7 +36,7 @@ public int getErrorCode() {
3636
}
3737

3838
public String getErrorMessage() {
39-
ErrorContent eo = getErrorObject();
39+
ErrorObject eo = getErrorObject();
4040
if (null != eo) {
4141
return eo.error.message;
4242
}

src/cn/jpush/api/common/ErrorCodeEnum.java

Lines changed: 0 additions & 75 deletions
This file was deleted.

src/cn/jpush/api/common/ResponseWrapper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class ResponseWrapper {
1414
public int responseCode = RESPONSE_CODE_NONE;
1515
public String responseContent;
1616

17-
public ErrorContent error; // error for non-200 response, used by new API
17+
public ErrorObject error; // error for non-200 response, used by new API
1818

1919
public int rateLimitQuota;
2020
public int rateLimitRemaining;
@@ -40,19 +40,19 @@ public void setRateLimit(String quota, String remaining, String reset) {
4040
}
4141

4242
public void setErrorObject() {
43-
error = _gson.fromJson(responseContent, ErrorContent.class);
43+
error = _gson.fromJson(responseContent, ErrorObject.class);
4444
}
4545

4646
@Override
4747
public String toString() {
4848
return _gson.toJson(this);
4949
}
5050

51-
public class ErrorContent {
52-
public Error error;
51+
public class ErrorObject {
52+
public ErrorEntity error;
5353
}
5454

55-
public class Error {
55+
public class ErrorEntity {
5656
public int code;
5757
public String message;
5858

test/cn/jpush/api/PushFunctionTests.java

Lines changed: 126 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
import org.junit.Test;
77

88
import cn.jpush.api.push.PushResult;
9+
import cn.jpush.api.push.model.Message;
910
import cn.jpush.api.push.model.Platform;
1011
import cn.jpush.api.push.model.PushPayload;
1112
import cn.jpush.api.push.model.audience.Audience;
1213
import cn.jpush.api.push.model.notification.AndroidNotification;
14+
import cn.jpush.api.push.model.notification.IosNotification;
1315
import cn.jpush.api.push.model.notification.Notification;
16+
import cn.jpush.api.push.model.notification.WinphoneNotification;
1417

1518
public class PushFunctionTests {
1619
private static final String appKey ="dd1066407b044738b6479275";
@@ -31,14 +34,27 @@ public void before() {
3134

3235

3336
@Test
34-
public void sendSimpleNotificationAll() {
37+
public void sendSimpleNotification_Pall_Ndefault() {
3538
PushPayload payload = PushPayload.notificationAlertAll(ALERT);
3639
PushResult result = _client.sendPush(payload);
3740
assertEquals(0, result.getErrorCode());
3841
}
3942

4043
@Test
41-
public void sendSimpleNotification_android() {
44+
public void sendSimpleNotification_Pandroid_Nandroid() {
45+
PushPayload payload = PushPayload.newBuilder()
46+
.setPlatform(Platform.android())
47+
.setAudience(Audience.all())
48+
.setNotification(Notification.newBuilder()
49+
.addPlatformNotification(AndroidNotification.alert("alert"))
50+
.build())
51+
.build();
52+
PushResult result = _client.sendPush(payload);
53+
assertEquals(0, result.getErrorCode());
54+
}
55+
56+
@Test
57+
public void sendSimpleNotification_Pall_Nandroid() {
4258
PushPayload payload = PushPayload.newBuilder()
4359
.setPlatform(Platform.all())
4460
.setAudience(Audience.all())
@@ -50,7 +66,114 @@ public void sendSimpleNotification_android() {
5066
assertEquals(0, result.getErrorCode());
5167
}
5268

53-
69+
@Test
70+
public void sendSimpleNotification_Pios_Nios() {
71+
PushPayload payload = PushPayload.newBuilder()
72+
.setPlatform(Platform.ios())
73+
.setAudience(Audience.all())
74+
.setNotification(Notification.newBuilder()
75+
.addPlatformNotification(IosNotification.alert("alert"))
76+
.build())
77+
.build();
78+
PushResult result = _client.sendPush(payload);
79+
assertEquals(0, result.getErrorCode());
80+
}
81+
82+
@Test
83+
public void sendSimpleNotification_Pall_Nios() {
84+
PushPayload payload = PushPayload.newBuilder()
85+
.setPlatform(Platform.all())
86+
.setAudience(Audience.all())
87+
.setNotification(Notification.newBuilder()
88+
.addPlatformNotification(IosNotification.alert("alert"))
89+
.build())
90+
.build();
91+
PushResult result = _client.sendPush(payload);
92+
assertEquals(0, result.getErrorCode());
93+
}
94+
95+
@Test
96+
public void sendSimpleNotification_Pwp_Nwp() {
97+
PushPayload payload = PushPayload.newBuilder()
98+
.setPlatform(Platform.winphone())
99+
.setAudience(Audience.all())
100+
.setNotification(Notification.newBuilder()
101+
.addPlatformNotification(WinphoneNotification.alert("alert"))
102+
.build())
103+
.build();
104+
PushResult result = _client.sendPush(payload);
105+
assertEquals(0, result.getErrorCode());
106+
}
107+
108+
@Test
109+
public void sendSimpleNotification_wp() {
110+
PushPayload payload = PushPayload.newBuilder()
111+
.setPlatform(Platform.all())
112+
.setAudience(Audience.all())
113+
.setNotification(Notification.newBuilder()
114+
.addPlatformNotification(WinphoneNotification.alert("alert"))
115+
.build())
116+
.build();
117+
PushResult result = _client.sendPush(payload);
118+
assertEquals(0, result.getErrorCode());
119+
}
120+
121+
122+
@Test
123+
public void sendSimpleNotification_Pall_Nall() {
124+
PushPayload payload = PushPayload.newBuilder()
125+
.setPlatform(Platform.all())
126+
.setAudience(Audience.all())
127+
.setNotification(Notification.newBuilder()
128+
.addPlatformNotification(WinphoneNotification.alert("alert"))
129+
.addPlatformNotification(IosNotification.alert("alert"))
130+
.addPlatformNotification(AndroidNotification.alert("alert"))
131+
.build())
132+
.build();
133+
PushResult result = _client.sendPush(payload);
134+
assertEquals(0, result.getErrorCode());
135+
}
136+
137+
@Test
138+
public void sendSimpleMessage_default() {
139+
PushPayload payload = PushPayload.simpleMessageAll(MSG_CONTENT);
140+
PushResult result = _client.sendPush(payload);
141+
assertEquals(0, result.getErrorCode());
142+
}
143+
144+
@Test
145+
public void sendSimpleMessage_Pandroid() {
146+
PushPayload payload = PushPayload.newBuilder()
147+
.setPlatform(Platform.android())
148+
.setAudience(Audience.all())
149+
.setMessage(Message.content(MSG_CONTENT))
150+
.build();
151+
PushResult result = _client.sendPush(payload);
152+
assertEquals(0, result.getErrorCode());
153+
}
154+
155+
@Test
156+
public void sendSimpleMessage_Pios() {
157+
PushPayload payload = PushPayload.newBuilder()
158+
.setPlatform(Platform.ios())
159+
.setAudience(Audience.all())
160+
.setMessage(Message.content(MSG_CONTENT))
161+
.build();
162+
PushResult result = _client.sendPush(payload);
163+
assertEquals(0, result.getErrorCode());
164+
}
165+
166+
@Test
167+
public void sendSimpleMessage_Pwinphone() {
168+
PushPayload payload = PushPayload.newBuilder()
169+
.setPlatform(Platform.winphone())
170+
.setAudience(Audience.all())
171+
.setMessage(Message.content(MSG_CONTENT))
172+
.build();
173+
PushResult result = _client.sendPush(payload);
174+
assertEquals(400, result.getErrorCode());
175+
}
176+
54177

55178

56179
}

0 commit comments

Comments
 (0)