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
}
}
}
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);
}
}
Aggregations