diff --git a/src/test/java/seedu/address/logic/commands/ViewCommandTest.java b/src/test/java/seedu/address/logic/commands/ViewCommandTest.java index b608efe6fd8..11e12317fde 100644 --- a/src/test/java/seedu/address/logic/commands/ViewCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ViewCommandTest.java @@ -1,5 +1,6 @@ package seedu.address.logic.commands; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.logic.Messages.MESSAGE_NO_PERSON_FOUND; @@ -71,4 +72,14 @@ public void execute_invalidNric_noPersonFound() { assertCommandFailure(viewCommand, model, MESSAGE_NO_PERSON_FOUND); } + @Test + public void toStringMethod() { + NricMatchesPredicate predicate = new NricMatchesPredicate("S1234567A"); + ViewCommand viewCommand = new ViewCommand("S1234567A"); + + String expectedString = ViewCommand.class.getCanonicalName() + "{predicate=" + predicate + "}"; + + assertEquals(expectedString, viewCommand.toString()); + } + } diff --git a/src/test/java/seedu/address/model/person/NricMatchesPredicateTest.java b/src/test/java/seedu/address/model/person/NricMatchesPredicateTest.java index e9603eb2560..66080a9ae3f 100644 --- a/src/test/java/seedu/address/model/person/NricMatchesPredicateTest.java +++ b/src/test/java/seedu/address/model/person/NricMatchesPredicateTest.java @@ -43,7 +43,7 @@ public void test_nricMatches_returnsTrue() { } @Test - public void test_nricMatches_caseInsensitive_returnsTrue() { + public void test_caseInsensitive_returnsTrue() { NricMatchesPredicate predicate = new NricMatchesPredicate("s1234567a"); Person person = new PersonBuilder().withNric("S1234567A").build(); diff --git a/src/test/java/seedu/address/model/person/NricTest.java b/src/test/java/seedu/address/model/person/NricTest.java new file mode 100644 index 00000000000..c50e57b248a --- /dev/null +++ b/src/test/java/seedu/address/model/person/NricTest.java @@ -0,0 +1,70 @@ +package seedu.address.model.person; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.Assert.assertThrows; + +import org.junit.jupiter.api.Test; + +public class NricTest { + + @Test + public void constructor_null_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new Nric(null)); + } + + @Test + public void constructor_invalidNric_throwsIllegalArgumentException() { + String invalidNric = "A123"; // Clearly invalid NRIC format + assertThrows(IllegalArgumentException.class, () -> new Nric(invalidNric)); + } + + @Test + public void isValidNric() { + // null NRIC + assertThrows(NullPointerException.class, () -> Nric.isValidNric(null)); + + // invalid NRICs + assertFalse(Nric.isValidNric("")); // empty string + assertFalse(Nric.isValidNric(" ")); // spaces only + assertFalse(Nric.isValidNric("S12345678")); // 8 numbers + assertFalse(Nric.isValidNric("S123456E")); // only 7 characters total + assertFalse(Nric.isValidNric("S12345E7A")); // non-digit in the middle + assertFalse(Nric.isValidNric("1234567A")); // no alphabet at the start + assertFalse(Nric.isValidNric("S1234567")); // no alphabet at the end + assertFalse(Nric.isValidNric("S1234567*")); // invalid character at the end + + // valid NRICs + assertTrue(Nric.isValidNric("S1234567A")); + assertTrue(Nric.isValidNric("T7654321Z")); + assertTrue(Nric.isValidNric("F0987654B")); // mixed with different first alphabets + assertTrue(Nric.isValidNric("G2345678K")); // different ending alphabet + assertTrue(Nric.isValidNric("s1234567a")); // lowercase letters at start and end + } + + @Test + public void equals() { + Nric nric = new Nric("S1234567A"); + + // same values -> returns true + assertTrue(nric.equals(new Nric("S1234567A"))); + + // same object -> returns true + assertTrue(nric.equals(nric)); + + // null -> returns false + assertFalse(nric.equals(null)); + + // different types -> returns false + assertFalse(nric.equals(5.0f)); + + // different values -> returns false + assertFalse(nric.equals(new Nric("T7654321Z"))); + } + + @Test + public void toStringMethod() { + Nric nric = new Nric("S1234567A"); + assertTrue(nric.toString().equals("S1234567A")); + } +}