forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from tanshiyu1999/branch-Update-Organization
- Loading branch information
Showing
13 changed files
with
336 additions
and
32 deletions.
There are no files selected for viewing
14 changes: 0 additions & 14 deletions
14
src/main/java/seedu/address/logic/commands/AddOrganizationCommand.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package seedu.address.storage; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonValue; | ||
|
||
import seedu.address.commons.exceptions.IllegalValueException; | ||
import seedu.address.model.person.Id; | ||
|
||
/** | ||
* Jackson-friendly version of {@link Id}. | ||
*/ | ||
class JsonAdaptedId { | ||
|
||
private final String idName; | ||
|
||
/** | ||
* Constructs a {@code JsonAdaptedId} with the given {@code idName}. | ||
*/ | ||
@JsonCreator | ||
public JsonAdaptedId(String idName) { | ||
this.idName = idName; | ||
} | ||
|
||
/** | ||
* Converts a given {@code Id} into this class for Jackson use. | ||
*/ | ||
public JsonAdaptedId(Id source) { | ||
idName = source.value; | ||
} | ||
|
||
@JsonValue | ||
public String getIdName() { | ||
return idName; | ||
} | ||
|
||
/** | ||
* Converts this Jackson-friendly adapted tag object into the model's {@code Id} object. | ||
* | ||
* @throws IllegalValueException if there were any data constraints violated in the adapted tag. | ||
*/ | ||
public Id toModelType() throws IllegalValueException { | ||
if (!Id.isValidId(idName)) { | ||
throw new IllegalValueException(Id.MESSAGE_CONSTRAINTS); | ||
} | ||
return new Id(idName); | ||
} | ||
|
||
} | ||
|
106 changes: 106 additions & 0 deletions
106
src/test/java/seedu/address/model/person/OrganizationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package seedu.address.model.person; | ||
|
||
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.commands.CommandTestUtil.VALID_ADDRESS_BOB; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_BOB; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB; | ||
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND; | ||
import static seedu.address.testutil.Assert.assertThrows; | ||
import static seedu.address.testutil.TypicalContacts.ALICE; | ||
import static seedu.address.testutil.TypicalContacts.BOB; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.address.testutil.ContactBuilder; | ||
|
||
public class OrganizationTest { | ||
|
||
@Test | ||
public void asObservableList_modifyList_throwsUnsupportedOperationException() { | ||
Contact contact = new ContactBuilder().build(); | ||
assertThrows(UnsupportedOperationException.class, () -> contact.getTags().remove(0)); | ||
} | ||
|
||
@Test | ||
public void isSameContact() { | ||
// same object -> returns true | ||
assertTrue(ALICE.isSameContact(ALICE)); | ||
|
||
// null -> returns false | ||
assertFalse(ALICE.isSameContact(null)); | ||
|
||
// same name, all other attributes different -> returns true | ||
Contact editedAlice = new ContactBuilder(ALICE).withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB) | ||
.withAddress(VALID_ADDRESS_BOB).withTags(VALID_TAG_HUSBAND).build(); | ||
assertTrue(ALICE.isSameContact(editedAlice)); | ||
|
||
// different name, all other attributes same -> returns false | ||
editedAlice = new ContactBuilder(ALICE).withName(VALID_NAME_BOB).build(); | ||
assertFalse(ALICE.isSameContact(editedAlice)); | ||
|
||
// name differs in case, all other attributes same -> returns false | ||
Contact editedBob = new ContactBuilder(BOB).withName(VALID_NAME_BOB.toLowerCase()).build(); | ||
assertFalse(BOB.isSameContact(editedBob)); | ||
|
||
// name has trailing spaces, all other attributes same -> returns false | ||
String nameWithTrailingSpaces = VALID_NAME_BOB + " "; | ||
editedBob = new ContactBuilder(BOB).withName(nameWithTrailingSpaces).build(); | ||
assertFalse(BOB.isSameContact(editedBob)); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
// same values -> returns true | ||
Contact aliceCopy = new ContactBuilder(ALICE).build(); | ||
assertTrue(ALICE.equals(aliceCopy)); | ||
|
||
// same object -> returns true | ||
assertTrue(ALICE.equals(ALICE)); | ||
|
||
// null -> returns false | ||
assertFalse(ALICE.equals(null)); | ||
|
||
// different type -> returns false | ||
assertFalse(ALICE.equals(5)); | ||
|
||
// different contact -> returns false | ||
assertFalse(ALICE.equals(BOB)); | ||
|
||
// different name -> returns false | ||
Contact editedAlice = new ContactBuilder(ALICE).withName(VALID_NAME_BOB).build(); | ||
assertFalse(ALICE.equals(editedAlice)); | ||
|
||
// different phone -> returns false | ||
editedAlice = new ContactBuilder(ALICE).withPhone(VALID_PHONE_BOB).build(); | ||
assertFalse(ALICE.equals(editedAlice)); | ||
|
||
// different email -> returns false | ||
editedAlice = new ContactBuilder(ALICE).withEmail(VALID_EMAIL_BOB).build(); | ||
assertFalse(ALICE.equals(editedAlice)); | ||
|
||
// different address -> returns false | ||
editedAlice = new ContactBuilder(ALICE).withAddress(VALID_ADDRESS_BOB).build(); | ||
assertFalse(ALICE.equals(editedAlice)); | ||
|
||
// different tags -> returns false | ||
editedAlice = new ContactBuilder(ALICE).withTags(VALID_TAG_HUSBAND).build(); | ||
assertFalse(ALICE.equals(editedAlice)); | ||
} | ||
|
||
@Test | ||
public void toStringMethod() { | ||
String expected = Contact.class.getCanonicalName() | ||
+ "{name=" + ALICE.getName() | ||
+ ", type=" + ALICE.getType() | ||
+ ", id=" + ALICE.getId() | ||
+ ", phone=" + ALICE.getPhone() | ||
+ ", email=" + ALICE.getEmail() | ||
+ ", url=" + ALICE.getUrl() | ||
+ ", address=" + ALICE.getAddress() | ||
+ ", tags=" + ALICE.getTags() + "}"; | ||
assertEquals(expected, ALICE.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.