Skip to content

Commit

Permalink
Fixed checkstyle
Browse files Browse the repository at this point in the history
  • Loading branch information
reidenong committed Oct 17, 2024
1 parent 45a47ca commit 112a00f
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public CommandResult execute(Model model) throws CommandException {
Person personToEdit = lastShownList.get(index.getZeroBased());
Person editedPerson = new Person(
personToEdit.getName(), personToEdit.getPhone(), personToEdit.getEmail(), personToEdit.getNric(),
personToEdit.getAddress(), personToEdit.getRemark(), personToEdit.getTags(), new Appointment(this.appointmentString));
personToEdit.getAddress(), personToEdit.getRemark(), personToEdit.getTags(),

Check warning on line 56 in src/main/java/seedu/address/logic/commands/AppointmentCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AppointmentCommand.java#L53-L56

Added lines #L53 - L56 were not covered by tests
new Appointment(this.appointmentString));
model.setPerson(personToEdit, editedPerson);
model.updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
return new CommandResult("Set appointment for " + personToEdit.getName() + " on " + this.appointmentString);

Check warning on line 60 in src/main/java/seedu/address/logic/commands/AppointmentCommand.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/seedu/address/logic/commands/AppointmentCommand.java#L58-L60

Added lines #L58 - L60 were not covered by tests
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ public class Person {
/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Nric nric, Address address, Remark remark, Set<Tag> tags, Appointment appointment) {
public Person(
Name name,
Phone phone,
Email email,
Nric nric,
Address address,
Remark remark,
Set<Tag> tags,
Appointment appointment) {
requireAllNonNull(name, phone, email, nric, address, tags);
this.name = name;
this.phone = phone;
Expand Down
13 changes: 9 additions & 4 deletions src/main/java/seedu/address/storage/JsonAdaptedPerson.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,14 @@ class JsonAdaptedPerson {
* Constructs a {@code JsonAdaptedPerson} with the given person details.
*/
@JsonCreator
public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone,
@JsonProperty("email") String email, @JsonProperty("address") String address,
@JsonProperty("tags") List<JsonAdaptedTag> tags, @JsonProperty("nric") String nric,
public JsonAdaptedPerson(
@JsonProperty("name") String name,
@JsonProperty("phone") String phone,
@JsonProperty("email") String email,
@JsonProperty("nric") String nric,
@JsonProperty("address") String address,
@JsonProperty("remark") String remark,
@JsonProperty("tags") List<JsonAdaptedTag> tags,
@JsonProperty("appointment") String appointment) {
this.name = name;
this.phone = phone;
Expand Down Expand Up @@ -142,7 +146,8 @@ public Person toModelType() throws IllegalValueException {
}
final Remark modelRemark = new Remark(remark);

return new Person(modelName, modelPhone, modelEmail, modelNric, modelAddress, modelRemark, modelTags, modelAppointment);
return new Person(modelName, modelPhone, modelEmail, modelNric, modelAddress,
modelRemark, modelTags, modelAppointment);
}

}
152 changes: 120 additions & 32 deletions src/test/java/seedu/address/storage/JsonAdaptedPersonTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,94 +38,175 @@ public class JsonAdaptedPersonTest {

@Test
public void toModelType_validPersonDetails_returnsPerson() throws Exception {
JsonAdaptedPerson person = new JsonAdaptedPerson(BENSON);
JsonAdaptedPerson person = new JsonAdaptedPerson(
BENSON.getName().toString(),
BENSON.getPhone().toString(),
BENSON.getEmail().toString(),
BENSON.getNric().toString(),
BENSON.getAddress().toString(),
BENSON.getRemark().toString(),
VALID_TAGS,
null
);
assertEquals(BENSON, person.toModelType());
}

@Test
public void toModelType_invalidName_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(INVALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_NRIC,
VALID_TAGS, VALID_REMARK, VALID_ADDRESS, null);
JsonAdaptedPerson person = new JsonAdaptedPerson(
INVALID_NAME,
VALID_PHONE,
VALID_EMAIL,
VALID_NRIC,
VALID_ADDRESS,
VALID_REMARK,
VALID_TAGS,
null
);
String expectedMessage = Name.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullName_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(null,
VALID_PHONE, VALID_EMAIL, VALID_NRIC,
VALID_TAGS, VALID_REMARK, VALID_ADDRESS, null);
JsonAdaptedPerson person = new JsonAdaptedPerson(
null,
VALID_PHONE,
VALID_EMAIL,
VALID_NRIC,
VALID_ADDRESS,
VALID_REMARK,
VALID_TAGS,
null
);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_invalidPhone_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, INVALID_PHONE, VALID_EMAIL, VALID_NRIC,
VALID_TAGS, VALID_REMARK, VALID_ADDRESS, null);
JsonAdaptedPerson person = new JsonAdaptedPerson(
VALID_NAME,
INVALID_PHONE,
VALID_EMAIL,
VALID_NRIC,
VALID_ADDRESS,
VALID_REMARK,
VALID_TAGS,
null
);
String expectedMessage = Phone.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullPhone_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME,
null, VALID_EMAIL, VALID_NRIC,
VALID_TAGS, VALID_REMARK, VALID_ADDRESS, null);
JsonAdaptedPerson person = new JsonAdaptedPerson(
VALID_NAME,
null,
VALID_EMAIL,
VALID_NRIC,
VALID_ADDRESS,
VALID_REMARK,
VALID_TAGS,
null
);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Phone.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_invalidEmail_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, INVALID_EMAIL, VALID_NRIC,
VALID_TAGS, VALID_REMARK, VALID_ADDRESS, null);
JsonAdaptedPerson person = new JsonAdaptedPerson(
VALID_NAME,
VALID_PHONE,
INVALID_EMAIL,
VALID_NRIC,
VALID_ADDRESS,
VALID_REMARK,
VALID_TAGS,
null
);
String expectedMessage = Email.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullEmail_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME,
VALID_PHONE, null, VALID_NRIC,
VALID_TAGS, VALID_REMARK, VALID_ADDRESS, null);
JsonAdaptedPerson person = new JsonAdaptedPerson(
VALID_NAME,
VALID_PHONE,
null,
VALID_NRIC,
VALID_ADDRESS,
VALID_REMARK,
VALID_TAGS,
null
);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Email.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_invalidNric_throwsIllegalValueException() {
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, INVALID_NRIC,
VALID_TAGS, VALID_REMARK, VALID_ADDRESS, null);
JsonAdaptedPerson person = new JsonAdaptedPerson(
VALID_NAME,
VALID_PHONE,
VALID_EMAIL,
INVALID_NRIC,
VALID_ADDRESS,
VALID_REMARK,
VALID_TAGS,
null
);
String expectedMessage = Nric.MESSAGE_CONSTRAINTS;
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

@Test
public void toModelType_nullNric_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, null,
VALID_TAGS, VALID_REMARK, VALID_ADDRESS, null);
JsonAdaptedPerson person = new JsonAdaptedPerson(
VALID_NAME,
VALID_PHONE,
VALID_EMAIL,
null,
VALID_ADDRESS,
VALID_REMARK,
VALID_TAGS,
null
);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Nric.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}

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

@Test
public void toModelType_nullAddress_throwsIllegalValueException() {
JsonAdaptedPerson person = new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_NRIC,
VALID_TAGS, VALID_REMARK, null, null);
JsonAdaptedPerson person = new JsonAdaptedPerson(
VALID_NAME,
VALID_PHONE,
VALID_EMAIL,
VALID_NRIC,
null,
VALID_REMARK,
VALID_TAGS,
null
);
String expectedMessage = String.format(MISSING_FIELD_MESSAGE_FORMAT, Address.class.getSimpleName());
assertThrows(IllegalValueException.class, expectedMessage, person::toModelType);
}
Expand All @@ -134,9 +215,16 @@ public void toModelType_nullAddress_throwsIllegalValueException() {
public void toModelType_invalidTags_throwsIllegalValueException() {
List<JsonAdaptedTag> invalidTags = new ArrayList<>(VALID_TAGS);
invalidTags.add(new JsonAdaptedTag(INVALID_TAG));
JsonAdaptedPerson person =
new JsonAdaptedPerson(VALID_NAME, VALID_PHONE, VALID_EMAIL, VALID_NRIC,
invalidTags, VALID_REMARK, VALID_ADDRESS, null);
JsonAdaptedPerson person = new JsonAdaptedPerson(
VALID_NAME,
VALID_PHONE,
VALID_EMAIL,
VALID_NRIC,
VALID_ADDRESS,
VALID_REMARK,
invalidTags,
null
);
assertThrows(IllegalValueException.class, person::toModelType);
}

Expand Down

0 comments on commit 112a00f

Please sign in to comment.