Search in sources :

Example 1 with ArgumentsException

use of com.squarespace.template.ArgumentsException in project template-compiler by Squarespace.

the class InternationalFormattersTest method testExtraArgument.

public void testExtraArgument() throws Exception {
    if (isJava8()) {
        try {
            MONEY_FORMATTER.validateArgs(new Arguments(new StringView(" en-US bad-arg")));
            Assert.fail("expected ArgumentsException, too many arguments passed");
        } catch (ArgumentsException e) {
        // fall through
        }
    }
}
Also used : ArgumentsException(com.squarespace.template.ArgumentsException) Arguments(com.squarespace.template.Arguments) StringView(com.squarespace.template.StringView)

Example 2 with ArgumentsException

use of com.squarespace.template.ArgumentsException in project template-compiler by Squarespace.

the class LegacyMoneyFormatter method validateArgs.

@Override
public void validateArgs(Arguments args) throws ArgumentsException {
    args.atMost(1);
    String localeStr = getLocaleArg(args);
    if (localeStr != null) {
        Locale locale;
        try {
            // LocaleUtils uses an underscore format (e.g. en_US), but the new Java standard
            // is a hyphenated format (e.g. en-US). This allows us to use LocaleUtils' validation.
            locale = LocaleUtils.toLocale(localeStr.replace('-', '_'));
        } catch (IllegalArgumentException e) {
            throw new ArgumentsException("Invalid locale: " + localeStr);
        }
        args.setOpaque(locale);
    } else {
        args.setOpaque(DEFAULT_LOCALE);
    }
}
Also used : Locale(java.util.Locale) ArgumentsException(com.squarespace.template.ArgumentsException)

Aggregations

ArgumentsException (com.squarespace.template.ArgumentsException)2 Arguments (com.squarespace.template.Arguments)1 StringView (com.squarespace.template.StringView)1 Locale (java.util.Locale)1