urn_perun_member_attribute_def_def_phone extends MemberAttributesModuleAbstract implements MemberAttributesModuleImplApi { public void checkAttributeSyntax(PerunSessionImpl perunSession, Member member, Attribute attribute) throws WrongAttributeValueException { if (attribute.getValue() == null) return; if (!(attribute.getValue() instanceof String)) throw new WrongAttributeValueException(attribute, "Wrong type of the attribute. Expected: String"); Matcher matcher = pattern.matcher(attribute.valueAsString()); if (!matcher.matches()) { throw new WrongAttributeValueException(attribute, "Phone is not in correct format!"); } }  void checkAttributeSyntax(PerunSessionImpl perunSession, Member member, Attribute attribute); @Override void checkAttributeSemantics(PerunSessionImpl perunSession, Member member, Attribute attribute); @Override void changedAttributeHook(PerunSessionImpl session, Member member, Attribute attribute); @Override AttributeDefinition getAttributeDefinition();  }
@Test(expected = WrongAttributeValueException.class) public void testCheckType() throws Exception { System.out.println("testCheckType()"); attributeToCheck.setValue(Lists.newArrayList("+420123456789")); classInstance.checkAttributeSyntax(session, member, attributeToCheck); }
@Test(expected = WrongAttributeValueException.class) public void testCheckEmailSyntax() throws Exception { System.out.println("testCheckEmailSyntax()"); attributeToCheck.setValue("a/-+"); classInstance.checkAttributeSyntax(session, member, attributeToCheck); }
@Test public void testCorrectSyntax() throws Exception { System.out.println("testCorrectSyntax()"); attributeToCheck.setValue("+420123456789"); classInstance.checkAttributeSyntax(session, member, attributeToCheck); }