Skip to content

Commit

Permalink
fix: Misc warnings & failures
Browse files Browse the repository at this point in the history
  • Loading branch information
SMadani committed Sep 13, 2023
1 parent 6408342 commit 341ddd1
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 36 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ need a Vonage account. You'll need to have [created a Vonage account](https://da

- [Account](https://developer.vonage.com/en/account/overview)
- [Application](https://developer.vonage.com/en/application/overview)
- [Conversion](https://developer.vonage.com/messaging/conversion-api/overview)
- [Meetings](https://developer.vonage.com/en/meetings/overview)
- [Messages](https://developer.vonage.com/en/messages/overview)
- [Number Insight](https://developer.vonage.com/en/number-insight/overview)
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/vonage/client/DynamicEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Modifier;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -195,7 +193,7 @@ else if (v instanceof Iterable<?>) {
else if (requestBody instanceof byte[]) {
rqb.setEntity(new ByteArrayEntity((byte[]) requestBody));
}
return rqb.setUri(URI.create(pathGetter.apply(this, requestBody)));
return rqb.setUri(pathGetter.apply(this, requestBody));
}

protected R parseResponseFromString(String response) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/account/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public String getName() {
return name;
}

enum Type {
public enum Type {
MOBILE, LANDLINE, PAGER, LANDLINE_TOLLFREE, UNKNOWN;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Map<String, String> makeParams() {
*
* @param number A single phone number that you need insight about in national or international format.
*
* @return A new {@link AdvancedInsightRequest} object.
* @return A new AdvancedInsightRequest object.
*/
public static AdvancedInsightRequest withNumber(String number) {
return new Builder(number).build();
Expand All @@ -112,7 +112,7 @@ public static AdvancedInsightRequest withNumber(String number) {
* @param number A single phone number that you need insight about in national or international format.
* @param country If a number does not have a country code, or it is uncertain, set the two-character country code.
*
* @return A new {@link AdvancedInsightRequest} object.
* @return A new AdvancedInsightRequest object.
*/
public static AdvancedInsightRequest withNumberAndCountry(String number, String country) {
return new Builder(number).country(country).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private BasicInsightRequest(Builder builder) {
*
* @param number A single phone number that you need insight about in national or international format.
*
* @return A new {@link BasicInsightRequest} object.
* @return A new BasicInsightRequest object.
*/
public static BasicInsightRequest withNumber(String number) {
return new Builder(number).build();
Expand All @@ -38,7 +38,7 @@ public static BasicInsightRequest withNumber(String number) {
* @param number A single phone number that you need insight about in national or international format.
* @param country If a number does not have a country code, or it is uncertain, set the two-character country code.
*
* @return A new {@link BasicInsightRequest} object.
* @return A new BasicInsightRequest object.
*/
public static BasicInsightRequest withNumberAndCountry(String number, String country) {
return new Builder(number).country(country).build();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/insight/InsightStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public enum InsightStatus {
}

/**
* Look up the {@link InsightStatus} based on the int value.
* Look up the InsightStatus based on the int value.
*
* @param insightStatus the integer value of the insight status.
* @return InsightStatus based on the int value given.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Boolean getCnam() {
*
* @param number A single phone number that you need insight about in national or international format.
*
* @return A new {@link StandardInsightRequest} object.
* @return A new StandardInsightRequest object.
*/
public static StandardInsightRequest withNumber(String number) {
return new Builder(number).build();
Expand All @@ -43,7 +43,7 @@ public static StandardInsightRequest withNumber(String number) {
* @param number A single phone number that you need insight about in national or international format.
* @param country If a number does not have a country code or it is uncertain, set the two-character country code.
*
* @return A new {@link StandardInsightRequest} object.
* @return A new StandardInsightRequest object.
*/
public static StandardInsightRequest withNumberAndCountry(String number, String country) {
return new Builder(number).country(country).build();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/sms/MessageStatus.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public enum MessageStatus {
));

/**
* Look up the {@link MessageStatus} based on the int value.
* Look up the MessageStatus based on the int value.
*
* @param messageStatus the int value of the message status.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public String getReference() {
* @param json The JSON string to parse.
* @return An instance of this class with the fields populated, if present.
*/
protected static MoneyTransfer fromJson(String json) {
public static MoneyTransfer fromJson(String json) {
MoneyTransfer transfer = new MoneyTransfer();
transfer.updateFromJson(json);
return transfer;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/verify/VerifyRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Map;

/**
* Describes a Verify request when passed to {@link VerifyEndpoint}.
* Describes a Verify request.
*/
public class VerifyRequest extends BaseRequest {
private final LineType type;
Expand Down
14 changes: 3 additions & 11 deletions src/main/java/com/vonage/client/verify2/VerificationCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.vonage.client.Jsonable;
import com.vonage.client.VonageResponseParseException;
import java.io.IOException;
import java.net.URI;
import java.time.Instant;
import java.util.List;
Expand Down Expand Up @@ -182,13 +179,8 @@ public URI getSilentAuthUrl() {
* @throws VonageResponseParseException If the response could not be deserialized.
*/
public static VerificationCallback fromJson(String json) {
try {
ObjectMapper mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
return mapper.readValue(json, VerificationCallback.class);
}
catch (IOException ex) {
throw new VonageResponseParseException("Failed to produce VerificationCallback from json.", ex);
}
VerificationCallback callback = new VerificationCallback();
callback.updateFromJson(json);
return callback;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Ncco getNcco() {
return ncco;
}

enum Type {
public enum Type {
NCCO;

@JsonValue
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/vonage/client/voice/ncco/InputAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static class Builder {

/**
* @param dtmf DTMF settings object to enable DTMF input.
* @return The {@link Builder} to keep building the input action.
* @return This builder to keep building the input action.
* @since 6.0.0
*/
public Builder dtmf(DtmfSettings dtmf) {
Expand All @@ -101,7 +101,7 @@ public Builder dtmf(DtmfSettings dtmf) {
* @param eventUrl Vonage sends the digits pressed by the callee to this URL after timeOut pause in activity or
* when # is pressed.
*
* @return The {@link Builder} to keep building the input action.
* @return This builder to keep building the input action.
*/
public Builder eventUrl(Collection<String> eventUrl) {
this.eventUrl = eventUrl;
Expand All @@ -112,7 +112,7 @@ public Builder eventUrl(Collection<String> eventUrl) {
* @param eventUrl Vonage sends the digits pressed by the callee to this URL after timeOut pause in activity or
* when # is pressed.
*
* @return The {@link Builder} to keep building the input action.
* @return This builder to keep building the input action.
*/
public Builder eventUrl(String... eventUrl) {
return eventUrl(Arrays.asList(eventUrl));
Expand All @@ -121,7 +121,7 @@ public Builder eventUrl(String... eventUrl) {
/**
* @param eventMethod The HTTP method used to send event information to event_url The default value is POST.
*
* @return The {@link Builder} to keep building the input action.
* @return This builder to keep building the input action.
*/
public Builder eventMethod(EventMethod eventMethod) {
this.eventMethod = eventMethod;
Expand All @@ -130,7 +130,7 @@ public Builder eventMethod(EventMethod eventMethod) {

/**
* @param speech Automatic speech recognition settings object to enable speech input. Required if dtmf is not provided.
* @return The {@link Builder} to keep building the input action.
* @return This builder to keep building the input action.
* @since 6.0.0
*/
public Builder speech(SpeechSettings speech){
Expand All @@ -141,7 +141,7 @@ public Builder speech(SpeechSettings speech){
/**
* @param type Acceptable input type, can be set as [ "dtmf" ] for DTMF input only, [ "speech" ] for ASR only,
* or [ "dtmf", "speech" ] for both.
* @return The {@link Builder} to keep building the input action.
* @return This builder to keep building the input action.
*/
public Builder type(Collection<String> type){
this.type = type;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/vonage/client/voice/ncco/PayAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Collection<PaymentPrompt> getPrompts() {
}

/**
* Entry point for constructing a {@linkplain PayAction}.
* Entry point for constructing a PayAction.
*
* @return A new {@linkplain Builder} instance.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public InvalidSecurityCode(String text) {
}

/**
* Entry point for constructing a {@linkplain PaymentPrompt}.
* Entry point for constructing a PaymentPrompt.
*
* @param type The prompt type.
* @return A new {@linkplain Builder} instance.
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/com/vonage/client/AbstractMethodTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,12 @@ public RequestBuilder makeRequest(String request) throws UnsupportedEncodingExce

@Test
public void testSocketTimeout() throws Exception {
// For some reason this test is flaky on GitHub's CI runner
if (
System.getProperty("os.name").startsWith("Windows") &&
System.getProperty("java.version").startsWith("1.")
) return;

ConcreteMethod method = mockServerAndMethod(9000, 0);
String requestBody = "Hello, World!";
assertEquals(requestBody, method.execute(requestBody));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,17 @@ protected RestEndpoint<MoneyTransfer, MoneyTransfer> endpoint() {
@Test
public void testTransferBalance() throws Exception {
MoneyTransfer request = MoneyTransfer.builder().amount(0.04).from(FROM_API_KEY).to(TO_API_KEY).build();
String requestJson = request.toJson();
assertEqualsExpectedMoneyTransfer(stubResponseAndGet(
MONEY_TRANSFER_RESPONSE_JSON, () -> client.transferBalance(request)
));
stubResponseAndAssertThrows(200, () -> client.transferBalance(null), NullPointerException.class);
stubResponseAndAssertThrows(401, () -> client.transferBalance(request), SubaccountsResponseException.class);
assert403ResponseException(() -> client.transferBalance(request));
assertEquals(requestJson, MoneyTransfer.fromJson(requestJson).toJson());
assertThrows(NullPointerException.class, () -> MoneyTransfer.builder()
.from(FROM_API_KEY).to(TO_API_KEY).build()
);

new MoneyTransferEndpointTestSpec() {

Expand All @@ -472,7 +477,7 @@ protected RestEndpoint<MoneyTransfer, MoneyTransfer> endpoint() {
public void testTransferNumber() throws Exception {
NumberTransfer request = NumberTransfer.builder()
.from(FROM_API_KEY).to(TO_API_KEY).number("447900000001").country("GB").build();
String responseJson = "{\n" +
String requestJson = request.toJson(), responseJson = "{\n" +
" \"number\": \"235077036\",\n" +
" \"country\": \"DE\",\n" +
" \"from\": \"7c9738e6\",\n" +
Expand All @@ -486,6 +491,11 @@ public void testTransferNumber() throws Exception {
stubResponseAndAssertThrows(200, () -> client.transferNumber(null), NullPointerException.class);
stubResponseAndAssertThrows(401, () -> client.transferNumber(request), SubaccountsResponseException.class);
assert403ResponseException(() -> client.transferNumber(request));
assertEquals(requestJson, NumberTransfer.fromJson(requestJson).toJson());
assertThrows(IllegalArgumentException.class, () -> NumberTransfer.builder()
.from(request.getFrom()).to(request.getTo()).number(request.getNumber())
.country("United Kingdom").build()
);

new SubaccountsEndpointTestSpec<NumberTransfer, NumberTransfer>() {

Expand Down
4 changes: 3 additions & 1 deletion src/test/java/com/vonage/client/verify/Psd2RequestTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ public void testConstructMissingRequiredParams() {

@Test
public void testConstructRequiredParams() {
assertNotNull(Psd2Request.builder().number("447700900001").amount(0.87).payee("Nexmo").build());
Psd2Request request = Psd2Request.builder().number("447700900001").amount(0.87).payee("Nexmo").build();
assertNotNull(request);
assertNull(request.getDashedLocale());
}

@Test(expected = IllegalArgumentException.class)
Expand Down

0 comments on commit 341ddd1

Please sign in to comment.