Skip to content

Commit

Permalink
Merge pull request #201 from wamps-jp/branch-test-cases
Browse files Browse the repository at this point in the history
Add test cases for `List`, `Sort`, and `Reminder`
  • Loading branch information
McNaBry authored Nov 13, 2023
2 parents 92a6187 + f359b55 commit ab2ecd2
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package seedu.address.logic.commands;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalContacts.getTypicalAddressBook;

import java.util.ArrayList;

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.jobapplication.JobApplication;

class ReminderCommandTest {
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());

@Test
public void equals() {
ReminderCommand r = new ReminderCommand(true);
ReminderCommand r2 = new ReminderCommand(true);
ReminderCommand r3 = new ReminderCommand(false);

assertEquals(r, r);
assertEquals(r, r2);
assertNotEquals(r, r3);
}

@Test
public void execute_remindEarliest_applicationsSorted() {
String expectedMessage = ReminderCommand.MESSAGE_REMINDED_EARLIEST;
ReminderCommand command = new ReminderCommand(true);
expectedModel.updateSortedApplicationList(JobApplication.DEADLINE_COMPARATOR);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
ArrayList<JobApplication> arrayList1 = new ArrayList<>(model.getDisplayedApplicationList());
ArrayList<JobApplication> arrayList2 = new ArrayList<>(expectedModel.getDisplayedApplicationList());
assertEquals(arrayList1, arrayList2);
}

@Test
public void execute_sortTitle_applicationsSorted() {
String expectedMessage = ReminderCommand.MESSAGE_REMINDED_LATEST;
ReminderCommand command = new ReminderCommand(false);
expectedModel.updateSortedApplicationList(JobApplication.DEADLINE_COMPARATOR.reversed());
assertCommandSuccess(command, model, expectedMessage, expectedModel);
ArrayList<JobApplication> arrayList1 = new ArrayList<>(model.getDisplayedApplicationList());
ArrayList<JobApplication> arrayList2 = new ArrayList<>(expectedModel.getDisplayedApplicationList());
assertEquals(arrayList1, arrayList2);
}
}
46 changes: 45 additions & 1 deletion src/test/java/seedu/address/logic/commands/SortCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,25 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalContacts.getTypicalAddressBook;

import java.util.ArrayList;
import java.util.Comparator;

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.contact.Contact;
import seedu.address.model.jobapplication.JobApplication;

class SortCommandTest {
private Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private Model unsortedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());

// TODO: tech debt - lousy tests
@Test
public void equals() {
Comparator<Contact> a = (c, b) -> c.getType().compareTo(b.getType());
Expand All @@ -34,4 +42,40 @@ public void equals() {
assertNotEquals(s, new SortCommand(d, j, false));
assertNotEquals(s, new SortCommand(a, j, true));
}

@Test
public void execute_sortName_contactsSorted() {
String expectedMessage = SortCommand.MESSAGE_SORTED_CONTACTS;
SortCommand command = new SortCommand(Model.COMPARATOR_NAME, null, false);
expectedModel.updateSortedContactList(Model.COMPARATOR_NAME);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
ArrayList<Contact> arrayList1 = new ArrayList<>(model.getDisplayedContactList());
ArrayList<Contact> arrayList2 = new ArrayList<>(expectedModel.getDisplayedContactList());
assertEquals(arrayList1, arrayList2);
}

@Test
public void execute_sortTitle_applicationsSorted() {
String expectedMessage = SortCommand.MESSAGE_SORTED_APPLICATIONS;
SortCommand command = new SortCommand(null, JobApplication.JOB_TITLE_COMPARATOR,
false);
expectedModel.updateSortedApplicationList(JobApplication.JOB_TITLE_COMPARATOR);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
ArrayList<JobApplication> arrayList1 = new ArrayList<>(model.getDisplayedApplicationList());
ArrayList<JobApplication> arrayList2 = new ArrayList<>(expectedModel.getDisplayedApplicationList());
assertEquals(arrayList1, arrayList2);
}

@Test
public void execute_sortNone_applicationsUnsorted() {
String expectedMessage = SortCommand.MESSAGE_RESET_SORTING;
SortCommand command = new SortCommand(null, null, true);
assertCommandSuccess(command, model, expectedMessage, unsortedModel);
ArrayList<Contact> arrayListContact1 = new ArrayList<>(model.getDisplayedContactList());
ArrayList<Contact> arrayListContact2 = new ArrayList<>(unsortedModel.getDisplayedContactList());
ArrayList<JobApplication> arrayListApp1 = new ArrayList<>(model.getDisplayedApplicationList());
ArrayList<JobApplication> arrayListApp2 = new ArrayList<>(unsortedModel.getDisplayedApplicationList());
assertEquals(arrayListApp1, arrayListApp2);
assertEquals(arrayListContact1, arrayListContact2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_CONTACTS;
import static seedu.address.model.Model.PREDICATE_SHOW_NOT_APPLIED_ORGANIZATIONS;
import static seedu.address.model.Model.PREDICATE_SHOW_ONLY_ORGANIZATIONS;
import static seedu.address.model.Model.PREDICATE_SHOW_ONLY_RECRUITERS;

import org.junit.jupiter.api.Test;

Expand All @@ -14,5 +17,8 @@ public class ListCommandParserTest {
@Test
public void parse_validArgs_returnsListCommand() {
assertParseSuccess(parser, "", new ListCommand(PREDICATE_SHOW_ALL_CONTACTS));
assertParseSuccess(parser, "--org", new ListCommand(PREDICATE_SHOW_ONLY_ORGANIZATIONS));
assertParseSuccess(parser, "--rec", new ListCommand(PREDICATE_SHOW_ONLY_RECRUITERS));
assertParseSuccess(parser, "--toapply", new ListCommand(PREDICATE_SHOW_NOT_APPLIED_ORGANIZATIONS));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_EXTRA_FIELDS;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.ReminderCommand;

public class ReminderCommandParserTest {

private ReminderCommandParser parser = new ReminderCommandParser();

@Test
public void parse_emptyArg_throwsParseException() {
assertParseFailure(parser, " ",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReminderCommand.MESSAGE_USAGE));
}

@Test
public void parse_invalidArg_throwsParseException() {
assertParseFailure(parser, "--org",
MESSAGE_EXTRA_FIELDS + "--org");
assertParseFailure(parser, "--by",
MESSAGE_EXTRA_FIELDS + "--by");
}

@Test
public void parse_validArgs_returnsReminderCommand() {
ReminderCommand expectedReminderCommand =
new ReminderCommand(true);
assertParseSuccess(parser, "--earliest", expectedReminderCommand);
ReminderCommand expectedReminderCommand2 =
new ReminderCommand(false);
assertParseSuccess(parser, "--latest", expectedReminderCommand2);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package seedu.address.logic.parser;

import static seedu.address.logic.Messages.MESSAGE_EXTRA_FIELDS;
import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.Messages.MESSAGE_SIMULTANEOUS_USE_DISALLOWED_FIELDS;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseSuccess;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.SortCommand;
import seedu.address.model.Model;

public class SortCommandParserTest {

private SortCommandParser parser = new SortCommandParser();

@Test
public void parse_emptyArg_throwsParseException() {
assertParseFailure(parser, " ",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, SortCommand.MESSAGE_USAGE));
}

@Test
public void parse_invalidArg_throwsParseException() {
assertParseFailure(parser, "--title --name",
MESSAGE_SIMULTANEOUS_USE_DISALLOWED_FIELDS + "--name, --title");
assertParseFailure(parser, "--none --descending",
MESSAGE_SIMULTANEOUS_USE_DISALLOWED_FIELDS + "--descending, --none");
assertParseFailure(parser, "--org",
MESSAGE_EXTRA_FIELDS + "--org");
}

@Test
public void parse_validArgs_returnsSortCommand() {
SortCommand expectedSortCommand =
new SortCommand(Model.COMPARATOR_ADDRESS, null, false);
assertParseSuccess(parser, "--address", expectedSortCommand);
SortCommand expectedSortCommand2 =
new SortCommand(Model.COMPARATOR_ADDRESS, null, true);
assertParseSuccess(parser, "--none", expectedSortCommand2);
}
}

0 comments on commit ab2ecd2

Please sign in to comment.