@Test(expected = ValidationException.class) public void testValidateFailEmptyList() { final HashMap<String, Serializable> map = new HashMap<String, Serializable>(); ArrayList<StreamScope> scopes = new ArrayList<StreamScope>(); map.put("key", scopes); sut = new MapParameterValidator("key", List.class, "message here"); sut.validate(map, new HashMap<String, String>()); }
@SuppressWarnings("unchecked") public void validate(final Map<String, Serializable> map, final Map<String, String> errors) { if (!map.containsKey(key) || map.get(key) == null || !clazz.isAssignableFrom(map.get(key).getClass()) || (map.get(key) instanceof String && ((String) map.get(key)).trim().isEmpty()) || (List.class.isAssignableFrom(map.get(key).getClass()) && ((List) map.get(key)).size() == 0)) { errors.put(key, message); } if (decorated != null) { decorated.validate(map, errors); } else if (!errors.isEmpty()) { ValidationException ve = new ValidationException(); for (String errorKey : errors.keySet()) { ve.addError(errorKey, errors.get(errorKey)); } throw ve; } }
MapParameterValidator implements MapParameterValidatorDecorator { @SuppressWarnings("unchecked") public void validate(final Map<String, Serializable> map, final Map<String, String> errors) { if (!map.containsKey(key) || map.get(key) == null || !clazz.isAssignableFrom(map.get(key).getClass()) || (map.get(key) instanceof String && ((String) map.get(key)).trim().isEmpty()) || (List.class.isAssignableFrom(map.get(key).getClass()) && ((List) map.get(key)).size() == 0)) { errors.put(key, message); } if (decorated != null) { decorated.validate(map, errors); } else if (!errors.isEmpty()) { ValidationException ve = new ValidationException(); for (String errorKey : errors.keySet()) { ve.addError(errorKey, errors.get(errorKey)); } throw ve; } } }
MapParameterValidator implements MapParameterValidatorDecorator { @SuppressWarnings("unchecked") public void validate(final Map<String, Serializable> map, final Map<String, String> errors) { if (!map.containsKey(key) || map.get(key) == null || !clazz.isAssignableFrom(map.get(key).getClass()) || (map.get(key) instanceof String && ((String) map.get(key)).trim().isEmpty()) || (List.class.isAssignableFrom(map.get(key).getClass()) && ((List) map.get(key)).size() == 0)) { errors.put(key, message); } if (decorated != null) { decorated.validate(map, errors); } else if (!errors.isEmpty()) { ValidationException ve = new ValidationException(); for (String errorKey : errors.keySet()) { ve.addError(errorKey, errors.get(errorKey)); } throw ve; } } MapParameterValidator(final String inKey, final Class< ? > inClazz, final String inMessage); }
MapParameterValidator implements MapParameterValidatorDecorator { @SuppressWarnings("unchecked") public void validate(final Map<String, Serializable> map, final Map<String, String> errors) { if (!map.containsKey(key) || map.get(key) == null || !clazz.isAssignableFrom(map.get(key).getClass()) || (map.get(key) instanceof String && ((String) map.get(key)).trim().isEmpty()) || (List.class.isAssignableFrom(map.get(key).getClass()) && ((List) map.get(key)).size() == 0)) { errors.put(key, message); } if (decorated != null) { decorated.validate(map, errors); } else if (!errors.isEmpty()) { ValidationException ve = new ValidationException(); for (String errorKey : errors.keySet()) { ve.addError(errorKey, errors.get(errorKey)); } throw ve; } } MapParameterValidator(final String inKey, final Class< ? > inClazz, final String inMessage); @SuppressWarnings("unchecked") void validate(final Map<String, Serializable> map, final Map<String, String> errors); void setMapParameterValidatorDecorator(final MapParameterValidatorDecorator inDecorated); }
MapParameterValidator implements MapParameterValidatorDecorator { @SuppressWarnings("unchecked") public void validate(final Map<String, Serializable> map, final Map<String, String> errors) { if (!map.containsKey(key) || map.get(key) == null || !clazz.isAssignableFrom(map.get(key).getClass()) || (map.get(key) instanceof String && ((String) map.get(key)).trim().isEmpty()) || (List.class.isAssignableFrom(map.get(key).getClass()) && ((List) map.get(key)).size() == 0)) { errors.put(key, message); } if (decorated != null) { decorated.validate(map, errors); } else if (!errors.isEmpty()) { ValidationException ve = new ValidationException(); for (String errorKey : errors.keySet()) { ve.addError(errorKey, errors.get(errorKey)); } throw ve; } } MapParameterValidator(final String inKey, final Class< ? > inClazz, final String inMessage); @SuppressWarnings("unchecked") void validate(final Map<String, Serializable> map, final Map<String, String> errors); void setMapParameterValidatorDecorator(final MapParameterValidatorDecorator inDecorated);  }