diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 00b78379874..5e36d8b1052 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -39,23 +39,24 @@ public AddCommand parse(String args) throws ParseException { ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG, PREFIX_GAME, PREFIX_PREFERREDTIME); - if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) + if (!arePrefixesPresent(argMultimap, PREFIX_NAME) || !argMultimap.getPreamble().isEmpty()) { throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE)); } argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS); Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get()); - Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).get()); - Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).get()); - Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).get()); + + Phone phone = ParserUtil.parsePhone(argMultimap.getValue(PREFIX_PHONE).orElse("")); + Email email = ParserUtil.parseEmail(argMultimap.getValue(PREFIX_EMAIL).orElse("")); + Address address = ParserUtil.parseAddress(argMultimap.getValue(PREFIX_ADDRESS).orElse("")); + Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); Map gameList = ParserUtil.parseGames(argMultimap.getAllValues(PREFIX_GAME)); Set preferredTimeList = ParserUtil.parsePreferredTimes(argMultimap.getAllValues(PREFIX_PREFERREDTIME)); Person person = new Person(name, phone, email, address, tagList, gameList, preferredTimeList); - return new AddCommand(person); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index 89674b1502d..aabb861b953 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -16,6 +16,7 @@ import seedu.address.model.game.SkillLevel; import seedu.address.model.game.Username; import seedu.address.model.person.Address; +import seedu.address.model.person.Blank; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; @@ -64,6 +65,9 @@ public static Name parseName(String name) throws ParseException { * @throws ParseException if the given {@code phone} is invalid. */ public static Phone parsePhone(String phone) throws ParseException { + if (phone.equals("")) { + return new Phone(new Blank()); + } requireNonNull(phone); String trimmedPhone = phone.trim(); if (!Phone.isValidPhone(trimmedPhone)) { @@ -79,6 +83,9 @@ public static Phone parsePhone(String phone) throws ParseException { * @throws ParseException if the given {@code address} is invalid. */ public static Address parseAddress(String address) throws ParseException { + if (address.equals("")) { + return new Address(new Blank()); + } requireNonNull(address); String trimmedAddress = address.trim(); if (!Address.isValidAddress(trimmedAddress)) { @@ -94,6 +101,9 @@ public static Address parseAddress(String address) throws ParseException { * @throws ParseException if the given {@code email} is invalid. */ public static Email parseEmail(String email) throws ParseException { + if (email.equals("")) { + return new Email(new Blank()); + } requireNonNull(email); String trimmedEmail = email.trim(); if (!Email.isValidEmail(trimmedEmail)) { diff --git a/src/main/java/seedu/address/model/person/Address.java b/src/main/java/seedu/address/model/person/Address.java index 469a2cc9a1e..299dd7d659b 100644 --- a/src/main/java/seedu/address/model/person/Address.java +++ b/src/main/java/seedu/address/model/person/Address.java @@ -30,6 +30,15 @@ public Address(String address) { value = address; } + /** + * Constructs an {@code Address}. + * + * @param blank A blank address. + */ + public Address(Blank blank) { + value = ""; + } + /** * Returns true if a given string is a valid email. */ diff --git a/src/main/java/seedu/address/model/person/Blank.java b/src/main/java/seedu/address/model/person/Blank.java new file mode 100644 index 00000000000..00a60f9db03 --- /dev/null +++ b/src/main/java/seedu/address/model/person/Blank.java @@ -0,0 +1,8 @@ +package seedu.address.model.person; + + +/** + * Used to create blank version of {@code Person} fields + */ +public class Blank { +} diff --git a/src/main/java/seedu/address/model/person/Email.java b/src/main/java/seedu/address/model/person/Email.java index c62e512bc29..795a38bb68d 100644 --- a/src/main/java/seedu/address/model/person/Email.java +++ b/src/main/java/seedu/address/model/person/Email.java @@ -44,6 +44,15 @@ public Email(String email) { value = email; } + /** + * Constructs an {@code Email}. + * + * @param blank A blank email. + */ + public Email(Blank blank) { + value = ""; + } + /** * Returns if a given string is a valid email. */ diff --git a/src/main/java/seedu/address/model/person/Phone.java b/src/main/java/seedu/address/model/person/Phone.java index c0dfd56700d..b27783c5ffa 100644 --- a/src/main/java/seedu/address/model/person/Phone.java +++ b/src/main/java/seedu/address/model/person/Phone.java @@ -26,6 +26,15 @@ public Phone(String phone) { value = phone; } + /** + * Constructs an {@code Phone}. + * + * @param blank A blank phone. + */ + public Phone(Blank blank) { + value = ""; + } + /** * Returns true if a given string is a valid phone number. */ diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index cab409290dd..4d9978cfccb 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -14,6 +14,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.game.Game; import seedu.address.model.person.Address; +import seedu.address.model.person.Blank; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -42,10 +43,10 @@ class JsonAdaptedPerson { */ @JsonCreator public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, - @JsonProperty("email") String email, @JsonProperty("address") String address, - @JsonProperty("tags") List tags, - @JsonProperty("games") List games, - @JsonProperty("preferred times") List preferredTimes) { + @JsonProperty("email") String email, @JsonProperty("address") String address, + @JsonProperty("tags") List tags, + @JsonProperty("games") List games, + @JsonProperty("preferred times") List preferredTimes) { this.name = name; this.phone = phone; this.email = email; @@ -95,7 +96,7 @@ public Person toModelType() throws IllegalValueException { personGames.put(game.getGameName(), game.toModelType()); } final List personPreferredTimes = new ArrayList<>(); - for (JsonAdaptedPreferredTime preferredTime: preferredTimes) { + for (JsonAdaptedPreferredTime preferredTime : preferredTimes) { personPreferredTimes.add(preferredTime.toModelType()); } @@ -107,29 +108,38 @@ public Person toModelType() throws IllegalValueException { } final Name modelName = new Name(name); - if (phone == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName())); - } - if (!Phone.isValidPhone(phone)) { - throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS); - } - final Phone modelPhone = new Phone(phone); - if (email == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName())); + final Phone modelPhone; + if (phone.isEmpty()) { + modelPhone = new Phone(new Blank()); + } else { + if (!Phone.isValidPhone(phone)) { + throw new IllegalValueException(Phone.MESSAGE_CONSTRAINTS); + } + modelPhone = new Phone(phone); } - if (!Email.isValidEmail(email)) { - throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS); - } - final Email modelEmail = new Email(email); - if (address == null) { - throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName())); + final Email modelEmail; + if (email.isEmpty()) { + System.out.println("help"); + modelEmail = new Email(new Blank()); + } else { + if (!Email.isValidEmail(email)) { + throw new IllegalValueException(Email.MESSAGE_CONSTRAINTS); + } + System.out.println("uh oh"); + modelEmail = new Email(email); } - if (!Address.isValidAddress(address)) { - throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); + + final Address modelAddress; + if (address.isEmpty()) { + modelAddress = new Address(new Blank()); + } else { + if (!Address.isValidAddress(address)) { + throw new IllegalValueException(Address.MESSAGE_CONSTRAINTS); + } + modelAddress = new Address(address); } - final Address modelAddress = new Address(address); final Set modelTags = new HashSet<>(personTags); final Map modelGames = new HashMap<>(personGames); diff --git a/src/main/java/seedu/address/ui/CommandBox.java b/src/main/java/seedu/address/ui/CommandBox.java index 6c694135f4b..ecc99d4b2be 100644 --- a/src/main/java/seedu/address/ui/CommandBox.java +++ b/src/main/java/seedu/address/ui/CommandBox.java @@ -5,7 +5,6 @@ import javafx.collections.ObservableList; import javafx.fxml.FXML; -import javafx.scene.input.KeyCode; import javafx.scene.layout.Region; import seedu.address.logic.commands.CommandResult; import seedu.address.logic.commands.exceptions.CommandException; @@ -43,32 +42,29 @@ public CommandBox(CommandExecutor commandExecutor) { commandTextField.textProperty().addListener((unused1, unused2, unused3) -> setStyleToDefault()); } + /** - * initialize() method from javaFx, used to check for arrow inputs inside the commandTextField + * Handles the Up button pressed event. */ @FXML - public void initialize() { - commandTextField.setOnKeyPressed(event -> { - if (event.getCode() == KeyCode.UP && !event.isShiftDown()) { - String previousCommand = commandHistory.getPreviousCommand(); - if (previousCommand != null) { - commandTextField.setText(previousCommand); - commandTextField.positionCaret(previousCommand.length()); // Move cursor to end - } - } - if (event.getCode() == KeyCode.DOWN && !event.isShiftDown()) { - String nextCommand = commandHistory.getNextCommand(); - if (nextCommand != null) { - commandTextField.setText(nextCommand); - commandTextField.positionCaret(nextCommand.length()); // Move cursor to end - } - } - if (event.getCode() == KeyCode.ENTER) { - handleCommandEntered(); - } - }); + public void handleUpEntered() { + String previousCommand = commandHistory.getPreviousCommand(); + if (previousCommand != null) { + commandTextField.setText(previousCommand); + commandTextField.positionCaret(previousCommand.length()); // Move cursor to end + } + } + /** + * Handles the Down button pressed event. + */ + @FXML + public void handleDownEntered() { + String nextCommand = commandHistory.getNextCommand(); + if (nextCommand != null) { + commandTextField.setText(nextCommand); + commandTextField.positionCaret(nextCommand.length()); // Move cursor to end + } } - /** * Handles the Enter button pressed event. diff --git a/src/main/java/seedu/address/ui/CommandHistory.java b/src/main/java/seedu/address/ui/CommandHistory.java index 16df4c710c3..211f0c02c57 100644 --- a/src/main/java/seedu/address/ui/CommandHistory.java +++ b/src/main/java/seedu/address/ui/CommandHistory.java @@ -35,6 +35,9 @@ public String getNextCommand() { currentHistoryIndex++; return commandHistory.get(currentHistoryIndex); } + if (currentHistoryIndex == commandHistory.size() - 1) { + currentHistoryIndex++; + } return ""; // No next command } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index 941d85c3332..f8b4f7f2c55 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -67,8 +67,23 @@ public PersonCard(Person person, int displayedIndex) { id.setText(displayedIndex + ". "); name.setText(person.getName().fullName); phone.setText(person.getPhone().value); + if (phone.getText().isEmpty()) { + phone.setMaxHeight(0); + phone.setMinHeight(0); + phone.setPrefHeight(0); + } address.setText(person.getAddress().value); + if (address.getText().isEmpty()) { + address.setMaxHeight(0); + address.setMinHeight(0); + address.setPrefHeight(0); + } email.setText(person.getEmail().value); + if (email.getText().isEmpty()) { + email.setMaxHeight(0); + email.setMinHeight(0); + email.setPrefHeight(0); + } person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); diff --git a/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java b/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java index 6d31f745a87..f501660d44c 100644 --- a/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java +++ b/src/main/java/seedu/address/ui/commandpopup/AutoSuggestionTextField.java @@ -5,7 +5,6 @@ import java.util.SortedSet; import java.util.stream.Collectors; -import javafx.application.Platform; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.event.EventHandler; @@ -43,7 +42,6 @@ public class AutoSuggestionTextField extends TextField { private PopupControl suggestionPopup; private ListView suggestionList; private CommandBox commandBox; - private ObservableList textFlowItems; /** @@ -66,7 +64,7 @@ public AutoSuggestionTextField() { // Listen for text changes textProperty().addListener((obs, oldText, newText) -> { - if (!newText.isEmpty()) { + if (!newText.trim().isEmpty()) { String[] text = newText.split("\\s+"); String command = text[0]; boolean hasParams = false; @@ -81,6 +79,12 @@ public AutoSuggestionTextField() { // Add key event handler to both the TextField and ListView EventHandler keyEventHandler = event -> { + if (event.getCode() == KeyCode.UP && !event.isShiftDown()) { + commandBox.handleUpEntered(); + } + if (event.getCode() == KeyCode.DOWN && !event.isShiftDown()) { + commandBox.handleDownEntered(); + } if (event.isShiftDown()) { switch (event.getCode()) { case UP: @@ -97,6 +101,8 @@ public AutoSuggestionTextField() { } else if (event.getCode() == KeyCode.TAB) { handleTab(); event.consume(); + } else if (event.getCode() == KeyCode.ENTER) { + handleCommandEntered(); } }; @@ -106,7 +112,6 @@ public AutoSuggestionTextField() { CommandTextFlow commandFlow = (CommandTextFlow) selectedTextFlow; setText(commandFlow.getCommandText()); this.positionCaret(commandFlow.getCommandText().length()); - suggestionPopup.hide(); } }); @@ -114,11 +119,6 @@ public AutoSuggestionTextField() { this.addEventHandler(KeyEvent.KEY_PRESSED, keyEventHandler); suggestionList.addEventHandler(KeyEvent.KEY_PRESSED, keyEventHandler); - // Ensure the TextField keeps focus when showing popup - suggestionPopup.setOnShowing(event -> { - Platform.runLater(() -> this.requestFocus()); - }); - // Prevent ListView from handling its default key events suggestionList.addEventFilter(KeyEvent.ANY, event -> { if (event.isControlDown() || (event.isShiftDown() && event.getCode() == KeyCode.ENTER)) { @@ -232,7 +232,7 @@ public void hidePopup() { } /** - * Sets the CommandBox object that processes commands entered in the TextField. + * Sets the CommandBox object that processes commands entered into the TextField. * * @param commandBox The CommandBox object to be set. */ @@ -353,6 +353,7 @@ public void populatePopup(List filteredList, String searchRequest) { } } + /** * Build TextFlow with selected text. Return "case" dependent. * diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index e1344d57411..99ae2ef9972 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -9,7 +9,7 @@ - + diff --git a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java index 8d910548bf0..3b617d847db 100644 --- a/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/AddCommandParserTest.java @@ -37,7 +37,6 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.AddCommand; -import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Person; @@ -146,17 +145,6 @@ public void parse_compulsoryFieldMissing_failure() { assertParseFailure(parser, VALID_NAME_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB, expectedMessage); - // missing phone prefix - assertParseFailure(parser, NAME_DESC_BOB + VALID_PHONE_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB, - expectedMessage); - - // missing email prefix - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + VALID_EMAIL_BOB + ADDRESS_DESC_BOB, - expectedMessage); - - // missing address prefix - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + VALID_ADDRESS_BOB, - expectedMessage); // all prefixes missing assertParseFailure(parser, VALID_NAME_BOB + VALID_PHONE_BOB + VALID_EMAIL_BOB + VALID_ADDRESS_BOB, @@ -177,10 +165,6 @@ public void parse_invalidValue_failure() { assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + INVALID_EMAIL_DESC + ADDRESS_DESC_BOB + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Email.MESSAGE_CONSTRAINTS); - // invalid address - assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + INVALID_ADDRESS_DESC - + TAG_DESC_HUSBAND + TAG_DESC_FRIEND, Address.MESSAGE_CONSTRAINTS); - // invalid tag assertParseFailure(parser, NAME_DESC_BOB + PHONE_DESC_BOB + EMAIL_DESC_BOB + ADDRESS_DESC_BOB + INVALID_TAG_DESC + VALID_TAG_FRIEND, Tag.MESSAGE_CONSTRAINTS); diff --git a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java index cc7175172d4..f0f7eaf3e0a 100644 --- a/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java +++ b/src/test/java/seedu/address/logic/parser/EditCommandParserTest.java @@ -38,7 +38,6 @@ import seedu.address.logic.Messages; import seedu.address.logic.commands.EditCommand; import seedu.address.logic.commands.EditCommand.EditPersonDescriptor; -import seedu.address.model.person.Address; import seedu.address.model.person.Email; import seedu.address.model.person.Name; import seedu.address.model.person.Phone; @@ -86,7 +85,6 @@ public void parse_invalidValue_failure() { assertParseFailure(parser, "1" + INVALID_NAME_DESC, Name.MESSAGE_CONSTRAINTS); // invalid name 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_TAG_DESC, Tag.MESSAGE_CONSTRAINTS); // invalid tag // invalid phone followed by valid email diff --git a/src/test/java/seedu/address/model/person/AddressTest.java b/src/test/java/seedu/address/model/person/AddressTest.java index 314885eca26..388334236ab 100644 --- a/src/test/java/seedu/address/model/person/AddressTest.java +++ b/src/test/java/seedu/address/model/person/AddressTest.java @@ -10,7 +10,7 @@ public class AddressTest { @Test public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new Address(null)); + assertThrows(NullPointerException.class, () -> new Address((String) null)); } @Test diff --git a/src/test/java/seedu/address/model/person/EmailTest.java b/src/test/java/seedu/address/model/person/EmailTest.java index f08cdff0a64..ee0fdd5276d 100644 --- a/src/test/java/seedu/address/model/person/EmailTest.java +++ b/src/test/java/seedu/address/model/person/EmailTest.java @@ -10,7 +10,7 @@ public class EmailTest { @Test public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new Email(null)); + assertThrows(NullPointerException.class, () -> new Email((String) null)); } @Test diff --git a/src/test/java/seedu/address/model/person/PhoneTest.java b/src/test/java/seedu/address/model/person/PhoneTest.java index deaaa5ba190..9dd6e7b4390 100644 --- a/src/test/java/seedu/address/model/person/PhoneTest.java +++ b/src/test/java/seedu/address/model/person/PhoneTest.java @@ -10,7 +10,7 @@ public class PhoneTest { @Test public void constructor_null_throwsNullPointerException() { - assertThrows(NullPointerException.class, () -> new Phone(null)); + assertThrows(NullPointerException.class, () -> new Phone((String) null)); } @Test diff --git a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java index 330256f69a4..30ffe02e878 100644 --- a/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java +++ b/src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java @@ -1,5 +1,6 @@ package seedu.address.storage; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static seedu.address.storage.JsonAdaptedPerson.MISSING_FIELD_MESSAGE_FORMAT; import static seedu.address.testutil.Assert.assertThrows; @@ -70,11 +71,12 @@ public void toModelType_invalidPhone_throwsIllegalValueException() { } @Test - public void toModelType_nullPhone_throwsIllegalValueException() { + public void toModelType_nullPhone_isValid() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS, VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName()); - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + assertDoesNotThrow(()-> new JsonAdaptedPerson(VALID_NAME, null, VALID_EMAIL, VALID_ADDRESS, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME)); } @Test @@ -86,27 +88,30 @@ public void toModelType_invalidEmail_throwsIllegalValueException() { } @Test - public void toModelType_nullEmail_throwsIllegalValueException() { + public void toModelType_nullEmail_isValid() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS, VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName()); - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + assertDoesNotThrow(()-> new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, null, VALID_ADDRESS, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME)); } @Test - public void toModelType_invalidAddress_throwsIllegalValueException() { + public void toModelType_invalidAddress_isValid() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = Address.MESSAGE_CONSTRAINTS; - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + assertDoesNotThrow(()-> new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_ADDRESS, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME)); } @Test - public void toModelType_nullAddress_throwsIllegalValueException() { + public void toModelType_nullAddress_isValid() { JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME); String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName()); - assertThrows(IllegalValueException.class, expectedMessage, person::toModelType); + assertDoesNotThrow(()-> new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null, + VALID_TAGS, VALID_GAMES, VALID_PREFERREDTIME)); } @Test diff --git a/src/test/java/seedu/address/ui/CommandHistoryTest.java b/src/test/java/seedu/address/ui/CommandHistoryTest.java index 7d22ed2a32c..d1e8c1e9755 100644 --- a/src/test/java/seedu/address/ui/CommandHistoryTest.java +++ b/src/test/java/seedu/address/ui/CommandHistoryTest.java @@ -40,6 +40,16 @@ public void testPrevCommand() { assertNull(commandHistory.getPreviousCommand()); } + @Test + public void testOneCommand() { + commandHistory.addCommand("first command"); + + commandHistory.getPreviousCommand(); + commandHistory.getNextCommand(); + + assertEquals("first command", commandHistory.getPreviousCommand()); + assertEquals("", commandHistory.getNextCommand()); // No further next command after latest + } @Test public void testNextCommand() { commandHistory.addCommand("first command"); @@ -76,5 +86,6 @@ public void testMixedNavigation() { // After the latest command, there should be no more next command and change the textfield back to a blank assertEquals("", commandHistory.getNextCommand()); + assertEquals("third command", commandHistory.getPreviousCommand()); } }