urn_perun_user_attribute_def_def_preferredMail extends UserAttributesModuleAbstract implements UserAttributesModuleImplApi { @Override public void checkAttributeSyntax(PerunSessionImpl sess, User user, Attribute attribute) throws WrongAttributeValueException { if(attribute.getValue() == null) return; String attributeValue = attribute.valueAsString(); Matcher emailMatcher = Utils.emailPattern.matcher(attributeValue); if(!emailMatcher.find()) throw new WrongAttributeValueException(attribute, user, "Email is not in correct form."); }  @Override void checkAttributeSyntax(PerunSessionImpl sess, User user, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl sess, User user, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test public void testCheckCorrectAttributeSyntax() throws Exception { System.out.println("testCheckCorrectAttributeSyntax()"); attributeToCheck.setValue("my@example.com"); classInstance.checkAttributeSyntax(session, user, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckAttributeSyntaxWithWrongValue() throws Exception { System.out.println("testCheckAttributeSyntaxWithWrongValue()"); attributeToCheck.setValue("bad@example"); classInstance.checkAttributeSyntax(session, user, attributeToCheck); }