urn_perun_user_attribute_def_def_vsupMailAliases extends UserAttributesModuleAbstract implements UserAttributesModuleImplApi { @Override public void checkAttributeSyntax(PerunSessionImpl sess, User user, Attribute attribute) throws WrongAttributeValueException { List<String> mails = (attribute.getValue() != null) ? (attribute.valueAsList()) : (new ArrayList<>()); for (String mail : mails) { Matcher emailMatcher = emailPattern.matcher(mail); if(!emailMatcher.find()) throw new WrongAttributeValueException(attribute, user, "Following value of School mail aliases is not in a correct form: '"+mail+"'."); } }  @Override void checkAttributeSyntax(PerunSessionImpl sess, User user, Attribute attribute); @Override void changedAttributeHook(PerunSessionImpl session, User user, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongAttributeValueException.class) public void testSyntaxWithIncorrectEmail() throws Exception { System.out.println("testSyntaxWithIncorrectEmail()"); List<String> value = new ArrayList<>(); value.add("bad@example"); attributeToCheck.setValue(value); classInstance.checkAttributeSyntax(session, user, attributeToCheck); }
@Test public void testCorrectSyntax() throws Exception { System.out.println("testCorrectSyntax()"); List<String> value = new ArrayList<>(); value.add("example@vsup.cz"); attributeToCheck.setValue(value); classInstance.checkAttributeSyntax(session, user, attributeToCheck); }