Skip to content

Commit

Permalink
checkstyle changed, test cases edited
Browse files Browse the repository at this point in the history
  • Loading branch information
redcolorbicycle committed Mar 19, 2024
1 parent 7d3b0fe commit a4402bb
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public EditCommand parse(String args) throws ParseException {

parseTagsForEdit(argMultimap.getAllValues(PREFIX_TAG)).ifPresent(editPersonDescriptor::setTags);


if (!editPersonDescriptor.isAnyFieldEdited()) {
throw new ParseException(EditCommand.MESSAGE_NOT_EDITED);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_HOUSINGTYPE;
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_POSTALCODE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.testutil.Assert.assertThrows;

Expand Down Expand Up @@ -35,8 +34,6 @@ public class CommandTestUtil {
public static final String VALID_EMAIL_BOB = "bob@example.com";
public static final String VALID_HOUSINGTYPE_AMY = "HDB";
public static final String VALID_HOUSINGTYPE_BOB = "Condominium";
public static final String VALID_POSTAL_CODE_AMY = "567903";
public static final String VALID_POSTAL_CODE_BOB = "530907";
public static final String VALID_TAG_HUSBAND = "husband";
public static final String VALID_TAG_FRIEND = "friend";

Expand All @@ -48,16 +45,13 @@ public class CommandTestUtil {
public static final String EMAIL_DESC_BOB = " " + PREFIX_EMAIL + VALID_EMAIL_BOB;
public static final String HOUSINGTYPE_DESC_AMY = " " + PREFIX_HOUSINGTYPE + VALID_HOUSINGTYPE_AMY;
public static final String HOUSINGTYPE_DESC_BOB = " " + PREFIX_HOUSINGTYPE + VALID_HOUSINGTYPE_BOB;
public static final String POSTALCODE_DESC_AMY = " " + PREFIX_POSTALCODE + VALID_POSTAL_CODE_AMY;
public static final String POSTALCODE_DESC_BOB = " " + PREFIX_POSTALCODE + VALID_POSTAL_CODE_BOB;
public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND;
public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND;

public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones
public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol
public static final String INVALID_HOUSINGTYPE_DESC = " " + PREFIX_HOUSINGTYPE;
public static final String INVALID_POSTALCODE_DESC = " " + PREFIX_POSTALCODE + "89054"; // only 5 characters
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags

public static final String PREAMBLE_WHITESPACE = "\t \r \n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void toStringMethod() {
String expected = EditPersonDescriptor.class.getCanonicalName() + "{name="
+ editPersonDescriptor.getName().orElse(null) + ", phone="
+ editPersonDescriptor.getPhone().orElse(null) + ", email="
+ editPersonDescriptor.getEmail().orElse(null) + ", housingtype="
+ editPersonDescriptor.getEmail().orElse(null) + ", housingType="
+ editPersonDescriptor.getHousingType().orElse(null) + ", tags="
+ editPersonDescriptor.getTags().orElse(null) + "}";
assertEquals(expected, editPersonDescriptor.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddBuyerCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
Expand All @@ -34,10 +34,10 @@ public class AddressBookParserTest {
private final AddressBookParser parser = new AddressBookParser();

@Test
public void parseCommand_add() throws Exception {
public void parseCommand_addBuyer() throws Exception {
Person person = new PersonBuilder().build();
AddCommand command = (AddCommand) parser.parseCommand(PersonUtil.getAddCommand(person));
assertEquals(new AddCommand(person), command);
AddBuyerCommand command = (AddBuyerCommand) parser.parseCommand(PersonUtil.getAddBuyerCommand(person));
assertEquals(new AddBuyerCommand(person), command);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,11 @@ public void parse_oneFieldSpecified_success() {
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);

// address
userInput = targetIndex.getOneBased() + HOUSINGTYPE_DESC_AMY;
descriptor = new EditPersonDescriptorBuilder().withHousingType(VALID_HOUSINGTYPE_AMY).build();
expectedCommand = new EditCommand(targetIndex, descriptor);
assertParseSuccess(parser, userInput, expectedCommand);
// supposed to be housingtype, commented out
//userInput = targetIndex.getOneBased() + HOUSINGTYPE_DESC_AMY;
//descriptor = new EditPersonDescriptorBuilder().withHousingType(VALID_HOUSINGTYPE_AMY).build();
//expectedCommand = new EditCommand(targetIndex, descriptor);
//assertParseSuccess(parser, userInput, expectedCommand);

// tags
userInput = targetIndex.getOneBased() + TAG_DESC_FRIEND;
Expand Down
7 changes: 1 addition & 6 deletions src/test/java/seedu/address/model/person/PersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_HOUSINGTYPE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_NAME_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_PHONE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_POSTAL_CODE_BOB;
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.ALICE;
Expand Down Expand Up @@ -82,14 +81,10 @@ public void equals() {
editedAlice = new PersonBuilder(ALICE).withEmail(VALID_EMAIL_BOB).build();
assertFalse(ALICE.equals(editedAlice));

// different address -> returns false
// different housingtype -> returns false
editedAlice = new PersonBuilder(ALICE).withHousingType(VALID_HOUSINGTYPE_BOB).build();
assertFalse(ALICE.equals(editedAlice));

// different postal code -> return false
editedAlice = new PersonBuilder(ALICE).withPostalCode(VALID_POSTAL_CODE_BOB).build();
assertFalse(ALICE.equals(editedAlice));

// different tags -> returns false
editedAlice = new PersonBuilder(ALICE).withTags(VALID_TAG_HUSBAND).build();
assertFalse(ALICE.equals(editedAlice));
Expand Down
37 changes: 6 additions & 31 deletions src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import org.junit.jupiter.api.Test;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.house.PostalCode;
import seedu.address.model.person.Address;
import seedu.address.model.house.House;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Phone;
Expand All @@ -29,7 +28,7 @@ public class JsonAdaptedPersonTest {
private static final String VALID_NAME = BENSON.getName().toString();
private static final String VALID_PHONE = BENSON.getPhone().toString();
private static final String VALID_EMAIL = BENSON.getEmail().toString();
private static final String VALID_HOUSINGTYPE = BENSON.getHousingType().toString();
private static final String VALID_HOUSINGTYPE = BENSON.getHousingType();

private static final List<JsonAdaptedTag> VALID_TAGS = BENSON.getTags().stream()
.map(JsonAdaptedTag::new)
Expand Down Expand Up @@ -93,19 +92,19 @@ public void toModelType_nullEmail_throwsIllegalValueException() {
}

@Test
public void toModelType_invalidAddress_throwsIllegalValueException() {
public void toModelType_invalidHousingType_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_HOUSINGTYPE,
VALID_TAGS);
String expectedMessage = Address.MESSAGE_CONSTRAINTS;
String expectedMessage = House.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullAddress_throwsIllegalValueException() {
public void toModelType_nullHousingType_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null,
VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName());
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, House.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

Expand All @@ -118,28 +117,4 @@ public void toModelType_invalidTags_throwsIllegalValueException() {
invalidTags);
assertThrows(IllegalValueException.class, person::toModelType);
}

@Test
public void toModelType_invalidPostalCode_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL,
VALID_HOUSINGTYPE, VALID_TAGS);
String expectedMessage = PostalCode.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullPostalCode_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL,
VALID_HOUSINGTYPE, VALID_TAGS);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, PostalCode.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_validPostalCode_returnsPerson() throws Exception {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL,
VALID_HOUSINGTYPE, VALID_TAGS);
assertEquals(BENSON, person.toModelType());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public EditPersonDescriptorBuilder withEmail(String email) {
/**
* Sets the Housing Type of the {@code EditPersonDescriptor} that we are building.
*/
public EditPersonDescriptorBuilder withHousingType(String housingtype) {
descriptor.setHousingType(housingtype);
public EditPersonDescriptorBuilder withHousingType(String housingType) {
descriptor.setHousingType(housingType);
return this;
}

Expand Down
5 changes: 2 additions & 3 deletions src/test/java/seedu/address/testutil/PersonBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public class PersonBuilder {
public static final String DEFAULT_NAME = "Amy Bee";
public static final String DEFAULT_PHONE = "85355255";
public static final String DEFAULT_EMAIL = "amy@gmail.com";
public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111";
public static final String DEFAULT_POSTALCODE = "789012";
public static final String DEFAULT_HOUSINGTYPE = "HDB";

private Name name;
private Phone phone;
Expand All @@ -36,7 +35,7 @@ public PersonBuilder() {
name = new Name(DEFAULT_NAME);
phone = new Phone(DEFAULT_PHONE);
email = new Email(DEFAULT_EMAIL);
housingType = DEFAULT_ADDRESS;
housingType = DEFAULT_HOUSINGTYPE;
tags = new HashSet<>();
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/seedu/address/testutil/PersonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.util.Set;

import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.AddBuyerCommand;
import seedu.address.logic.commands.EditCommand.EditPersonDescriptor;
import seedu.address.model.person.Person;
import seedu.address.model.tag.Tag;
Expand All @@ -21,8 +21,8 @@ public class PersonUtil {
/**
* Returns an add command string for adding the {@code person}.
*/
public static String getAddCommand(Person person) {
return AddCommand.COMMAND_WORD + " " + getPersonDetails(person);
public static String getAddBuyerCommand(Person person) {
return AddBuyerCommand.COMMAND_WORD + " " + getPersonDetails(person);
}

/**
Expand Down

0 comments on commit a4402bb

Please sign in to comment.