### Question:
DatabaseVendorValidator implements ConstraintValidator<ValidDatabaseVendor, String> { @Override public boolean isValid(String value, ConstraintValidatorContext context) { context.disableDefaultConstraintViolation(); if (value == null) { return true; } if (value.isEmpty()) { ValidatorUtil.addConstraintViolation(context, "Database vendor may not be empty"); return false; } try { DatabaseVendor.fromValue(value); return true; } catch (UnsupportedOperationException e) { ValidatorUtil.addConstraintViolation(context, value + " is not a valid database vendor"); return false; } }  @Override boolean isValid(String value, ConstraintValidatorContext context);  }### Answer:
@Test public void testValid() { assertTrue(underTest.isValid(DatabaseVendor.POSTGRES.databaseType(), context)); verify(context, never()).buildConstraintViolationWithTemplate(any(String.class)); }
@Test public void testInvalid() { assertFalse(underTest.isValid("foo", context)); verify(context).buildConstraintViolationWithTemplate(any(String.class)); }
@Test public void testNullIsValid() { assertTrue(underTest.isValid(null, context)); verify(context, never()).buildConstraintViolationWithTemplate(any(String.class)); }
@Test public void testEmptyIsInvalid() { assertFalse(underTest.isValid("", context)); verify(context).buildConstraintViolationWithTemplate(any(String.class)); }