// ------------------------------------------------- Individual Test Methods public void testPatternMatch() { String patternStr = "t.*"; RegexValidator validator = new RegexValidator(); validator.setPattern(patternStr); UIInput component = new UIInput(); String checkme = "test"; try { validator.validate(facesContext, component, checkme); assertTrue(true); } catch (ValidatorException ve) { fail("Exception thrown " + ve.getMessage()); } }
public void testPatterMismatch() { String patternStr = "t.*"; facesContext.getViewRoot().setLocale(Locale.US); RegexValidator validator = new RegexValidator(); validator.setPattern(patternStr); UIInput component = new UIInput(); String checkme = "jest"; try { validator.validate(facesContext, component, checkme); fail("Exception not thrown when tested " + checkme + " against " + patternStr); } catch (ValidatorException ve) { String detail = ve.getFacesMessage().getDetail(); System.out.println("Detail in test: " + detail); assertTrue(detail.equalsIgnoreCase("Regex pattern of 't.*' not matched")); } }