@Test public void isValidStripsJavaElFromExceptionMessage() { String value = "value ${java el} {el}"; when(scheduleFactory.cron(any(Date.class), eq(value))).thenThrow(new IllegalArgumentException(value)); when(context.buildConstraintViolationWithTemplate(any())).thenReturn(mock(ConstraintValidatorContext.ConstraintViolationBuilder.class)); boolean isValid = validator.isValid(value, context); assertThat(isValid, is(false)); verify(context).buildConstraintViolationWithTemplate("value {java el} {el}"); }
@Override public boolean isValid(final String value, final ConstraintValidatorContext context) { try { scheduleFactory.cron(new Date(), value); } catch (IllegalArgumentException e) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(getEscapeHelper().stripJavaEl(e.getMessage())) .addConstraintViolation(); return false; } return true; }
CronExpressionValidator extends ConstraintValidatorSupport<CronExpression, String> { @Override public boolean isValid(final String value, final ConstraintValidatorContext context) { try { scheduleFactory.cron(new Date(), value); } catch (IllegalArgumentException e) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(getEscapeHelper().stripJavaEl(e.getMessage())) .addConstraintViolation(); return false; } return true; } }
CronExpressionValidator extends ConstraintValidatorSupport<CronExpression, String> { @Override public boolean isValid(final String value, final ConstraintValidatorContext context) { try { scheduleFactory.cron(new Date(), value); } catch (IllegalArgumentException e) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(getEscapeHelper().stripJavaEl(e.getMessage())) .addConstraintViolation(); return false; } return true; } @Inject  CronExpressionValidator(final TaskScheduler taskScheduler); }
CronExpressionValidator extends ConstraintValidatorSupport<CronExpression, String> { @Override public boolean isValid(final String value, final ConstraintValidatorContext context) { try { scheduleFactory.cron(new Date(), value); } catch (IllegalArgumentException e) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(getEscapeHelper().stripJavaEl(e.getMessage())) .addConstraintViolation(); return false; } return true; } @Inject  CronExpressionValidator(final TaskScheduler taskScheduler); @Override void initialize(final CronExpression annotation); @Override boolean isValid(final String value, final ConstraintValidatorContext context); }
CronExpressionValidator extends ConstraintValidatorSupport<CronExpression, String> { @Override public boolean isValid(final String value, final ConstraintValidatorContext context) { try { scheduleFactory.cron(new Date(), value); } catch (IllegalArgumentException e) { context.disableDefaultConstraintViolation(); context.buildConstraintViolationWithTemplate(getEscapeHelper().stripJavaEl(e.getMessage())) .addConstraintViolation(); return false; } return true; } @Inject  CronExpressionValidator(final TaskScheduler taskScheduler); @Override void initialize(final CronExpression annotation); @Override boolean isValid(final String value, final ConstraintValidatorContext context);  }