CurrencyCodeSanitizer implements Sanitizer<String> { @Override public String execute(String content) { if (StringUtils.isBlank(content)) { return content; } try { return Currency.getInstance(StringUtils.upperCase(content)).toString(); } catch (Exception e) { HtmlSanitizer htmlSanitizer = new HtmlSanitizer(); String sanitized = htmlSanitizer.execute(content); _logger.warn("Invalid currency code (" + sanitized + "). Setting currency code to \"USD\"."); return "USD"; } }  @Override String execute(String content);  }
@Test public void testExecute() throws Exception { CurrencyCodeSanitizer sanitizer = new CurrencyCodeSanitizer(); assertEquals("USD", sanitizer.execute("USD")); assertEquals("USD", sanitizer.execute("usd")); assertEquals("EUR", sanitizer.execute("EUR")); assertEquals("", sanitizer.execute("")); assertEquals(" ", sanitizer.execute(" ")); assertEquals(null, sanitizer.execute(null)); assertEquals("USD", sanitizer.execute("abc")); assertEquals("USD", sanitizer.execute("abcd")); assertEquals("USD", sanitizer.execute("1234")); assertEquals("USD", sanitizer.execute("!?")); assertEquals("USD", sanitizer.execute("<script>")); }