|
| 1 | +package seedu.address.model.article; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 5 | +import static seedu.address.testutil.Assert.assertThrows; |
| 6 | + |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | + |
| 9 | +public class LinkTest { |
| 10 | + |
| 11 | + @Test |
| 12 | + public void constructor_null_createsEmptyLink() { |
| 13 | + assertTrue(new Link("").equals(new Link(null))); |
| 14 | + } |
| 15 | + |
| 16 | + @Test |
| 17 | + public void constructor_invalidLink_throwsIllegalArgumentException() { |
| 18 | + String invalidLink = " "; |
| 19 | + assertThrows(IllegalArgumentException.class, () -> new Link(invalidLink)); |
| 20 | + } |
| 21 | + |
| 22 | + @Test |
| 23 | + public void isValidLink() { |
| 24 | + //null Link |
| 25 | + assertThrows(NullPointerException.class, () -> Link.isValidLink(null)); |
| 26 | + |
| 27 | + // blank Link |
| 28 | + assertTrue(Link.isValidLink("")); // empty string |
| 29 | + |
| 30 | + // whitespaces only |
| 31 | + assertFalse(Link.isValidLink(" ")); // space only |
| 32 | + assertFalse(Link.isValidLink(" ")); // multiple spaces only |
| 33 | + |
| 34 | + // whitespaces in Link |
| 35 | + assertTrue(Link.isValidLink("mylink ")); // trailing space |
| 36 | + assertTrue(Link.isValidLink("mylink ")); // multiple trailing spaces |
| 37 | + assertTrue(Link.isValidLink("my link")); // middle space |
| 38 | + assertTrue(Link.isValidLink("my link")); // multiple middle spaces |
| 39 | + |
| 40 | + // invalid Links |
| 41 | + assertFalse(Link.isValidLink(" mylink")); // leading space |
| 42 | + assertFalse(Link.isValidLink(" mylink")); // multiple leading spaces |
| 43 | + |
| 44 | + // valid Links |
| 45 | + assertTrue(Link.isValidLink("mylink")); // alphabets only |
| 46 | + assertTrue(Link.isValidLink("12345")); // numbers only |
| 47 | + assertTrue(Link.isValidLink("my link")); // alphabets with space |
| 48 | + assertTrue(Link.isValidLink("123 45")); // numbers with space |
| 49 | + assertTrue(Link.isValidLink("my link 123")); // alphanumeric with spaces |
| 50 | + assertTrue(Link.isValidLink("~!@#$%^&*()_+`-={}|[]:,.?/;" + "\"")); // special characters only |
| 51 | + assertTrue(Link.isValidLink("~!@#$%^&* ()_+`-={}|[]:,.?/;" + " \"")); // special characters with spaces |
| 52 | + assertTrue(Link.isValidLink("my link: 123")); // alphanumeric with special characters and spaces |
| 53 | + assertTrue(Link.isValidLink("my link: 123 ")); // alphanumeric with special characters and trailing space |
| 54 | + assertTrue(Link.isValidLink("试试看")); // non-english unicode characters |
| 55 | + assertTrue(Link.isValidLink("试试 看")); // non-english unicode characters with space |
| 56 | + assertTrue(Link.isValidLink("试试看 123")); // non-english unicode characters with numbers and space |
| 57 | + assertTrue(Link.isValidLink("试试看: #123@")); // unicode characters with special characters, and spaces |
| 58 | + assertTrue(Link.isValidLink("试试看: #123@ ")); // mixed unicode characters with trailing space |
| 59 | + } |
| 60 | + |
| 61 | + @Test |
| 62 | + public void equals() { |
| 63 | + Link link = new Link("my link"); |
| 64 | + |
| 65 | + // same values -> returns true |
| 66 | + assertTrue(link.equals(new Link("my link"))); |
| 67 | + |
| 68 | + // same object -> returns true |
| 69 | + assertTrue(link.equals(link)); |
| 70 | + |
| 71 | + // null -> returns false |
| 72 | + assertFalse(link.equals(null)); |
| 73 | + |
| 74 | + // different types -> returns false |
| 75 | + assertFalse(link.equals(5.0f)); |
| 76 | + |
| 77 | + // different link -> returns false |
| 78 | + assertFalse(link.equals(new Link("not my link"))); |
| 79 | + } |
| 80 | +} |
0 commit comments