Skip to content

Commit

Permalink
Merge pull request AY2324S2-CS2103T-T15-1#236 from alfaloo/debug
Browse files Browse the repository at this point in the history
Add logging and assertions
  • Loading branch information
Alteqa authored Apr 15, 2024
2 parents e24edd6 + ceb6b09 commit 23eecd3
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import seedu.address.Main;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
Expand Down Expand Up @@ -38,7 +37,7 @@ public class AddDoctorCommand extends Command {

public static final String MESSAGE_SUCCESS = "New doctor added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
private static Logger logger = LogsCenter.getLogger(Main.class);
private static Logger logger = LogsCenter.getLogger(AddDoctorCommand.class);

private final Doctor toAdd;

Expand All @@ -60,6 +59,7 @@ public CommandResult execute(Model model) throws CommandException {
}

model.addPerson(toAdd);
logger.log(Level.INFO, "Doctor successfully added (when executing command: adddoctor)");
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import static seedu.address.logic.parser.CliSyntax.PREFIX_NRIC;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;

import java.util.logging.Level;
import java.util.logging.Logger;

import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.logic.commands.exceptions.CommandException;
Expand Down Expand Up @@ -33,6 +37,7 @@ public class AddPatientCommand extends Command {

public static final String MESSAGE_SUCCESS = "New patient added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This person already exists in the address book";
private static Logger logger = LogsCenter.getLogger(AddPatientCommand.class);

private final Patient toAdd;

Expand All @@ -49,10 +54,12 @@ public CommandResult execute(Model model) throws CommandException {
requireNonNull(model);

if (model.hasPerson(toAdd)) {
logger.log(Level.INFO, "Duplicate person detected! (when executing command: addpatient)");
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
}

model.addPerson(toAdd);
logger.log(Level.INFO, "Patient successfully added (when executing command: addpatient)");
return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(toAdd)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public CommandResult execute(Model model) throws CommandException {

Person personToDelete = lastShownList.get(targetIndex.getZeroBased());
model.deletePerson(personToDelete);
logger.log(Level.INFO, "Person succesfully deleted. (when executing command: delete)");
String message = (personToDelete.getType() == Type.PATIENT
? MESSAGE_DELETE_PATIENT_SUCCESS
: MESSAGE_DELETE_DOCTOR_SUCCESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import static java.util.Objects.requireNonNull;

import java.util.logging.Level;
import java.util.logging.Logger;

import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.util.ToStringBuilder;
import seedu.address.logic.Messages;
import seedu.address.model.Model;
Expand All @@ -22,6 +26,8 @@ public class QueryDoctorCommand extends Command {
+ "Parameters: KEYWORD [MORE_KEYWORDS]...\n"
+ "Example: " + COMMAND_WORD + " alice bob charlie";

private static Logger logger = LogsCenter.getLogger(QueryDoctorCommand.class);

private final DoctorContainsKeywordsPredicate predicate;

public QueryDoctorCommand(DoctorContainsKeywordsPredicate predicate) {
Expand All @@ -31,7 +37,10 @@ public QueryDoctorCommand(DoctorContainsKeywordsPredicate predicate) {
@Override
public CommandResult execute(Model model) {
requireNonNull(model);
logger.log(Level.INFO, "Executing QueryDoctorCommand");
model.updateFilteredPersonList(predicate);
int numberOfDoctors = model.getFilteredPersonList().size();
logger.log(Level.INFO, "Number of Doctor found: " + numberOfDoctors);
return new CommandResult(
String.format(Messages.MESSAGE_PERSONS_LISTED_OVERVIEW, model.getFilteredPersonList().size()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class AppointmentDateTime {
* @param dateStr input string to be stored
*/
public AppointmentDateTime(String dateStr) {
assert dateStr.length() == 16 : "Appointment date-time string is of incorrect length";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
requireNonNull(dateStr);
checkArgument(isValidDate(dateStr), MESSAGE_CONSTRAINTS);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/person/DoB.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class DoB {
*/
public DoB(String dob) {
requireNonNull(dob);
assert dob.length() == 10 : "Person dob string is of incorrect length";
checkArgument(isValidDoB(dob), MESSAGE_CONSTRAINTS);
dateOfBirth = LocalDate.parse(dob);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/person/Nric.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Nric {
*/
public Nric(String nric) {
requireNonNull(nric);
assert nric.length() == 9 : "Person nric string is of incorrect length";
checkArgument(isValidNric(nric), MESSAGE_CONSTRAINTS);
this.nric = nric;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/person/Phone.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Phone {
*/
public Phone(String phone) {
requireNonNull(phone);
assert phone.length() == 8 : "Person phone string is of incorrect length";
checkArgument(isValidPhone(phone), MESSAGE_CONSTRAINTS);
value = phone;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/model/person/DoBTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void constructor_null_throwsNullPointerException() {
@Test
public void constructor_invalidDoB_throwsIllegalArgumentException() {
String invalidDoB = "";
assertThrows(IllegalArgumentException.class, () -> new DoB(invalidDoB));
assertThrows(AssertionError.class, () -> new DoB(invalidDoB));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/model/person/NricTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void constructor_null_throwsNullPointerException() {
@Test
public void constructor_invalidNric_throwsIllegalArgumentException() {
String invalidNric = "A0234";
assertThrows(IllegalArgumentException.class, () -> new Nric(invalidNric));
assertThrows(AssertionError.class, () -> new Nric(invalidNric));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/model/person/PhoneTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void constructor_null_throwsNullPointerException() {
@Test
public void constructor_invalidPhone_throwsIllegalArgumentException() {
String invalidPhone = "";
assertThrows(IllegalArgumentException.class, () -> new Phone(invalidPhone));
assertThrows(AssertionError.class, () -> new Phone(invalidPhone));
}

@Test
Expand Down

0 comments on commit 23eecd3

Please sign in to comment.