diff --git a/src/main/java/com/vonage/client/verify2/TemplateFragment.java b/src/main/java/com/vonage/client/verify2/TemplateFragment.java index 64a4067c8..dd356192f 100644 --- a/src/main/java/com/vonage/client/verify2/TemplateFragment.java +++ b/src/main/java/com/vonage/client/verify2/TemplateFragment.java @@ -142,7 +142,7 @@ private static final class LocaleSerializer extends StdConverter @Override public String convert(Locale value) { - return value == null ? null : value.toString().toLowerCase().replace('_', '-'); + return value.toString().toLowerCase().replace('_', '-'); } } } diff --git a/src/test/java/com/vonage/client/verify2/VerificationCallbackTest.java b/src/test/java/com/vonage/client/verify2/VerificationCallbackTest.java index cd31c5c59..7e4564b92 100644 --- a/src/test/java/com/vonage/client/verify2/VerificationCallbackTest.java +++ b/src/test/java/com/vonage/client/verify2/VerificationCallbackTest.java @@ -82,7 +82,8 @@ public void testParseRequestUpdateMultipleWorkflows() { " }\n" + " ],\n" + " \"price\": \"0.300000125\",\n" + - " \"client_ref\": \"my-personal-ref\"\n" + + " \"client_ref\": \"my-personal-ref\",\n" + + " \"action\": {}\n" + "}" ); TestUtils.testJsonableBaseObject(webhook); diff --git a/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java b/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java index cdd1775d6..5b9d9416f 100644 --- a/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java +++ b/src/test/java/com/vonage/client/verify2/VerificationRequestTest.java @@ -348,10 +348,13 @@ public void testSilentAuthMustBeFirstWorkflow() { } @Test - public void testInvalidLocale() throws Exception { + public void testInvalidLocale() { VerificationRequest.Builder builder = getBuilderRequiredParamsSingleWorkflow(Channel.SMS); assertThrows(IllegalArgumentException.class, () -> builder.locale("--++").build()); assertThrows(IllegalArgumentException.class, () -> builder.locale("en_GB").build()); + assertThrows(IllegalArgumentException.class, () -> builder.locale(" ").build()); + assertThrows(IllegalArgumentException.class, () -> builder.locale((Locale) null).build()); + assertThrows(NullPointerException.class, () -> builder.locale((String) null).build()); assertNotNull(builder.locale("ab-cd").build().getLocale()); } diff --git a/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java b/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java index 8b27e2e8c..dfc241b01 100644 --- a/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java +++ b/src/test/java/com/vonage/client/verify2/Verify2ClientTest.java @@ -17,6 +17,8 @@ import com.vonage.client.*; import static com.vonage.client.TestUtils.testJsonableBaseObject; +import com.vonage.client.auth.ApiKeyHeaderAuthMethod; +import com.vonage.client.auth.NoAuthMethod; import com.vonage.client.common.HttpMethod; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.*; @@ -152,6 +154,9 @@ void stubSuccessfulVerifyUserResponseAndRun(VerificationRequest request) throws @Test public void testVerifyUserSuccess() throws Exception { stubSuccessfulVerifyUserResponseAndRun(newVerificationRequestWithAllParamsAndWorkflows()); + stubSuccessfulVerifyUserResponseAndRun(VerificationRequest.builder() + .brand("Vonage").addWorkflow(new SilentAuthWorkflow("447700900001")).build() + ); } @Test @@ -199,16 +204,16 @@ protected String sampleRequestBodyString() { @Override public void runTests() throws Exception { super.runTests(); - testCodelessAndBasicAuth(); + testCodelessAndNoJwtAuth(); testParseResponseFailureAllParams(); testParseResponseFailureNoBody(); } - void testCodelessAndBasicAuth() throws Exception { + void testCodelessAndNoJwtAuth() throws Exception { VerificationRequest request = VerificationRequest.builder() .brand("Vonage").addWorkflow(new SilentAuthWorkflow("447700900001")).build(); - Verify2Client tempClient = new Verify2Client(new HttpWrapper()); + var tempClient = new Verify2Client(new HttpWrapper()); assertThrows(IllegalStateException.class, () -> tempClient.sendVerification(request)); String expectedJson = "{\"brand\":\""+request.getBrand() + "\",\"workflow\":[{\"channel\":\"silent_auth\",\"to\":\"447700900001\"}]}"; @@ -619,6 +624,9 @@ protected UUID sampleRequest() { public void testGetTemplateFragmentSuccess() throws Exception { stubResponse(200, FRAGMENT_RESPONSE); assertEqualsSampleFragment(client.getTemplateFragment(TEMPLATE_ID, FRAGMENT_ID)); + + stubResponse(200, "{\"locale\":null}"); + assertEqualsEmptyFragment(client.getTemplateFragment(TEMPLATE_ID, FRAGMENT_ID)); } @Test @@ -934,6 +942,10 @@ public void testListTemplatesSuccess() throws Exception { assertEquals(2, templates.size()); assertEqualsEmptyTemplate(templates.getFirst()); assertEqualsSampleTemplate(templates.getLast()); + + stubResponse(200, "{}"); + templates = client.listTemplates(); + assertNull(templates); } @Test @@ -1050,6 +1062,10 @@ public void testListTemplateFragmentsSuccess() throws Exception { assertEquals(2, fragments.size()); assertEqualsEmptyFragment(fragments.getFirst()); assertEqualsSampleFragment(fragments.getLast()); + + stubResponse(200, "{}"); + fragments = client.listTemplateFragments(TEMPLATE_ID); + assertNull(fragments); } @Test