Skip to content

Commit fe49805

Browse files
committed
Deprecates SMS get without parameters action
1 parent 0a61c00 commit fe49805

6 files changed

Lines changed: 78 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
3232
- `pl.smsapi.api.action.vms.VMSSend` without parameters marked as deprecated
3333
- `pl.smsapi.api.SmsFactory.actionSend` without parameters marked as deprecated
3434
- `pl.smsapi.api.action.sms.SMSSend` without parameters marked as deprecated
35+
- `pl.smsapi.api.SmsFactory.actionGet` without parameters marked as deprecated
36+
- `pl.smsapi.api.action.sms.SMSGet` without parameters marked as deprecated
3537

3638
### Removed
3739
- legacy `phonebook.do` contacts API support

src/main/java/pl/smsapi/api/SmsFactory.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public SMSSend actionSend(String[] to, String text) {
4545
return action;
4646
}
4747

48+
/**
49+
* @deprecated use {@link #actionGet(String)} instead
50+
*/
51+
@Deprecated
4852
public SMSGet actionGet() {
4953
SMSGet action = new SMSGet();
5054
action.client(client);
@@ -53,8 +57,9 @@ public SMSGet actionGet() {
5357
}
5458

5559
public SMSGet actionGet(String id) {
56-
SMSGet action = actionGet();
57-
action.id(id);
60+
SMSGet action = new SMSGet(id);
61+
action.client(client);
62+
action.proxy(proxy);
5863
return action;
5964
}
6065

src/main/java/pl/smsapi/api/action/sms/SMSGet.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,33 @@
77

88
public class SMSGet extends AbstractAction<StatusResponse> {
99

10+
/**
11+
* @deprecated use {@link SMSGet(String)} or {@link SMSGet(String[])} instead
12+
*/
13+
@Deprecated
1014
public SMSGet() {
1115
setJson(true);
1216
id("");
1317
}
1418

19+
public SMSGet(String id) {
20+
setJson(true);
21+
params.put("status", id);
22+
}
23+
24+
public SMSGet(String[] ids) {
25+
setJson(true);
26+
params.put("status", StringUtils.join(ids, '|'));
27+
}
28+
1529
/**
1630
* Set ID of message to check.
1731
* <p/>
1832
* This id was returned after sending message.
33+
*
34+
* @deprecated use {@link SMSGet(String)} instead
1935
*/
36+
@Deprecated
2037
public SMSGet id(String id) {
2138
params.put("status", id);
2239
return this;
@@ -26,7 +43,10 @@ public SMSGet id(String id) {
2643
* Set IDs of messages to check.
2744
* <p/>
2845
* This id was returned after sending message.
46+
*
47+
* @deprecated use {@link SMSGet(String[])} instead
2948
*/
49+
@Deprecated
3050
public SMSGet ids(String[] ids) {
3151
params.put("status", StringUtils.join(ids, '|'));
3252
return this;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package pl.smsapi.api.action.sms;
2+
3+
import org.junit.Test;
4+
import pl.smsapi.exception.SmsapiException;
5+
import pl.smsapi.test.doubles.ClientStub;
6+
import pl.smsapi.test.doubles.ProxyRequestSpy;
7+
8+
import java.util.HashMap;
9+
10+
import static org.junit.Assert.assertEquals;
11+
12+
public class SMSGetTest {
13+
14+
@Test
15+
public void executeGetSmsRequest() throws SmsapiException {
16+
ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create());
17+
SMSGet action = new SMSGet("0f0f0f0f0f0f0f0f0f0f0f0f");
18+
action.client(new ClientStub());
19+
action.proxy(requestStub);
20+
21+
action.execute();
22+
23+
assertEquals("POST", requestStub.requestMethod);
24+
assertEquals("sms.do", requestStub.requestEndpoint);
25+
HashMap<String, String> expectedRequestPayload = new HashMap<>();
26+
expectedRequestPayload.put("status", "0f0f0f0f0f0f0f0f0f0f0f0f");
27+
expectedRequestPayload.put("format", "json");
28+
assertEquals(expectedRequestPayload, requestStub.requestPayload);
29+
}
30+
31+
@Test
32+
public void executeGetMultipleSmsRequest() throws SmsapiException {
33+
ProxyRequestSpy requestStub = new ProxyRequestSpy(StatusJsonMother.create());
34+
SMSGet action = new SMSGet(new String[]{"0f0f0f0f0f0f0f0f0f0f0f0f", "0f0f0f0f0f0f0f0f0f0f0f01"});
35+
action.client(new ClientStub());
36+
action.proxy(requestStub);
37+
38+
action.execute();
39+
40+
assertEquals("POST", requestStub.requestMethod);
41+
assertEquals("sms.do", requestStub.requestEndpoint);
42+
HashMap<String, String> expectedRequestPayload = new HashMap<>();
43+
expectedRequestPayload.put("status", "0f0f0f0f0f0f0f0f0f0f0f0f|0f0f0f0f0f0f0f0f0f0f0f01");
44+
expectedRequestPayload.put("format", "json");
45+
assertEquals(expectedRequestPayload, requestStub.requestPayload);
46+
}
47+
}

src/test/java/pl/smsapi/api/action/sms/SmsFactoryTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void getSms() throws SmsapiException {
4747
Optional<MessageResponse> sendMessageResponse = responseSend.list.stream().findFirst();
4848
assertTrue(sendMessageResponse.isPresent());
4949

50-
SMSGet actionGet = apiFactory.actionGet().id(sendMessageResponse.get().getId());
50+
SMSGet actionGet = apiFactory.actionGet(sendMessageResponse.get().getId());
5151
StatusResponse responseGet = actionGet.execute();
5252

5353
assertNotNull(responseGet);

src/test/java/pl/smsapi/test/unit/response/StatusResponseTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class StatusResponseTest {
1717

1818
@Test
1919
public void deserialize_response() throws SmsapiException {
20-
SMSGet action = new SMSGet();
20+
SMSGet action = new SMSGet("7074294081650020450");
2121
action.client(new ClientStub());
2222
action.proxy(new ProxyResponseStub(
2323
"{" +

0 commit comments

Comments
 (0)