ExpressionValidator extends ValidatorSupport { public void validate(Object object) throws ValidationException { Boolean answer = Boolean.FALSE; Object obj = null; try { obj = getFieldValue(expression); } catch (ValidationException e) { throw e; } catch (Exception e) { } if ((obj != null) && (obj instanceof Boolean)) { answer = (Boolean) obj; } else { logger.warn("Got result of " + obj + " when trying to get Boolean."); } if (!answer.booleanValue()) { if (logger.isDebugEnabled()) logger.debug("Validation failed on expression " + expression + " with validated object " + object); addValidationError(object); } }  String getName(); void setName(String name); void setExpression(String expression); String getExpression(); void validate(Object object); @Override String describeValidateName();  }
@Test public void testSuccess() { HashMap<String, Object> map = new HashMap<String, Object>(); map.put("val1", 1); map.put("val2", new int[] { 1, 3, 6 }); map.put("val3", "abc"); try { this.validate(map); } catch (ValidationException e) { Assert.fail(e.getMessage()); } }
@Test public void testFailure() { boolean success = false; HashMap<String, Object> map = new HashMap<String, Object>(); map.put("val1", 1); map.put("val2", new int[] { 1, 3, 6 }); map.put("val3", "accc"); try { this.validate(map); } catch (ValidationException e) { success = true; } Assert.assertTrue(success); }