class ValidatorTest { @Test testUsernameValidator() { String username = "someName"; Validator validator = new Validator(); Assert.assertTrue(validator.isValidUsername(username)); } }
public String getString(Scanner sc, String prompt) { } // Use the suitable constructor here. Validator validator = new Validator(); String productCode = validator.getString(sc, "Enter product code: ");
validator = new Validator(getActivity()); /*====*/
public class ValidatorTest { Validator validator = new Validator(); // not a mock @Test public void when_<some_part_of_the_domain>_is_incorrect_report_validation_error() throws Exception { // given Domain domain = createDomainWithInvalidData(); // when validator.validate(domain, validationInfo); // then assertThat(validationInfo.getMessages()).isNotEmpty()); // not really necessary assertThat(validationInfo.getLastMessage().text()).contains("<some_part_of_the_domain> is wrong"); } }
// see if the user wants to continue Validator validator = new Validator(); choice = validator.getString(sc, "Continue? (y/n): "); System.out.println();
validator = new Validator(form);
var form = $('form'); form.find('*').off(); var validator = new Validator(form); validator.validate();
public class Something{ @NotEmpty //not empty validation @Email //email validation @SerializedName("emailAddress") private String emailAddress; } private void checkValidation() { Something forgotpass.setEmailAddress(LoginActivity.this.dialog_email.getText().toString()); Validator validator = new Validator(); //collect the constraint violations List<ConstraintViolation> violations = validator.validate(forgotpass); if(violations.size()>0){ for (ConstraintViolation cv : violations){ if(cv.getMessage().contains("emailAddress")){ dialog_email.setError(ValidationMessage.formattedError(cv.getMessage(), forgotpass)); } } } }
Validator validator = new Validator(); BusinessObject bo = new BusinessObject(); // collect the constraint violations List<ConstraintViolation> violations = validator.validate(bo);
public class SomeValueClass { @FormCollection Map variables; public static void main(String[] args) { SomeValueClass svc1 = new SomeValueClass(); svc1.variables = new HashMap(); svc1.variables.put("greeting", ""); Validator validator = new Validator(); List<ConstraintViolation> violations = validator.validate(svc1); System.out.println("svc1 violations.size() = " + violations.size()); }
public class Something{ @NotEmpty //not empty validation @Email //email validation @SerializedName("emailAddress") private String emailAddress; } private void checkValidation() { Something forgotpass.setEmailAddress(LoginActivity.this.dialog_email.getText().toString()); Validator validator = new Validator(); //collect the constraint violations List<ConstraintViolation> violations = validator.validate(forgotpass); if(violations.size()>0){ for (ConstraintViolation cv : violations){ if(cv.getMessage().contains("emailAddress")){ dialog_email.setError(ValidationMessage.formattedError(cv.getMessage(), forgotpass)); } } } }
private static final Validator VALIDATOR = new Validator(); static { VALIDATOR.getExpressionLanguageRegistry().registerExpressionLanguage("js", new ExpressionLanguageJavaScriptImpl()); }
// configure OVal to interprete OVal constraint annotations as well as built-in JSR303 annotations Validator validator = new Validator(new AnnotationsConfigurer(), new BeanValidationAnnotationsConfigurer());
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.commons.io.IOUtils; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setValidating(true); factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", schemaUrl); DocumentBuilder builder = factory.newDocumentBuilder(); Validator handler = new Validator(); builder.setErrorHandler(handler); builder.parse(IOUtils.toInputStream(xmlString)); if (handler._validationError) { StringBuilder xmsg = new StringBuilder(); for (SAXParseException exception : handler.getExceptions()) { xmsg.append(exception.getMessage()); xmsg.append("\n"); } //show xmsg in your dialog }
public class CustomMessageValueFormatter implements MessageValueFormatter { public static final CustomMessageValueFormatter INSTANCE = new CustomMessageValueFormatter(); @Override public String format(Object value) { Validator validator = new Validator(); List<ConstraintViolation> constraintViolations = validator.validate(value); List<String> errorMessages = new ArrayList<>(); constraintViolations.forEach(v -> errorMessages.add(v.getMessage())); return errorMessages.isEmpty() ? value.toString() : errorMessages.toString(); } } class A{ @AssertValid(message = "{invalidValue}") List<B> items; } class B{ @NotNull(message="ID can't be null") Integer id; }
Validator tweetValidator = new Validator(); private final int max;
@Override public void onClick(View v) { Validator validator = new Validator();
Validator validator = new Validator(resources, "ValidateBean");