Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Tag References #267

Merged
merged 1 commit into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import static java.util.Objects.requireNonNull;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import seedu.address.commons.core.index.Index;
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -148,24 +144,12 @@ public static Remark parseRemark(String remark) throws ParseException {
*
* @throws ParseException if the given {@code tag} is invalid.
*/
public static RoomTypeTag parseTag(String tag) throws ParseException {
public static RoomTypeTag parseRoomTypeTag(String tag) throws ParseException {
requireNonNull(tag);
String trimmedTag = tag.trim();
if (!RoomTypeTag.isValidRoomTypeTagName(trimmedTag)) {
throw new ParseException(RoomTypeTag.MESSAGE_CONSTRAINTS);
}
return new RoomTypeTag(trimmedTag);
}

/**
* Parses {@code Collection<String> tags} into a {@code Set<Tag>}.
*/
public static Set<RoomTypeTag> parseTags(Collection<String> tags) throws ParseException {
requireNonNull(tags);
final Set<RoomTypeTag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(parseTag(tagName));
}
return tagSet;
}
}
38 changes: 4 additions & 34 deletions src/test/java/seedu/address/logic/parser/ParserUtilTest.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
package seedu.address.logic.parser;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.parser.ParserUtil.MESSAGE_INVALID_INDEX;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.junit.jupiter.api.Test;

import seedu.address.logic.parser.exceptions.ParseException;
Expand Down Expand Up @@ -171,48 +165,24 @@ public void parseEmail_validValueWithWhitespace_returnsTrimmedEmail() throws Exc

@Test
public void parseTag_null_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> ParserUtil.parseTag(null));
assertThrows(NullPointerException.class, () -> ParserUtil.parseRoomTypeTag(null));
}

@Test
public void parseTag_invalidValue_throwsParseException() {
assertThrows(ParseException.class, () -> ParserUtil.parseTag(INVALID_TAG));
assertThrows(ParseException.class, () -> ParserUtil.parseRoomTypeTag(INVALID_TAG));
}

@Test
public void parseTag_validValueWithoutWhitespace_returnsTag() throws Exception {
RoomTypeTag expectedTag = new RoomTypeTag(VALID_TAG_1);
assertEquals(expectedTag, ParserUtil.parseTag(VALID_TAG_1));
assertEquals(expectedTag, ParserUtil.parseRoomTypeTag(VALID_TAG_1));
}

@Test
public void parseTag_validValueWithWhitespace_returnsTrimmedTag() throws Exception {
String tagWithWhitespace = WHITESPACE + VALID_TAG_1 + WHITESPACE;
RoomTypeTag expectedTag = new RoomTypeTag(VALID_TAG_1);
assertEquals(expectedTag, ParserUtil.parseTag(tagWithWhitespace));
}

@Test
public void parseTags_null_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> ParserUtil.parseTags(null));
}

@Test
public void parseTags_collectionWithInvalidTags_throwsParseException() {
assertThrows(ParseException.class, () -> ParserUtil.parseTags(Arrays.asList(VALID_TAG_1, INVALID_TAG)));
}

@Test
public void parseTags_emptyCollection_returnsEmptySet() throws Exception {
assertTrue(ParserUtil.parseTags(Collections.emptyList()).isEmpty());
}

@Test
public void parseTags_collectionWithValidTags_returnsTagSet() throws Exception {
Set<RoomTypeTag> actualTagSet = ParserUtil.parseTags(Arrays.asList(VALID_TAG_1, VALID_TAG_2));
Set<RoomTypeTag> expectedTagSet = new HashSet<RoomTypeTag>(Arrays.asList(new RoomTypeTag(VALID_TAG_1),
new RoomTypeTag(VALID_TAG_2)));

assertEquals(expectedTagSet, actualTagSet);
assertEquals(expectedTag, ParserUtil.parseRoomTypeTag(tagWithWhitespace));
}
}