Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List all internship application feature #65

Merged
merged 3 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/main/java/seedu/address/logic/commands/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
import static seedu.address.model.Model.PREDICATE_SHOW_ALL;

import seedu.address.model.Model;
import seedu.address.model.internshipapplication.InternshipApplication;

/**
* Lists all internship applications in the address book to the user.
* Lists all internship applications in hire me to the user.
*/
public class ListCommand extends Command {
public class ListCommand extends Command<InternshipApplication> {

public static final String COMMAND_WORD = "list";

public static final String MESSAGE_SUCCESS = "Listed all internship applications";


@Override
public CommandResult execute(Model model) {
public CommandResult execute(Model<InternshipApplication> model) {
requireNonNull(model);
model.updateFilteredList(PREDICATE_SHOW_ALL);
return new CommandResult(MESSAGE_SUCCESS);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/seedu/address/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.model.internshipapplication.InternshipApplication;

/**
* The API of the Model component.
*/
public interface Model<T> {
/** {@code Predicate} that always evaluate to true */
Predicate<?> PREDICATE_SHOW_ALL = unused -> true;
Predicate<InternshipApplication> PREDICATE_SHOW_ALL = unused -> true;

/**
* Replaces user prefs data with the data in {@code userPrefs}.
Expand Down
1 change: 1 addition & 0 deletions src/main/java/seedu/address/model/ReadOnlyAddressBook.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package seedu.address.model;

import javafx.collections.ObservableList;
import seedu.address.model.internshipapplication.UniqueList;

/**
* Unmodifiable view of a book
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
/**
* A list of persons that enforces uniqueness between its elements and does not allow nulls.
* A person is considered unique by comparing using {@code Person#isSamePerson(Person)}. As such, adding and updating of
* persons uses Person#isSamePerson(Person) for equality so as to ensure that the person being added or updated is
* persons uses Person#isSamePerson(Person) for equality to ensure that the person being added or updated is
* unique in terms of identity in the UniquePersonList. However, the removal of a person uses Person#equals(Object) so
* as to ensure that the person with exactly the same fields will be removed.
* to ensure that the person with exactly the same fields will be removed.
*
* Supports a minimal set of list operations.
*
Expand Down Expand Up @@ -80,15 +80,15 @@ public void remove(T toRemove) {
}
}

/**
* Replaces the contents of this list with {@code persons}.
* {@code persons} must not contain duplicate persons.
*/
public void setItems(UniqueList<T> replacement) {
requireNonNull(replacement);
internalList.setAll(replacement.internalList);
}

/**
* Replaces the contents of this list with {@code persons}.
* {@code persons} must not contain duplicate persons.
*/
public void setItems(List<T> items) {
requireAllNonNull(items);
if (!areUnique(items)) {
Expand Down
82 changes: 42 additions & 40 deletions src/test/java/seedu/address/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS;
import static seedu.address.logic.parser.CliSyntax.PREFIX_ROLE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL;
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
import static seedu.address.logic.parser.CliSyntax.PREFIX_PHONE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG;
import static seedu.address.testutil.Assert.assertThrows;

Expand All @@ -17,55 +17,57 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.internshipapplication.InternshipApplication;
import seedu.address.model.internshipapplication.NameContainsKeywordsPredicate;
import seedu.address.model.internshipapplication.Person;
import seedu.address.testutil.EditPersonDescriptorBuilder;
import seedu.address.testutil.InternshipApplicationBuilder;

/**
* Contains helper methods for testing commands.
*/
public class CommandTestUtil {

public static final String VALID_NAME_AMY = "Amy Bee";
public static final String VALID_NAME_BOB = "Bob Choo";
public static final String VALID_PHONE_AMY = "11111111";
public static final String VALID_PHONE_BOB = "22222222";
public static final String VALID_EMAIL_AMY = "amy@example.com";
public static final String VALID_EMAIL_BOB = "bob@example.com";
public static final String VALID_ADDRESS_AMY = "Block 312, Amy Street 1";
public static final String VALID_ADDRESS_BOB = "Block 123, Bobby Street 3";
public static final String VALID_NAME_APPLE = "Apple";
public static final String VALID_NAME_BOFA = "BOFA";
public static final String VALID_DATE_APPLE = "01/01/24";
public static final String VALID_DATE_BOFA = "02/02/24";
public static final String VALID_EMAIL_APPLE = "apple@example.com";
public static final String VALID_EMAIL_BOFA = "bofa@example.com";
public static final String VALID_ROLE_APPLE = "Software Engineer Intern";
public static final String VALID_ROLE_BOFA = "Backend Intern";
public static final String VALID_TAG_HUSBAND = "husband";
public static final String VALID_TAG_FRIEND = "friend";

public static final String NAME_DESC_AMY = " " + PREFIX_NAME + VALID_NAME_AMY;
public static final String NAME_DESC_BOB = " " + PREFIX_NAME + VALID_NAME_BOB;
public static final String PHONE_DESC_AMY = " " + PREFIX_PHONE + VALID_PHONE_AMY;
public static final String PHONE_DESC_BOB = " " + PREFIX_PHONE + VALID_PHONE_BOB;
public static final String EMAIL_DESC_AMY = " " + PREFIX_EMAIL + VALID_EMAIL_AMY;
public static final String EMAIL_DESC_BOB = " " + PREFIX_EMAIL + VALID_EMAIL_BOB;
public static final String ADDRESS_DESC_AMY = " " + PREFIX_ADDRESS + VALID_ADDRESS_AMY;
public static final String ADDRESS_DESC_BOB = " " + PREFIX_ADDRESS + VALID_ADDRESS_BOB;
public static final String NAME_DESC_APPLE = " " + PREFIX_NAME + VALID_NAME_APPLE;
public static final String NAME_DESC_BOFA = " " + PREFIX_NAME + VALID_NAME_BOFA;
public static final String DATE_DESC_APPLE = " " + PREFIX_DATE + VALID_DATE_APPLE;
public static final String DATE_DESC_BOFA = " " + PREFIX_DATE + VALID_DATE_BOFA;
public static final String EMAIL_DESC_APPLE = " " + PREFIX_EMAIL + VALID_EMAIL_APPLE;
public static final String EMAIL_DESC_BOFA = " " + PREFIX_EMAIL + VALID_EMAIL_BOFA;
public static final String ROLE_DESC_APPLE = " " + PREFIX_ROLE + VALID_ROLE_APPLE;
public static final String ROLE_DESC_BOFA = " " + PREFIX_ROLE + VALID_ROLE_BOFA;
public static final String TAG_DESC_FRIEND = " " + PREFIX_TAG + VALID_TAG_FRIEND;
public static final String TAG_DESC_HUSBAND = " " + PREFIX_TAG + VALID_TAG_HUSBAND;

public static final String INVALID_NAME_DESC = " " + PREFIX_NAME + "James&"; // '&' not allowed in names
public static final String INVALID_PHONE_DESC = " " + PREFIX_PHONE + "911a"; // 'a' not allowed in phones
public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bob!yahoo"; // missing '@' symbol
public static final String INVALID_ADDRESS_DESC = " " + PREFIX_ADDRESS; // empty string not allowed for addresses
public static final String INVALID_DATE_DESC = " " + PREFIX_DATE + "911a"; // 'a' not allowed in dates
public static final String INVALID_EMAIL_DESC = " " + PREFIX_EMAIL + "bofa!yahoo"; // missing '@' symbol
public static final String INVALID_ROLE_DESC = " " + PREFIX_ROLE; // empty string not allowed for role
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags

public static final String PREAMBLE_WHITESPACE = "\t \r \n";
public static final String PREAMBLE_NON_EMPTY = "NonEmptyPreamble";

public static final EditCommand.EditPersonDescriptor DESC_AMY;
public static final EditCommand.EditPersonDescriptor DESC_BOB;
public static final EditCommand.EditPersonDescriptor DESC_APPLE;
public static final EditCommand.EditPersonDescriptor DESC_BOFA;

static {
DESC_AMY = new EditPersonDescriptorBuilder().withName(VALID_NAME_AMY)
.withPhone(VALID_PHONE_AMY).withEmail(VALID_EMAIL_AMY).withAddress(VALID_ADDRESS_AMY)
DESC_APPLE = new EditPersonDescriptorBuilder().withName(VALID_NAME_APPLE)
.withPhone(VALID_DATE_APPLE).withEmail(VALID_EMAIL_APPLE).withAddress(VALID_ROLE_APPLE)
.withTags(VALID_TAG_FRIEND).build();
DESC_BOB = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOB)
.withPhone(VALID_PHONE_BOB).withEmail(VALID_EMAIL_BOB).withAddress(VALID_ADDRESS_BOB)
DESC_BOFA = new EditPersonDescriptorBuilder().withName(VALID_NAME_BOFA)
.withPhone(VALID_DATE_BOFA).withEmail(VALID_EMAIL_BOFA).withAddress(VALID_ROLE_BOFA)
.withTags(VALID_TAG_HUSBAND, VALID_TAG_FRIEND).build();
}

Expand All @@ -74,8 +76,8 @@ public class CommandTestUtil {
* - the returned {@link CommandResult} matches {@code expectedCommandResult} <br>
* - the {@code actualModel} matches {@code expectedModel}
*/
public static void assertCommandSuccess(Command command, Model actualModel, CommandResult expectedCommandResult,
Model expectedModel) {
public static void assertCommandSuccess(Command<InternshipApplication> command, Model<InternshipApplication> actualModel, CommandResult expectedCommandResult,
Model<InternshipApplication> expectedModel) {
try {
CommandResult result = command.execute(actualModel);
assertEquals(expectedCommandResult, result);
Expand All @@ -89,8 +91,8 @@ public static void assertCommandSuccess(Command command, Model actualModel, Comm
* Convenience wrapper to {@link #assertCommandSuccess(Command, Model, CommandResult, Model)}
* that takes a string {@code expectedMessage}.
*/
public static void assertCommandSuccess(Command command, Model actualModel, String expectedMessage,
Model expectedModel) {
public static void assertCommandSuccess(Command<InternshipApplication> command, Model<InternshipApplication> actualModel, String expectedMessage,
Model<InternshipApplication> expectedModel) {
CommandResult expectedCommandResult = new CommandResult(expectedMessage);
assertCommandSuccess(command, actualModel, expectedCommandResult, expectedModel);
}
Expand All @@ -101,28 +103,28 @@ public static void assertCommandSuccess(Command command, Model actualModel, Stri
* - the CommandException message matches {@code expectedMessage} <br>
* - the address book, filtered person list and selected person in {@code actualModel} remain unchanged
*/
public static void assertCommandFailure(Command command, Model actualModel, String expectedMessage) {
public static void assertCommandFailure(Command<InternshipApplication> command, Model<InternshipApplication> actualModel, String expectedMessage) {
// we are unable to defensively copy the model for comparison later, so we can
// only do so by copying its components.
AddressBook expectedAddressBook = new AddressBook(actualModel.getAddressBook());
List<Person> expectedFilteredList = new ArrayList<>(actualModel.getFilteredPersonList());
List<InternshipApplication> expectedFilteredList = new ArrayList<>(actualModel.getFilteredList());

assertThrows(CommandException.class, expectedMessage, () -> command.execute(actualModel));
assertEquals(expectedAddressBook, actualModel.getAddressBook());
assertEquals(expectedFilteredList, actualModel.getFilteredPersonList());
assertEquals(expectedFilteredList, actualModel.getFilteredList());
}
/**
* Updates {@code model}'s filtered list to show only the person at the given {@code targetIndex} in the
* {@code model}'s address book.
*/
public static void showPersonAtIndex(Model model, Index targetIndex) {
assertTrue(targetIndex.getZeroBased() < model.getFilteredPersonList().size());
public static void showPersonAtIndex(Model<InternshipApplication> model, Index targetIndex) {
assertTrue(targetIndex.getZeroBased() < model.getFilteredList().size());

Person person = model.getFilteredPersonList().get(targetIndex.getZeroBased());
final String[] splitName = person.getName().getValue().split("\\s+");
model.updateFilteredPersonList(new NameContainsKeywordsPredicate(Arrays.asList(splitName[0])));
InternshipApplication internshipApplication = model.getFilteredList().get(targetIndex.getZeroBased());
final String[] splitName = internshipApplication.getCompany().getName().getValue().split("\\s+");
model.updateFilteredList(new NameContainsKeywordsPredicate(Arrays.asList(splitName[0])));

assertEquals(1, model.getFilteredPersonList().size());
assertEquals(1, model.getFilteredList().size());
}

}
11 changes: 6 additions & 5 deletions src/test/java/seedu/address/logic/commands/ListCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,28 @@
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
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;

import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.internshipapplication.InternshipApplication;

/**
* Contains integration tests (interaction with the Model) and unit tests for ListCommand.
*/
public class ListCommandTest {

private Model model;
private Model expectedModel;
private Model<InternshipApplication> model;
private Model<InternshipApplication> expectedModel;

@BeforeEach
public void setUp() {
model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel = new ModelManager(model.getAddressBook(), new UserPrefs());
model = new ModelManager<>(getTypicalAddressBook(), new UserPrefs());
expectedModel = new ModelManager<>(model.getAddressBook(), new UserPrefs());
}

@Test
Expand Down
Loading
Loading