@Test public void invalidDateOfBirthTest() { Client client = getTestClient(); LocalDate dob = LocalDate.of(2000, 5, 4); editPrivateField(dob, "month", (short) 14); client.setDateOfBirth(dob); assertNotNull(ClientValidator.validate(client)); }
public static String validate(Client client) { StringBuilder errors = new StringBuilder(); if (!uidValid(client)) { errors.append("UID must be an integer greater than 0.\n"); } if (!firstNameValid(client)) { errors.append("First name must not be empty.\n"); } if (!lastNameValid(client)) { errors.append("Last name must not be empty.\n"); } if (!dateOfBirthValid(client)) { errors.append("Date of birth must be in a valid format and must represent a date in the past.\n"); } else if (!deathDetailsValid(client)) { errors.append("Death details must either all be empty, or all filled in.\n" + "If filled in, the time and date of death must be in the past,\n" + "and the date of birth must not be after the date of death.\n" + "The death country must be a valid country,\n" + "the death region must be non-empty " + "(and, if the country is set to New Zealand, a valid NZ region),\n" + "and the death city must be non-empty.\n"); } if (!heightValid(client)) { errors.append("Height must be a non-negative number.\n"); } if (!weightValid(client)) { errors.append("Weight must be a non-negative number.\n"); } if (!createdTimestampValid(client)) { errors.append("Created timestamp must be in a valid format and must represent a date in the past.\n"); } else if (!modifiedTimestampValid(client)) { errors.append("Modified timestamp must be either empty, or a datetime in a valid format that represents " + "a time after the profile was created.\n"); } for (TransplantRequest request : client.getTransplantRequests()) { String validationMsg = TransplantRequestValidator.validate(request); if (validationMsg != null) { errors.append(validationMsg); } } for (MedicationRecord record : client.getMedications()) { String validationMsg = MedicationRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } for (IllnessRecord record : client.getIllnesses()) { String validationMsg = IllnessRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } for (ProcedureRecord record : client.getProcedures()) { String validationMsg = ProcedureRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } if (errors.length() == 0) { return null; } else { return errors.toString(); } }
ClientValidator { public static String validate(Client client) { StringBuilder errors = new StringBuilder(); if (!uidValid(client)) { errors.append("UID must be an integer greater than 0.\n"); } if (!firstNameValid(client)) { errors.append("First name must not be empty.\n"); } if (!lastNameValid(client)) { errors.append("Last name must not be empty.\n"); } if (!dateOfBirthValid(client)) { errors.append("Date of birth must be in a valid format and must represent a date in the past.\n"); } else if (!deathDetailsValid(client)) { errors.append("Death details must either all be empty, or all filled in.\n" + "If filled in, the time and date of death must be in the past,\n" + "and the date of birth must not be after the date of death.\n" + "The death country must be a valid country,\n" + "the death region must be non-empty " + "(and, if the country is set to New Zealand, a valid NZ region),\n" + "and the death city must be non-empty.\n"); } if (!heightValid(client)) { errors.append("Height must be a non-negative number.\n"); } if (!weightValid(client)) { errors.append("Weight must be a non-negative number.\n"); } if (!createdTimestampValid(client)) { errors.append("Created timestamp must be in a valid format and must represent a date in the past.\n"); } else if (!modifiedTimestampValid(client)) { errors.append("Modified timestamp must be either empty, or a datetime in a valid format that represents " + "a time after the profile was created.\n"); } for (TransplantRequest request : client.getTransplantRequests()) { String validationMsg = TransplantRequestValidator.validate(request); if (validationMsg != null) { errors.append(validationMsg); } } for (MedicationRecord record : client.getMedications()) { String validationMsg = MedicationRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } for (IllnessRecord record : client.getIllnesses()) { String validationMsg = IllnessRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } for (ProcedureRecord record : client.getProcedures()) { String validationMsg = ProcedureRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } if (errors.length() == 0) { return null; } else { return errors.toString(); } } }
ClientValidator { public static String validate(Client client) { StringBuilder errors = new StringBuilder(); if (!uidValid(client)) { errors.append("UID must be an integer greater than 0.\n"); } if (!firstNameValid(client)) { errors.append("First name must not be empty.\n"); } if (!lastNameValid(client)) { errors.append("Last name must not be empty.\n"); } if (!dateOfBirthValid(client)) { errors.append("Date of birth must be in a valid format and must represent a date in the past.\n"); } else if (!deathDetailsValid(client)) { errors.append("Death details must either all be empty, or all filled in.\n" + "If filled in, the time and date of death must be in the past,\n" + "and the date of birth must not be after the date of death.\n" + "The death country must be a valid country,\n" + "the death region must be non-empty " + "(and, if the country is set to New Zealand, a valid NZ region),\n" + "and the death city must be non-empty.\n"); } if (!heightValid(client)) { errors.append("Height must be a non-negative number.\n"); } if (!weightValid(client)) { errors.append("Weight must be a non-negative number.\n"); } if (!createdTimestampValid(client)) { errors.append("Created timestamp must be in a valid format and must represent a date in the past.\n"); } else if (!modifiedTimestampValid(client)) { errors.append("Modified timestamp must be either empty, or a datetime in a valid format that represents " + "a time after the profile was created.\n"); } for (TransplantRequest request : client.getTransplantRequests()) { String validationMsg = TransplantRequestValidator.validate(request); if (validationMsg != null) { errors.append(validationMsg); } } for (MedicationRecord record : client.getMedications()) { String validationMsg = MedicationRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } for (IllnessRecord record : client.getIllnesses()) { String validationMsg = IllnessRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } for (ProcedureRecord record : client.getProcedures()) { String validationMsg = ProcedureRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } if (errors.length() == 0) { return null; } else { return errors.toString(); } } private  ClientValidator(); }
ClientValidator { public static String validate(Client client) { StringBuilder errors = new StringBuilder(); if (!uidValid(client)) { errors.append("UID must be an integer greater than 0.\n"); } if (!firstNameValid(client)) { errors.append("First name must not be empty.\n"); } if (!lastNameValid(client)) { errors.append("Last name must not be empty.\n"); } if (!dateOfBirthValid(client)) { errors.append("Date of birth must be in a valid format and must represent a date in the past.\n"); } else if (!deathDetailsValid(client)) { errors.append("Death details must either all be empty, or all filled in.\n" + "If filled in, the time and date of death must be in the past,\n" + "and the date of birth must not be after the date of death.\n" + "The death country must be a valid country,\n" + "the death region must be non-empty " + "(and, if the country is set to New Zealand, a valid NZ region),\n" + "and the death city must be non-empty.\n"); } if (!heightValid(client)) { errors.append("Height must be a non-negative number.\n"); } if (!weightValid(client)) { errors.append("Weight must be a non-negative number.\n"); } if (!createdTimestampValid(client)) { errors.append("Created timestamp must be in a valid format and must represent a date in the past.\n"); } else if (!modifiedTimestampValid(client)) { errors.append("Modified timestamp must be either empty, or a datetime in a valid format that represents " + "a time after the profile was created.\n"); } for (TransplantRequest request : client.getTransplantRequests()) { String validationMsg = TransplantRequestValidator.validate(request); if (validationMsg != null) { errors.append(validationMsg); } } for (MedicationRecord record : client.getMedications()) { String validationMsg = MedicationRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } for (IllnessRecord record : client.getIllnesses()) { String validationMsg = IllnessRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } for (ProcedureRecord record : client.getProcedures()) { String validationMsg = ProcedureRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } if (errors.length() == 0) { return null; } else { return errors.toString(); } } private  ClientValidator(); static String validate(Client client); }
ClientValidator { public static String validate(Client client) { StringBuilder errors = new StringBuilder(); if (!uidValid(client)) { errors.append("UID must be an integer greater than 0.\n"); } if (!firstNameValid(client)) { errors.append("First name must not be empty.\n"); } if (!lastNameValid(client)) { errors.append("Last name must not be empty.\n"); } if (!dateOfBirthValid(client)) { errors.append("Date of birth must be in a valid format and must represent a date in the past.\n"); } else if (!deathDetailsValid(client)) { errors.append("Death details must either all be empty, or all filled in.\n" + "If filled in, the time and date of death must be in the past,\n" + "and the date of birth must not be after the date of death.\n" + "The death country must be a valid country,\n" + "the death region must be non-empty " + "(and, if the country is set to New Zealand, a valid NZ region),\n" + "and the death city must be non-empty.\n"); } if (!heightValid(client)) { errors.append("Height must be a non-negative number.\n"); } if (!weightValid(client)) { errors.append("Weight must be a non-negative number.\n"); } if (!createdTimestampValid(client)) { errors.append("Created timestamp must be in a valid format and must represent a date in the past.\n"); } else if (!modifiedTimestampValid(client)) { errors.append("Modified timestamp must be either empty, or a datetime in a valid format that represents " + "a time after the profile was created.\n"); } for (TransplantRequest request : client.getTransplantRequests()) { String validationMsg = TransplantRequestValidator.validate(request); if (validationMsg != null) { errors.append(validationMsg); } } for (MedicationRecord record : client.getMedications()) { String validationMsg = MedicationRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } for (IllnessRecord record : client.getIllnesses()) { String validationMsg = IllnessRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } for (ProcedureRecord record : client.getProcedures()) { String validationMsg = ProcedureRecordValidator.validate(record); if (validationMsg != null) { errors.append(validationMsg); } } if (errors.length() == 0) { return null; } else { return errors.toString(); } } private  ClientValidator(); static String validate(Client client);  }