Skip to content

Commit

Permalink
Remove unused prefixes from test classes
Browse files Browse the repository at this point in the history
  • Loading branch information
DESKTOP-CP7BI1I\Eujin committed Mar 20, 2024
1 parent 1775ae9 commit cf840f3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public AddCommand parse(String args) throws ParseException {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_IC);
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG));
Dob dob = ParserUtil.parseDob(argMultimap.getValue(PREFIX_DOB).orElse(null));
Expand Down
18 changes: 8 additions & 10 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class CommandTestUtil {

public static final String VALID_NAME_AMY = "Amy Bee";
public static final String VALID_NAME_BOB = "Bob Choo";
public static final String VALID_TAG_HUSBAND = "husband";
public static final String VALID_TAG_FRIEND = "friend";
public static final String VALID_TAG_FALL_RISK = "Fall risk";
public static final String VALID_TAG_DIABETES = "Diabetes";
public static final String VALID_DOB_AMY = "02/02/2012";
public static final String VALID_DOB_BOB = "01/01/2010";
public static final String VALID_IC_AMY = "M1111111W";
Expand All @@ -46,8 +46,8 @@ public class CommandTestUtil {
// description + value
public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY;
public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB;
public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND;
public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND;
public static final String TAG_DESC_DIABETES = " " + PREFIX_TAG + VALID_TAG_DIABETES;
public static final String TAG_DESC_FALL_RISK = " " + PREFIX_TAG + VALID_TAG_FALL_RISK;
public static final String DOB_DESC_AMY = " " + PREFIX_DOB + VALID_DOB_AMY;
public static final String DOB_DESC_BOB = " " + PREFIX_DOB + VALID_DOB_BOB;
public static final String IC_DESC_AMY = " " + PREFIX_IC + VALID_IC_AMY;
Expand All @@ -58,8 +58,7 @@ public class CommandTestUtil {
public static final String WARD_DESC_BOB = " " + PREFIX_WARD + VALID_WARD_BOB;

public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "diabetes*"; // '*' not allowed in tags

public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";
Expand All @@ -68,11 +67,10 @@ public class CommandTestUtil {
public static final EditCommand.EditPersonDescriptor DESC_BOB;

static {
DESC_AMY = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY)
.withAddress(VALID_ADDRESS_AMY).withTags(VALID_TAG_FRIEND).build();
DESC_AMY = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY).withWard(VALID_WARD_AMY)
.withTags(VALID_TAG_DIABETES).build();
DESC_BOB = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
.withAddress(VALID_ADDRESS_BOB)
.withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build();
.withTags(VALID_TAG_FALL_RISK, VALID_TAG_DIABETES).build();
}

/**
Expand Down
77 changes: 29 additions & 48 deletions src/test/java/seedu/address/logic/parser/EditCommandParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@
import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_TAG_DESC;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_FRIEND;
import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_HUSBAND;
import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_DIABETES;
import static seedu.address.logic.commands.CommandTestUtil.TAG_DESC_FALL_RISK;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_FRIEND;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.logic.commands.CommandTestUtil.VALID_DOB_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_DOB_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_IC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_IC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADMISSION_DATE_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADMISSION_DATE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.String VALID_WARD_AMY;
import static seedu.address.logic.commands.CommandTestUtil.String VALID_WARD_BOB;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB;
Expand Down Expand Up @@ -76,29 +82,25 @@ public void parse_invalidValue_failure() {
assertParseFailure(parser, "1" + INVALID_NAME_DESC, Name.MESSAGE_CONSTRAINTS); // invalid name
assertParseFailure(parser, "1" + INVALID_TAG_DESC, Tag.MESSAGE_CONSTRAINTS); // invalid tag

// invalid phone followed by valid email
assertParseFailure(parser, "1" + INVALID_PHONE_DESC + EMAIL_DESC_AMY, Phone.MESSAGE_CONSTRAINTS);

// while parsing {@code PREFIX_TAG} alone will reset the tags of the {@code Person} being edited,
// parsing it together with a valid tag results in error
assertParseFailure(parser, "1" + TAG_DESC_FRIEND + TAG_DESC_HUSBAND + TAG_EMPTY, Tag.MESSAGE_CONSTRAINTS);
assertParseFailure(parser, "1" + TAG_DESC_FRIEND + TAG_EMPTY + TAG_DESC_HUSBAND, Tag.MESSAGE_CONSTRAINTS);
assertParseFailure(parser, "1" + TAG_EMPTY + TAG_DESC_FRIEND + TAG_DESC_HUSBAND, Tag.MESSAGE_CONSTRAINTS);
assertParseFailure(parser, "1" + TAG_DESC_DIABETES + TAG_DESC_FALL_RISK + TAG_EMPTY, Tag.MESSAGE_CONSTRAINTS);
assertParseFailure(parser, "1" + TAG_DESC_DIABETES + TAG_EMPTY + TAG_DESC_FALL_RISK, Tag.MESSAGE_CONSTRAINTS);
assertParseFailure(parser, "1" + TAG_EMPTY + TAG_DESC_DIABETES + TAG_DESC_FALL_RISK, Tag.MESSAGE_CONSTRAINTS);

// multiple invalid values, but only the first invalid value is captured
assertParseFailure(parser, "1" + INVALID_NAME_DESC + INVALID_EMAIL_DESC + VALID_ADDRESS_AMY + VALID_PHONE_AMY,
assertParseFailure(parser, "1" + INVALID_NAME_DESC + INVALID_TAG_DESC,
Name.MESSAGE_CONSTRAINTS);
}

@Test
public void parse_allFieldsSpecified_success() {
Index targetIndex = INDEX_SECOND_PERSON;
String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + TAG_DESC_HUSBAND
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY + NAME_DESC_AMY + TAG_DESC_FRIEND;
String userInput = targetIndex.getOneBased() + TAG_DESC_FALL_RISK
+ NAME_DESC_AMY + TAG_DESC_DIABETES;

EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY)
.withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY)
.withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build();
.withTags(TAG_DESC_FALL_RISK, TAG_DESC_DIABETES).build();
EditCommand expectedCommand = new EditCommand(targetIndex, descriptor);

assertParseSuccess(parser, userInput, expectedCommand);
Expand All @@ -107,10 +109,9 @@ public void parse_allFieldsSpecified_success() {
@Test
public void parse_someFieldsSpecified_success() {
Index targetIndex = INDEX_FIRST_PERSON;
String userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + EMAIL_DESC_AMY;
String userInput = targetIndex.getOneBased();

EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().withPhone(VALID_PHONE_BOB)
.withEmail(VALID_EMAIL_AMY).build();
EditPersonDescriptor descriptor = new EditPersonDescriptorBuilder().build();
EditCommand expectedCommand = new EditCommand(targetIndex, descriptor);

assertParseSuccess(parser, userInput, expectedCommand);
Expand All @@ -125,27 +126,9 @@ public void parse_oneFieldSpecified_success() {
EditCommand expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

// phone
userInput = targetIndex.getOneBased() + PHONE_DESC_AMY;
descriptor = new EditPersonDescriptorBuilder().withPhone(VALID_PHONE_AMY).build();
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

// email
userInput = targetIndex.getOneBased() + EMAIL_DESC_AMY;
descriptor = new EditPersonDescriptorBuilder().withEmail(VALID_EMAIL_AMY).build();
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

// address
userInput = targetIndex.getOneBased() + ADDRESS_DESC_AMY;
descriptor = new EditPersonDescriptorBuilder().withAddress(VALID_ADDRESS_AMY).build();
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

// tags
userInput = targetIndex.getOneBased() + TAG_DESC_FRIEND;
descriptor = new EditPersonDescriptorBuilder().withTags(VALID_TAG_FRIEND).build();
descriptor = new EditPersonDescriptorBuilder().withTags(TAG_DESC_DIABETES).build();
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);
}
Expand All @@ -157,29 +140,27 @@ public void parse_multipleRepeatedFields_failure() {

// valid followed by invalid
Index targetIndex = INDEX_FIRST_PERSON;
String userInput = targetIndex.getOneBased() + INVALID_PHONE_DESC + PHONE_DESC_BOB;
String userInput = targetIndex.getOneBased() + VALID_NAME_AMY + INVALID_TAG_DESC;

assertParseFailure(parser, userInput, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE));
assertParseFailure(parser, userInput, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_TAG));

// invalid followed by valid
userInput = targetIndex.getOneBased() + PHONE_DESC_BOB + INVALID_PHONE_DESC;
userInput = targetIndex.getOneBased() + INVALID_TAG_DESC + VALID_DOB_AMY;

assertParseFailure(parser, userInput, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE));
assertParseFailure(parser, userInput, Messages.getErrorMessageForDuplicatePrefixes(PREFIX_TAG));

// mulltiple valid fields repeated
userInput = targetIndex.getOneBased() + PHONE_DESC_AMY + ADDRESS_DESC_AMY + EMAIL_DESC_AMY
+ TAG_DESC_FRIEND + PHONE_DESC_AMY + ADDRESS_DESC_AMY + EMAIL_DESC_AMY + TAG_DESC_FRIEND
+ PHONE_DESC_BOB + ADDRESS_DESC_BOB + EMAIL_DESC_BOB + TAG_DESC_HUSBAND;
userInput = targetIndex.getOneBased() + TAG_DESC_DIABETES + TAG_DESC_FALL_RISK
+ WARD_DESC_AMY + WARD_DESC_BOB + DOB_DESC_AMY + DOB_DESC_BOB;

assertParseFailure(parser, userInput,
Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS));
Messages.getErrorMessageForDuplicatePrefixes(PREFIX_DOB, PREFIX_WARD, PREFIX_TAG));

// multiple invalid values
userInput = targetIndex.getOneBased() + INVALID_PHONE_DESC + INVALID_ADDRESS_DESC + INVALID_EMAIL_DESC
+ INVALID_PHONE_DESC + INVALID_ADDRESS_DESC + INVALID_EMAIL_DESC;
userInput = targetIndex.getOneBased() + INVALID_TAG_DESC;

assertParseFailure(parser, userInput,
Messages.getErrorMessageForDuplicatePrefixes(PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS));
Messages.getErrorMessageForDuplicatePrefixes(PREFIX_TAG));
}

@Test
Expand Down
56 changes: 0 additions & 56 deletions src/test/java/seedu/address/model/person/AddressTest.java

This file was deleted.

88 changes: 0 additions & 88 deletions src/test/java/seedu/address/model/person/EmailTest.java

This file was deleted.

Loading

0 comments on commit cf840f3

Please sign in to comment.