Skip to content

Commit

Permalink
Merge pull request #293 from Bandov/phone-number-attr-fix
Browse files Browse the repository at this point in the history
fixed the error message
  • Loading branch information
Bandov authored Apr 10, 2024
2 parents ae1a541 + 86ebed3 commit 1564108
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/main/java/seedu/address/logic/commands/AttributeUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ public static Attribute createAttribute(String attributeName, String attributeVa
if (phoneNumber < 0) {
throw new CommandException("Phone number cannot be negative for " + attributeName + ".");
}
if (attributeValue.length() > 8) {
throw new CommandException("Phone number for " + attributeName + " must be lesser than 9 digits.");
}
} catch (NumberFormatException e) {
throw new CommandException("Phone number for " + attributeName + " must be a number. "
+ "A number is only valid if it is a positive integer. "
+ "Additionally, please make sure the phone number is lesser than 9 digits.");
+ "A number is only valid if it is a positive integer. ");
}
attribute = new PhoneNumberAttribute("Phone", phoneNumber);
break;
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/seedu/address/logic/commands/AttributeUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,14 @@ public void sex_validSex_female() throws CommandException {
public void sex_attributeValueNull_throwsError() {
assertThrows(CommandException.class, () -> AttributeUtil.createAttribute("Sex", null));
}

@Test
public void phone_invalidPhone_throwsError() {
assertThrows(CommandException.class, () -> AttributeUtil.createAttribute("phone", "-1"));
}

@Test
public void phone_invalidPhoneLength_throwsError() {
assertThrows(CommandException.class, () -> AttributeUtil.createAttribute("phone", "123456789"));
}
}

0 comments on commit 1564108

Please sign in to comment.