Skip to content

Commit

Permalink
Merge pull request #69 from choaticman/branch-dylan-update-testcases
Browse files Browse the repository at this point in the history
Update test cases
  • Loading branch information
Raghava-Chittidi authored Oct 16, 2024
2 parents e716d3f + bcc52ce commit 37530d3
Show file tree
Hide file tree
Showing 28 changed files with 865 additions and 770 deletions.
4 changes: 2 additions & 2 deletions src/main/java/seedu/address/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class AddCommand extends Command<InternshipApplication> {
+ PREFIX_DATE + "16/09/24";

public static final String MESSAGE_SUCCESS = "New internship application added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON =
public static final String MESSAGE_DUPLICATE_APPLICATION =
"This internship application already exists in the address book";

private final InternshipApplication toAdd;
Expand All @@ -50,7 +50,7 @@ public CommandResult execute(Model<InternshipApplication> model) throws CommandE
requireNonNull(model);

if (model.hasItem(toAdd)) {
throw new CommandException(MESSAGE_DUPLICATE_PERSON);
throw new CommandException(MESSAGE_DUPLICATE_APPLICATION);
}

model.addItem(toAdd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class Name {

public static final String MESSAGE_CONSTRAINTS =
"Names should only contain alphanumeric characters and spaces, and it should not be blank";
"Names should only contain alphanumeric characters, underscores and spaces, and it should not be blank";

/*
* The first character of the name must not be a whitespace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class Role {

public static final String MESSAGE_CONSTRAINTS =
"Role should only contain alphanumeric characters, single spaces between words, "
+ "and should not start or end with spaces or special characters.";
+ "and should not start nor end with spaces or special characters.";

/*
* Roles should start with an alphanumeric character, and can contain single spaces between words.
Expand Down
25 changes: 13 additions & 12 deletions src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.logic.Messages.MESSAGE_INVALID_PERSON_DISPLAYED_INDEX;
import static seedu.address.logic.Messages.MESSAGE_UNKNOWN_COMMAND;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.EMAIL_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.NAME_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.PHONE_DESC_AMY;
import static seedu.address.logic.commands.CommandTestUtil.DATE_DESC_APPLE;
import static seedu.address.logic.commands.CommandTestUtil.COMPANY_EMAIL_DESC_APPLE;
import static seedu.address.logic.commands.CommandTestUtil.COMPANY_NAME_DESC_APPLE;
import static seedu.address.logic.commands.CommandTestUtil.ROLE_DESC_APPLE;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.AMY;
import static seedu.address.testutil.TypicalInternshipApplications.GOOGLE;


import java.io.IOException;
import java.nio.file.AccessDeniedException;
Expand All @@ -27,11 +28,11 @@
import seedu.address.model.ModelManager;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.UserPrefs;
import seedu.address.model.internshipapplication.Person;
import seedu.address.model.internshipapplication.InternshipApplication;
import seedu.address.storage.JsonAddressBookStorage;
import seedu.address.storage.JsonUserPrefsStorage;
import seedu.address.storage.StorageManager;
import seedu.address.testutil.PersonBuilder;
import seedu.address.testutil.InternshipApplicationBuilder;

public class LogicManagerTest {
private static final IOException DUMMY_IO_EXCEPTION = new IOException("dummy IO exception");
Expand Down Expand Up @@ -84,7 +85,7 @@ public void execute_storageThrowsAdException_throwsCommandException() {

@Test
public void getFilteredPersonList_modifyList_throwsUnsupportedOperationException() {
assertThrows(UnsupportedOperationException.class, () -> logic.getFilteredPersonList().remove(0));
assertThrows(UnsupportedOperationException.class, () -> logic.getFilteredList().remove(0));
}

/**
Expand Down Expand Up @@ -165,11 +166,11 @@ public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath)
logic = new LogicManager(model, storage);

// Triggers the saveAddressBook method by executing an add command
String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ EMAIL_DESC_AMY + ADDRESS_DESC_AMY;
Person expectedPerson = new PersonBuilder(AMY).withTags().build();
String addCommand = AddCommand.COMMAND_WORD + COMPANY_NAME_DESC_APPLE + ROLE_DESC_APPLE
+ COMPANY_EMAIL_DESC_APPLE + DATE_DESC_APPLE;
InternshipApplication expectedApplication = new InternshipApplicationBuilder(GOOGLE).build();
ModelManager expectedModel = new ModelManager();
expectedModel.addPerson(expectedPerson);
expectedModel.addItem(expectedApplication);
assertCommandFailure(addCommand, CommandException.class, expectedMessage, expectedModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import static seedu.address.logic.commands.CommandTestUtil.assertCommandFailure;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
import static seedu.address.testutil.TypicalInternshipApplications.getTypicalAddressBook;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -11,38 +11,39 @@
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.internshipapplication.Person;
import seedu.address.testutil.PersonBuilder;
import seedu.address.model.internshipapplication.InternshipApplication;
import seedu.address.testutil.InternshipApplicationBuilder;

/**
* Contains integration tests (interaction with the Model) for {@code AddCommand}.
*/
public class AddCommandIntegrationTest {

private Model model;
private Model<InternshipApplication> model;

@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
}

@Test
public void execute_newPerson_success() {
Person validPerson = new PersonBuilder().build();
public void execute_newInternshipApplication_success() {
InternshipApplication validApplication = new InternshipApplicationBuilder().build();

Model expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
expectedModel.addPerson(validPerson);
expectedModel.addItem(validApplication);

assertCommandSuccess(new AddCommand(validPerson), model,
String.format(AddCommand.MESSAGE_SUCCESS, Messages.format(validPerson)),
assertCommandSuccess(new AddCommand(validApplication), model,
String.format(AddCommand.MESSAGE_SUCCESS, Messages.format(validApplication)),
expectedModel);
}

@Test
public void execute_duplicatePerson_throwsCommandException() {
Person personInList = model.getAddressBook().getPersonList().get(0);
assertCommandFailure(new AddCommand(personInList), model,
AddCommand.MESSAGE_DUPLICATE_PERSON);
public void execute_duplicateInternshipApplication_throwsCommandException() {
InternshipApplication applicationInList = model.getAddressBook().getList().get(0);

assertCommandFailure(new AddCommand(applicationInList), model,
AddCommand.MESSAGE_DUPLICATE_APPLICATION);
}

}
79 changes: 41 additions & 38 deletions src/test/java/seedu/address/logic/commands/AddCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalInternshipApplications.GOOGLE;
import static seedu.address.testutil.TypicalPersons.ALICE;

import java.nio.file.Path;
Expand All @@ -22,41 +23,43 @@
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.internshipapplication.InternshipApplication;
import seedu.address.model.internshipapplication.Person;
import seedu.address.testutil.InternshipApplicationBuilder;
import seedu.address.testutil.PersonBuilder;

public class AddCommandTest {

@Test
public void constructor_nullPerson_throwsNullPointerException() {
public void constructor_nullApplication_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new AddCommand(null));
}

@Test
public void execute_personAcceptedByModel_addSuccessful() throws Exception {
ModelStubAcceptingPersonAdded modelStub = new ModelStubAcceptingPersonAdded();
Person validPerson = new PersonBuilder().build();
public void execute_applicationAcceptedByModel_addSuccessful() throws Exception {
ModelStubAcceptingInternshipApplicationAdded modelStub = new ModelStubAcceptingInternshipApplicationAdded();
InternshipApplication validApplication = new InternshipApplicationBuilder().build();

CommandResult commandResult = new AddCommand(validPerson).execute(modelStub);
CommandResult commandResult = new AddCommand(validApplication).execute(modelStub);

assertEquals(String.format(AddCommand.MESSAGE_SUCCESS, Messages.format(validPerson)),
assertEquals(String.format(AddCommand.MESSAGE_SUCCESS, Messages.format(validApplication)),
commandResult.getFeedbackToUser());
assertEquals(Arrays.asList(validPerson), modelStub.personsAdded);
assertEquals(Arrays.asList(validApplication), modelStub.internshipApplicationsAdded);
}

@Test
public void execute_duplicatePerson_throwsCommandException() {
Person validPerson = new PersonBuilder().build();
AddCommand addCommand = new AddCommand(validPerson);
ModelStub modelStub = new ModelStubWithPerson(validPerson);
InternshipApplication validApplication = new InternshipApplicationBuilder().build();
AddCommand addCommand = new AddCommand(validApplication);
ModelStub modelStub = new ModelStubWithInternshipApplication(validApplication);

assertThrows(CommandException.class, AddCommand.MESSAGE_DUPLICATE_PERSON, () -> addCommand.execute(modelStub));
assertThrows(CommandException.class, AddCommand.MESSAGE_DUPLICATE_APPLICATION, () -> addCommand.execute(modelStub));
}

@Test
public void equals() {
Person alice = new PersonBuilder().withName("Alice").build();
Person bob = new PersonBuilder().withName("Bob").build();
InternshipApplication alice = new InternshipApplicationBuilder().withName("Alice").build();
InternshipApplication bob = new InternshipApplicationBuilder().withName("Bob").build();
AddCommand addAliceCommand = new AddCommand(alice);
AddCommand addBobCommand = new AddCommand(bob);

Expand All @@ -79,15 +82,15 @@ public void equals() {

@Test
public void toStringMethod() {
AddCommand addCommand = new AddCommand(ALICE);
String expected = AddCommand.class.getCanonicalName() + "{toAdd=" + ALICE + "}";
AddCommand addCommand = new AddCommand(GOOGLE);
String expected = AddCommand.class.getCanonicalName() + "{toAdd=" + GOOGLE + "}";
assertEquals(expected, addCommand.toString());
}

/**
* A default model stub that have all of the methods failing.
*/
private class ModelStub implements Model {
private class ModelStub implements Model<InternshipApplication> {
@Override
public void setUserPrefs(ReadOnlyUserPrefs userPrefs) {
throw new AssertionError("This method should not be called.");
Expand Down Expand Up @@ -119,7 +122,7 @@ public void setHireMeFilePath(Path addressBookFilePath) {
}

@Override
public void addPerson(Person person) {
public void addItem(InternshipApplication application) {
throw new AssertionError("This method should not be called.");
}

Expand All @@ -134,65 +137,65 @@ public ReadOnlyAddressBook getAddressBook() {
}

@Override
public boolean hasPerson(Person person) {
public boolean hasItem(InternshipApplication application) {
throw new AssertionError("This method should not be called.");
}

@Override
public void deletePerson(Person target) {
public void deleteItem(InternshipApplication target) {
throw new AssertionError("This method should not be called.");
}

@Override
public void setPerson(Person target, Person editedPerson) {
public void setItem(InternshipApplication target, InternshipApplication editedApplication) {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Person> getFilteredPersonList() {
public ObservableList<InternshipApplication> getFilteredList() {
throw new AssertionError("This method should not be called.");
}

@Override
public void updateFilteredPersonList(Predicate<Person> predicate) {
public void updateFilteredList(Predicate<InternshipApplication> predicate) {
throw new AssertionError("This method should not be called.");
}
}

/**
* A Model stub that contains a single person.
*/
private class ModelStubWithPerson extends ModelStub {
private final Person person;
private class ModelStubWithInternshipApplication extends ModelStub {
private final InternshipApplication application;

ModelStubWithPerson(Person person) {
requireNonNull(person);
this.person = person;
ModelStubWithInternshipApplication(InternshipApplication application) {
requireNonNull(application);
this.application = application;
}

@Override
public boolean hasPerson(Person person) {
requireNonNull(person);
return this.person.isSamePerson(person);
public boolean hasItem(InternshipApplication application) {
requireNonNull(application);
return this.application.isSame(application);
}
}

/**
* A Model stub that always accept the person being added.
*/
private class ModelStubAcceptingPersonAdded extends ModelStub {
final ArrayList<Person> personsAdded = new ArrayList<>();
private class ModelStubAcceptingInternshipApplicationAdded extends ModelStub {
final ArrayList<InternshipApplication> internshipApplicationsAdded = new ArrayList<>();

@Override
public boolean hasPerson(Person person) {
requireNonNull(person);
return personsAdded.stream().anyMatch(person::isSamePerson);
public boolean hasItem(InternshipApplication application) {
requireNonNull(application);
return internshipApplicationsAdded.stream().anyMatch(application::isSame);
}

@Override
public void addPerson(Person person) {
requireNonNull(person);
personsAdded.add(person);
public void addItem(InternshipApplication application) {
requireNonNull(application);
internshipApplicationsAdded.add(application);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
import static seedu.address.testutil.TypicalInternshipApplications.getTypicalAddressBook;

import org.junit.jupiter.api.Test;

Expand Down
Loading

0 comments on commit 37530d3

Please sign in to comment.