From 636bc26ceef2711e01fd04a1cd6ecaed1aaacdcd Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Tue, 3 Oct 2023 21:55:47 +0800 Subject: [PATCH 01/12] Basic Functionality of Claim Works Just left the JavaDoc and the test cases --- .../java/seedu/address/logic/Messages.java | 1 + .../address/logic/commands/ClaimCommand.java | 70 +++++++++++++++++++ .../logic/parser/AddressBookParser.java | 4 ++ .../logic/parser/ClaimCommandParser.java | 36 ++++++++++ .../seedu/address/logic/parser/CliSyntax.java | 1 + .../logic/parser/EditCommandParser.java | 10 +-- .../address/logic/parser/ParserUtil.java | 19 +++-- .../seedu/address/model/person/Claim.java | 31 ++++++++ 8 files changed, 156 insertions(+), 16 deletions(-) create mode 100644 src/main/java/seedu/address/logic/commands/ClaimCommand.java create mode 100644 src/main/java/seedu/address/logic/parser/ClaimCommandParser.java create mode 100644 src/main/java/seedu/address/model/person/Claim.java diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 7f9e17148e7..bc87a6f0262 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -18,6 +18,7 @@ public class Messages { public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; public static final String MESSAGE_DUPLICATE_FIELDS = "Multiple values specified for the following single-valued field(s): "; + public static final String MESSAGE_OVER_CLAIM = "Claim is REJECTED as the amount is greater than the funds the Employee currently has!"; /** * Returns an error message indicating the duplicate prefixes. diff --git a/src/main/java/seedu/address/logic/commands/ClaimCommand.java b/src/main/java/seedu/address/logic/commands/ClaimCommand.java new file mode 100644 index 00000000000..29cc4ff0741 --- /dev/null +++ b/src/main/java/seedu/address/logic/commands/ClaimCommand.java @@ -0,0 +1,70 @@ +package seedu.address.logic.commands; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.person.Money; +import seedu.address.model.person.Person; + +import java.util.List; + +import static java.util.Objects.requireNonNull; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; + +public class ClaimCommand extends Command { + + public static final String COMMAND_WORD = "claim"; + public static final String MESSAGE_EMPTY = "Kindly state the index and amount that the employee hopes to process!"; + public static final String AMOUNT_EMPTY = "Kindly state the amount that the employee hopes to process!"; + public static final String CLAIM_SUCCESS = "Claim has been successfully processed!\n"; + + private final Index index; + private final Boolean isSubtract; + private final long amount; + + public ClaimCommand(Index index, Boolean isSubtract, long amount) { + this.index = index; + this.isSubtract = isSubtract; + this.amount = amount; + } + + @Override + public CommandResult execute(Model model) throws CommandException { + requireNonNull(model); + List lastShownList = model.getFilteredPersonList(); + + if (index.getZeroBased() >= lastShownList.size()) { + throw new CommandException(Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX); + } + + Person personToEdit = lastShownList.get(index.getZeroBased()); + long prevClaimBudget = Integer.parseInt(personToEdit.getClaimBudget().amount); + Money claimBudget = calculateNewClaimBudget(prevClaimBudget); + Person editedPerson = postClaimPerson(personToEdit, claimBudget); + + model.setPerson(personToEdit, editedPerson); + model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); + + return new CommandResult(String.format("%s Remaining claim %s has: %s", CLAIM_SUCCESS, editedPerson.getName(), claimBudget)); + } + + private Money calculateNewClaimBudget(long prevClaimBudget) throws CommandException{ + if (this.isSubtract && (this.amount > prevClaimBudget)) { + throw new CommandException(Messages.MESSAGE_OVER_CLAIM); + } + long newClaimBudget; + if (this.isSubtract) { + newClaimBudget = prevClaimBudget - this.amount; + } else { + newClaimBudget = prevClaimBudget + this.amount; + } + return new Money(String.valueOf(newClaimBudget)); + } + + private Person postClaimPerson(Person personToEdit, Money claimBudget) { + return new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), + personToEdit.getAddress(), personToEdit.getSalary(), claimBudget, + personToEdit.getDepartment(), personToEdit.getDob()); + } +} diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 3149ee07e0b..cb775794bae 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -17,6 +17,7 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; +import seedu.address.logic.commands.ClaimCommand; import seedu.address.logic.parser.exceptions.ParseException; /** @@ -77,6 +78,9 @@ public Command parseCommand(String userInput) throws ParseException { case HelpCommand.COMMAND_WORD: return new HelpCommand(); + case ClaimCommand.COMMAND_WORD: + return new ClaimCommandParser().parse(arguments); + default: logger.finer("This user input caused a ParseException: " + userInput); throw new ParseException(MESSAGE_UNKNOWN_COMMAND); diff --git a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java new file mode 100644 index 00000000000..b918f31b8c5 --- /dev/null +++ b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java @@ -0,0 +1,36 @@ +package seedu.address.logic.parser; + +import seedu.address.commons.core.index.Index; +import seedu.address.logic.commands.AddCommand; +import seedu.address.logic.commands.ClaimCommand; +import seedu.address.logic.commands.EditCommand; +import seedu.address.logic.parser.exceptions.ParseException; +import seedu.address.model.person.Claim; + +import static java.util.Objects.requireNonNull; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.*; +public class ClaimCommandParser implements Parser { + + public ClaimCommand parse(String args) throws ParseException { + requireNonNull(args); + ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_CLAIM_AMOUNT); + + Index index; + Claim claim; + + try { + index = ParserUtil.parseIndex(argMultimap.getPreamble()); + } catch (ParseException pe) { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ClaimCommand.MESSAGE_EMPTY), pe); + } + + if (argMultimap.getValue(PREFIX_CLAIM_AMOUNT).isPresent()) { + claim = ParserUtil.parseClaim(argMultimap.getValue(PREFIX_CLAIM_AMOUNT).get()); + } else { + throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, ClaimCommand.AMOUNT_EMPTY)); + } + + return new ClaimCommand(index, claim.isSubtract, claim.amount); + } +} diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index be594563301..e5871c51bbc 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -15,4 +15,5 @@ public class CliSyntax { public static final Prefix PREFIX_DEPARTMENT = new Prefix("d/"); public static final Prefix PREFIX_DOB = new Prefix("dob/"); public static final Prefix PREFIX_TAG = new Prefix("t/"); + public static final Prefix PREFIX_CLAIM_AMOUNT = new Prefix("$/"); } diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index cd188e56043..1dff1f6146d 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -2,14 +2,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; -import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_BUDGET; -import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB; -import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY; +import static seedu.address.logic.parser.CliSyntax.*; import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.EditCommand; @@ -71,7 +64,6 @@ public EditCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_DOB).isPresent()) { editPersonDescriptor.setDob(ParserUtil.parseDob(argMultimap.getValue(PREFIX_DOB).get())); } - if (!editPersonDescriptor.isAnyFieldEdited()) { throw new ParseException(EditCommand.MESSAGE_NOT_EDITED); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 09771c09d18..262a5a74908 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -9,13 +9,7 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Address; -import seedu.address.model.person.Birthday; -import seedu.address.model.person.Department; -import seedu.address.model.person.Email; -import seedu.address.model.person.Money; -import seedu.address.model.person.Name; -import seedu.address.model.person.Phone; +import seedu.address.model.person.*; import seedu.address.model.tag.Tag; /** @@ -143,6 +137,17 @@ public static Birthday parseDob(String dob) throws ParseException { return new Birthday(trimmed); } + public static Claim parseClaim(String claimAmount) throws ParseException { + requireNonNull(claimAmount); + String trimmed = claimAmount.trim(); + if (!Claim.comtainsSymbol(trimmed)) { + throw new ParseException(Claim.NO_SYMBOLS_ERROR); + } else if (!Claim.isCorrectAmountType(trimmed)) { + throw new ParseException(Claim.ALPHABETS_ERROR); + } + return new Claim(trimmed); + } + /** * Parses a {@code String tag} into a {@code Tag}. * Leading and trailing whitespaces will be trimmed. diff --git a/src/main/java/seedu/address/model/person/Claim.java b/src/main/java/seedu/address/model/person/Claim.java new file mode 100644 index 00000000000..97ba2a687a3 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Claim.java @@ -0,0 +1,31 @@ +package seedu.address.model.person; + +import java.util.Objects; + +public class Claim { + public static final String NO_SYMBOLS_ERROR = "Kindly state whether the employee wants to deduct/add the claim amount! Provide either +/- in front of the amount!"; + public static final String ALPHABETS_ERROR = "Kindly only input integers for the claim amount!"; + + public final boolean isSubtract; + public final int amount; + + public Claim(String numStr) { + char firstChar = numStr.charAt(0); + if (firstChar == '+') { + this.isSubtract = false; + } else { + this.isSubtract = true; + } + this.amount = Integer.parseInt(numStr.substring(1)); + } + + public static boolean comtainsSymbol(String args) { + char firstChar = args.charAt(0); + return firstChar == '+' || firstChar == '-'; + } + + public static boolean isCorrectAmountType(String args) { + String amount = args.substring(1); + return amount.matches("\\d+"); + } +} From d47df6261116ea7f723aa9155629c40cade2c681 Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Fri, 6 Oct 2023 22:35:44 +0800 Subject: [PATCH 02/12] Added JavaDoc Comments for my code --- .classpath | 32 +++++++++++++++++ .project | 34 +++++++++++++++++++ .settings/org.eclipse.buildship.core.prefs | 13 +++++++ .settings/org.eclipse.jdt.core.prefs | 4 +++ .../address/logic/commands/ClaimCommand.java | 29 ++++++++++++++++ .../logic/parser/ClaimCommandParser.java | 9 +++++ .../address/logic/parser/ParserUtil.java | 9 +++++ .../seedu/address/model/person/Claim.java | 20 +++++++++++ 8 files changed, 150 insertions(+) create mode 100644 .classpath create mode 100644 .project create mode 100644 .settings/org.eclipse.buildship.core.prefs create mode 100644 .settings/org.eclipse.jdt.core.prefs diff --git a/.classpath b/.classpath new file mode 100644 index 00000000000..66f8050c07c --- /dev/null +++ b/.classpath @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 00000000000..958cf8ed32d --- /dev/null +++ b/.project @@ -0,0 +1,34 @@ + + + tp + Project tp created by Buildship. + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.buildship.core.gradleprojectbuilder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.buildship.core.gradleprojectnature + + + + 1696599672119 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/.settings/org.eclipse.buildship.core.prefs b/.settings/org.eclipse.buildship.core.prefs new file mode 100644 index 00000000000..5e7a5d23bb9 --- /dev/null +++ b/.settings/org.eclipse.buildship.core.prefs @@ -0,0 +1,13 @@ +arguments= +auto.sync=false +build.scans.enabled=false +connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) +connection.project.dir= +eclipse.preferences.version=1 +gradle.user.home= +java.home=/usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home +jvm.arguments= +offline.mode=false +override.workspace.settings=true +show.console.view=true +show.executions.view=true diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 00000000000..18ad895236b --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 +org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.source=11 diff --git a/src/main/java/seedu/address/logic/commands/ClaimCommand.java b/src/main/java/seedu/address/logic/commands/ClaimCommand.java index 29cc4ff0741..58b737b58ac 100644 --- a/src/main/java/seedu/address/logic/commands/ClaimCommand.java +++ b/src/main/java/seedu/address/logic/commands/ClaimCommand.java @@ -23,12 +23,26 @@ public class ClaimCommand extends Command { private final Boolean isSubtract; private final long amount; + /** + * Initialises a ClaimCommand Objects with three variables being index, isSubtract and amount. + * + * @param index Index Object representing the position of individual within the list of employees. + * @param isSubtract Boolean Object where True represents deduction and False represents addition. + * @param amount Long Object representing the claim amount user is submitting. + */ public ClaimCommand(Index index, Boolean isSubtract, long amount) { this.index = index; this.isSubtract = isSubtract; this.amount = amount; } + /** + * Returns CommandResult Object after successfully updating user's claim budget and updating the Person Object in the list. + * + * @param model {@code Model} which the command should operate on. + * @return CommandResult which highlights the new claim budget the individual has. + * @throws CommandException Exception thrown if index input from HR is beyond the pre-existing max list index. + */ @Override public CommandResult execute(Model model) throws CommandException { requireNonNull(model); @@ -49,6 +63,13 @@ public CommandResult execute(Model model) throws CommandException { return new CommandResult(String.format("%s Remaining claim %s has: %s", CLAIM_SUCCESS, editedPerson.getName(), claimBudget)); } + /** + * Returns a Money Object which represents the new amount the user has after the claiming process is completed. + * + * @param prevClaimBudget long object that highlighted how many claim budget user was left with before the claim process. + * @return Money Object that highlights the new claim budget the user has. + * @throws CommandException Exception if the subtracted claim amount is more the user's claim budget. + */ private Money calculateNewClaimBudget(long prevClaimBudget) throws CommandException{ if (this.isSubtract && (this.amount > prevClaimBudget)) { throw new CommandException(Messages.MESSAGE_OVER_CLAIM); @@ -62,6 +83,14 @@ private Money calculateNewClaimBudget(long prevClaimBudget) throws CommandExcept return new Money(String.valueOf(newClaimBudget)); } + /** + * Returns a Person object which contains the new claim budget. + * Other variables of the person remains unchanged. + * + * @param personToEdit Person object (Old). + * @param claimBudget Money object which reflects the new claim budget user has. + * @return Person Object that contains the new claim budget whilst other variables remain unchanged. + */ private Person postClaimPerson(Person personToEdit, Money claimBudget) { return new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), personToEdit.getAddress(), personToEdit.getSalary(), claimBudget, diff --git a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java index b918f31b8c5..b1492df9d1e 100644 --- a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java @@ -12,6 +12,15 @@ import static seedu.address.logic.parser.CliSyntax.*; public class ClaimCommandParser implements Parser { + /** + * Returns ClaimCommand which contains the employee-of-interest's index, boolean to represent subtraction/addition as well as the claim amount. + * Parser to parse out the index as well as claim amount (containing both symbol [+/-] and amount) based on delimiter of "$/". + * Checks are in place to ensure the index is inputted and claim amount consists of only digits. + * + * @param args String object which represents the user's input. + * @return ClaimCommand which consists of employee's index, subtraction/addition boolean indicator and claim amount. + * @throws ParseException Exception thrown either when index is not inputted or claim amount contains non-digits. + */ public ClaimCommand parse(String args) throws ParseException { requireNonNull(args); ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_CLAIM_AMOUNT); diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 262a5a74908..7053689ccc6 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -137,6 +137,15 @@ public static Birthday parseDob(String dob) throws ParseException { return new Birthday(trimmed); } + /** + * Returns a Claim Object upon successful checks. + * Checks consist of ensuring user inputted either + or - before the claim amount. + * Checks also consist of ensuring the claim amount contains only digits. + * + * @param claimAmount String Object which is parsed out from the user's command line input. Example: +500 + * @return Claim Object which stores variables like claim amount as well as boolean variable to indicate addition/subtraction. + * @throws ParseException Exception thrown when no symbols were inputted (+/-) or claim amount consists of non-digits. + */ public static Claim parseClaim(String claimAmount) throws ParseException { requireNonNull(claimAmount); String trimmed = claimAmount.trim(); diff --git a/src/main/java/seedu/address/model/person/Claim.java b/src/main/java/seedu/address/model/person/Claim.java index 97ba2a687a3..c189fcefca2 100644 --- a/src/main/java/seedu/address/model/person/Claim.java +++ b/src/main/java/seedu/address/model/person/Claim.java @@ -9,6 +9,13 @@ public class Claim { public final boolean isSubtract; public final int amount; + /** + * Returns a Claim Object which contains of two variables, isSubtract and amount. + * isSubtract variable represents whether this claim is either addition/subtraction of claim budget. + * amount variable represents whether the claim amount employee is hoping to claim. + * + * @param numStr String Object of user's input. + */ public Claim(String numStr) { char firstChar = numStr.charAt(0); if (firstChar == '+') { @@ -19,11 +26,24 @@ public Claim(String numStr) { this.amount = Integer.parseInt(numStr.substring(1)); } + /** + * Returns a boolean object where True if symbol (+/-) is provided before claim amount else False. + * + * @param args String Object that contains parsed out portions from user's CLI input. + * @return Boolean where True represents correct claim input format else False. + */ public static boolean comtainsSymbol(String args) { char firstChar = args.charAt(0); return firstChar == '+' || firstChar == '-'; } + /** + * Returns boolean object where True if claim amount only contains of digits else False. + * This portion represents post symbol portion. For example, if args == "+500", we are obly care about "500". + * + * @param args String object that contains parsed out partions from user's CLI input. + * @return Boolean where True represents claim amount was given in correct format else False. + */ public static boolean isCorrectAmountType(String args) { String amount = args.substring(1); return amount.matches("\\d+"); From 552703f4d2d383ddb3720233cfaa8cd9c860095d Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Sat, 7 Oct 2023 01:57:23 +0800 Subject: [PATCH 03/12] Added test cases for both Command & Parser --- .../address/logic/commands/ClaimCommand.java | 18 ++++- .../logic/commands/ClaimCommandTest.java | 74 +++++++++++++++++++ .../logic/commands/CommandTestUtil.java | 12 ++- .../logic/parser/ClaimCommandParserTest.java | 47 ++++++++++++ 4 files changed, 148 insertions(+), 3 deletions(-) create mode 100644 src/test/java/seedu/address/logic/commands/ClaimCommandTest.java create mode 100644 src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java diff --git a/src/main/java/seedu/address/logic/commands/ClaimCommand.java b/src/main/java/seedu/address/logic/commands/ClaimCommand.java index 58b737b58ac..23548c983c2 100644 --- a/src/main/java/seedu/address/logic/commands/ClaimCommand.java +++ b/src/main/java/seedu/address/logic/commands/ClaimCommand.java @@ -70,7 +70,7 @@ public CommandResult execute(Model model) throws CommandException { * @return Money Object that highlights the new claim budget the user has. * @throws CommandException Exception if the subtracted claim amount is more the user's claim budget. */ - private Money calculateNewClaimBudget(long prevClaimBudget) throws CommandException{ + public Money calculateNewClaimBudget(long prevClaimBudget) throws CommandException{ if (this.isSubtract && (this.amount > prevClaimBudget)) { throw new CommandException(Messages.MESSAGE_OVER_CLAIM); } @@ -91,9 +91,23 @@ private Money calculateNewClaimBudget(long prevClaimBudget) throws CommandExcept * @param claimBudget Money object which reflects the new claim budget user has. * @return Person Object that contains the new claim budget whilst other variables remain unchanged. */ - private Person postClaimPerson(Person personToEdit, Money claimBudget) { + public Person postClaimPerson(Person personToEdit, Money claimBudget) { return new Person(personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), personToEdit.getAddress(), personToEdit.getSalary(), claimBudget, personToEdit.getDepartment(), personToEdit.getDob()); } + + @Override + public boolean equals(Object other) { + if (this == other) { + return true; // Both are the same instance + } + if (other == null || getClass() != other.getClass()) { + return false; // Other is not an instance of ClaimCommand + } + ClaimCommand that = (ClaimCommand) other; + return index.equals(that.index) && + isSubtract.equals(that.isSubtract) && + amount == that.amount; + } } diff --git a/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java new file mode 100644 index 00000000000..ce2aa9a953d --- /dev/null +++ b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java @@ -0,0 +1,74 @@ +package seedu.address.logic.commands; + +import org.junit.jupiter.api.Test; +import seedu.address.commons.core.index.Index; +import seedu.address.logic.Messages; +import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.Model; +import seedu.address.model.ModelManager; +import seedu.address.model.UserPrefs; +import seedu.address.model.person.Money; +import seedu.address.model.person.Person; + +import static org.junit.jupiter.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + +public class ClaimCommandTest { + + private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); + private final boolean IS_SUBTRACT = true; + private Person targetPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getOneBased()); + private long originalBudget = Long.parseLong(targetPerson.getClaimBudget().amount); + + @Test + public void execute_calculationNewBudget_success() throws CommandException { + long claimAmount = originalBudget - 1; + ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, IS_SUBTRACT, claimAmount); + Money newMoney = claimCommand.calculateNewClaimBudget(originalBudget); + long expectedBudgetAmount = originalBudget - claimAmount; + Money expectedMoney = new Money(String.valueOf(expectedBudgetAmount)); + assertEquals(newMoney, expectedMoney); + } + + @Test + public void execute_calculationExcessBudget_failure() { + long claimAmount = originalBudget + 1; + ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, IS_SUBTRACT, claimAmount); + assertThrows(CommandException.class, () -> { + claimCommand.calculateNewClaimBudget(originalBudget); + }, Messages.MESSAGE_OVER_CLAIM); + } + + @Test + public void execute_generateNewPerson_success() { + Money newClaimBudget = new Money(String.valueOf(originalBudget + 1)); + Person expectedPerson = new Person(targetPerson.getName(), targetPerson.getPhone(), targetPerson.getEmail(), + targetPerson.getAddress(), targetPerson.getSalary(), newClaimBudget, targetPerson.getDepartment(), + targetPerson.getDob()); + ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, true, 0); + Person newPerson = claimCommand.postClaimPerson(targetPerson, newClaimBudget); + assertEquals(newPerson.toString(), expectedPerson.toString()); + } + + @Test + public void execute_generateNewPerson_failure() { + Money newClaimBudget = new Money(String.valueOf(originalBudget + 1)); + Person expectedPerson = new Person(targetPerson.getName(), targetPerson.getPhone(), targetPerson.getEmail(), + targetPerson.getAddress(), targetPerson.getSalary(), targetPerson.getClaimBudget(), targetPerson.getDepartment(), + targetPerson.getDob()); + ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, true, 0); + Person newPerson = claimCommand.postClaimPerson(targetPerson, newClaimBudget); + assertNotEquals(newPerson.toString(), expectedPerson.toString()); + } + + @Test + public void equals() { + ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, true, 1); + ClaimCommand commandWithSameValues = new ClaimCommand(INDEX_FIRST_PERSON, true, 1); + ClaimCommand commandWithDifferentValues = new ClaimCommand(INDEX_FIRST_PERSON, false, 1); + assertTrue(claimCommand.equals(commandWithSameValues)); + assertFalse(claimCommand.equals(commandWithDifferentValues)); + } +} diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 03124663481..985bab892fc 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -2,6 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_BUDGET; import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT; @@ -21,6 +22,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.AddressBook; import seedu.address.model.Model; +import seedu.address.model.person.Money; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; import seedu.address.testutil.EditPersonDescriptorBuilder; @@ -72,6 +74,14 @@ public class CommandTestUtil { public static final EditCommand.EditPersonDescriptor DESC_AMY; public static final EditCommand.EditPersonDescriptor DESC_BOB; + public static final long CLAIM_AMOUNT = 500; + public static final String CLAIM_AMOUNT_STR = "500"; + public static final String CLAIM_ADDITION = "+"; + public static final String CLAIM_DELIMITER = "$/"; + public static final String CLAIM_EMPTY_INDEX = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ClaimCommand.MESSAGE_EMPTY); + public static final String CLAIM_EMPTY_AMOUNT = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ClaimCommand.AMOUNT_EMPTY); + + static { DESC_AMY = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY) .withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY) @@ -123,6 +133,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. @@ -136,5 +147,4 @@ public static void showPersonAtIndex(Model model, Index targetIndex) { assertEquals(1, model.getFilteredPersonList().size()); } - } diff --git a/src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java b/src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java new file mode 100644 index 00000000000..ac536f0f522 --- /dev/null +++ b/src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java @@ -0,0 +1,47 @@ +package seedu.address.logic.parser; + +import org.junit.jupiter.api.Test; +import seedu.address.logic.commands.ClaimCommand; + +import static seedu.address.logic.commands.CommandTestUtil.*; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; +import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; +import static seedu.address.model.person.Claim.ALPHABETS_ERROR; +import static seedu.address.model.person.Claim.NO_SYMBOLS_ERROR; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; + +public class ClaimCommandParserTest { + + private ClaimCommandParser parser = new ClaimCommandParser(); + + @Test + public void parse_allFieldsPresent_Success() { + String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER + CLAIM_ADDITION + CLAIM_AMOUNT_STR; + ClaimCommand successClaimCommand = new ClaimCommand(INDEX_FIRST_PERSON, false, CLAIM_AMOUNT); + assertParseSuccess(parser, userInput, successClaimCommand); + } + + @Test + public void parse_emptyIndex_Failure() { + String userInput = CLAIM_DELIMITER + CLAIM_ADDITION + CLAIM_AMOUNT_STR; + assertParseFailure(parser, userInput, CLAIM_EMPTY_INDEX); + } + + @Test + public void parse_emptyAmount_Failure() { + String userInput = String.valueOf(INDEX_FIRST_PERSON.getOneBased()); + assertParseFailure(parser, userInput, CLAIM_EMPTY_AMOUNT); + } + + @Test + public void parse_emptySymbols_Failure() { + String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER + CLAIM_AMOUNT_STR; + assertParseFailure(parser, userInput, NO_SYMBOLS_ERROR); + } + + @Test + public void parse_claimAmount_NonDigits_Failure() { + String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER + CLAIM_ADDITION + CLAIM_AMOUNT_STR + "b"; + assertParseFailure(parser, userInput, ALPHABETS_ERROR); + } +} From b5de2e35fd98dbe6d954c4cf3a69bc9d5c2c6f5e Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Mon, 9 Oct 2023 14:42:52 +0800 Subject: [PATCH 04/12] Edited the checkstyle failures --- .../java/seedu/address/logic/Messages.java | 6 ++++-- .../address/logic/commands/ClaimCommand.java | 21 ++++++++++++------- .../logic/parser/AddressBookParser.java | 8 +++---- .../logic/parser/ClaimCommandParser.java | 14 ++++++++----- .../logic/parser/EditCommandParser.java | 9 +++++++- .../address/logic/parser/ParserUtil.java | 13 +++++++++--- .../seedu/address/model/person/Claim.java | 9 +++++--- 7 files changed, 54 insertions(+), 26 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 49c1b463927..20541516970 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -16,8 +16,10 @@ public class Messages { public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid"; public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; - public static final String MESSAGE_DUPLICATE_FIELDS = "Multiple values specified for the following single-valued field(s): "; - public static final String MESSAGE_OVER_CLAIM = "Claim is REJECTED as the amount is greater than the funds the Employee currently has!"; + public static final String MESSAGE_DUPLICATE_FIELDS = "Multiple values specified for the " + + "following single-valued field(s): "; + public static final String MESSAGE_OVER_CLAIM = "Claim is REJECTED as the amount is greater than " + + "the funds the Employee currently has!"; public static final String MESSAGE_EMPTY_DEPARTMENT_FILTER = "department name cannot be empty!"; public static final String MESSAGE_LIST_SUCCESS = "Listed all employees (%1$d)"; diff --git a/src/main/java/seedu/address/logic/commands/ClaimCommand.java b/src/main/java/seedu/address/logic/commands/ClaimCommand.java index 23548c983c2..c143138af7c 100644 --- a/src/main/java/seedu/address/logic/commands/ClaimCommand.java +++ b/src/main/java/seedu/address/logic/commands/ClaimCommand.java @@ -1,5 +1,7 @@ package seedu.address.logic.commands; +import java.util.List; + import seedu.address.commons.core.index.Index; import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; @@ -7,11 +9,12 @@ import seedu.address.model.person.Money; import seedu.address.model.person.Person; -import java.util.List; - import static java.util.Objects.requireNonNull; import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; +/** + * Performs claims for each employee and alters respective claim budgets. + */ public class ClaimCommand extends Command { public static final String COMMAND_WORD = "claim"; @@ -37,7 +40,8 @@ public ClaimCommand(Index index, Boolean isSubtract, long amount) { } /** - * Returns CommandResult Object after successfully updating user's claim budget and updating the Person Object in the list. + * Returns CommandResult Object after successfully updating user's claim budget. + * Updating the Person Object in the list. * * @param model {@code Model} which the command should operate on. * @return CommandResult which highlights the new claim budget the individual has. @@ -60,7 +64,8 @@ public CommandResult execute(Model model) throws CommandException { model.setPerson(personToEdit, editedPerson); model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS); - return new CommandResult(String.format("%s Remaining claim %s has: %s", CLAIM_SUCCESS, editedPerson.getName(), claimBudget)); + return new CommandResult(String.format("%s Remaining claim %s has: %s", + CLAIM_SUCCESS, editedPerson.getName(), claimBudget)); } /** @@ -70,7 +75,7 @@ public CommandResult execute(Model model) throws CommandException { * @return Money Object that highlights the new claim budget the user has. * @throws CommandException Exception if the subtracted claim amount is more the user's claim budget. */ - public Money calculateNewClaimBudget(long prevClaimBudget) throws CommandException{ + public Money calculateNewClaimBudget(long prevClaimBudget) throws CommandException { if (this.isSubtract && (this.amount > prevClaimBudget)) { throw new CommandException(Messages.MESSAGE_OVER_CLAIM); } @@ -106,8 +111,8 @@ public boolean equals(Object other) { return false; // Other is not an instance of ClaimCommand } ClaimCommand that = (ClaimCommand) other; - return index.equals(that.index) && - isSubtract.equals(that.isSubtract) && - amount == that.amount; + return index.equals(that.index) + && isSubtract.equals(that.isSubtract) + && amount == that.amount; } } diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 2d372bc31bc..94d4f09d0a4 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -1,8 +1,5 @@ package seedu.address.logic.parser; -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; - import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -20,6 +17,9 @@ import seedu.address.logic.commands.ClaimCommand; import seedu.address.logic.parser.exceptions.ParseException; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; + /** * Parses user input. */ @@ -79,7 +79,7 @@ public Command parseCommand(String userInput) throws ParseException { return new HelpCommand(); case ClaimCommand.COMMAND_WORD: - return new ClaimCommandParser().parse(arguments); + return new ClaimCommandParser().parse(arguments); default: logger.finer("This user input caused a ParseException: " + userInput); diff --git a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java index b1492df9d1e..839b47e6d6a 100644 --- a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java @@ -1,20 +1,24 @@ package seedu.address.logic.parser; import seedu.address.commons.core.index.Index; -import seedu.address.logic.commands.AddCommand; import seedu.address.logic.commands.ClaimCommand; -import seedu.address.logic.commands.EditCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Claim; import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.*; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_AMOUNT; + +/** + * Parses input arguments and creates a new ClaimCommand object. + */ public class ClaimCommandParser implements Parser { /** - * Returns ClaimCommand which contains the employee-of-interest's index, boolean to represent subtraction/addition as well as the claim amount. - * Parser to parse out the index as well as claim amount (containing both symbol [+/-] and amount) based on delimiter of "$/". + * Returns ClaimCommand which contains the employee-of-interest's index, + * boolean to represent subtraction/addition as well as the claim amount. + * Parser to parse out the index as well as claim amount + * (containing both symbol [+/-] and amount) based on delimiter of "$/". * Checks are in place to ensure the index is inputted and claim amount consists of only digits. * * @param args String object which represents the user's input. diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 1dff1f6146d..5772381ac99 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -2,7 +2,14 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.*; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_BUDGET; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB; import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.EditCommand; diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 7053689ccc6..b23f47b2a1b 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -9,7 +9,14 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.*; +import seedu.address.model.person.Name; +import seedu.address.model.person.Phone; +import seedu.address.model.person.Address; +import seedu.address.model.person.Email; +import seedu.address.model.person.Money; +import seedu.address.model.person.Department; +import seedu.address.model.person.Birthday; +import seedu.address.model.person.Claim; import seedu.address.model.tag.Tag; /** @@ -143,8 +150,8 @@ public static Birthday parseDob(String dob) throws ParseException { * Checks also consist of ensuring the claim amount contains only digits. * * @param claimAmount String Object which is parsed out from the user's command line input. Example: +500 - * @return Claim Object which stores variables like claim amount as well as boolean variable to indicate addition/subtraction. - * @throws ParseException Exception thrown when no symbols were inputted (+/-) or claim amount consists of non-digits. + * @return Claim Object which stores claim amount as well as boolean to indicate addition/subtraction. + * @throws ParseException Exception when no symbols were inputted or amount consists of non-digits. */ public static Claim parseClaim(String claimAmount) throws ParseException { requireNonNull(claimAmount); diff --git a/src/main/java/seedu/address/model/person/Claim.java b/src/main/java/seedu/address/model/person/Claim.java index c189fcefca2..dc81a52a69c 100644 --- a/src/main/java/seedu/address/model/person/Claim.java +++ b/src/main/java/seedu/address/model/person/Claim.java @@ -1,9 +1,12 @@ package seedu.address.model.person; -import java.util.Objects; - +/** + * Represents a Person's Claim in the address book. + * Ensures boolean variable and amount is provided. + */ public class Claim { - public static final String NO_SYMBOLS_ERROR = "Kindly state whether the employee wants to deduct/add the claim amount! Provide either +/- in front of the amount!"; + public static final String NO_SYMBOLS_ERROR = "Kindly state whether the employee wants to deduct/add " + + "the claim amount! Provide either +/- in front of the amount!"; public static final String ALPHABETS_ERROR = "Kindly only input integers for the claim amount!"; public final boolean isSubtract; From 8afedd2f032f9a35fafe12e2495dd76c96209d71 Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Mon, 9 Oct 2023 14:52:47 +0800 Subject: [PATCH 05/12] Reediting of checkstyle --- src/main/java/seedu/address/logic/Messages.java | 8 ++++---- .../seedu/address/logic/commands/ClaimCommand.java | 8 ++++---- .../seedu/address/logic/parser/AddressBookParser.java | 8 ++++---- .../seedu/address/logic/parser/ClaimCommandParser.java | 7 ++++--- .../seedu/address/logic/parser/EditCommandParser.java | 10 +++++----- .../java/seedu/address/logic/parser/ParserUtil.java | 10 +++++----- src/main/java/seedu/address/model/person/Claim.java | 4 ++-- 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index 20541516970..60154600561 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -16,10 +16,10 @@ public class Messages { public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s"; public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid"; public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!"; - public static final String MESSAGE_DUPLICATE_FIELDS = "Multiple values specified for the " + - "following single-valued field(s): "; - public static final String MESSAGE_OVER_CLAIM = "Claim is REJECTED as the amount is greater than " + - "the funds the Employee currently has!"; + public static final String MESSAGE_DUPLICATE_FIELDS = "Multiple values specified for the " + + "following single-valued field(s): "; + public static final String MESSAGE_OVER_CLAIM = "Claim is REJECTED as the amount is greater than " + + "the funds the Employee currently has!"; public static final String MESSAGE_EMPTY_DEPARTMENT_FILTER = "department name cannot be empty!"; public static final String MESSAGE_LIST_SUCCESS = "Listed all employees (%1$d)"; diff --git a/src/main/java/seedu/address/logic/commands/ClaimCommand.java b/src/main/java/seedu/address/logic/commands/ClaimCommand.java index c143138af7c..cb3c1e98b00 100644 --- a/src/main/java/seedu/address/logic/commands/ClaimCommand.java +++ b/src/main/java/seedu/address/logic/commands/ClaimCommand.java @@ -2,6 +2,9 @@ import java.util.List; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; +import static java.util.Objects.requireNonNull; + import seedu.address.commons.core.index.Index; import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; @@ -9,9 +12,6 @@ import seedu.address.model.person.Money; import seedu.address.model.person.Person; -import static java.util.Objects.requireNonNull; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; - /** * Performs claims for each employee and alters respective claim budgets. */ @@ -71,7 +71,7 @@ public CommandResult execute(Model model) throws CommandException { /** * Returns a Money Object which represents the new amount the user has after the claiming process is completed. * - * @param prevClaimBudget long object that highlighted how many claim budget user was left with before the claim process. + * @param prevClaimBudget long object on user's claim budget before the claim process. * @return Money Object that highlights the new claim budget the user has. * @throws CommandException Exception if the subtracted claim amount is more the user's claim budget. */ diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 94d4f09d0a4..9280716f71f 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -4,8 +4,12 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; + import seedu.address.commons.core.LogsCenter; import seedu.address.logic.commands.AddCommand; +import seedu.address.logic.commands.ClaimCommand; import seedu.address.logic.commands.ClearCommand; import seedu.address.logic.commands.Command; import seedu.address.logic.commands.DeleteCommand; @@ -14,12 +18,8 @@ import seedu.address.logic.commands.FindCommand; import seedu.address.logic.commands.HelpCommand; import seedu.address.logic.commands.ListCommand; -import seedu.address.logic.commands.ClaimCommand; import seedu.address.logic.parser.exceptions.ParseException; -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; - /** * Parses user input. */ diff --git a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java index 839b47e6d6a..1da73809b56 100644 --- a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java @@ -1,13 +1,14 @@ package seedu.address.logic.parser; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_AMOUNT; +import static java.util.Objects.requireNonNull; + import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.ClaimCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Claim; -import static java.util.Objects.requireNonNull; -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_AMOUNT; /** * Parses input arguments and creates a new ClaimCommand object. diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 5772381ac99..15795a70492 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -1,15 +1,15 @@ package seedu.address.logic.parser; -import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; -import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; -import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY; import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_BUDGET; import static seedu.address.logic.parser.CliSyntax.PREFIX_DEPARTMENT; import static seedu.address.logic.parser.CliSyntax.PREFIX_DOB; +import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; +import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; +import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; +import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY; +import static java.util.Objects.requireNonNull; import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.EditCommand; diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index b23f47b2a1b..fd802067dda 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -9,14 +9,14 @@ import seedu.address.commons.core.index.Index; import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; -import seedu.address.model.person.Name; -import seedu.address.model.person.Phone; import seedu.address.model.person.Address; -import seedu.address.model.person.Email; -import seedu.address.model.person.Money; -import seedu.address.model.person.Department; import seedu.address.model.person.Birthday; import seedu.address.model.person.Claim; +import seedu.address.model.person.Department; +import seedu.address.model.person.Email; +import seedu.address.model.person.Money; +import seedu.address.model.person.Name; +import seedu.address.model.person.Phone; import seedu.address.model.tag.Tag; /** diff --git a/src/main/java/seedu/address/model/person/Claim.java b/src/main/java/seedu/address/model/person/Claim.java index dc81a52a69c..6aeb35f955e 100644 --- a/src/main/java/seedu/address/model/person/Claim.java +++ b/src/main/java/seedu/address/model/person/Claim.java @@ -5,8 +5,8 @@ * Ensures boolean variable and amount is provided. */ public class Claim { - public static final String NO_SYMBOLS_ERROR = "Kindly state whether the employee wants to deduct/add " + - "the claim amount! Provide either +/- in front of the amount!"; + public static final String NO_SYMBOLS_ERROR = "Kindly state whether the employee wants to deduct/add " + + "the claim amount! Provide either +/- in front of the amount!"; public static final String ALPHABETS_ERROR = "Kindly only input integers for the claim amount!"; public final boolean isSubtract; From e87249059a777a91e9550f6dcd72870e3afc2b51 Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Mon, 9 Oct 2023 14:59:14 +0800 Subject: [PATCH 06/12] Re-edit of checkstyle --- .../java/seedu/address/logic/commands/ClaimCommand.java | 4 ++-- .../java/seedu/address/logic/parser/AddressBookParser.java | 6 +++--- .../java/seedu/address/logic/parser/ClaimCommandParser.java | 2 +- .../java/seedu/address/logic/parser/EditCommandParser.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/ClaimCommand.java b/src/main/java/seedu/address/logic/commands/ClaimCommand.java index cb3c1e98b00..c2f9b6e10dc 100644 --- a/src/main/java/seedu/address/logic/commands/ClaimCommand.java +++ b/src/main/java/seedu/address/logic/commands/ClaimCommand.java @@ -1,10 +1,10 @@ package seedu.address.logic.commands; -import java.util.List; - import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import static java.util.Objects.requireNonNull; +import java.util.List; + import seedu.address.commons.core.index.Index; import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; diff --git a/src/main/java/seedu/address/logic/parser/AddressBookParser.java b/src/main/java/seedu/address/logic/parser/AddressBookParser.java index 9280716f71f..392be23cb27 100644 --- a/src/main/java/seedu/address/logic/parser/AddressBookParser.java +++ b/src/main/java/seedu/address/logic/parser/AddressBookParser.java @@ -1,12 +1,12 @@ package seedu.address.logic.parser; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; +import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; + import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; -import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND; -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; - import seedu.address.commons.core.LogsCenter; import seedu.address.logic.commands.AddCommand; import seedu.address.logic.commands.ClaimCommand; diff --git a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java index 1da73809b56..9a29f2b0e09 100644 --- a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java @@ -1,8 +1,8 @@ package seedu.address.logic.parser; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; -import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_AMOUNT; import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_AMOUNT; import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.ClaimCommand; diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index 15795a70492..a449ddbf88b 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -8,8 +8,8 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY; import static java.util.Objects.requireNonNull; +import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY; import seedu.address.commons.core.index.Index; import seedu.address.logic.commands.EditCommand; From a1b750c368f8dacc8ec6778a8c1a2b638348bbfb Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Mon, 9 Oct 2023 15:01:37 +0800 Subject: [PATCH 07/12] edit checkstyle again --- src/main/java/seedu/address/logic/commands/ClaimCommand.java | 2 +- .../java/seedu/address/logic/parser/ClaimCommandParser.java | 2 +- src/main/java/seedu/address/logic/parser/EditCommandParser.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/seedu/address/logic/commands/ClaimCommand.java b/src/main/java/seedu/address/logic/commands/ClaimCommand.java index c2f9b6e10dc..fc4fd8c6773 100644 --- a/src/main/java/seedu/address/logic/commands/ClaimCommand.java +++ b/src/main/java/seedu/address/logic/commands/ClaimCommand.java @@ -1,7 +1,7 @@ package seedu.address.logic.commands; -import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import static java.util.Objects.requireNonNull; +import static seedu.address.model.Model.PREDICATE_SHOW_ALL_PERSONS; import java.util.List; diff --git a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java index 9a29f2b0e09..cbb1b77f43a 100644 --- a/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/ClaimCommandParser.java @@ -1,7 +1,7 @@ package seedu.address.logic.parser; -import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static java.util.Objects.requireNonNull; +import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_AMOUNT; import seedu.address.commons.core.index.Index; diff --git a/src/main/java/seedu/address/logic/parser/EditCommandParser.java b/src/main/java/seedu/address/logic/parser/EditCommandParser.java index a449ddbf88b..ed35aad6ef4 100644 --- a/src/main/java/seedu/address/logic/parser/EditCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/EditCommandParser.java @@ -1,5 +1,6 @@ package seedu.address.logic.parser; +import static java.util.Objects.requireNonNull; import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; import static seedu.address.logic.parser.CliSyntax.PREFIX_CLAIM_BUDGET; @@ -8,7 +9,6 @@ import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE; -import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_SALARY; import seedu.address.commons.core.index.Index; From b7b6c209ee0d45b08dd47dc1f0b798d8040b958f Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Mon, 9 Oct 2023 15:16:02 +0800 Subject: [PATCH 08/12] edit checkstyle for test files --- .../logic/commands/ClaimCommandTest.java | 27 +++++++------- .../logic/commands/CommandTestUtil.java | 7 ++-- .../logic/parser/ClaimCommandParserTest.java | 36 ++++++++++++------- 3 files changed, 42 insertions(+), 28 deletions(-) diff --git a/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java index ce2aa9a953d..25b04692b3a 100644 --- a/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java @@ -1,7 +1,15 @@ package seedu.address.logic.commands; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; + import org.junit.jupiter.api.Test; -import seedu.address.commons.core.index.Index; + import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; @@ -10,22 +18,17 @@ import seedu.address.model.person.Money; import seedu.address.model.person.Person; -import static org.junit.jupiter.api.Assertions.*; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; -import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; - public class ClaimCommandTest { private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs()); - private final boolean IS_SUBTRACT = true; + private final boolean isSubtract = true; private Person targetPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getOneBased()); private long originalBudget = Long.parseLong(targetPerson.getClaimBudget().amount); @Test public void execute_calculationNewBudget_success() throws CommandException { long claimAmount = originalBudget - 1; - ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, IS_SUBTRACT, claimAmount); + ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, isSubtract, claimAmount); Money newMoney = claimCommand.calculateNewClaimBudget(originalBudget); long expectedBudgetAmount = originalBudget - claimAmount; Money expectedMoney = new Money(String.valueOf(expectedBudgetAmount)); @@ -35,7 +38,7 @@ public void execute_calculationNewBudget_success() throws CommandException { @Test public void execute_calculationExcessBudget_failure() { long claimAmount = originalBudget + 1; - ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, IS_SUBTRACT, claimAmount); + ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, isSubtract, claimAmount); assertThrows(CommandException.class, () -> { claimCommand.calculateNewClaimBudget(originalBudget); }, Messages.MESSAGE_OVER_CLAIM); @@ -46,7 +49,7 @@ public void execute_generateNewPerson_success() { Money newClaimBudget = new Money(String.valueOf(originalBudget + 1)); Person expectedPerson = new Person(targetPerson.getName(), targetPerson.getPhone(), targetPerson.getEmail(), targetPerson.getAddress(), targetPerson.getSalary(), newClaimBudget, targetPerson.getDepartment(), - targetPerson.getDob()); + targetPerson.getDob()); ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, true, 0); Person newPerson = claimCommand.postClaimPerson(targetPerson, newClaimBudget); assertEquals(newPerson.toString(), expectedPerson.toString()); @@ -56,8 +59,8 @@ public void execute_generateNewPerson_success() { public void execute_generateNewPerson_failure() { Money newClaimBudget = new Money(String.valueOf(originalBudget + 1)); Person expectedPerson = new Person(targetPerson.getName(), targetPerson.getPhone(), targetPerson.getEmail(), - targetPerson.getAddress(), targetPerson.getSalary(), targetPerson.getClaimBudget(), targetPerson.getDepartment(), - targetPerson.getDob()); + targetPerson.getAddress(), targetPerson.getSalary(), targetPerson.getClaimBudget(), + targetPerson.getDepartment(), targetPerson.getDob()); ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, true, 0); Person newPerson = claimCommand.postClaimPerson(targetPerson, newClaimBudget); assertNotEquals(newPerson.toString(), expectedPerson.toString()); diff --git a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java index 985bab892fc..dbb4ffc0509 100644 --- a/src/test/java/seedu/address/logic/commands/CommandTestUtil.java +++ b/src/test/java/seedu/address/logic/commands/CommandTestUtil.java @@ -22,7 +22,6 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.AddressBook; import seedu.address.model.Model; -import seedu.address.model.person.Money; import seedu.address.model.person.NameContainsKeywordsPredicate; import seedu.address.model.person.Person; import seedu.address.testutil.EditPersonDescriptorBuilder; @@ -78,8 +77,10 @@ public class CommandTestUtil { public static final String CLAIM_AMOUNT_STR = "500"; public static final String CLAIM_ADDITION = "+"; public static final String CLAIM_DELIMITER = "$/"; - public static final String CLAIM_EMPTY_INDEX = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ClaimCommand.MESSAGE_EMPTY); - public static final String CLAIM_EMPTY_AMOUNT = String.format(MESSAGE_INVALID_COMMAND_FORMAT, ClaimCommand.AMOUNT_EMPTY); + public static final String CLAIM_EMPTY_INDEX = String.format(MESSAGE_INVALID_COMMAND_FORMAT, + ClaimCommand.MESSAGE_EMPTY); + public static final String CLAIM_EMPTY_AMOUNT = String.format(MESSAGE_INVALID_COMMAND_FORMAT, + ClaimCommand.AMOUNT_EMPTY); static { diff --git a/src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java b/src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java index ac536f0f522..11cf84635f3 100644 --- a/src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java @@ -1,47 +1,57 @@ package seedu.address.logic.parser; -import org.junit.jupiter.api.Test; -import seedu.address.logic.commands.ClaimCommand; - -import static seedu.address.logic.commands.CommandTestUtil.*; +import static seedu.address.logic.commands.CommandTestUtil.CLAIM_ADDITION; +import static seedu.address.logic.commands.CommandTestUtil.CLAIM_AMOUNT; +import static seedu.address.logic.commands.CommandTestUtil.CLAIM_AMOUNT_STR; +import static seedu.address.logic.commands.CommandTestUtil.CLAIM_DELIMITER; +import static seedu.address.logic.commands.CommandTestUtil.CLAIM_EMPTY_AMOUNT; +import static seedu.address.logic.commands.CommandTestUtil.CLAIM_EMPTY_INDEX; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure; import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess; import static seedu.address.model.person.Claim.ALPHABETS_ERROR; import static seedu.address.model.person.Claim.NO_SYMBOLS_ERROR; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; +import org.junit.jupiter.api.Test; + +import seedu.address.logic.commands.ClaimCommand; + public class ClaimCommandParserTest { private ClaimCommandParser parser = new ClaimCommandParser(); @Test - public void parse_allFieldsPresent_Success() { - String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER + CLAIM_ADDITION + CLAIM_AMOUNT_STR; - ClaimCommand successClaimCommand = new ClaimCommand(INDEX_FIRST_PERSON, false, CLAIM_AMOUNT); + public void parse_withAllFields_presentReturnsSuccess() { + String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER + + CLAIM_ADDITION + CLAIM_AMOUNT_STR; + ClaimCommand successClaimCommand = new ClaimCommand(INDEX_FIRST_PERSON, + false, CLAIM_AMOUNT); assertParseSuccess(parser, userInput, successClaimCommand); } @Test - public void parse_emptyIndex_Failure() { + public void parse_withEmptyIndex_returnsFailure() { String userInput = CLAIM_DELIMITER + CLAIM_ADDITION + CLAIM_AMOUNT_STR; assertParseFailure(parser, userInput, CLAIM_EMPTY_INDEX); } @Test - public void parse_emptyAmount_Failure() { + public void parse_withEmptyAmount_returnsFailure() { String userInput = String.valueOf(INDEX_FIRST_PERSON.getOneBased()); assertParseFailure(parser, userInput, CLAIM_EMPTY_AMOUNT); } @Test - public void parse_emptySymbols_Failure() { - String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER + CLAIM_AMOUNT_STR; + public void parse_withEmptySymbols_returnsFailure() { + String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER + + CLAIM_AMOUNT_STR; assertParseFailure(parser, userInput, NO_SYMBOLS_ERROR); } @Test - public void parse_claimAmount_NonDigits_Failure() { - String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER + CLAIM_ADDITION + CLAIM_AMOUNT_STR + "b"; + public void parse_withNonDigitClaimAmount_returnsFailure() { + String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER + + CLAIM_ADDITION + CLAIM_AMOUNT_STR + "b"; assertParseFailure(parser, userInput, ALPHABETS_ERROR); } } From e044207bc01eb63a92d81ad669f184cf28d9dad5 Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Mon, 9 Oct 2023 15:25:17 +0800 Subject: [PATCH 09/12] Edit test checkstyle 2.0 --- .../address/logic/commands/ClaimCommandTest.java | 4 ++-- .../address/logic/parser/ClaimCommandParserTest.java | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java index 25b04692b3a..722191b1231 100644 --- a/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java @@ -1,9 +1,9 @@ package seedu.address.logic.commands; -import static org.junit.jupiter.api.Assertions.assertNotEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; diff --git a/src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java b/src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java index 11cf84635f3..4be2552a218 100644 --- a/src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/ClaimCommandParserTest.java @@ -22,8 +22,8 @@ public class ClaimCommandParserTest { @Test public void parse_withAllFields_presentReturnsSuccess() { - String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER - + CLAIM_ADDITION + CLAIM_AMOUNT_STR; + String userInput = String.format("%s %s%s%s", INDEX_FIRST_PERSON.getOneBased(), + CLAIM_DELIMITER, CLAIM_ADDITION, CLAIM_AMOUNT_STR); ClaimCommand successClaimCommand = new ClaimCommand(INDEX_FIRST_PERSON, false, CLAIM_AMOUNT); assertParseSuccess(parser, userInput, successClaimCommand); @@ -43,15 +43,15 @@ public void parse_withEmptyAmount_returnsFailure() { @Test public void parse_withEmptySymbols_returnsFailure() { - String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER - + CLAIM_AMOUNT_STR; + String userInput = String.format("%s %s%s", INDEX_FIRST_PERSON.getOneBased(), + CLAIM_DELIMITER, CLAIM_AMOUNT_STR); assertParseFailure(parser, userInput, NO_SYMBOLS_ERROR); } @Test public void parse_withNonDigitClaimAmount_returnsFailure() { - String userInput = INDEX_FIRST_PERSON.getOneBased() + " " + CLAIM_DELIMITER - + CLAIM_ADDITION + CLAIM_AMOUNT_STR + "b"; + String userInput = String.format("%s %s%s%s%s", INDEX_FIRST_PERSON.getOneBased(), + CLAIM_DELIMITER, CLAIM_ADDITION, CLAIM_AMOUNT_STR, "b"); assertParseFailure(parser, userInput, ALPHABETS_ERROR); } } From 0a541fcda218d8ebe2f9bbdf5d3ff57236823dce Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Mon, 9 Oct 2023 16:04:04 +0800 Subject: [PATCH 10/12] Added more code coverage --- .../logic/commands/ClaimCommandTest.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java index 722191b1231..cedf0721fe9 100644 --- a/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java @@ -5,6 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; +import static seedu.address.logic.commands.ClaimCommand.CLAIM_SUCCESS; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook; @@ -12,6 +14,7 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.exceptions.CommandException; +import seedu.address.model.AddressBook; import seedu.address.model.Model; import seedu.address.model.ModelManager; import seedu.address.model.UserPrefs; @@ -25,6 +28,22 @@ public class ClaimCommandTest { private Person targetPerson = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getOneBased()); private long originalBudget = Long.parseLong(targetPerson.getClaimBudget().amount); + @Test + public void execute_validPersonIndexUnfilteredList_success() { + Person personToClaim = model.getFilteredPersonList().get(INDEX_FIRST_PERSON.getZeroBased()); + long prevClaimBudget = Integer.parseInt(personToClaim.getClaimBudget().amount); + Money claimBudget = new Money(Long.toString(prevClaimBudget - 1)); + Person expectedPersonAfterClaim = new Person(personToClaim.getName(), personToClaim.getPhone(), + personToClaim.getEmail(), personToClaim.getAddress(), personToClaim.getSalary(), + claimBudget, personToClaim.getDepartment(), personToClaim.getDob()); + ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, true, 1); + Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); + expectedModel.setPerson(personToClaim, expectedPersonAfterClaim); + String expectedMessage = String.format("%s Remaining claim %s has: %s", + CLAIM_SUCCESS, expectedPersonAfterClaim.getName(), claimBudget); + assertCommandSuccess(claimCommand, model, expectedMessage, expectedModel); + } + @Test public void execute_calculationNewBudget_success() throws CommandException { long claimAmount = originalBudget - 1; @@ -35,6 +54,16 @@ public void execute_calculationNewBudget_success() throws CommandException { assertEquals(newMoney, expectedMoney); } + @Test + public void execute_calculationNewBudget_addsuccess() throws CommandException { + long claimAmount = originalBudget + 1; + ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, false, claimAmount); + Money newMoney = claimCommand.calculateNewClaimBudget(originalBudget); + long expectedBudgetAmount = originalBudget + claimAmount; + Money expectedMoney = new Money(String.valueOf(expectedBudgetAmount)); + assertEquals(newMoney, expectedMoney); + } + @Test public void execute_calculationExcessBudget_failure() { long claimAmount = originalBudget + 1; @@ -71,7 +100,11 @@ public void equals() { ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, true, 1); ClaimCommand commandWithSameValues = new ClaimCommand(INDEX_FIRST_PERSON, true, 1); ClaimCommand commandWithDifferentValues = new ClaimCommand(INDEX_FIRST_PERSON, false, 1); + String notACommand = "This is a string, not a command"; + assertTrue(claimCommand.equals(claimCommand)); assertTrue(claimCommand.equals(commandWithSameValues)); assertFalse(claimCommand.equals(commandWithDifferentValues)); + assertFalse(claimCommand == null); + assertFalse(claimCommand.equals(notACommand)); } } From 12f93ef9ecb714e5a6091306a7cd886b30e2f63e Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Mon, 9 Oct 2023 16:07:01 +0800 Subject: [PATCH 11/12] Removed trailing whitespaces --- .../java/seedu/address/logic/commands/ClaimCommandTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java index cedf0721fe9..8a99f511f05 100644 --- a/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java @@ -35,7 +35,7 @@ public void execute_validPersonIndexUnfilteredList_success() { Money claimBudget = new Money(Long.toString(prevClaimBudget - 1)); Person expectedPersonAfterClaim = new Person(personToClaim.getName(), personToClaim.getPhone(), personToClaim.getEmail(), personToClaim.getAddress(), personToClaim.getSalary(), - claimBudget, personToClaim.getDepartment(), personToClaim.getDob()); + claimBudget, personToClaim.getDepartment(), personToClaim.getDob()); ClaimCommand claimCommand = new ClaimCommand(INDEX_FIRST_PERSON, true, 1); Model expectedModel = new ModelManager(new AddressBook(model.getAddressBook()), new UserPrefs()); expectedModel.setPerson(personToClaim, expectedPersonAfterClaim); @@ -43,7 +43,7 @@ public void execute_validPersonIndexUnfilteredList_success() { CLAIM_SUCCESS, expectedPersonAfterClaim.getName(), claimBudget); assertCommandSuccess(claimCommand, model, expectedMessage, expectedModel); } - + @Test public void execute_calculationNewBudget_success() throws CommandException { long claimAmount = originalBudget - 1; From 41ac68ce8c41eb01b5a5a3c753728b0b46658714 Mon Sep 17 00:00:00 2001 From: Sher Yew Date: Mon, 9 Oct 2023 16:13:13 +0800 Subject: [PATCH 12/12] edit lexicographically checkstyle --- .../java/seedu/address/logic/commands/ClaimCommandTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java index 8a99f511f05..a566842da1a 100644 --- a/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java +++ b/src/test/java/seedu/address/logic/commands/ClaimCommandTest.java @@ -5,8 +5,8 @@ import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.logic.commands.ClaimCommand.CLAIM_SUCCESS; +import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess; import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON; import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;