Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Darren159 committed Oct 19, 2023
1 parent 1cc2453 commit 776e65a
Show file tree
Hide file tree
Showing 27 changed files with 530 additions and 84 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/logic/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static String format(Person person) {
*/
public static String format(Appointment appointment, Person person) {
final StringBuilder builder = new StringBuilder();
builder.append(appointment.getTitle())
builder.append(appointment.getName())
.append("; Date & Time: ")
.append(appointment.getDateTime())
.append("; Patient: ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static java.util.Objects.requireNonNull;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TITLE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;

import java.util.List;

Expand All @@ -24,10 +24,10 @@ public class AddAppointmentCommand extends Command {

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an appointment to the address book.\n"
+ "Parameters: INDEX (must be a positive integer) "
+ PREFIX_TITLE + "TITLE "
+ PREFIX_NAME + "NAME "
+ PREFIX_DATE + "DATE\n"
+ "Example: " + COMMAND_WORD + " 1 "
+ PREFIX_TITLE + "Eye Examination "
+ PREFIX_NAME + "Eye Examination "
+ PREFIX_DATE + "18-09-2023 1800 ";


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import static java.util.Objects.requireNonNull;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TITLE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;

import java.util.stream.Stream;

import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.AddAppointmentCommand;
Expand All @@ -24,25 +26,36 @@ public class AddAppointmentCommandParser implements Parser<AddAppointmentCommand
*/
public AddAppointmentCommand parse(String args) throws ParseException {
requireNonNull(args);
ArgumentMultimap argMultimap =
ArgumentTokenizer.tokenize(args, PREFIX_TITLE, PREFIX_DATE);
ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_DATE);

Index index;

try {
index = ParserUtil.parseIndex(argMultimap.getPreamble());
} catch (ParseException pe) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
AddAppointmentCommand.MESSAGE_USAGE), pe);
AddAppointmentCommand.MESSAGE_USAGE), pe);
}

if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_DATE)) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddAppointmentCommand.MESSAGE_USAGE));
}

argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_TITLE, PREFIX_DATE);
argMultimap.verifyNoDuplicatePrefixesFor(PREFIX_NAME, PREFIX_DATE);

Name title = ParserUtil.parseName(argMultimap.getValue(PREFIX_TITLE).get());
Name name = ParserUtil.parseName(argMultimap.getValue(PREFIX_NAME).get());
DateTime dateTime = ParserUtil.parseDateTime(argMultimap.getValue(PREFIX_DATE).get());

Appointment appointment = new Appointment(title, dateTime);
Appointment appointment = new Appointment(name, dateTime);

return new AddAppointmentCommand(index, appointment);
}

/**
* Returns true if none of the prefixes contains empty {@code Optional} values in the given
* {@code ArgumentMultimap}.
*/
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) {
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent());
}
}
1 change: 0 additions & 1 deletion src/main/java/seedu/address/logic/parser/CliSyntax.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ public class CliSyntax {
public static final Prefix PREFIX_BLOODTYPE = new Prefix("bt/");
public static final Prefix PREFIX_ALLERGIES = new Prefix("al/");
public static final Prefix PREFIX_DATE = new Prefix("d/");
public static final Prefix PREFIX_TITLE = new Prefix("t/");
}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/person/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public String toString() {
.add("bloodType", bloodType)
.add("allergies", allergies)
.add("isPinned", isPinned)
.add("appointments", appointments)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
public class Appointment {

// Identity fields
private final Name title;
private final Name name;
private final DateTime dateTime;
/**
* Every field must be present and not null.
*/
public Appointment(Name title, DateTime dateTime) {
requireAllNonNull(title, dateTime);
this.title = title;
public Appointment(Name name, DateTime dateTime) {
requireAllNonNull(name, dateTime);
this.name = name;
this.dateTime = dateTime;
}

public Name getTitle() {
return title;
public Name getName() {
return name;
}

public DateTime getDateTime() {
Expand All @@ -45,20 +45,20 @@ public boolean equals(Object other) {
}

Appointment otherAppointment = (Appointment) other;
return title.equals(otherAppointment.title)
return name.equals(otherAppointment.name)
&& dateTime.equals(otherAppointment.dateTime);
}

@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(title, dateTime);
return Objects.hash(name, dateTime);
}

@Override
public String toString() {
return new ToStringBuilder(this)
.add("title", title)
.add("name", name)
.add("dateTime", dateTime)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void add(Appointment toAdd) {
* The appointment identity of {@code editedappointment} must not be the same as
* another existing appointment in the list.
*/
public void setappointment(Appointment target, Appointment editedappointment) {
public void setAppointment(Appointment target, Appointment editedappointment) {
requireAllNonNull(target, editedappointment);

int index = internalList.indexOf(target);
Expand Down Expand Up @@ -86,7 +86,7 @@ public void setAppointments(UniqueAppointmentList replacement) {
* Replaces the contents of this list with {@code appointments}.
* {@code appointments} must not contain duplicate appointments.
*/
public void setappointments(List<Appointment> appointments) {
public void setAppointments(List<Appointment> appointments) {
requireAllNonNull(appointments);
if (!appointmentsAreUnique(appointments)) {
throw new DuplicateAppointmentException();
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/seedu/address/storage/JsonAdaptedAppointment.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ class JsonAdaptedAppointment {

public static final String MISSING_FIELD_MESSAGE_FORMAT = "Appointment's %s field is missing!";

private final String title;
private final String name;
private final String dateTime;

/**
* Constructs a {@code JsonAdaptedAppointment} with the given person details.
*/
@JsonCreator
public JsonAdaptedAppointment(@JsonProperty("title") String title, @JsonProperty("dateTime") String dateTime) {
this.title = title;
public JsonAdaptedAppointment(@JsonProperty("name") String name, @JsonProperty("dateTime") String dateTime) {
this.name = name;
this.dateTime = dateTime;
}

/**
* Converts a given {@code Appointment} into this class for Jackson use.
*/
public JsonAdaptedAppointment(Appointment source) {
title = source.getTitle().fullName;
name = source.getName().fullName;
dateTime = source.getDateTime().toString();
}

Expand All @@ -42,13 +42,13 @@ public JsonAdaptedAppointment(Appointment source) {
* @throws IllegalValueException if there were any data constraints violated in the adapted appointment.
*/
public Appointment toModelType() throws IllegalValueException {
if (title == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "Title"));
if (name == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "Name"));
}
if (!Name.isValidName(title)) {
if (!Name.isValidName(name)) {
throw new IllegalValueException(Name.MESSAGE_CONSTRAINTS);
}
final Name modelTitle = new Name(title);
final Name modelname = new Name(name);

if (dateTime == null) {
throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, "DateTime"));
Expand All @@ -58,6 +58,6 @@ public Appointment toModelType() throws IllegalValueException {
}
final DateTime modelDateTime = new DateTime(dateTime);

return new Appointment(modelTitle, modelDateTime);
return new Appointment(modelname, modelDateTime);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"name": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
Expand All @@ -27,7 +27,7 @@
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"name": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"name": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"name": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
Expand All @@ -28,7 +28,7 @@
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"name": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"isPinned": true,
"appointments": [
{
"title": "Eye Examination",
"name": "Eye Examination",
"dateTime": "18-09-2023 1800"
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@
"isPinned": true,
"appointments": [
{
"title": "Eye Exam",
"name": "Eye Exam",
"dateTime": "01-01-2001 1200"
},
{
"name": "Vaccination",
"dateTime": "11-09-2001 1200"
},
{
"name": "Colonoscopy",
"dateTime": "21-12-2001 1200"
}
]
},
Expand All @@ -28,8 +36,16 @@
"isPinned": false,
"appointments": [
{
"title": "Vaccination",
"name": "Eye Exam",
"dateTime": "01-01-2001 1200"
},
{
"name": "Vaccination",
"dateTime": "11-09-2001 1200"
},
{
"name": "Colonoscopy",
"dateTime": "21-12-2001 1200"
}
]
},
Expand All @@ -44,7 +60,15 @@
"isPinned": false,
"appointments": [
{
"title": "Colonoscopy",
"name": "Eye Exam",
"dateTime": "01-01-2001 1200"
},
{
"name": "Vaccination",
"dateTime": "11-09-2001 1200"
},
{
"name": "Colonoscopy",
"dateTime": "21-12-2001 1200"
}
]
Expand Down
Loading

0 comments on commit 776e65a

Please sign in to comment.