@Test public void testEmptyIsInvalid() { assertFalse(underTest.isValid("", context)); verify(context).buildConstraintViolationWithTemplate(any(String.class)); }
@Override public boolean isValid(String value, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (value == null) { return true; } if (value.isEmpty()) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL may not be empty"); return false; } try { DatabaseCommon.JdbcConnectionUrlFields fields = new DatabaseCommon().parseJdbcConnectionUrl(value); if (databaseExpected != fields.getDatabase().isPresent()) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL must " + (databaseExpected ? "" : "not ") + "have a database name"); return false; } } catch (IllegalArgumentException e) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL is not valid"); return false; } return true; }
JdbcConnectionUrlValidator implements ConstraintValidator<ValidJdbcConnectionUrl, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (value == null) { return true; } if (value.isEmpty()) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL may not be empty"); return false; } try { DatabaseCommon.JdbcConnectionUrlFields fields = new DatabaseCommon().parseJdbcConnectionUrl(value); if (databaseExpected != fields.getDatabase().isPresent()) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL must " + (databaseExpected ? "" : "not ") + "have a database name"); return false; } } catch (IllegalArgumentException e) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL is not valid"); return false; } return true; } }
JdbcConnectionUrlValidator implements ConstraintValidator<ValidJdbcConnectionUrl, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (value == null) { return true; } if (value.isEmpty()) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL may not be empty"); return false; } try { DatabaseCommon.JdbcConnectionUrlFields fields = new DatabaseCommon().parseJdbcConnectionUrl(value); if (databaseExpected != fields.getDatabase().isPresent()) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL must " + (databaseExpected ? "" : "not ") + "have a database name"); return false; } } catch (IllegalArgumentException e) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL is not valid"); return false; } return true; }  }
JdbcConnectionUrlValidator implements ConstraintValidator<ValidJdbcConnectionUrl, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (value == null) { return true; } if (value.isEmpty()) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL may not be empty"); return false; } try { DatabaseCommon.JdbcConnectionUrlFields fields = new DatabaseCommon().parseJdbcConnectionUrl(value); if (databaseExpected != fields.getDatabase().isPresent()) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL must " + (databaseExpected ? "" : "not ") + "have a database name"); return false; } } catch (IllegalArgumentException e) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL is not valid"); return false; } return true; }  @Override void initialize(ValidJdbcConnectionUrl constraintAnnotation); @Override boolean isValid(String value, ConstraintValidatorContext context); }
JdbcConnectionUrlValidator implements ConstraintValidator<ValidJdbcConnectionUrl, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (value == null) { return true; } if (value.isEmpty()) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL may not be empty"); return false; } try { DatabaseCommon.JdbcConnectionUrlFields fields = new DatabaseCommon().parseJdbcConnectionUrl(value); if (databaseExpected != fields.getDatabase().isPresent()) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL must " + (databaseExpected ? "" : "not ") + "have a database name"); return false; } } catch (IllegalArgumentException e) { ValidatorUtil.addConstraintViolation(context, "JDBC connection URL is not valid"); return false; } return true; }  @Override void initialize(ValidJdbcConnectionUrl constraintAnnotation); @Override boolean isValid(String value, ConstraintValidatorContext context);  }