Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #113 from rayshawntan/update-test-data
Browse files Browse the repository at this point in the history
Update test data
  • Loading branch information
mamayuan authored Oct 26, 2023
2 parents 950cdbf + 3ea7103 commit 6d9c3b8
Show file tree
Hide file tree
Showing 17 changed files with 315 additions and 303 deletions.
10 changes: 2 additions & 8 deletions src/test/java/swe/context/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static swe.context.testutil.Assert.assertThrows;
import static swe.context.testutil.TestData.Valid.EMAIL_DESC_AMY;
import static swe.context.testutil.TestData.Valid.NAME_DESC_AMY;
import static swe.context.testutil.TestData.Valid.NOTE_DESC_AMY;
import static swe.context.testutil.TestData.Valid.PHONE_DESC_AMY;

import java.io.IOException;
import java.nio.file.AccessDeniedException;
Expand All @@ -31,8 +27,6 @@
import swe.context.testutil.ContactBuilder;
import swe.context.testutil.TestData;



public class LogicManagerTest {
private static final IOException DUMMY_IO_EXCEPTION = new IOException("dummy IO exception");
private static final IOException DUMMY_AD_EXCEPTION = new AccessDeniedException("dummy access denied exception");
Expand Down Expand Up @@ -165,8 +159,8 @@ public void saveContacts(ReadOnlyContacts contactList) throws IOException {
logic = new LogicManager(model, storage);

// Triggers the saveContacts method by executing an add command
String addCommand = AddCommand.COMMAND_WORD + NAME_DESC_AMY + PHONE_DESC_AMY
+ EMAIL_DESC_AMY + NOTE_DESC_AMY;
String addCommand = AddCommand.COMMAND_WORD + TestData.Valid.NAME_DESC_AMY + TestData.Valid.PHONE_DESC_AMY
+ TestData.Valid.EMAIL_DESC_AMY + TestData.Valid.NOTE_DESC_AMY;
Contact expectedContact = new ContactBuilder(TestData.Valid.Contact.AMY).withTags().build();
ModelManager expectedModel = new ModelManager();
expectedModel.addContact(expectedContact);
Expand Down
28 changes: 14 additions & 14 deletions src/test/java/swe/context/logic/commands/DeleteCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
import static swe.context.logic.commands.CommandTestUtil.assertCommandFailure;
import static swe.context.logic.commands.CommandTestUtil.assertCommandSuccess;
import static swe.context.logic.commands.CommandTestUtil.showContactAtIndex;
import static swe.context.testutil.TestData.IndexContact.FIRST_CONTACT;
import static swe.context.testutil.TestData.IndexContact.SECOND_CONTACT;
import static swe.context.testutil.TestData.Valid.Contact.getTypicalContacts;

import org.junit.jupiter.api.Test;

Expand All @@ -18,19 +15,21 @@
import swe.context.model.ModelManager;
import swe.context.model.Settings;
import swe.context.model.contact.Contact;
import swe.context.testutil.TestData;

/**
* Contains integration tests (interaction with the Model) and unit tests for
* {@code DeleteCommand}.
*/
public class DeleteCommandTest {

private Model model = new ModelManager(getTypicalContacts(), new Settings());
private Model model = new ModelManager(TestData.Valid.Contact.getTypicalContacts(), new Settings());

@Test
public void execute_validIndexUnfilteredList_success() {
Contact contactToDelete = model.getFilteredContactList().get(FIRST_CONTACT.getZeroBased());
DeleteCommand deleteCommand = new DeleteCommand(FIRST_CONTACT);
Contact contactToDelete =
model.getFilteredContactList().get(TestData.IndexContact.FIRST_CONTACT.getZeroBased());
DeleteCommand deleteCommand = new DeleteCommand(TestData.IndexContact.FIRST_CONTACT);

String expectedMessage = String.format(Messages.DELETE_COMMAND_SUCCESS,
Contact.format(contactToDelete));
Expand All @@ -51,10 +50,11 @@ public void execute_invalidIndexUnfilteredList_throwsCommandException() {

@Test
public void execute_validIndexFilteredList_success() {
showContactAtIndex(model, FIRST_CONTACT);
showContactAtIndex(model, TestData.IndexContact.FIRST_CONTACT);

Contact contactToDelete = model.getFilteredContactList().get(FIRST_CONTACT.getZeroBased());
DeleteCommand deleteCommand = new DeleteCommand(FIRST_CONTACT);
Contact contactToDelete =
model.getFilteredContactList().get(TestData.IndexContact.FIRST_CONTACT.getZeroBased());
DeleteCommand deleteCommand = new DeleteCommand(TestData.IndexContact.FIRST_CONTACT);

String expectedMessage = String.format(Messages.DELETE_COMMAND_SUCCESS,
Contact.format(contactToDelete));
Expand All @@ -68,9 +68,9 @@ public void execute_validIndexFilteredList_success() {

@Test
public void execute_invalidIndexFilteredList_throwsCommandException() {
showContactAtIndex(model, FIRST_CONTACT);
showContactAtIndex(model, TestData.IndexContact.FIRST_CONTACT);

Index outOfBoundIndex = SECOND_CONTACT;
Index outOfBoundIndex = TestData.IndexContact.SECOND_CONTACT;
// ensures that outOfBoundIndex is still in bounds of address book list
assertTrue(outOfBoundIndex.getZeroBased() < model.getContacts().getUnmodifiableList().size());

Expand All @@ -81,14 +81,14 @@ public void execute_invalidIndexFilteredList_throwsCommandException() {

@Test
public void equals() {
DeleteCommand deleteFirstCommand = new DeleteCommand(FIRST_CONTACT);
DeleteCommand deleteSecondCommand = new DeleteCommand(SECOND_CONTACT);
DeleteCommand deleteFirstCommand = new DeleteCommand(TestData.IndexContact.FIRST_CONTACT);
DeleteCommand deleteSecondCommand = new DeleteCommand(TestData.IndexContact.SECOND_CONTACT);

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

// same values -> returns true
DeleteCommand deleteFirstCommandCopy = new DeleteCommand(FIRST_CONTACT);
DeleteCommand deleteFirstCommandCopy = new DeleteCommand(TestData.IndexContact.FIRST_CONTACT);
assertTrue(deleteFirstCommand.equals(deleteFirstCommandCopy));

// different types -> returns false
Expand Down
64 changes: 32 additions & 32 deletions src/test/java/swe/context/logic/commands/EditCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
import static swe.context.logic.commands.CommandTestUtil.assertCommandFailure;
import static swe.context.logic.commands.CommandTestUtil.assertCommandSuccess;
import static swe.context.logic.commands.CommandTestUtil.showContactAtIndex;
import static swe.context.testutil.TestData.IndexContact.FIRST_CONTACT;
import static swe.context.testutil.TestData.IndexContact.SECOND_CONTACT;
import static swe.context.testutil.TestData.Valid.NAME_BOB;
import static swe.context.testutil.TestData.Valid.PHONE_BOB;
import static swe.context.testutil.TestData.Valid.Contact.getTypicalContacts;

import org.junit.jupiter.api.Test;

Expand All @@ -26,20 +21,18 @@
import swe.context.testutil.EditContactDescriptorBuilder;
import swe.context.testutil.TestData;



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

private Model model = new ModelManager(getTypicalContacts(), new Settings());
private Model model = new ModelManager(TestData.Valid.Contact.getTypicalContacts(), new Settings());

@Test
public void execute_allFieldsSpecifiedUnfilteredList_success() {
Contact editedContact = new ContactBuilder().build();
EditContactDescriptor descriptor = new EditContactDescriptorBuilder(editedContact).build();
EditCommand editCommand = new EditCommand(FIRST_CONTACT, descriptor);
EditCommand editCommand = new EditCommand(TestData.IndexContact.FIRST_CONTACT, descriptor);

String expectedMessage = String.format(Messages.EDIT_COMMAND_SUCCESS, Contact.format(editedContact));

Expand All @@ -55,11 +48,11 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() {
Contact lastContact = model.getFilteredContactList().get(indexLastContact.getZeroBased());

ContactBuilder contactInList = new ContactBuilder(lastContact);
Contact editedContact = contactInList.withName(NAME_BOB).withPhone(PHONE_BOB)
Contact editedContact = contactInList.withName(TestData.Valid.NAME_BOB).withPhone(TestData.Valid.PHONE_BOB)
.withTags(TestData.Valid.Tag.ALPHANUMERIC_SPACES).build();

EditContactDescriptor descriptor = new EditContactDescriptorBuilder().withName(NAME_BOB)
.withPhone(PHONE_BOB).withTags(TestData.Valid.Tag.ALPHANUMERIC_SPACES).build();
EditContactDescriptor descriptor = new EditContactDescriptorBuilder().withName(TestData.Valid.NAME_BOB)
.withPhone(TestData.Valid.PHONE_BOB).withTags(TestData.Valid.Tag.ALPHANUMERIC_SPACES).build();
EditCommand editCommand = new EditCommand(indexLastContact, descriptor);

String expectedMessage = String.format(Messages.EDIT_COMMAND_SUCCESS, Contact.format(editedContact));
Expand All @@ -72,8 +65,8 @@ public void execute_someFieldsSpecifiedUnfilteredList_success() {

@Test
public void execute_noFieldSpecifiedUnfilteredList_success() {
EditCommand editCommand = new EditCommand(FIRST_CONTACT, new EditContactDescriptor());
Contact editedContact = model.getFilteredContactList().get(FIRST_CONTACT.getZeroBased());
EditCommand editCommand = new EditCommand(TestData.IndexContact.FIRST_CONTACT, new EditContactDescriptor());
Contact editedContact = model.getFilteredContactList().get(TestData.IndexContact.FIRST_CONTACT.getZeroBased());

String expectedMessage = String.format(Messages.EDIT_COMMAND_SUCCESS, Contact.format(editedContact));

Expand All @@ -84,12 +77,13 @@ public void execute_noFieldSpecifiedUnfilteredList_success() {

@Test
public void execute_filteredList_success() {
showContactAtIndex(model, FIRST_CONTACT);
showContactAtIndex(model, TestData.IndexContact.FIRST_CONTACT);

Contact contactInFilteredList = model.getFilteredContactList().get(FIRST_CONTACT.getZeroBased());
Contact editedContact = new ContactBuilder(contactInFilteredList).withName(NAME_BOB).build();
EditCommand editCommand = new EditCommand(FIRST_CONTACT,
new EditContactDescriptorBuilder().withName(NAME_BOB).build());
Contact contactInFilteredList =
model.getFilteredContactList().get(TestData.IndexContact.FIRST_CONTACT.getZeroBased());
Contact editedContact = new ContactBuilder(contactInFilteredList).withName(TestData.Valid.NAME_BOB).build();
EditCommand editCommand = new EditCommand(TestData.IndexContact.FIRST_CONTACT,
new EditContactDescriptorBuilder().withName(TestData.Valid.NAME_BOB).build());

String expectedMessage = String.format(Messages.EDIT_COMMAND_SUCCESS, Contact.format(editedContact));

Expand All @@ -101,20 +95,21 @@ public void execute_filteredList_success() {

@Test
public void execute_duplicateContactUnfilteredList_failure() {
Contact firstContact = model.getFilteredContactList().get(FIRST_CONTACT.getZeroBased());
Contact firstContact = model.getFilteredContactList().get(TestData.IndexContact.FIRST_CONTACT.getZeroBased());
EditContactDescriptor descriptor = new EditContactDescriptorBuilder(firstContact).build();
EditCommand editCommand = new EditCommand(SECOND_CONTACT, descriptor);
EditCommand editCommand = new EditCommand(TestData.IndexContact.SECOND_CONTACT, descriptor);

assertCommandFailure(editCommand, model, Messages.COMMAND_DUPLICATE_CONTACT);
}

@Test
public void execute_duplicateContactFilteredList_failure() {
showContactAtIndex(model, FIRST_CONTACT);
showContactAtIndex(model, TestData.IndexContact.FIRST_CONTACT);

// edit contact in filtered list into a duplicate
Contact contactInList = model.getContacts().getUnmodifiableList().get(SECOND_CONTACT.getZeroBased());
EditCommand editCommand = new EditCommand(FIRST_CONTACT,
Contact contactInList =
model.getContacts().getUnmodifiableList().get(TestData.IndexContact.SECOND_CONTACT.getZeroBased());
EditCommand editCommand = new EditCommand(TestData.IndexContact.FIRST_CONTACT,
new EditContactDescriptorBuilder(contactInList).build());

assertCommandFailure(editCommand, model, Messages.COMMAND_DUPLICATE_CONTACT);
Expand All @@ -123,7 +118,7 @@ public void execute_duplicateContactFilteredList_failure() {
@Test
public void execute_invalidContactIndexUnfilteredList_failure() {
Index outOfBoundIndex = Index.fromOneBased(model.getFilteredContactList().size() + 1);
EditContactDescriptor descriptor = new EditContactDescriptorBuilder().withName(NAME_BOB).build();
EditContactDescriptor descriptor = new EditContactDescriptorBuilder().withName(TestData.Valid.NAME_BOB).build();
EditCommand editCommand = new EditCommand(outOfBoundIndex, descriptor);

assertCommandFailure(editCommand, model, Messages.INVALID_CONTACT_DISPLAYED_INDEX);
Expand All @@ -135,24 +130,25 @@ public void execute_invalidContactIndexUnfilteredList_failure() {
*/
@Test
public void execute_invalidContactIndexFilteredList_failure() {
showContactAtIndex(model, FIRST_CONTACT);
Index outOfBoundIndex = SECOND_CONTACT;
showContactAtIndex(model, TestData.IndexContact.FIRST_CONTACT);
Index outOfBoundIndex = TestData.IndexContact.SECOND_CONTACT;
// ensures that outOfBoundIndex is still in bounds of Contacts
assertTrue(outOfBoundIndex.getZeroBased() < model.getContacts().getUnmodifiableList().size());

EditCommand editCommand = new EditCommand(outOfBoundIndex,
new EditContactDescriptorBuilder().withName(NAME_BOB).build());
new EditContactDescriptorBuilder().withName(TestData.Valid.NAME_BOB).build());

assertCommandFailure(editCommand, model, Messages.INVALID_CONTACT_DISPLAYED_INDEX);
}

@Test
public void equals() {
final EditCommand standardCommand = new EditCommand(FIRST_CONTACT, TestData.Valid.EditDescriptor.AMY);
final EditCommand standardCommand =
new EditCommand(TestData.IndexContact.FIRST_CONTACT, TestData.Valid.EditDescriptor.AMY);

// same values -> returns true
EditContactDescriptor copyDescriptor = new EditContactDescriptor(TestData.Valid.EditDescriptor.AMY);
EditCommand commandWithSameValues = new EditCommand(FIRST_CONTACT, copyDescriptor);
EditCommand commandWithSameValues = new EditCommand(TestData.IndexContact.FIRST_CONTACT, copyDescriptor);
assertTrue(standardCommand.equals(commandWithSameValues));

// same object -> returns true
Expand All @@ -165,10 +161,14 @@ public void equals() {
assertFalse(standardCommand.equals(new ClearCommand()));

// different index -> returns false
assertFalse(standardCommand.equals(new EditCommand(SECOND_CONTACT, TestData.Valid.EditDescriptor.AMY)));
assertFalse(standardCommand.equals(
new EditCommand(TestData.IndexContact.SECOND_CONTACT, TestData.Valid.EditDescriptor.AMY)
));

// different descriptor -> returns false
assertFalse(standardCommand.equals(new EditCommand(FIRST_CONTACT, TestData.Valid.EditDescriptor.BOB)));
assertFalse(standardCommand.equals(
new EditCommand(TestData.IndexContact.FIRST_CONTACT, TestData.Valid.EditDescriptor.BOB))
);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static swe.context.testutil.TestData.Valid.EMAIL_BOB;
import static swe.context.testutil.TestData.Valid.NAME_BOB;
import static swe.context.testutil.TestData.Valid.NOTE_BOB;
import static swe.context.testutil.TestData.Valid.PHONE_BOB;

import org.junit.jupiter.api.Test;

import swe.context.logic.commands.EditCommand.EditContactDescriptor;
import swe.context.testutil.EditContactDescriptorBuilder;
import swe.context.testutil.TestData;



public class EditContactDescriptorTest {
@Test
public void equals() {
Expand All @@ -38,28 +32,28 @@ public void equals() {
// different name -> returns false
EditContactDescriptor editedAmy =
new EditContactDescriptorBuilder(TestData.Valid.EditDescriptor.AMY)
.withName(NAME_BOB)
.withName(TestData.Valid.NAME_BOB)
.build();
assertFalse(TestData.Valid.EditDescriptor.AMY.equals(editedAmy));

// different phone -> returns false
editedAmy =
new EditContactDescriptorBuilder(TestData.Valid.EditDescriptor.AMY)
.withPhone(PHONE_BOB)
.withPhone(TestData.Valid.PHONE_BOB)
.build();
assertFalse(TestData.Valid.EditDescriptor.AMY.equals(editedAmy));

// different email -> returns false
editedAmy =
new EditContactDescriptorBuilder(TestData.Valid.EditDescriptor.AMY)
.withEmail(EMAIL_BOB)
.withEmail(TestData.Valid.EMAIL_BOB)
.build();
assertFalse(TestData.Valid.EditDescriptor.AMY.equals(editedAmy));

// different address -> returns false
editedAmy =
new EditContactDescriptorBuilder(TestData.Valid.EditDescriptor.AMY)
.withNote(NOTE_BOB)
.withNote(TestData.Valid.NOTE_BOB)
.build();
assertFalse(TestData.Valid.EditDescriptor.AMY.equals(editedAmy));

Expand Down
2 changes: 0 additions & 2 deletions src/test/java/swe/context/logic/commands/ExitCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import swe.context.model.Model;
import swe.context.model.ModelManager;



public class ExitCommandTest {
private Model model = new ModelManager();
private Model expectedModel = new ModelManager();
Expand Down
16 changes: 7 additions & 9 deletions src/test/java/swe/context/logic/commands/FindCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static swe.context.logic.commands.CommandTestUtil.assertCommandSuccess;
import static swe.context.testutil.TestData.Valid.Contact.CARL;
import static swe.context.testutil.TestData.Valid.Contact.ELLE;
import static swe.context.testutil.TestData.Valid.Contact.FIONA;
import static swe.context.testutil.TestData.Valid.Contact.getTypicalContacts;

import java.util.Arrays;
import java.util.Collections;
Expand All @@ -19,15 +15,14 @@
import swe.context.model.ModelManager;
import swe.context.model.Settings;
import swe.context.model.contact.NameContainsKeywordsPredicate;


import swe.context.testutil.TestData;

/**
* Contains integration tests (interaction with the Model) for {@code FindCommand}.
*/
public class FindCommandTest {
private Model model = new ModelManager(getTypicalContacts(), new Settings());
private Model expectedModel = new ModelManager(getTypicalContacts(), new Settings());
private Model model = new ModelManager(TestData.Valid.Contact.getTypicalContacts(), new Settings());
private Model expectedModel = new ModelManager(TestData.Valid.Contact.getTypicalContacts(), new Settings());

@Test
public void equals() {
Expand Down Expand Up @@ -73,7 +68,10 @@ public void execute_multipleKeywords_multipleContactsFound() {
FindCommand command = new FindCommand(predicate);
expectedModel.setContactsFilter(predicate);
assertCommandSuccess(command, model, expectedMessage, expectedModel);
assertEquals(Arrays.asList(CARL, ELLE, FIONA), model.getFilteredContactList());
assertEquals(
Arrays.asList(TestData.Valid.Contact.CARL, TestData.Valid.Contact.ELLE, TestData.Valid.Contact.FIONA),
model.getFilteredContactList()
);
}

@Test
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/swe/context/logic/commands/HelpCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import swe.context.model.Model;
import swe.context.model.ModelManager;



public class HelpCommandTest {
private Model model = new ModelManager();
private Model expectedModel = new ModelManager();
Expand Down
Loading

0 comments on commit 6d9c3b8

Please sign in to comment.