Skip to content

Commit

Permalink
Merge pull request #232 from e1121208/many-many-more-code-coverage
Browse files Browse the repository at this point in the history
Add more test for code coverage
  • Loading branch information
e1121208 authored Nov 5, 2024
2 parents 85a5ec2 + b164ce5 commit a841cbb
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

import static java.util.Objects.requireNonNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.BENSON;
import static seedu.address.testutil.TypicalPersons.DANIEL;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -61,7 +65,7 @@ public void execute_invalidIndex_throwsCommandException() {
}

@Test
public void execute_validIndex_addAppointmentSuccess() throws Exception {
public void execute_validSellerIndex_addAppointmentSuccess() throws Exception {
// Arrange
Person personToEdit = ALICE;
ModelStubWithPerson modelStub = new ModelStubWithPerson(personToEdit);
Expand All @@ -78,6 +82,24 @@ public void execute_validIndex_addAppointmentSuccess() throws Exception {
result.getFeedbackToUser());
}

@Test
public void execute_validBuyerIndex_addAppointmentSuccess() throws Exception {
// Arrange
Person personToEdit = DANIEL;
ModelStubWithPerson modelStub = new ModelStubWithPerson(personToEdit);

AppointmentCommand command = new AppointmentCommand(DANIEL.getName(), validAppointment);

// Act
CommandResult result = command.execute(modelStub);

// Assert
Person editedPerson = new PersonBuilder(personToEdit).withAppointment(VALID_DATE, VALID_FROM, VALID_TO)
.buildBuyer();
assertEquals(String.format(AppointmentCommand.MESSAGE_ADD_APPOINTMENT_SUCCESS, Messages.format(editedPerson)),
result.getFeedbackToUser());
}

@Test
public void execute_validIndex_updatesPersonWithAppointment() throws Exception {
// Arrange
Expand All @@ -94,6 +116,30 @@ public void execute_validIndex_updatesPersonWithAppointment() throws Exception {
.buildBuyer();
assertEquals(editedPerson.getAppointment(), validAppointment);
}
@Test
public void equals() {
AppointmentCommand firstAppointmentCommand =
new AppointmentCommand(ALICE.getName(), validAppointment);
AppointmentCommand secondAppointmentCommand =
new AppointmentCommand(BENSON.getName(), validAppointment);

// same object -> returns true
assertTrue(firstAppointmentCommand.equals(firstAppointmentCommand));

// same values -> returns true
AppointmentCommand firstAppointmentCommandCopy =
new AppointmentCommand(ALICE.getName(), validAppointment);
assertTrue(firstAppointmentCommand.equals(firstAppointmentCommandCopy));

// different types -> returns false
assertFalse(firstAppointmentCommand.equals(1));

// null -> returns false
assertFalse(firstAppointmentCommand.equals(null));

// different person -> returns false
assertFalse(firstAppointmentCommand.equals(secondAppointmentCommand));
}

/**
* A Model stub that contains a single person.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static seedu.address.logic.commands.CommandTestUtil.showPersonWithName;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.BENSON;
import static seedu.address.testutil.TypicalPersons.DANIEL;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
import static seedu.address.testutil.TypicalPersons.getTypicalNames;

Expand All @@ -25,40 +26,47 @@
import seedu.address.model.person.Buyer;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Seller;

public class DeleteAppointmentCommandTest {
private static final Name DO_NOT_EXIST_NAME = new Name("DO NOT EXIST NAME");
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs(), new Listings());


@Test
public void execute_validNameUnfilteredList_success() {
Random random = new Random();
List<Name> typicalNames = getTypicalNames();
int randomIndex = random.nextInt(typicalNames.size() - 1);
Person personToDeleteAppointment = model.getPersonByName(typicalNames.get(randomIndex));
public void execute_validBuyerNameUnfilteredList_success() {
Person personToDeleteAppointment = DANIEL;
DeleteAppointmentCommand deleteAppointmentCommand =
new DeleteAppointmentCommand(personToDeleteAppointment.getName());

String expectedMessage = String.format(DeleteAppointmentCommand.MESSAGE_DELETE_APPOINTMENT_SUCCESS,
personToDeleteAppointment.getName());

Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs(), new Listings());
Person personWithoutAppointment;
if (personToDeleteAppointment instanceof Buyer) {
personWithoutAppointment = new Buyer(personToDeleteAppointment.getName(),
personToDeleteAppointment.getPhone(),
personToDeleteAppointment.getEmail(),
personToDeleteAppointment.getTags(),
Appointment.EMPTY_APPOINTMENT);
} else { // Assuming it's a Seller if not a Buyer
personWithoutAppointment = new Seller(personToDeleteAppointment.getName(),
Person personWithoutAppointment = new Buyer(personToDeleteAppointment.getName(),
personToDeleteAppointment.getPhone(),
personToDeleteAppointment.getEmail(),
personToDeleteAppointment.getTags(),
Appointment.EMPTY_APPOINTMENT);
}
expectedModel.setPerson(personToDeleteAppointment, personWithoutAppointment);

assertCommandSuccess(deleteAppointmentCommand, model, expectedMessage, expectedModel);
}

@Test
public void execute_validSellerNameUnfilteredList_success() {
Person personToDeleteAppointment = ALICE;
DeleteAppointmentCommand deleteAppointmentCommand =
new DeleteAppointmentCommand(personToDeleteAppointment.getName());

String expectedMessage = String.format(DeleteAppointmentCommand.MESSAGE_DELETE_APPOINTMENT_SUCCESS,
personToDeleteAppointment.getName());

Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs(), new Listings());
Person personWithoutAppointment = new Buyer(personToDeleteAppointment.getName(),
personToDeleteAppointment.getPhone(),
personToDeleteAppointment.getEmail(),
personToDeleteAppointment.getTags(),
Appointment.EMPTY_APPOINTMENT);
expectedModel.setPerson(personToDeleteAppointment, personWithoutAppointment);

assertCommandSuccess(deleteAppointmentCommand, model, expectedMessage, expectedModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,22 @@ public void execute_sellerInListing_throwsCommandException() {

assertCommandFailure(deleteCommand, model, expectedMessage);
}
@Test
public void execute_subName_throwsCommandException() {
Random random = new Random();
List<Name> typicalNames = getTypicalNames();
int randomIndex = random.nextInt(typicalNames.size() - 1);
Person personToDelete = model.getPersonByName(typicalNames.get(randomIndex));
String personToDeleteNameString = personToDelete.getName().toString();
Name subNamePersonToDelete =
new Name(personToDeleteNameString
.substring(0, personToDeleteNameString.length() - 1));
DeleteClientProfileCommand deleteClientProfileCommand =
new DeleteClientProfileCommand(subNamePersonToDelete);

assertCommandFailure(deleteClientProfileCommand, model,
String.format(Messages.MESSAGE_SUGGESTION, personToDelete.getName()));
}

@Test
public void equals() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;

public class MoreInfoCommandTest {
private static final Name DO_NOT_EXIST_NAME = new Name("DO NOT EXIST NAME");
Expand All @@ -44,6 +45,22 @@ public void execute_invalidNameFilteredList_throwsCommandException() {

assertCommandFailure(moreInfoCommand, model, Messages.MESSAGE_INVALID_PERSON_INPUT);
}
@Test
public void execute_subName_throwsCommandException() {
Random random = new Random();
List<Name> typicalNames = getTypicalNames();
int randomIndex = random.nextInt(typicalNames.size() - 1);
Person personToMoreInfo = model.getPersonByName(typicalNames.get(randomIndex));
String personToMoreInfoNameString = personToMoreInfo.getName().toString();
Name subNamePersonToMoreInfo =
new Name(personToMoreInfoNameString
.substring(0, personToMoreInfoNameString.length() - 1));
MoreInfoCommand moreInfoCommand =
new MoreInfoCommand(subNamePersonToMoreInfo);

assertCommandFailure(moreInfoCommand, model,
String.format(Messages.MESSAGE_SUGGESTION, personToMoreInfo.getName()));
}

@Test
public void equals() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_FROM;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TO;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.ALICE;

Expand All @@ -15,8 +18,10 @@

import seedu.address.logic.commands.AddBuyerProfile;
import seedu.address.logic.commands.AddSellerProfile;
import seedu.address.logic.commands.AppointmentCommand;
import seedu.address.logic.commands.ChatWindowCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.DeleteAppointmentCommand;
import seedu.address.logic.commands.DeleteClientProfileCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.EditCommand.EditPersonDescriptor;
Expand All @@ -27,6 +32,10 @@
import seedu.address.logic.commands.ShowListingsCommand;
import seedu.address.logic.commands.TodayCommand;
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.appointment.Appointment;
import seedu.address.model.appointment.Date;
import seedu.address.model.appointment.From;
import seedu.address.model.appointment.To;
import seedu.address.model.person.Buyer;
import seedu.address.model.person.NameContainsKeywordsPredicate;
import seedu.address.model.person.Person;
Expand Down Expand Up @@ -59,13 +68,35 @@ public void parseCommand_clear() throws Exception {
assertTrue(parser.parseCommand(ClearCommand.COMMAND_WORD + " 3") instanceof ClearCommand);
}

@Test
public void parseCommand_appointment() throws Exception {
Person sean = new PersonBuilder().withName("Sean Kevin Dias")
.withPhone("94351253").withEmail("[email protected]").buildBuyer();
Appointment appointment = new Appointment(
new Date("01-01-24"),
new From("0900"),
new To("1000")
);
AppointmentCommand command = (AppointmentCommand) parser.parseCommand(
AppointmentCommand.COMMAND_WORD + " " + sean.getName()
+ " " + PREFIX_DATE + appointment.getDate()
+ " " + PREFIX_FROM + appointment.getFrom()
+ " " + PREFIX_TO + appointment.getTo()
);
assertEquals(new AppointmentCommand(sean.getName(), appointment), command);
}
@Test
public void parseCommand_deleteAppointment() throws Exception {
DeleteAppointmentCommand command = (DeleteAppointmentCommand) parser.parseCommand(
DeleteAppointmentCommand.COMMAND_WORD + " " + ALICE.getName());
assertEquals(new DeleteAppointmentCommand(ALICE.getName()), command);
}
@Test
public void parseCommand_deleteClientProfile() throws Exception {
DeleteClientProfileCommand command = (DeleteClientProfileCommand) parser.parseCommand(
DeleteClientProfileCommand.COMMAND_WORD + " " + ALICE.getName());
assertEquals(new DeleteClientProfileCommand(ALICE.getName()), command);
}

@Test
public void parseCommand_edit() throws Exception {
Person person = new PersonBuilder().buildBuyer();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/address/ui/CommandBoxUiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class CommandBoxUiTest extends ApplicationTest {
private final List<String> testCommandHistory = new ArrayList<>(Arrays.asList(
"showclients",
"buyer n/SOMEONE THAT WILL NEVER EXIST p/99999999 e/[email protected]",
"delete n/SOMEONE THAT WILL NEVER EXIST",
"delete SOMEONE THAT WILL NEVER EXIST",
"showlistings"
));

Expand Down

0 comments on commit a841cbb

Please sign in to comment.