@Override public void onError(Exception error) { assertEquals("CVV verification failed", ((ErrorWithResponse) error).errorFor("creditCard").getFieldErrors().get(0).getMessage()); countDownLatch.countDown(); } });
@Test public void constructor_canHandleMultipleCategories() { String errors = stringFromFixture("errors/complex_error_response.json"); ErrorWithResponse errorWithResponse = new ErrorWithResponse(422, errors); assertEquals(3, errorWithResponse.errorFor("creditCard").getFieldErrors().size()); assertEquals("is invalid", errorWithResponse.errorFor("customer").getMessage()); assertEquals(0, errorWithResponse.errorFor("customer").getFieldErrors().size()); }
@Override public void onError(Exception error) { assertEquals("Postal code verification failed", ((ErrorWithResponse) error).errorFor("creditCard").errorFor("billingAddress") .getFieldErrors().get(0).getMessage()); countDownLatch.countDown(); } });
@Override public void onError(Exception error) { assertEquals("Country code (alpha3) is not an accepted country", ((ErrorWithResponse) error).errorFor("creditCard").errorFor("billingAddress") .getFieldErrors().get(0).getMessage()); countDownLatch.countDown(); } });
@Test public void fromJson_parsesErrorsCorrectly() throws JSONException { String response = stringFromFixture("errors/credit_card_error_response.json"); ErrorWithResponse errorWithResponse = ErrorWithResponse.fromJson(response); assertEquals("Credit card is invalid", errorWithResponse.getMessage()); assertNull(errorWithResponse.errorFor("creditCard").errorFor("postalCode")); assertEquals("Credit card must include number, payment_method_nonce, or venmo_sdk_payment_method_code", errorWithResponse.errorFor("creditCard").errorFor("base").getMessage()); assertEquals("Credit card number is required", errorWithResponse.errorFor("creditCard").errorFor("number").getMessage()); assertEquals("Expiration year is invalid", errorWithResponse.errorFor("creditCard").errorFor("expirationYear").getMessage()); }
@Test public void constructor_parsesErrorsCorrectly() { String response = stringFromFixture("errors/credit_card_error_response.json"); ErrorWithResponse errorWithResponse = new ErrorWithResponse(422, response); assertEquals("Credit card is invalid", errorWithResponse.getMessage()); assertEquals(422, errorWithResponse.getStatusCode()); assertNull(errorWithResponse.errorFor("creditCard").errorFor("postalCode")); assertEquals("Credit card must include number, payment_method_nonce, or venmo_sdk_payment_method_code", errorWithResponse.errorFor("creditCard").errorFor("base").getMessage()); assertEquals("Credit card number is required", errorWithResponse.errorFor("creditCard").errorFor("number").getMessage()); assertEquals("Expiration year is invalid", errorWithResponse.errorFor("creditCard").errorFor("expirationYear").getMessage()); }
@Test public void fromGraphQLJson_parsesErrorsCorrectly() { String response = stringFromFixture("errors/graphql/credit_card_error.json"); ErrorWithResponse errorWithResponse = ErrorWithResponse.fromGraphQLJson(response); assertEquals("Input is invalid.", errorWithResponse.getMessage()); assertEquals(422, errorWithResponse.getStatusCode()); assertEquals("Expiration month is invalid", errorWithResponse.errorFor("creditCard").errorFor("expirationMonth").getMessage()); assertEquals("Expiration year is invalid", errorWithResponse.errorFor("creditCard").errorFor("expirationYear").getMessage()); assertEquals("CVV verification failed", errorWithResponse.errorFor("creditCard").errorFor("cvv").getMessage()); }
@Test public void parseResponseFailsWithUserErrors() throws Exception { String baseUrl = "http://example.com/graphql"; HttpClient httpClient = new BraintreeGraphQLHttpClient(baseUrl, TOKENIZATION_KEY); httpClient = HttpClientTestUtils.stubResponse(httpClient, 200, FixturesHelper.stringFromFixture("errors/graphql/credit_card_error.json")); HttpURLConnection connection = httpClient.init(baseUrl); try { httpClient.parseResponse(connection); fail("No exception was thrown"); } catch (ErrorWithResponse e) { assertEquals("Input is invalid.", e.getMessage()); assertNotNull(e.errorFor("creditCard")); } }