Skip to content

Commit

Permalink
Merge pull request #93 from ZShunRen/remark-test-dev
Browse files Browse the repository at this point in the history
Add tests + fix build.gradle file
  • Loading branch information
ZShunRen authored Oct 17, 2024
2 parents a7bbdfc + 7c7b444 commit d52a45b
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 13 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dependencies {
implementation group: 'org.openjfx', name: 'javafx-web', version: javaFxVersion, classifier: 'win'
implementation group: 'org.openjfx', name: 'javafx-web', version: javaFxVersion, classifier: 'mac'
implementation group: 'org.openjfx', name: 'javafx-web', version: javaFxVersion, classifier: 'linux'
implementation group: 'org.openjfx', name: 'javafx-media' , version:javaFxVersion, classifier: 'win'

implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.7.0'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.7.4'
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,9 @@ public static Remark parseNewRemark(String remark) throws ParseException {
requireNonNull(remark);
String trimmedRemark = remark.trim();
if (!Remark.isValidRemark(trimmedRemark)) {
System.out.println("exception thrown");
throw new ParseException(Remark.MESSAGE_CONSTRAINTS);
}
System.out.println(trimmedRemark);
return new Remark(trimmedRemark);
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/java/seedu/address/ui/CommandBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ private void handleCommandEntered() {
commandExecutor.execute(commandText);
commandTextArea.setText("");
} catch (CommandException | ParseException e) {
commandTextArea.setText(commandText.replace("\n", ""));
setStyleToIndicateCommandFailure();
commandTextArea.positionCaret(commandText.length() - 1);
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NEW_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_REMARK;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIER;
import static seedu.address.testutil.Assert.assertThrows;

Expand Down Expand Up @@ -40,7 +41,7 @@ public class CommandTestUtil {
public static final String VALID_JOB_AMY = "Teacher";
public static final String VALID_JOB_BOB = "Developer";
public static final String VALID_INCOME_AMY = "999999999";
public static final String VALID_INCOME_BOB = "9";
public static final String VALID_INCOME_BOB = "0";
public static final String VALID_TIER_REJECT = "REJECT";
public static final String VALID_TIER_GOLD = "GOLD";

Expand All @@ -56,6 +57,7 @@ public class CommandTestUtil {
public static final String JOB_DESC_BOB = " " + PREFIX_JOB + VALID_JOB_BOB;
public static final String INCOME_DESC_AMY = " " + PREFIX_INCOME + VALID_INCOME_AMY;
public static final String INCOME_DESC_BOB = " " + PREFIX_INCOME + VALID_INCOME_BOB;

public static final String TIER_DESC_REJECT = " " + PREFIX_TIER + VALID_TIER_REJECT;
public static final String TIER_DESC_GOLD = " " + PREFIX_TIER + VALID_TIER_GOLD;

Expand All @@ -67,14 +69,16 @@ public class CommandTestUtil {
public static final String INVALID_INCOME_DESC = " " + PREFIX_INCOME + "-999"; // negative numbers should not be
// allowed
public static final String INVALID_TIER_DESC = " " + PREFIX_TIER + "platinum"; // not one of the 4 TierEnums
public static final String INVALID_REMARK_DESC = " " + PREFIX_REMARK;
public static final String INVALID_NEW_REMARK_DESC = " " + PREFIX_NEW_REMARK;
public static final String INVALID_APPEND_REMARK_DESC = " " + PREFIX_APPEND_REMARK;

public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";

public static final String VALID_REMARK_AMY = "Like skiing.";
public static final String VALID_REMARK_BOB = "Favourite pastime: Eating";
public static final String REMARK_DESC_BOB = " " + PREFIX_NEW_REMARK + VALID_REMARK_BOB;

public static final String NEW_REMARK_DESC_BOB = " " + PREFIX_NEW_REMARK + VALID_REMARK_BOB;
public static final String APPEND_REMARK_DESC_BOB = " " + PREFIX_APPEND_REMARK + VALID_REMARK_BOB;

public static final EditCommand.EditPersonDescriptor DESC_AMY;
Expand Down Expand Up @@ -134,6 +138,7 @@ public static void assertCommandFailure(Command command, Model actualModel, Stri
assertEquals(expectedAddressBook, actualModel.getAddressBook());
assertEquals(expectedFilteredList, actualModel.getFilteredPersonList());
}

/**
* Updates {@code model}'s filtered list to show only the person at the given {@code targetIndex} in the
* {@code model}'s address book.
Expand Down
37 changes: 31 additions & 6 deletions src/test/java/seedu/address/logic/parser/AddCommandParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
import static seedu.address.logic.commands.CommandTestUtil.INVALID_JOB_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_PHONE_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_REMARK_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_TIER_DESC;
import static seedu.address.logic.commands.CommandTestUtil.JOB_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.JOB_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.NEW_REMARK_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.PREAMBLE_NON_EMPTY;
Expand All @@ -26,6 +28,8 @@
import static seedu.address.logic.commands.CommandTestUtil.TIER_DESC_REJECT;
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_INCOME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_JOB_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_TIER_GOLD;
Expand Down Expand Up @@ -64,7 +68,8 @@ public void parse_allFieldsPresent_success() {

// whitespace only preamble
assertParseSuccess(parser, PREAMBLE_WHITESPACE + NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB
+ ADDRESS_DESC_BOB + JOB_DESC_BOB + INCOME_DESC_BOB + TIER_DESC_GOLD, new AddCommand(expectedPerson));
+ ADDRESS_DESC_BOB + JOB_DESC_BOB + INCOME_DESC_BOB + TIER_DESC_GOLD + NEW_REMARK_DESC_BOB,
new AddCommand(expectedPerson));
}


Expand Down Expand Up @@ -144,23 +149,38 @@ public void parse_compulsoryFieldMissing_failure() {
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE);

// missing name prefix
assertParseFailure(parser, VALID_NAME_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB,
assertParseFailure(parser, VALID_NAME_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ JOB_DESC_BOB + INCOME_DESC_BOB,
expectedMessage);

// missing phone prefix
assertParseFailure(parser, NAME_DESC_BOB + VALID_PHONE_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB,
assertParseFailure(parser, NAME_DESC_BOB + VALID_PHONE_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ JOB_DESC_BOB + INCOME_DESC_BOB,
expectedMessage);

// missing email prefix
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + VALID_EMAIL_BOB + ADDRESS_DESC_BOB,
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + VALID_EMAIL_BOB + ADDRESS_DESC_BOB
+ JOB_DESC_BOB + INCOME_DESC_BOB,
expectedMessage);

// missing address prefix
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VALID_ADDRESS_BOB,
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VALID_ADDRESS_BOB
+ JOB_DESC_BOB + INCOME_DESC_BOB,
expectedMessage);

// missing job prefix
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ VALID_JOB_BOB + INCOME_DESC_BOB,
expectedMessage);

// missing income prefix
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ JOB_DESC_BOB + VALID_INCOME_BOB,
expectedMessage);

// all prefixes missing
assertParseFailure(parser, VALID_NAME_BOB + VALID_PHONE_BOB + VALID_EMAIL_BOB + VALID_ADDRESS_BOB,
assertParseFailure(parser, VALID_NAME_BOB + VALID_PHONE_BOB + VALID_EMAIL_BOB + VALID_ADDRESS_BOB
+ VALID_JOB_BOB + VALID_INCOME_BOB,
expectedMessage);
}

Expand Down Expand Up @@ -194,6 +214,11 @@ public void parse_invalidValue_failure() {
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ INCOME_DESC_BOB + JOB_DESC_BOB + INVALID_TIER_DESC + VALID_TIER_GOLD, Tier.MESSAGE_CONSTRAINTS);

// invalid remark
assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB
+ INCOME_DESC_BOB + JOB_DESC_BOB + TIER_DESC_GOLD + INVALID_REMARK_DESC, Tier.MESSAGE_CONSTRAINTS);


// two invalid values, only first invalid value reported
assertParseFailure(parser, INVALID_NAME_DESC + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ADDRESS_DESC
+ INCOME_DESC_BOB + JOB_DESC_BOB, Name.MESSAGE_CONSTRAINTS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,30 @@
import static seedu.address.logic.commands.CommandTestUtil.APPEND_REMARK_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.INCOME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.INCOME_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_ADDRESS_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_APPEND_REMARK_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_EMAIL_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_INCOME_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_NAME_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_NEW_REMARK_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_PHONE_DESC;
import static seedu.address.logic.commands.CommandTestUtil.INVALID_TIER_DESC;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NEW_REMARK_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.REMARK_DESC_BOB;
import static seedu.address.logic.commands.CommandTestUtil.TIER_DESC_GOLD;
import static seedu.address.logic.commands.CommandTestUtil.TIER_DESC_REJECT;
import static seedu.address.logic.commands.CommandTestUtil.VALID_ADDRESS_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_EMAIL_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_INCOME_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_INCOME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_AMY;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_REMARK_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TIER_GOLD;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TIER_REJECT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
Expand All @@ -42,8 +50,10 @@
import seedu.address.logic.commands.EditCommand.EditPersonDescriptor;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Income;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
import seedu.address.model.person.Remark;
import seedu.address.model.tier.Tier;
import seedu.address.testutil.EditPersonDescriptorBuilder;

Expand Down Expand Up @@ -89,6 +99,13 @@ public void parse_invalidValue_failure() {
assertParseFailure(parser, "1" + INVALID_PHONE_DESC, Phone.MESSAGE_CONSTRAINTS); // invalid phone
assertParseFailure(parser, "1" + INVALID_EMAIL_DESC, Email.MESSAGE_CONSTRAINTS); // invalid email
assertParseFailure(parser, "1" + INVALID_ADDRESS_DESC, Address.MESSAGE_CONSTRAINTS); // invalid address
assertParseFailure(parser, "1" + INVALID_INCOME_DESC, Income.MESSAGE_CONSTRAINTS);
// invalid new remark which is negative
assertParseFailure(parser, "1" + INVALID_NEW_REMARK_DESC, Remark.MESSAGE_CONSTRAINTS);
// invalid new remark which is empty
assertParseFailure(parser, "1" + INVALID_APPEND_REMARK_DESC, Remark.MESSAGE_CONSTRAINTS);
// invalid appended remark which is empty

// 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, Name.MESSAGE_CONSTRAINTS);
Expand Down Expand Up @@ -155,11 +172,35 @@ public void parse_oneFieldSpecified_success() {
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

// tags
// income
userInput = targetIndex.getOneBased() + INCOME_DESC_AMY;
descriptor = new EditPersonDescriptorBuilder().withIncome(Integer.parseInt(VALID_INCOME_AMY)).build();
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

// income but 0 dollars
userInput = targetIndex.getOneBased() + INCOME_DESC_BOB;
descriptor = new EditPersonDescriptorBuilder().withIncome(Integer.parseInt(VALID_INCOME_BOB)).build();
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);
// tier
userInput = targetIndex.getOneBased() + TIER_DESC_GOLD;
descriptor = new EditPersonDescriptorBuilder().withTier(VALID_TIER_GOLD).build();
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

// new remark
userInput = targetIndex.getOneBased() + NEW_REMARK_DESC_BOB;
descriptor = new EditPersonDescriptorBuilder().withNewRemark(VALID_REMARK_BOB).build();
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

// remark append
userInput = targetIndex.getOneBased() + APPEND_REMARK_DESC_BOB;
descriptor = new EditPersonDescriptorBuilder().withAppendedRemark(VALID_REMARK_BOB).build();
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

}

@Test
Expand Down Expand Up @@ -208,10 +249,11 @@ public void parse_resetTags_success() {
@Test
public void parse_remarkNewRemarkAppend_failure() {
Index targetIndex = INDEX_FIRST_PERSON;
String userInput = targetIndex.getOneBased() + APPEND_REMARK_DESC_BOB + REMARK_DESC_BOB;
String userInput = targetIndex.getOneBased() + APPEND_REMARK_DESC_BOB + NEW_REMARK_DESC_BOB;
assertParseFailure(parser, userInput,
String.format(MESSAGE_INVALID_COMMAND_FORMAT,
Messages.MESSAGE_CONCURRENT_RN_RA_FIELDS + EditCommand.MESSAGE_USAGE));

}

}

0 comments on commit d52a45b

Please sign in to comment.