<commit_before>package com.currencycloud.client;

import co.freeside.betamax.Betamax;
import com.currencycloud.client.model.CurrencyCloudException;
import org.junit.Test;
import org.testng.Assert;

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public class ErrorTest extends BetamaxTestSupport {

    @Test
    @Betamax(tape = "contains_full_details_for_api_error")
    public void testContainsFullDetailsForApiError() throws Exception {
        CurrencyCloudException e = testFailedLogin("auth_invalid_user_login_details", 400);
        Assert.assertEquals(e.getErrorMessages().get("api_key").size(), 1);
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getCode(), "api_key_length_is_invalid");
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getMessage(), "api_key should be 64 character(s) long");
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getParams().get("length"), new Integer(64));
    }

    @Test
    @Betamax(tape = "is_raised_on_a_bad_request")
    public void testIsRaisedOnABadRequest() throws Exception {
        CurrencyCloudException e = testFailedLogin("auth_invalid_user_login_details", 400);
        Assert.assertEquals(e.getErrorMessages().get("api_key").size(), 1);
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getCode(), "api_key_length_is_invalid");
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getMessage(), "api_key should be 64 character(s) long");
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getParams().get("length"), new Integer(64));
    }

    @Test
    @Betamax(tape = "is_raised_on_a_forbidden_request")
    public void testIsRaisedOnAForbiddenRequest() throws Exception {
        testFailedLogin("auth_failed", 403);
    }

    @Test
    @Betamax(tape = "is_raised_on_an_internal_server_error")
    public void testIsRaisedOnAnInternalServerError() throws Exception {
        testFailedLogin("internal_application_error", 500);
    }

    @Test
    @Betamax(tape = "is_raised_on_incorrect_authentication_details")
    public void testIsRaisedOnIncorrectAuthenticationDetails() throws Exception {
        CurrencyCloudException e = testFailedLogin("auth_failed", 401);
        Assert.assertEquals(e.getErrorMessages().get("username").size(), 1);
        Assert.assertEquals(e.getErrorMessages().get("username").get(0).getCode(), "invalid_supplied_credentials");
        Assert.assertEquals(e.getErrorMessages().get("username").get(0).getMessage(), "Authentication failed with the supplied credentials");
        Assert.assertEquals(e.getErrorMessages().get("username").get(0).getParams().size(), 0);
    }

    @Test
    @Betamax(tape = "is_raised_when_too_many_requests_have_been_issued")
    public void testIsRaisedWhenTooManyRequestsHaveBeenIssued() throws Exception {
        testFailedLogin("too_many_requests", 429);
    }

    private CurrencyCloudException testFailedLogin(String errorCode, int httpStatusCode) {
        try {
            client.authenticate("non-existent-login-id", "ef0fd50fca1fb14c1fab3a8436b9ecb57528f0");
            throw new AssertionError("An exception should be thown.");
        } catch (CurrencyCloudException e) {
            Assert.assertEquals(e.getHttpStatusCode(), httpStatusCode);
            Assert.assertEquals(e.getErrorCode(), errorCode);
            Assert.assertEquals(e.getErrorMessages().size(), 1);
            return e;
        }
    }
}<commit_msg>#2: Test that the client creates correct request bodies too.<commit_after>package com.currencycloud.client;

import co.freeside.betamax.Betamax;
import co.freeside.betamax.MatchRule;
import com.currencycloud.client.model.CurrencyCloudException;
import org.junit.Test;
import org.testng.Assert;

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
public class ErrorTest extends BetamaxTestSupport {

    @Test
    @Betamax(tape = "contains_full_details_for_api_error", match = {MatchRule.method, MatchRule.uri, MatchRule.body})
    public void testContainsFullDetailsForApiError() throws Exception {
        CurrencyCloudException e = testFailedLogin("non-existent-login-id", "ef0fd50fca1fb14c1fab3a8436b9ecb57528f0", "auth_invalid_user_login_details", 400);
        Assert.assertEquals(e.getErrorMessages().get("api_key").size(), 1);
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getCode(), "api_key_length_is_invalid");
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getMessage(), "api_key should be 64 character(s) long");
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getParams().get("length"), new Integer(64));
    }

    @Test
    @Betamax(tape = "is_raised_on_a_bad_request", match = {MatchRule.method, MatchRule.uri, MatchRule.body})
    public void testIsRaisedOnABadRequest() throws Exception {
        CurrencyCloudException e = testFailedLogin("non-existent-login-id", "ef0fd50fca1fb14c1fab3a8436b9ecb57528f0", "auth_invalid_user_login_details", 400);
        Assert.assertEquals(e.getErrorMessages().get("api_key").size(), 1);
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getCode(), "api_key_length_is_invalid");
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getMessage(), "api_key should be 64 character(s) long");
        Assert.assertEquals(e.getErrorMessages().get("api_key").get(0).getParams().get("length"), new Integer(64));
    }

    @Test
    @Betamax(tape = "is_raised_on_a_forbidden_request", match = {MatchRule.method, MatchRule.uri, MatchRule.body})
    public void testIsRaisedOnAForbiddenRequest() throws Exception {
        testFailedLogin("<EMAIL>", "<PASSWORD>", "auth_failed", 403);
    }

    @Test
    @Betamax(tape = "is_raised_on_an_internal_server_error", match = {MatchRule.method, MatchRule.uri, MatchRule.body})
    public void testIsRaisedOnAnInternalServerError() throws Exception {
        testFailedLogin("<EMAIL>", "<PASSWORD>", "internal_application_error", 500);
    }

    @Test
    @Betamax(tape = "is_raised_on_incorrect_authentication_details", match = {MatchRule.method, MatchRule.uri, MatchRule.body})
    public void testIsRaisedOnIncorrectAuthenticationDetails() throws Exception {
        CurrencyCloudException e = testFailedLogin("non-existent-login-id", "efb5ae2af84978b7a37f18dd61c8bbe139b403009faea83484405a3dcb64c4d8", "auth_failed", 401);
        Assert.assertEquals(e.getErrorMessages().get("username").size(), 1);
        Assert.assertEquals(e.getErrorMessages().get("username").get(0).getCode(), "invalid_supplied_credentials");
        Assert.assertEquals(e.getErrorMessages().get("username").get(0).getMessage(), "Authentication failed with the supplied credentials");
        Assert.assertEquals(e.getErrorMessages().get("username").get(0).getParams().size(), 0);
    }

    @Test
    @Betamax(tape = "is_raised_when_too_many_requests_have_been_issued", match = {MatchRule.method, MatchRule.uri, MatchRule.body})
    public void testIsRaisedWhenTooManyRequestsHaveBeenIssued() throws Exception {
        testFailedLogin("<EMAIL>", "<PASSWORD>", "too_many_requests", 429);
    }

    private CurrencyCloudException testFailedLogin(String loginId, String apiKey, String errorCode, int httpStatusCode) {
        try {
            client.authenticate(loginId, apiKey);
            throw new AssertionError("An exception should be thown.");
        } catch (CurrencyCloudException e) {
            Assert.assertEquals(e.getHttpStatusCode(), httpStatusCode);
            Assert.assertEquals(e.getErrorCode(), errorCode);
            Assert.assertEquals(e.getErrorMessages().size(), 1);
            return e;
        }
    }
}
{'fraction_non_alphanumeric': 0.12921202695697254, 'fraction_numerical': 0.022680145152928977, 'mean_word_length': 4.855083459787557, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3430720', 'n_tokens_mistral': 2416, 'n_tokens_neox': 2302, 'n_words': 351}