diff --git a/src/main/java/tagline/logic/commands/note/DeleteNoteCommand.java b/src/main/java/tagline/logic/commands/note/DeleteNoteCommand.java index 52ed0d363cf..f76de883236 100644 --- a/src/main/java/tagline/logic/commands/note/DeleteNoteCommand.java +++ b/src/main/java/tagline/logic/commands/note/DeleteNoteCommand.java @@ -1,9 +1,8 @@ package tagline.logic.commands.note; import static java.util.Objects.requireNonNull; -import static tagline.model.note.NoteModel.PREDICATE_SHOW_ALL_NOTES; -import java.util.List; +import java.util.Optional; import tagline.commons.core.Messages; import tagline.logic.commands.CommandResult; @@ -11,7 +10,6 @@ import tagline.model.Model; import tagline.model.note.Note; import tagline.model.note.NoteId; -import tagline.model.note.NoteIdEqualsTargetIdPredicate; /** * Deletes a note identified using it's index. @@ -37,18 +35,16 @@ public DeleteNoteCommand(NoteId noteId) { @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); - NoteIdEqualsTargetIdPredicate predicate = new NoteIdEqualsTargetIdPredicate(targetId); - model.updateFilteredNoteList(predicate); - List filteredList = model.getFilteredNoteList(); - if (filteredList.size() < 1) { + Optional noteFound = model.findNote(targetId); + + if (noteFound.isEmpty()) { throw new CommandException(Messages.MESSAGE_INVALID_NOTE_INDEX); } - Note noteToDelete = filteredList.get(0); + Note noteToDelete = noteFound.get(); model.deleteNote(noteToDelete); - model.updateFilteredNoteList(PREDICATE_SHOW_ALL_NOTES); return new CommandResult(String.format(MESSAGE_SUCCESS, noteToDelete), CommandResult.ViewType.NOTE); } diff --git a/src/main/java/tagline/model/Model.java b/src/main/java/tagline/model/Model.java index 084a3948dc9..1d80867cd22 100644 --- a/src/main/java/tagline/model/Model.java +++ b/src/main/java/tagline/model/Model.java @@ -10,6 +10,7 @@ import tagline.model.contact.ContactId; import tagline.model.contact.ReadOnlyAddressBook; import tagline.model.note.Note; +import tagline.model.note.NoteId; import tagline.model.note.ReadOnlyNoteBook; /** @@ -142,6 +143,12 @@ public interface Model { */ void deleteNote(Note target); + /** + * Finds a {@code Note} in the note book based on the {@code noteId}. + * @return Optional object if corresponding note is found, empty otherwise + */ + public Optional findNote(NoteId noteId); + /** * Returns an unmodifiable view of the filtered note list */ diff --git a/src/main/java/tagline/model/ModelManager.java b/src/main/java/tagline/model/ModelManager.java index 5a9e5c4e2f4..8ca36738f16 100644 --- a/src/main/java/tagline/model/ModelManager.java +++ b/src/main/java/tagline/model/ModelManager.java @@ -18,6 +18,7 @@ import tagline.model.contact.ReadOnlyAddressBook; import tagline.model.note.Note; import tagline.model.note.NoteBook; +import tagline.model.note.NoteId; import tagline.model.note.NoteManager; import tagline.model.note.ReadOnlyNoteBook; @@ -190,6 +191,11 @@ public void deleteNote(Note target) { noteManager.deleteNote(target); } + @Override + public Optional findNote(NoteId noteId) { + return noteManager.findNote(noteId); + } + //=========== Filtered Note List Accessors ============================================================= /** diff --git a/src/main/java/tagline/model/contact/AddressBook.java b/src/main/java/tagline/model/contact/AddressBook.java index 05e9811fa3e..29198983e0c 100644 --- a/src/main/java/tagline/model/contact/AddressBook.java +++ b/src/main/java/tagline/model/contact/AddressBook.java @@ -63,7 +63,7 @@ public void resetData(ReadOnlyAddressBook newData) { */ public boolean hasContact(Contact contact) { requireNonNull(contact); - return contacts.contains(contact); + return contacts.containsContact(contact); } /** @@ -73,7 +73,7 @@ public boolean hasContact(Contact contact) { public void addContact(Contact p) { requireNonNull(p.getContactId()); assert (findContact(p.getContactId()).isEmpty()) : "Contact id is not unique"; - contacts.add(p); + contacts.addContact(p); } /** @@ -94,12 +94,16 @@ public void setContact(Contact target, Contact editedContact) { * {@code key} must exist in the address book. */ public void removeContact(Contact key) { - contacts.remove(key); + contacts.removeContact(key); } + /** + * Finds a contact with ID equal to {@code contactId}. + */ public Optional findContact(ContactId contactId) { return contacts.findContact(contactId); } + //// util methods /** diff --git a/src/main/java/tagline/model/contact/UniqueContactList.java b/src/main/java/tagline/model/contact/UniqueContactList.java index 1bc1cabcb58..becea28db4d 100644 --- a/src/main/java/tagline/model/contact/UniqueContactList.java +++ b/src/main/java/tagline/model/contact/UniqueContactList.java @@ -34,7 +34,7 @@ public class UniqueContactList implements Iterable { /** * Returns true if the list contains an equivalent contact as the given argument. */ - public boolean contains(Contact toCheck) { + public boolean containsContact(Contact toCheck) { requireNonNull(toCheck); return internalList.stream().anyMatch(toCheck::isSameContact); } @@ -64,9 +64,9 @@ public int size() { * Adds a contact to the list. * The contact must not already exist in the list. */ - public void add(Contact toAdd) { + public void addContact(Contact toAdd) { requireNonNull(toAdd); - if (contains(toAdd)) { + if (containsContact(toAdd)) { throw new DuplicateContactException(); } internalList.add(toAdd); @@ -85,7 +85,7 @@ public void setContact(Contact target, Contact editedContact) { throw new ContactNotFoundException(); } - if (!target.isSameContact(editedContact) && contains(editedContact)) { + if (!target.isSameContact(editedContact) && containsContact(editedContact)) { throw new DuplicateContactException(); } @@ -96,7 +96,7 @@ public void setContact(Contact target, Contact editedContact) { * Removes the equivalent contact from the list. * The contact must exist in the list. */ - public void remove(Contact toRemove) { + public void removeContact(Contact toRemove) { requireNonNull(toRemove); if (!internalList.remove(toRemove)) { throw new ContactNotFoundException(); diff --git a/src/main/java/tagline/model/note/NoteBook.java b/src/main/java/tagline/model/note/NoteBook.java index 0a386c1dd26..5a482e514d6 100644 --- a/src/main/java/tagline/model/note/NoteBook.java +++ b/src/main/java/tagline/model/note/NoteBook.java @@ -3,11 +3,12 @@ import static java.util.Objects.requireNonNull; import java.util.List; +import java.util.Optional; import javafx.collections.ObservableList; /** - * Wraps all data at the address-book level + * Wraps all data at the note book level * Duplicates are not allowed (by .isSameNote comparison) */ public class NoteBook implements ReadOnlyNoteBook { @@ -61,7 +62,7 @@ public void resetData(ReadOnlyNoteBook newData) { */ public boolean hasNote(Note note) { requireNonNull(note); - return notes.contains(note); + return notes.containsNote(note); } /** @@ -69,7 +70,15 @@ public boolean hasNote(Note note) { * The note must not already exist in the address book. */ public void addNote(Note p) { - notes.add(p); + notes.addNote(p); + } + + /** + * Finds a {@code Note} based on the {@code noteId}. + * @return Optional object if corresponding note is found, empty otherwise + */ + public Optional findNote(NoteId noteId) { + return notes.findNote(noteId); } /** @@ -88,7 +97,7 @@ public void setNote(Note target, Note editedNote) { * {@code key} must exist in the address book. */ public void removeNote(Note key) { - notes.remove(key); + notes.removeNote(key); } //// util methods diff --git a/src/main/java/tagline/model/note/NoteManager.java b/src/main/java/tagline/model/note/NoteManager.java index 7780038155c..5d648f30d53 100644 --- a/src/main/java/tagline/model/note/NoteManager.java +++ b/src/main/java/tagline/model/note/NoteManager.java @@ -4,6 +4,7 @@ import static tagline.commons.util.CollectionUtil.requireAllNonNull; import java.nio.file.Path; +import java.util.Optional; import java.util.function.Predicate; import java.util.logging.Logger; @@ -121,6 +122,11 @@ public void setNote(Note target, Note editedNote) { noteBook.setNote(target, editedNote); } + @Override + public Optional findNote(NoteId noteId) { + return noteBook.findNote(noteId); + } + //=========== Filtered Note List Accessors ============================================================= /** diff --git a/src/main/java/tagline/model/note/NoteModel.java b/src/main/java/tagline/model/note/NoteModel.java index 44243f71323..e3ccd4f5ecb 100644 --- a/src/main/java/tagline/model/note/NoteModel.java +++ b/src/main/java/tagline/model/note/NoteModel.java @@ -1,6 +1,7 @@ package tagline.model.note; import java.nio.file.Path; +import java.util.Optional; import java.util.function.Predicate; import javafx.collections.ObservableList; @@ -76,6 +77,12 @@ public interface NoteModel { */ void setNote(Note target, Note editedNote); + /** + * Finds a {@code Note} based on the {@code noteId}. + * @return Optional object if corresponding note is found, empty otherwise + */ + public Optional findNote(NoteId noteId); + /** Returns an unmodifiable view of the filtered note list */ ObservableList getFilteredNoteList(); diff --git a/src/main/java/tagline/model/note/UniqueNoteList.java b/src/main/java/tagline/model/note/UniqueNoteList.java index d597b9a4281..30e52eced79 100644 --- a/src/main/java/tagline/model/note/UniqueNoteList.java +++ b/src/main/java/tagline/model/note/UniqueNoteList.java @@ -5,6 +5,7 @@ import java.util.Iterator; import java.util.List; +import java.util.Optional; import javafx.collections.FXCollections; import javafx.collections.ObservableList; @@ -31,7 +32,7 @@ public class UniqueNoteList implements Iterable { /** * Returns true if the list contains an equivalent note as the given argument. */ - public boolean contains(Note toCheck) { + public boolean containsNote(Note toCheck) { requireNonNull(toCheck); return internalList.stream().anyMatch(toCheck::isSameNote); } @@ -40,14 +41,31 @@ public boolean contains(Note toCheck) { * Adds a note to the list. * The note must not already exist in the list. */ - public void add(Note toAdd) { + public void addNote(Note toAdd) { requireNonNull(toAdd); - if (contains(toAdd)) { + if (containsNote(toAdd)) { throw new DuplicateNoteException(); } internalList.add(toAdd); } + /** + * Find a note by id. + * + * @param id of the note + * @return an optional object which implies whether the corresponding note is found or not. + */ + public Optional findNote(NoteId id) { + var it = iterator(); + while (it.hasNext()) { + Note currentNote = it.next(); + if (currentNote.getNoteId().equals(id)) { + return Optional.of(currentNote); + } + } + return Optional.empty(); + } + /** * Replaces the note {@code target} in the list with {@code editedNote}. * {@code target} must exist in the list. @@ -61,7 +79,7 @@ public void setNote(Note target, Note editedNote) { throw new NoteNotFoundException(); } - if (!target.isSameNote(editedNote) && contains(editedNote)) { + if (!target.isSameNote(editedNote) && containsNote(editedNote)) { throw new DuplicateNoteException(); } @@ -72,7 +90,7 @@ public void setNote(Note target, Note editedNote) { * Removes the equivalent note from the list. * The note must exist in the list. */ - public void remove(Note toRemove) { + public void removeNote(Note toRemove) { requireNonNull(toRemove); if (!internalList.remove(toRemove)) { throw new NoteNotFoundException(); diff --git a/src/main/java/tagline/model/tag/ReadOnlyTagList.java b/src/main/java/tagline/model/tag/ReadOnlyTagBook.java similarity index 87% rename from src/main/java/tagline/model/tag/ReadOnlyTagList.java rename to src/main/java/tagline/model/tag/ReadOnlyTagBook.java index b4ce7393f3d..f65af228e0f 100644 --- a/src/main/java/tagline/model/tag/ReadOnlyTagList.java +++ b/src/main/java/tagline/model/tag/ReadOnlyTagBook.java @@ -5,7 +5,7 @@ /** * Unmodifiable view of a tag list. */ -public interface ReadOnlyTagList { +public interface ReadOnlyTagBook { /** * Returns an unmodifiable view of the tag list. diff --git a/src/main/java/tagline/model/tag/Tag.java b/src/main/java/tagline/model/tag/Tag.java index 41c817e2ff5..eb6c639a3d5 100644 --- a/src/main/java/tagline/model/tag/Tag.java +++ b/src/main/java/tagline/model/tag/Tag.java @@ -16,8 +16,6 @@ public enum TagType { GROUP_TAG, } - private static int nextId = 1; //temporary implementation of an incrementing tag ID - public final TagId tagId; public final TagType tagType; @@ -42,11 +40,26 @@ public Tag(TagId tagId, TagType tagType) { this.tagType = tagType; } + /** + * Returns true if {@code other} has the same data and ID as this object. + * This defines a stronger notion of equality between two tags. + */ @Override public boolean equals(Object other) { return other == this // short circuit if same object || (other instanceof Tag // instanceof handles nulls - && tagType.equals(((Tag) other).tagType)); // state check + && tagType.equals(((Tag) other).tagType) // state check + && tagId.equals(((Tag) other).tagId)); + } + + /** + * Returns true if {@code other} has the same data as this object. + * This defines a weaker notion of equality between two tags. + */ + public boolean isSameContent(Object other) { + return other == this // short circuit if same object + || (other instanceof Tag // instanceof handles nulls + && tagType.equals(((Tag) other).tagType)); } @Override diff --git a/src/main/java/tagline/model/tag/TagBook.java b/src/main/java/tagline/model/tag/TagBook.java new file mode 100644 index 00000000000..719b798ad7d --- /dev/null +++ b/src/main/java/tagline/model/tag/TagBook.java @@ -0,0 +1,107 @@ +package tagline.model.tag; + +import static java.util.Objects.requireNonNull; + +import java.util.List; + +import javafx.collections.ObservableList; + +/** + * Wraps all tag data at a level suitable for other components. + * Duplicates are not allowed. + */ +public class TagBook implements ReadOnlyTagBook { + + private final UniqueTagList tags; + + /* + * The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication + * between constructors. See https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html + * + * Note that non-static init blocks are not recommended to use. There are other ways to avoid duplication + * among constructors. + */ + { + tags = new UniqueTagList(); + } + + public TagBook() { + } + + /** + * Creates an TagBook using the Tags in the {@code toBeCopied} + */ + public TagBook(ReadOnlyTagBook toBeCopied) { + this(); + resetData(toBeCopied); + } + + //// list overwrite operations + + /** + * Replaces the contents of the tag list with {@code tags}. + * {@code tags} must not contain duplicate tags. + */ + public void setTags(List tags) { + this.tags.setTags(tags); + } + + /** + * Resets the existing data of this {@code TagBook} with {@code newData}. + */ + public void resetData(ReadOnlyTagBook newData) { + requireNonNull(newData); + setTags(newData.getTagList()); + } + + //// tag-level operations + + /** + * Returns true if a tag with the same identity as {@code tag} exists in the address book. + */ + public boolean hasTag(Tag tag) { + requireNonNull(tag); + return tags.containsTag(tag); + } + + /** + * Adds a tag to the address book. + * The tag must not already exist in the address book. + */ + public void addTag(Tag p) { + tags.addTag(p); + } + + /** + * Finds all tags with ID equal to {@code tagId}. + * Returns an unmodifiable list. + */ + public List findTag(TagId tagId) { + return tags.findTag(tagId); + } + + //// util methods + + @Override + public String toString() { + return tags.asUnmodifiableObservableList().size() + " tags"; + // TODO: refine later + } + + @Override + public ObservableList getTagList() { + return tags.asUnmodifiableObservableList(); + } + + @Override + public boolean equals(Object other) { + return other == this // short circuit if same object + || (other instanceof TagBook // instanceof handles nulls + && tags.equals(((TagBook) other).tags)); + } + + @Override + public int hashCode() { + return tags.hashCode(); + } +} diff --git a/src/main/java/tagline/model/tag/TagManager.java b/src/main/java/tagline/model/tag/TagManager.java index 7e0fbd08ac7..8fa8f91a03f 100644 --- a/src/main/java/tagline/model/tag/TagManager.java +++ b/src/main/java/tagline/model/tag/TagManager.java @@ -1,37 +1,47 @@ package tagline.model.tag; +import static java.util.Objects.requireNonNull; + import java.util.List; /** * Represents the in-memory model of all tag data. */ public class TagManager implements TagModel { - private final TagList tagList; + private final TagBook tagBook; /** - * Initializes a TagManager with the given tagList. + * Initializes a TagManager with the given {@code tagBook}. */ - public TagManager(ReadOnlyTagList tagList) { - this.tagList = new TagList(tagList); + public TagManager(ReadOnlyTagBook tagBook) { + this.tagBook = new TagBook(tagBook); } - public void setTagList(ReadOnlyTagList tagList) { - this.tagList.setTagList(tagList); + @Override + public void setTagBook(ReadOnlyTagBook tagBook) { + this.tagBook.resetData(tagBook); } - public ReadOnlyTagList getTagList() { - return this.tagList; + @Override + public ReadOnlyTagBook getTagBook() { + return tagBook; } - public boolean containsTag(Tag tag) { - return tagList.containsTag(tag); + @Override + public boolean hasTag(Tag tag) { + requireNonNull(tag); + return tagBook.hasTag(tag); } + @Override public void addTag(Tag tag) { - tagList.addTag(tag); + requireNonNull(tag); + tagBook.addTag(tag); } + @Override public List findTag(TagId tagId) { - return tagList.findTag(tagId); + requireNonNull(tagId); + return tagBook.findTag(tagId); } } diff --git a/src/main/java/tagline/model/tag/TagModel.java b/src/main/java/tagline/model/tag/TagModel.java index 1b359e714cf..3feff96eae4 100644 --- a/src/main/java/tagline/model/tag/TagModel.java +++ b/src/main/java/tagline/model/tag/TagModel.java @@ -7,19 +7,19 @@ */ public interface TagModel { /** - * Replaces address book data with the data in {@code addressBook}. + * Replaces tag book data with the data in {@code tagBook}. */ - void setTagList(ReadOnlyTagList tagList); + void setTagBook(ReadOnlyTagBook tagList); /** - * Returns a read-only view of the tag list. + * Returns a read-only view of the tag book. */ - ReadOnlyTagList getTagList(); + ReadOnlyTagBook getTagBook(); /** * Returns true if {@code tag} exists in the tag list. */ - boolean containsTag(Tag tag); + boolean hasTag(Tag tag); /** * Adds the given tag. diff --git a/src/main/java/tagline/model/tag/TagList.java b/src/main/java/tagline/model/tag/UniqueTagList.java similarity index 72% rename from src/main/java/tagline/model/tag/TagList.java rename to src/main/java/tagline/model/tag/UniqueTagList.java index 6ae7bc08442..c1f1f89be06 100644 --- a/src/main/java/tagline/model/tag/TagList.java +++ b/src/main/java/tagline/model/tag/UniqueTagList.java @@ -8,35 +8,26 @@ import java.util.Iterator; import java.util.List; +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; import tagline.model.tag.exceptions.DuplicateTagException; /** * Stores and handles a list of {@code Tag}s. */ -public class TagList implements Iterable, ReadOnlyTagList { - private List tagList; - - { - tagList = new ArrayList(); - } - - public TagList() { - } - - public TagList(ReadOnlyTagList newData) { - this(); - requireNonNull(newData); - setTagList(newData.getTagList()); - } +public class UniqueTagList implements Iterable { + private final ObservableList internalList = FXCollections.observableArrayList(); + private final ObservableList internalUnmodifiableList = + FXCollections.unmodifiableObservableList(internalList); /** * Replaces the contents of the tag list with {@code replacement}. * * @throws DuplicateTagException If {@code replacement} contains duplicate tags */ - public void setTagList(ReadOnlyTagList replacement) { + public void setTags(UniqueTagList replacement) { requireNonNull(replacement); - setTagList(replacement.getTagList()); + internalList.setAll(replacement.internalList); } /** @@ -44,14 +35,13 @@ public void setTagList(ReadOnlyTagList replacement) { * * @throws DuplicateTagException If {@code tags} contains duplicate tags */ - public void setTagList(List tags) { + public void setTags(List tags) { requireAllNonNull(tags); if (!tagsAreUnique(tags)) { throw new DuplicateTagException(); } - tagList = new ArrayList<>(); - tagList.addAll(tags); + internalList.setAll(tags); } /** @@ -61,7 +51,7 @@ public void setTagList(List tags) { * @return True if a matching tag was found */ public boolean containsTag(TagId tagId) { - return tagList.stream().anyMatch(t -> (t.tagId.equals(tagId))); + return internalList.stream().anyMatch(t -> (t.tagId.equals(tagId))); } /** @@ -72,7 +62,7 @@ public boolean containsTag(TagId tagId) { */ public boolean containsTag(Tag toCheck) { requireNonNull(toCheck); - return tagList.stream().anyMatch(t -> t.equals(toCheck)); + return internalList.stream().anyMatch(t -> t.equals(toCheck)); } /** @@ -85,13 +75,14 @@ public List findTag(String tagName) { requireNonNull(tagName); List result = new ArrayList<>(); - /*for (Tag tag : tagList) { - if (tag.tagName.equals(tagName)) { + /* + for (Tag tag : tagList) { + if (tag.getTagName().equals(tagName)) { result.add(tag); } }*/ - return result; + return Collections.unmodifiableList(result); } /** @@ -102,14 +93,14 @@ public List findTag(String tagName) { */ public List findTag(TagId tagId) { List result = new ArrayList<>(); - for (Tag tag : tagList) { + for (Tag tag : internalList) { if (tag.tagId.equals(tagId)) { result.add(tag); return result; //tags are assumed to be unique } } - return result; + return Collections.unmodifiableList(result); } /** @@ -123,7 +114,7 @@ public void addTag(Tag toAdd) { throw new DuplicateTagException(); } - tagList.add(toAdd); + internalList.add(toAdd); } /** @@ -132,12 +123,12 @@ public void addTag(Tag toAdd) { * @return The number of tags */ public int size() { - return tagList.size(); + return internalList.size(); } @Override public String toString() { - return size() + " contacts"; + return size() + " tags"; // TODO: refine later } @@ -146,27 +137,26 @@ public String toString() { */ @Override public Iterator iterator() { - return tagList.iterator(); + return internalList.iterator(); } /** * Returns a read-only view of the tag list. */ - @Override - public List getTagList() { - return Collections.unmodifiableList(tagList); + public ObservableList asUnmodifiableObservableList() { + return internalUnmodifiableList; } @Override public boolean equals(Object other) { return other == this // short circuit if same object - || (other instanceof TagList // instanceof handles nulls - && tagList.equals(((TagList) other).tagList)); + || (other instanceof UniqueTagList // instanceof handles nulls + && internalList.equals(((UniqueTagList) other).internalList)); } @Override public int hashCode() { - return tagList.hashCode(); + return internalList.hashCode(); } /** diff --git a/src/main/java/tagline/storage/tag/JsonSeriazableTagList.java b/src/main/java/tagline/storage/tag/JsonSerializableTagBook.java similarity index 67% rename from src/main/java/tagline/storage/tag/JsonSeriazableTagList.java rename to src/main/java/tagline/storage/tag/JsonSerializableTagBook.java index 3b2284a2f54..91591fda10d 100644 --- a/src/main/java/tagline/storage/tag/JsonSeriazableTagList.java +++ b/src/main/java/tagline/storage/tag/JsonSerializableTagBook.java @@ -8,14 +8,14 @@ import com.fasterxml.jackson.annotation.JsonProperty; import tagline.commons.exceptions.IllegalValueException; -import tagline.model.tag.ReadOnlyTagList; +import tagline.model.tag.ReadOnlyTagBook; import tagline.model.tag.Tag; -import tagline.model.tag.TagList; +import tagline.model.tag.TagBook; /** - * An Immutable TagList that is serializable to JSON format. + * An Immutable UniqueTagList that is serializable to JSON format. */ -public class JsonSeriazableTagList { +public class JsonSerializableTagBook { public static final String MESSAGE_DUPLICATE_TAG = "Tag list contains duplicate tag(s)."; @@ -25,7 +25,7 @@ public class JsonSeriazableTagList { * Constructs a {@code JsonSerializableNoteBook} with the given notes. */ @JsonCreator - public JsonSeriazableTagList(@JsonProperty("tags") List tags) { + public JsonSerializableTagBook(@JsonProperty("tags") List tags) { this.tags.addAll(tags); } @@ -34,25 +34,25 @@ public JsonSeriazableTagList(@JsonProperty("tags") List tags) { * * @param source future changes to this will not affect the created {@code JsonSerializableNoteBook}. */ - public JsonSeriazableTagList(ReadOnlyTagList source) { + public JsonSerializableTagBook(ReadOnlyTagBook source) { tags.addAll(source.getTagList().stream().map(JsonAdaptedTag::new).collect(Collectors.toList())); } /** - * Converts this address book into the model's {@code NoteBook} object. + * Converts this tag book into the model's {@code TagBook} object. * * @throws IllegalValueException if there were any data constraints violated. */ - public TagList toModelType() throws IllegalValueException { - TagList tagList = new TagList(); + public TagBook toModelType() throws IllegalValueException { + TagBook tagBook = new TagBook(); for (JsonAdaptedTag jsonAdaptedTag : tags) { Tag tag = jsonAdaptedTag.toModelType(); - if (tagList.containsTag(tag)) { + if (tagBook.hasTag(tag)) { throw new IllegalValueException(MESSAGE_DUPLICATE_TAG); } - tagList.addTag(tag); + tagBook.addTag(tag); } - return tagList; + return tagBook; } } diff --git a/src/main/java/tagline/storage/tag/JsonTagListStorage.java b/src/main/java/tagline/storage/tag/JsonTagBookStorage.java similarity index 57% rename from src/main/java/tagline/storage/tag/JsonTagListStorage.java rename to src/main/java/tagline/storage/tag/JsonTagBookStorage.java index 53868c01457..de427076a83 100644 --- a/src/main/java/tagline/storage/tag/JsonTagListStorage.java +++ b/src/main/java/tagline/storage/tag/JsonTagBookStorage.java @@ -12,48 +12,48 @@ import tagline.commons.exceptions.IllegalValueException; import tagline.commons.util.FileUtil; import tagline.commons.util.JsonUtil; -import tagline.model.tag.ReadOnlyTagList; +import tagline.model.tag.ReadOnlyTagBook; import tagline.storage.note.JsonNoteBookStorage; /** - * A class to access TagList data stored as a json file on the hard disk. + * A class to access UniqueTagBook data stored as a json file on the hard disk. */ -public class JsonTagListStorage implements TagListStorage { +public class JsonTagBookStorage implements TagBookStorage { private static final Logger logger = LogsCenter.getLogger(JsonNoteBookStorage.class); private Path filePath; - public JsonTagListStorage(Path filePath) { + public JsonTagBookStorage(Path filePath) { this.filePath = filePath; } - public Path getTagListFilePath() { + public Path getTagBookFilePath() { return filePath; } @Override - public Optional readTagList() throws DataConversionException { - return readTagList(filePath); + public Optional readTagBook() throws DataConversionException { + return readTagBook(filePath); } /** - * Similar to {@link #readTagList()}. + * Similar to {@link #readTagBook()}. * * @param filePath location of the data. Cannot be null. * @throws DataConversionException if the file is not in the correct format. */ - public Optional readTagList(Path filePath) throws DataConversionException { + public Optional readTagBook(Path filePath) throws DataConversionException { requireNonNull(filePath); - Optional jsonTagList = JsonUtil.readJsonFile( - filePath, JsonSeriazableTagList.class); - if (!jsonTagList.isPresent()) { + Optional jsonTagBook = JsonUtil.readJsonFile( + filePath, JsonSerializableTagBook.class); + if (!jsonTagBook.isPresent()) { return Optional.empty(); } try { - return Optional.of(jsonTagList.get().toModelType()); + return Optional.of(jsonTagBook.get().toModelType()); } catch (IllegalValueException ive) { logger.info("Illegal values found in " + filePath + ": " + ive.getMessage()); throw new DataConversionException(ive); @@ -61,21 +61,21 @@ public Optional readTagList(Path filePath) throws DataConversio } @Override - public void saveTagList(ReadOnlyTagList tagList) throws IOException { - saveTagList(tagList, filePath); + public void saveTagBook(ReadOnlyTagBook tagBook) throws IOException { + saveTagBook(tagBook, filePath); } /** - * Similar to {@link #saveTagList(ReadOnlyTagList)}. + * Similar to {@link #saveTagBook(ReadOnlyTagBook)}. * * @param filePath location of the data. Cannot be null. */ - public void saveTagList(ReadOnlyTagList tagList, Path filePath) throws IOException { - requireNonNull(tagList); + public void saveTagBook(ReadOnlyTagBook tagBook, Path filePath) throws IOException { + requireNonNull(tagBook); requireNonNull(filePath); FileUtil.createIfMissing(filePath); - JsonUtil.saveJsonFile(new JsonSeriazableTagList(tagList), filePath); + JsonUtil.saveJsonFile(new JsonSerializableTagBook(tagBook), filePath); } } diff --git a/src/main/java/tagline/storage/tag/TagListStorage.java b/src/main/java/tagline/storage/tag/TagBookStorage.java similarity index 54% rename from src/main/java/tagline/storage/tag/TagListStorage.java rename to src/main/java/tagline/storage/tag/TagBookStorage.java index 2e7cc993eb4..a9a2f9df89d 100644 --- a/src/main/java/tagline/storage/tag/TagListStorage.java +++ b/src/main/java/tagline/storage/tag/TagBookStorage.java @@ -5,42 +5,43 @@ import java.util.Optional; import tagline.commons.exceptions.DataConversionException; -import tagline.model.tag.ReadOnlyTagList; +import tagline.model.tag.ReadOnlyTagBook; +import tagline.model.tag.UniqueTagList; /** - * Represents a storage for {@link tagline.model.tag.TagList}. + * Represents a storage for {@link UniqueTagList}. */ -public interface TagListStorage { +public interface TagBookStorage { /** * Returns the file path of the data file. */ - Path getTagListFilePath(); + Path getTagBookFilePath(); /** - * Returns TagList data as a {@link ReadOnlyTagList}. + * Returns TagBook data as a {@link ReadOnlyTagBook}. * Returns {@code Optional.empty()} if storage file is not found. * * @throws DataConversionException if the data in storage is not in the expected format. * @throws IOException if there was any problem when reading from the storage. */ - Optional readTagList() throws DataConversionException, IOException; + Optional readTagBook() throws DataConversionException, IOException; /** - * @see #readTagList() + * @see #readTagBook() */ - Optional readTagList(Path filePath) throws DataConversionException, IOException; + Optional readTagBook(Path filePath) throws DataConversionException, IOException; /** - * Saves the given {@link ReadOnlyTagList} to the storage. + * Saves the given {@link ReadOnlyTagBook} to the storage. * * @param tagList cannot be null. * @throws IOException if there was any problem writing to the file. */ - void saveTagList(ReadOnlyTagList tagList) throws IOException; + void saveTagBook(ReadOnlyTagBook tagList) throws IOException; /** - * @see #saveTagList(ReadOnlyTagList) + * @see #saveTagBook(ReadOnlyTagBook) */ - void saveTagList(ReadOnlyTagList addressBook, Path filePath) throws IOException; + void saveTagBook(ReadOnlyTagBook addressBook, Path filePath) throws IOException; } diff --git a/src/test/java/tagline/logic/commands/CreateContactCommandTest.java b/src/test/java/tagline/logic/commands/CreateContactCommandTest.java index 9795732b7ec..28aca963954 100644 --- a/src/test/java/tagline/logic/commands/CreateContactCommandTest.java +++ b/src/test/java/tagline/logic/commands/CreateContactCommandTest.java @@ -26,6 +26,7 @@ import tagline.model.contact.ContactId; import tagline.model.contact.ReadOnlyAddressBook; import tagline.model.note.Note; +import tagline.model.note.NoteId; import tagline.model.note.ReadOnlyNoteBook; public class CreateContactCommandTest { @@ -200,6 +201,11 @@ public void setNote(Note target, Note editedNote) { throw new AssertionError("This method should not be called."); } + @Override + public Optional findNote(NoteId noteId) { + throw new AssertionError("This method should not be called."); + } + @Override public ObservableList getFilteredNoteList() { throw new AssertionError("This method should not be called."); diff --git a/src/test/java/tagline/logic/commands/DeleteContactCommandTest.java b/src/test/java/tagline/logic/commands/DeleteContactCommandTest.java index adfbc79f592..c5a68344aed 100644 --- a/src/test/java/tagline/logic/commands/DeleteContactCommandTest.java +++ b/src/test/java/tagline/logic/commands/DeleteContactCommandTest.java @@ -8,7 +8,7 @@ import static tagline.logic.commands.CommandTestUtil.assertCommandFailure; import static tagline.logic.commands.CommandTestUtil.assertCommandSuccess; import static tagline.testutil.TypicalContacts.getTypicalAddressBook; -import static tagline.testutil.TypicalIndexes.INDEX_FIRST_CONTACT; +import static tagline.testutil.TypicalIndexes.INDEX_FIRST; import org.junit.jupiter.api.Test; @@ -32,7 +32,7 @@ public class DeleteContactCommandTest { @Test public void execute_validContactId_success() { - Contact contactToDelete = model.getAddressBook().getContactList().get(INDEX_FIRST_CONTACT.getZeroBased()); + Contact contactToDelete = model.getAddressBook().getContactList().get(INDEX_FIRST.getZeroBased()); DeleteContactCommand deleteContactCommand = new DeleteContactCommand(contactToDelete.getContactId()); String expectedMessage = String.format(DeleteContactCommand.MESSAGE_DELETE_CONTACT_SUCCESS, contactToDelete); @@ -46,7 +46,7 @@ public void execute_validContactId_success() { @Test public void execute_validContactIdButUnfiltered_success() { - Contact contactToDelete = model.getAddressBook().getContactList().get(INDEX_FIRST_CONTACT.getZeroBased()); + Contact contactToDelete = model.getAddressBook().getContactList().get(INDEX_FIRST.getZeroBased()); DeleteContactCommand deleteContactCommand = new DeleteContactCommand(contactToDelete.getContactId()); String expectedMessage = String.format(DeleteContactCommand.MESSAGE_DELETE_CONTACT_SUCCESS, contactToDelete); diff --git a/src/test/java/tagline/logic/commands/EditContactCommandTest.java b/src/test/java/tagline/logic/commands/EditContactCommandTest.java index e87bf0acda6..2a5f2178327 100644 --- a/src/test/java/tagline/logic/commands/EditContactCommandTest.java +++ b/src/test/java/tagline/logic/commands/EditContactCommandTest.java @@ -10,8 +10,8 @@ import static tagline.logic.commands.CommandTestUtil.assertCommandFailure; import static tagline.logic.commands.CommandTestUtil.assertCommandSuccess; import static tagline.testutil.TypicalContacts.getTypicalAddressBook; -import static tagline.testutil.TypicalIndexes.INDEX_FIRST_CONTACT; -import static tagline.testutil.TypicalIndexes.INDEX_SECOND_CONTACT; +import static tagline.testutil.TypicalIndexes.INDEX_FIRST; +import static tagline.testutil.TypicalIndexes.INDEX_SECOND; import org.junit.jupiter.api.Test; @@ -40,7 +40,7 @@ public class EditContactCommandTest { @Test public void execute_allFieldsSpecified_success() { - Contact originalContact = model.getAddressBook().getContactList().get(INDEX_FIRST_CONTACT.getZeroBased()); + Contact originalContact = model.getAddressBook().getContactList().get(INDEX_FIRST.getZeroBased()); Contact editedContact = new ContactBuilder().withId(originalContact.getContactId().toInteger()).build(); EditContactDescriptor descriptor = new EditContactDescriptorBuilder(editedContact).build(); @@ -80,7 +80,7 @@ public void execute_someFieldsSpecified_success() { @Test public void execute_noFieldSpecified_success() { - Contact editedContact = model.getFilteredContactList().get(INDEX_FIRST_CONTACT.getZeroBased()); + Contact editedContact = model.getFilteredContactList().get(INDEX_FIRST.getZeroBased()); EditContactCommand editContactCommand = new EditContactCommand(editedContact.getContactId(), new EditContactDescriptor()); @@ -95,8 +95,8 @@ public void execute_noFieldSpecified_success() { @Test public void execute_duplicateContact_failure() { var contactList = model.getAddressBook().getContactList(); - Contact firstContact = contactList.get(INDEX_FIRST_CONTACT.getZeroBased()); - Contact secondContact = contactList.get(INDEX_SECOND_CONTACT.getZeroBased()); + Contact firstContact = contactList.get(INDEX_FIRST.getZeroBased()); + Contact secondContact = contactList.get(INDEX_SECOND.getZeroBased()); EditContactDescriptor descriptor = new EditContactDescriptorBuilder(firstContact).build(); EditContactCommand editContactCommand = new EditContactCommand(secondContact.getContactId(), descriptor); diff --git a/src/test/java/tagline/logic/commands/ListContactCommandTest.java b/src/test/java/tagline/logic/commands/ListContactCommandTest.java index aa3f7f6b81c..3ccdb113f12 100644 --- a/src/test/java/tagline/logic/commands/ListContactCommandTest.java +++ b/src/test/java/tagline/logic/commands/ListContactCommandTest.java @@ -3,7 +3,7 @@ import static tagline.logic.commands.CommandTestUtil.assertCommandSuccess; import static tagline.logic.commands.CommandTestUtil.showContactAtIndex; import static tagline.testutil.TypicalContacts.getTypicalAddressBook; -import static tagline.testutil.TypicalIndexes.INDEX_FIRST_CONTACT; +import static tagline.testutil.TypicalIndexes.INDEX_FIRST; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -38,7 +38,7 @@ public void execute_listIsNotFiltered_showsSameList() { @Test public void execute_listIsFiltered_showsEverything() { - showContactAtIndex(model, INDEX_FIRST_CONTACT); + showContactAtIndex(model, INDEX_FIRST); assertCommandSuccess(new ListContactCommand(), model, ListContactCommand.MESSAGE_SUCCESS, LIST_CONTACT_COMMAND_VIEW_TYPE, expectedModel); } diff --git a/src/test/java/tagline/logic/commands/NoteCommandTestUtil.java b/src/test/java/tagline/logic/commands/NoteCommandTestUtil.java index c72a31ff9d1..b96f28851c6 100644 --- a/src/test/java/tagline/logic/commands/NoteCommandTestUtil.java +++ b/src/test/java/tagline/logic/commands/NoteCommandTestUtil.java @@ -3,9 +3,16 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static tagline.logic.parser.note.NoteCliSyntax.PREFIX_CONTENT; import static tagline.logic.parser.note.NoteCliSyntax.PREFIX_TITLE; +import static tagline.testutil.Assert.assertThrows; + +import java.util.ArrayList; +import java.util.List; import tagline.logic.commands.exceptions.CommandException; import tagline.model.Model; +import tagline.model.note.Note; +import tagline.model.note.NoteBook; +import tagline.model.note.NoteId; /** * Contains helper methods for testing commands. @@ -44,6 +51,8 @@ public class NoteCommandTestUtil { public static final String PREAMBLE_WHITESPACE = "\t \r \n"; public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble"; + public static final NoteId NON_EXISTING_NOTE_ID = new NoteId(99999); + /** * Executes the given {@code command}, confirms that
* - the returned {@link CommandResult} matches {@code expectedCommandResult}
@@ -69,4 +78,21 @@ public static void assertCommandSuccess(Command command, Model actualModel, Stri CommandResult expectedCommandResult = new CommandResult(expectedMessage); assertCommandSuccess(command, actualModel, expectedCommandResult, expectedModel); } + + /** + * Executes the given {@code command}, confirms that
+ * - a {@code CommandException} is thrown
+ * - the CommandException message matches {@code expectedMessage}
+ * - the note book, filtered note list and selected contact in {@code actualModel} remain unchanged + */ + public static void assertCommandFailure(Command command, Model actualModel, String expectedMessage) { + // we are unable to defensively copy the model for comparison later, so we can + // only do so by copying its components. + NoteBook expectedNoteBook = new NoteBook(actualModel.getNoteBook()); + List expectedFilteredList = new ArrayList<>(actualModel.getFilteredNoteList()); + + assertThrows(CommandException.class, expectedMessage, () -> command.execute(actualModel)); + assertEquals(expectedNoteBook, actualModel.getNoteBook()); + assertEquals(expectedFilteredList, actualModel.getFilteredNoteList()); + } } diff --git a/src/test/java/tagline/logic/commands/note/CreateNoteCommandTest.java b/src/test/java/tagline/logic/commands/note/CreateNoteCommandTest.java index 58a0632838c..efd64bdc32a 100644 --- a/src/test/java/tagline/logic/commands/note/CreateNoteCommandTest.java +++ b/src/test/java/tagline/logic/commands/note/CreateNoteCommandTest.java @@ -24,6 +24,7 @@ import tagline.model.contact.ContactId; import tagline.model.contact.ReadOnlyAddressBook; import tagline.model.note.Note; +import tagline.model.note.NoteId; import tagline.model.note.NoteModel; import tagline.model.note.ReadOnlyNoteBook; import tagline.testutil.NoteBuilder; @@ -146,6 +147,11 @@ public void setNote(Note target, Note editedNote) { throw new AssertionError("This method should not be called."); } + @Override + public Optional findNote(NoteId noteId) { + throw new AssertionError("This method should not be called."); + } + @Override public ObservableList getFilteredNoteList() { throw new AssertionError("This method should not be called."); @@ -313,6 +319,11 @@ public void setNote(Note target, Note editedNote) { throw new AssertionError("This method should not be called."); } + @Override + public Optional findNote(NoteId noteId) { + throw new AssertionError("This method should not be called."); + } + @Override public ObservableList getFilteredNoteList() { throw new AssertionError("This method should not be called."); diff --git a/src/test/java/tagline/logic/commands/note/DeleteNoteCommandTest.java b/src/test/java/tagline/logic/commands/note/DeleteNoteCommandTest.java new file mode 100644 index 00000000000..e1d7c62bbcd --- /dev/null +++ b/src/test/java/tagline/logic/commands/note/DeleteNoteCommandTest.java @@ -0,0 +1,80 @@ +package tagline.logic.commands.note; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static tagline.logic.commands.CommandResult.ViewType; +import static tagline.logic.commands.CommandTestUtil.assertCommandSuccess; +import static tagline.logic.commands.NoteCommandTestUtil.NON_EXISTING_NOTE_ID; +import static tagline.testutil.Assert.assertThrows; +import static tagline.testutil.TypicalIndexes.INDEX_FIRST; +import static tagline.testutil.TypicalNotes.getTypicalNoteBook; + +import org.junit.jupiter.api.Test; + +import tagline.commons.core.Messages; +import tagline.logic.commands.NoteCommandTestUtil; +import tagline.model.Model; +import tagline.model.ModelManager; +import tagline.model.UserPrefs; +import tagline.model.note.Note; +import tagline.model.note.NoteId; + +/** + * Contains integration tests (interaction with the Model) and unit tests for + * {@code DeleteNoteCommand}. + */ +class DeleteNoteCommandTest { + + private static final ViewType DELETE_NOTE_COMMAND_VIEW_TYPE = ViewType.NOTE; + private Model model = new ModelManager(getTypicalNoteBook(), new UserPrefs()); + + @Test + public void constructor_nullNote_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> new DeleteNoteCommand(null)); + } + + @Test + public void execute_validNoteIdUnfilteredList_success() { + Note noteToDelete = model.getNoteBook().getNoteList().get(INDEX_FIRST.getZeroBased()); + DeleteNoteCommand deleteNoteCommand = new DeleteNoteCommand(noteToDelete.getNoteId()); + + String expectedMessage = String.format(DeleteNoteCommand.MESSAGE_SUCCESS, noteToDelete); + + Model expectedModel = new ModelManager(model.getNoteBook(), new UserPrefs()); + expectedModel.deleteNote(noteToDelete); + + assertCommandSuccess(deleteNoteCommand, model, expectedMessage, DELETE_NOTE_COMMAND_VIEW_TYPE, expectedModel); + } + + @Test + public void execute_validNoteIdFilteredList_success() { + Note noteToDelete = model.getNoteBook().getNoteList().get(INDEX_FIRST.getZeroBased()); + DeleteNoteCommand deleteNoteCommand = new DeleteNoteCommand(noteToDelete.getNoteId()); + + String expectedMessage = String.format(DeleteNoteCommand.MESSAGE_SUCCESS, noteToDelete); + + Model expectedModel = new ModelManager(model.getNoteBook(), new UserPrefs()); + expectedModel.deleteNote(noteToDelete); + + showNoNote(model); + showNoNote(expectedModel); + + assertCommandSuccess(deleteNoteCommand, model, expectedMessage, DELETE_NOTE_COMMAND_VIEW_TYPE, expectedModel); + } + + @Test + public void execute_nonExistingNoteId_throwsCommandException() { + NoteId nonExistingNoteId = NON_EXISTING_NOTE_ID; + DeleteNoteCommand deleteNoteCommand = new DeleteNoteCommand(nonExistingNoteId); + + NoteCommandTestUtil.assertCommandFailure(deleteNoteCommand, model, Messages.MESSAGE_INVALID_NOTE_INDEX); + } + + /** + * Updates {@code model}'s filtered list to show no one. + */ + private void showNoNote(Model model) { + model.updateFilteredNoteList(p -> false); + + assertTrue(model.getFilteredNoteList().isEmpty()); + } +} diff --git a/src/test/java/tagline/logic/parser/ContactParserUtilTest.java b/src/test/java/tagline/logic/parser/ContactParserUtilTest.java index c92878d3953..6125c36c19a 100644 --- a/src/test/java/tagline/logic/parser/ContactParserUtilTest.java +++ b/src/test/java/tagline/logic/parser/ContactParserUtilTest.java @@ -3,7 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static tagline.logic.parser.contact.ContactParserUtil.MESSAGE_INVALID_INDEX; import static tagline.testutil.Assert.assertThrows; -import static tagline.testutil.TypicalIndexes.INDEX_FIRST_CONTACT; +import static tagline.testutil.TypicalIndexes.INDEX_FIRST; import org.junit.jupiter.api.Test; @@ -40,10 +40,10 @@ public void parseIndex_outOfRangeInput_throwsParseException() { @Test public void parseIndex_validInput_success() throws Exception { // No whitespaces - assertEquals(INDEX_FIRST_CONTACT, ContactParserUtil.parseIndex("1")); + assertEquals(INDEX_FIRST, ContactParserUtil.parseIndex("1")); // Leading and trailing whitespaces - assertEquals(INDEX_FIRST_CONTACT, ContactParserUtil.parseIndex(" 1 ")); + assertEquals(INDEX_FIRST, ContactParserUtil.parseIndex(" 1 ")); } @Test diff --git a/src/test/java/tagline/logic/parser/TagParserUtilTest.java b/src/test/java/tagline/logic/parser/TagParserUtilTest.java index dbdc96c57ad..6ebbcf8562c 100644 --- a/src/test/java/tagline/logic/parser/TagParserUtilTest.java +++ b/src/test/java/tagline/logic/parser/TagParserUtilTest.java @@ -1,6 +1,5 @@ package tagline.logic.parser; -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static tagline.testutil.Assert.assertThrows; @@ -33,14 +32,14 @@ public void parseTag_invalidValue_throwsParseException() { @Test public void parseTag_validValueWithoutWhitespace_returnsTag() throws Exception { Tag expectedTag = new ContactTag(new ContactId(VALID_TAG_1.substring(1))); - assertEquals(expectedTag, TagParserUtil.parseTag(VALID_TAG_1)); + assertTrue(expectedTag.isSameContent(TagParserUtil.parseTag(VALID_TAG_1))); } @Test public void parseTag_validValueWithWhitespace_returnsTrimmedTag() throws Exception { String tagWithWhitespace = WHITESPACE + VALID_TAG_1 + WHITESPACE; Tag expectedTag = new ContactTag(new ContactId(VALID_TAG_1.substring(1))); - assertEquals(expectedTag, TagParserUtil.parseTag(tagWithWhitespace)); + assertTrue(expectedTag.isSameContent(TagParserUtil.parseTag(tagWithWhitespace))); } @Test @@ -52,11 +51,11 @@ public void parseTags_collectionWithInvalidTags_throwsParseException() { } @Test - public void parseTags_emptyCollection_returnsEmptySet() throws Exception { + public void parseTags_emptyCollection_returnsEmptySet() { assertTrue(TagParserUtil.parseTags(Collections.emptyList()).isEmpty()); } @Test - public void parseTags_collectionWithValidTags_returnsTagSet() throws Exception { + public void parseTags_collectionWithValidTags_returnsTagSet() { } } diff --git a/src/test/java/tagline/model/contact/UniqueContactListTest.java b/src/test/java/tagline/model/contact/UniqueContactListTest.java index 6c1d39846f0..cd7385b45ec 100644 --- a/src/test/java/tagline/model/contact/UniqueContactListTest.java +++ b/src/test/java/tagline/model/contact/UniqueContactListTest.java @@ -22,38 +22,38 @@ public class UniqueContactListTest { private final UniqueContactList uniqueContactList = new UniqueContactList(); @Test - public void contains_nullContact_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> uniqueContactList.contains(null)); + public void containsContact_nullContact_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueContactList.containsContact(null)); } @Test - public void contains_contactNotInList_returnsFalse() { - assertFalse(uniqueContactList.contains(ALICE)); + public void containsContact_contactNotInList_returnsFalse() { + assertFalse(uniqueContactList.containsContact(ALICE)); } @Test - public void contains_contactInList_returnsTrue() { - uniqueContactList.add(ALICE); - assertTrue(uniqueContactList.contains(ALICE)); + public void containsContact_contactInList_returnsTrue() { + uniqueContactList.addContact(ALICE); + assertTrue(uniqueContactList.containsContact(ALICE)); } @Test - public void contains_contactWithSameIdentityFieldsInList_returnsTrue() { - uniqueContactList.add(ALICE); + public void containsContact_contactWithSameIdentityFieldsInList_returnsTrue() { + uniqueContactList.addContact(ALICE); Contact editedAlice = new ContactBuilder(ALICE).withAddress(VALID_ADDRESS_BOB) .build(); - assertTrue(uniqueContactList.contains(editedAlice)); + assertTrue(uniqueContactList.containsContact(editedAlice)); } @Test - public void add_nullContact_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> uniqueContactList.add(null)); + public void addContact_nullContact_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueContactList.addContact(null)); } @Test - public void add_duplicateContact_throwsDuplicateContactException() { - uniqueContactList.add(ALICE); - assertThrows(DuplicateContactException.class, () -> uniqueContactList.add(ALICE)); + public void addContact_duplicateContact_throwsDuplicateContactException() { + uniqueContactList.addContact(ALICE); + assertThrows(DuplicateContactException.class, () -> uniqueContactList.addContact(ALICE)); } @Test @@ -73,54 +73,54 @@ public void setContact_targetContactNotInList_throwsContactNotFoundException() { @Test public void setContact_editedContactIsSameContact_success() { - uniqueContactList.add(ALICE); + uniqueContactList.addContact(ALICE); uniqueContactList.setContact(ALICE, ALICE); UniqueContactList expectedUniqueContactList = new UniqueContactList(); - expectedUniqueContactList.add(ALICE); + expectedUniqueContactList.addContact(ALICE); assertEquals(expectedUniqueContactList, uniqueContactList); } @Test public void setContact_editedContactHasSameIdentity_success() { - uniqueContactList.add(ALICE); + uniqueContactList.addContact(ALICE); Contact editedAlice = new ContactBuilder(ALICE).withAddress(VALID_ADDRESS_BOB) .build(); uniqueContactList.setContact(ALICE, editedAlice); UniqueContactList expectedUniqueContactList = new UniqueContactList(); - expectedUniqueContactList.add(editedAlice); + expectedUniqueContactList.addContact(editedAlice); assertEquals(expectedUniqueContactList, uniqueContactList); } @Test public void setContact_editedContactHasDifferentIdentity_success() { - uniqueContactList.add(ALICE); + uniqueContactList.addContact(ALICE); uniqueContactList.setContact(ALICE, BOB); UniqueContactList expectedUniqueContactList = new UniqueContactList(); - expectedUniqueContactList.add(BOB); + expectedUniqueContactList.addContact(BOB); assertEquals(expectedUniqueContactList, uniqueContactList); } @Test public void setContact_editedContactHasNonUniqueIdentity_throwsDuplicateContactException() { - uniqueContactList.add(ALICE); - uniqueContactList.add(BOB); + uniqueContactList.addContact(ALICE); + uniqueContactList.addContact(BOB); assertThrows(DuplicateContactException.class, () -> uniqueContactList.setContact(ALICE, BOB)); } @Test - public void remove_nullContact_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> uniqueContactList.remove(null)); + public void removeContact_nullContact_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueContactList.removeContact(null)); } @Test - public void remove_contactDoesNotExist_throwsContactNotFoundException() { - assertThrows(ContactNotFoundException.class, () -> uniqueContactList.remove(ALICE)); + public void removeContact_contactDoesNotExist_throwsContactNotFoundException() { + assertThrows(ContactNotFoundException.class, () -> uniqueContactList.removeContact(ALICE)); } @Test - public void remove_existingContact_removesContact() { - uniqueContactList.add(ALICE); - uniqueContactList.remove(ALICE); + public void removeContact_existingContact_removesContact() { + uniqueContactList.addContact(ALICE); + uniqueContactList.removeContact(ALICE); UniqueContactList expectedUniqueContactList = new UniqueContactList(); assertEquals(expectedUniqueContactList, uniqueContactList); } @@ -132,9 +132,9 @@ public void setContacts_nullUniqueContactList_throwsNullPointerException() { @Test public void setContacts_uniqueContactList_replacesOwnListWithProvidedUniqueContactList() { - uniqueContactList.add(ALICE); + uniqueContactList.addContact(ALICE); UniqueContactList expectedUniqueContactList = new UniqueContactList(); - expectedUniqueContactList.add(BOB); + expectedUniqueContactList.addContact(BOB); uniqueContactList.setContacts(expectedUniqueContactList); assertEquals(expectedUniqueContactList, uniqueContactList); } @@ -146,11 +146,11 @@ public void setContacts_nullList_throwsNullPointerException() { @Test public void setContacts_list_replacesOwnListWithProvidedList() { - uniqueContactList.add(ALICE); + uniqueContactList.addContact(ALICE); List contactList = Collections.singletonList(BOB); uniqueContactList.setContacts(contactList); UniqueContactList expectedUniqueContactList = new UniqueContactList(); - expectedUniqueContactList.add(BOB); + expectedUniqueContactList.addContact(BOB); assertEquals(expectedUniqueContactList, uniqueContactList); } diff --git a/src/test/java/tagline/model/note/NoteManagerTest.java b/src/test/java/tagline/model/note/NoteManagerTest.java index 9d909946b4c..49f35610963 100644 --- a/src/test/java/tagline/model/note/NoteManagerTest.java +++ b/src/test/java/tagline/model/note/NoteManagerTest.java @@ -34,7 +34,7 @@ public void setUserPrefs_nullUserPrefs_throwsNullPointerException() { assertThrows(NullPointerException.class, () -> noteManager.setUserPrefs(null)); } - // TODO renable after userprefs is edited for Notes + // TODO re-enable after userprefs is edited for Notes //@Test //public void setUserPrefs_validUserPrefs_copiesUserPrefs() { // UserPrefs userPrefs = new UserPrefs(); diff --git a/src/test/java/tagline/model/note/UniqueNoteListTest.java b/src/test/java/tagline/model/note/UniqueNoteListTest.java index 718124d2e7f..be4eef8f3ad 100644 --- a/src/test/java/tagline/model/note/UniqueNoteListTest.java +++ b/src/test/java/tagline/model/note/UniqueNoteListTest.java @@ -22,22 +22,22 @@ public class UniqueNoteListTest { @Test public void contains_nullNote_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> uniqueNoteList.contains(null)); + assertThrows(NullPointerException.class, () -> uniqueNoteList.containsNote(null)); } @Test - public void contains_personNotInList_returnsFalse() { - assertFalse(uniqueNoteList.contains(PROTECTOR)); + public void containsNote_personNotInList_returnsFalse() { + assertFalse(uniqueNoteList.containsNote(PROTECTOR)); } @Test - public void contains_personInList_returnsTrue() { - uniqueNoteList.add(PROTECTOR); - assertTrue(uniqueNoteList.contains(PROTECTOR)); + public void containsNote_personInList_returnsTrue() { + uniqueNoteList.addNote(PROTECTOR); + assertTrue(uniqueNoteList.containsNote(PROTECTOR)); } @Test - public void contains_personWithSameIdentityFieldsInList_returnsTrue() { + public void containsNote_personWithSameIdentityFieldsInList_returnsTrue() { //uniqueNoteList.add(PROTECTOR); //Note editedProtector = new NoteBuilder(PROTECTOR).withTimeLastUpdated(VALID_TIMELASTUPDATED_INCIDENT) // .withTags(VALID_TAG_AVENGERS) @@ -46,14 +46,14 @@ public void contains_personWithSameIdentityFieldsInList_returnsTrue() { } @Test - public void add_nullNote_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> uniqueNoteList.add(null)); + public void addNote_nullNote_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueNoteList.addNote(null)); } @Test - public void add_duplicateNote_throwsDuplicateNoteException() { - uniqueNoteList.add(PROTECTOR); - assertThrows(DuplicateNoteException.class, () -> uniqueNoteList.add(PROTECTOR)); + public void addNote_duplicateNote_throwsDuplicateNoteException() { + uniqueNoteList.addNote(PROTECTOR); + assertThrows(DuplicateNoteException.class, () -> uniqueNoteList.addNote(PROTECTOR)); } @Test @@ -73,10 +73,10 @@ public void setNote_targetNoteNotInList_throwsNoteNotFoundException() { @Test public void setNote_editedNoteIsSameNote_success() { - uniqueNoteList.add(PROTECTOR); + uniqueNoteList.addNote(PROTECTOR); uniqueNoteList.setNote(PROTECTOR, PROTECTOR); UniqueNoteList expectedUniqueNoteList = new UniqueNoteList(); - expectedUniqueNoteList.add(PROTECTOR); + expectedUniqueNoteList.addNote(PROTECTOR); assertEquals(expectedUniqueNoteList, uniqueNoteList); } @@ -94,34 +94,34 @@ public void setNote_editedNoteHasSameIdentity_success() { @Test public void setNote_editedNoteHasDifferentIdentity_success() { - uniqueNoteList.add(PROTECTOR); + uniqueNoteList.addNote(PROTECTOR); uniqueNoteList.setNote(PROTECTOR, INCIDENT); UniqueNoteList expectedUniqueNoteList = new UniqueNoteList(); - expectedUniqueNoteList.add(INCIDENT); + expectedUniqueNoteList.addNote(INCIDENT); assertEquals(expectedUniqueNoteList, uniqueNoteList); } @Test public void setNote_editedNoteHasNonUniqueIdentity_throwsDuplicateNoteException() { - uniqueNoteList.add(PROTECTOR); - uniqueNoteList.add(INCIDENT); + uniqueNoteList.addNote(PROTECTOR); + uniqueNoteList.addNote(INCIDENT); assertThrows(DuplicateNoteException.class, () -> uniqueNoteList.setNote(PROTECTOR, INCIDENT)); } @Test - public void remove_nullNote_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> uniqueNoteList.remove(null)); + public void removeNote_nullNote_throwsNullPointerException() { + assertThrows(NullPointerException.class, () -> uniqueNoteList.removeNote(null)); } @Test - public void remove_personDoesNotExist_throwsNoteNotFoundException() { - assertThrows(NoteNotFoundException.class, () -> uniqueNoteList.remove(PROTECTOR)); + public void removeNote_personDoesNotExist_throwsNoteNotFoundException() { + assertThrows(NoteNotFoundException.class, () -> uniqueNoteList.removeNote(PROTECTOR)); } @Test - public void remove_existingNote_removesNote() { - uniqueNoteList.add(PROTECTOR); - uniqueNoteList.remove(PROTECTOR); + public void removeNote_existingNote_removesNote() { + uniqueNoteList.addNote(PROTECTOR); + uniqueNoteList.removeNote(PROTECTOR); UniqueNoteList expectedUniqueNoteList = new UniqueNoteList(); assertEquals(expectedUniqueNoteList, uniqueNoteList); } @@ -133,9 +133,9 @@ public void setNotes_nullUniqueNoteList_throwsNullPointerException() { @Test public void setNotes_uniqueNoteList_replacesOwnListWithProvidedUniqueNoteList() { - uniqueNoteList.add(PROTECTOR); + uniqueNoteList.addNote(PROTECTOR); UniqueNoteList expectedUniqueNoteList = new UniqueNoteList(); - expectedUniqueNoteList.add(INCIDENT); + expectedUniqueNoteList.addNote(INCIDENT); uniqueNoteList.setNotes(expectedUniqueNoteList); assertEquals(expectedUniqueNoteList, uniqueNoteList); } @@ -147,11 +147,11 @@ public void setNotes_nullList_throwsNullPointerException() { @Test public void setNotes_list_replacesOwnListWithProvidedList() { - uniqueNoteList.add(PROTECTOR); + uniqueNoteList.addNote(PROTECTOR); List personList = Collections.singletonList(INCIDENT); uniqueNoteList.setNotes(personList); UniqueNoteList expectedUniqueNoteList = new UniqueNoteList(); - expectedUniqueNoteList.add(INCIDENT); + expectedUniqueNoteList.addNote(INCIDENT); assertEquals(expectedUniqueNoteList, uniqueNoteList); } diff --git a/src/test/java/tagline/testutil/TypicalIndexes.java b/src/test/java/tagline/testutil/TypicalIndexes.java index a5388e03aab..eb51e5516be 100644 --- a/src/test/java/tagline/testutil/TypicalIndexes.java +++ b/src/test/java/tagline/testutil/TypicalIndexes.java @@ -6,7 +6,7 @@ * A utility class containing a list of {@code Index} objects to be used in tests. */ public class TypicalIndexes { - public static final Index INDEX_FIRST_CONTACT = Index.fromOneBased(1); - public static final Index INDEX_SECOND_CONTACT = Index.fromOneBased(2); - public static final Index INDEX_THIRD_CONTACT = Index.fromOneBased(3); + public static final Index INDEX_FIRST = Index.fromOneBased(1); + public static final Index INDEX_SECOND = Index.fromOneBased(2); + public static final Index INDEX_THIRD = Index.fromOneBased(3); }