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

Refactor Parser & Command's testcases into modules #59

Merged
merged 2 commits into from
Oct 10, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/MainApp.java
Expand Up @@ -81,7 +81,7 @@ private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
if (!addressBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample TrackIter");
}
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleTrackIter);
} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty TrackIter");
initialData = new TrackIter();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/util/SampleDataUtil.java
Expand Up @@ -40,7 +40,7 @@ public static Contact[] getSampleContacts() {
};
}

public static ReadOnlyTrackIter getSampleAddressBook() {
public static ReadOnlyTrackIter getSampleTrackIter() {
TrackIter sampleAb = new TrackIter();
for (Contact sampleContact : getSampleContacts()) {
sampleAb.addContact(sampleContact);
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/address/storage/JsonTrackIterStorage.java
Expand Up @@ -45,14 +45,14 @@ public Optional<ReadOnlyTrackIter> readTrackIter() throws DataConversionExceptio
public Optional<ReadOnlyTrackIter> readTrackIter(Path filePath) throws DataConversionException {
requireNonNull(filePath);

Optional<JsonSerializableTrackIter> jsonAddressBook = JsonUtil.readJsonFile(
Optional<JsonSerializableTrackIter> jsonTrackIter = JsonUtil.readJsonFile(
filePath, JsonSerializableTrackIter.class);
if (!jsonAddressBook.isPresent()) {
if (!jsonTrackIter.isPresent()) {
return Optional.empty();
}

try {
return Optional.of(jsonAddressBook.get().toModelType());
return Optional.of(jsonTrackIter.get().toModelType());
} catch (IllegalValueException ive) {
logger.info("Illegal values found in " + filePath + ": " + ive.getMessage());
throw new DataConversionException(ive);
Expand Down
@@ -1,13 +1,12 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.contact;

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.TypicalPersons.getTypicalTrackIter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.contact.AddContactCommand;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
Expand All @@ -23,7 +22,7 @@ public class AddContactCommandIntegrationTest {

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

@Test
Expand Down
@@ -1,4 +1,4 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.contact;

import static java.util.Objects.requireNonNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
Expand All @@ -15,7 +15,7 @@

import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.logic.commands.contact.AddContactCommand;
import seedu.address.logic.commands.CommandResult;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ReadOnlyTrackIter;
Expand Down Expand Up @@ -52,7 +52,7 @@ public void execute_duplicatePerson_throwsCommandException() {
ModelStub modelStub = new ModelStubWithPerson(validContact);

assertThrows(CommandException.class,
AddContactCommand.MESSAGE_DUPLICATE_CONTACT, () -> addContactCommand.execute(modelStub));
AddContactCommand.MESSAGE_DUPLICATE_CONTACT, () -> addContactCommand.execute(modelStub));
}

@Test
Expand Down
@@ -1,11 +1,10 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.contact;

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

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.contact.ClearContactCommand;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.TrackIter;
Expand All @@ -23,8 +22,8 @@ public void execute_emptyAddressBook_success() {

@Test
public void execute_nonEmptyAddressBook_success() {
Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
Model model = new ModelManager(getTypicalTrackIter(), new UserPrefs());
Model expectedModel = new ModelManager(getTypicalTrackIter(), new UserPrefs());
expectedModel.setTrackIter(new TrackIter());

assertCommandSuccess(new ClearContactCommand(), model, ClearContactCommand.MESSAGE_SUCCESS, expectedModel);
Expand Down
@@ -1,4 +1,4 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.contact;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -7,13 +7,12 @@
import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
import static seedu.address.testutil.TypicalPersons.getTypicalTrackIter;

import org.junit.jupiter.api.Test;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.contact.DeleteContactCommand;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
Expand All @@ -25,7 +24,7 @@
*/
public class DeleteContactCommandTest {

private final Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private final Model model = new ModelManager(getTypicalTrackIter(), new UserPrefs());

@Test
public void execute_validIndexUnfilteredList_success() {
Expand Down
@@ -1,4 +1,4 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.contact;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand All @@ -12,14 +12,12 @@
import static seedu.address.logic.commands.CommandTestUtil.showPersonAtIndex;
import static seedu.address.testutil.TypicalIndexes.INDEX_FIRST_PERSON;
import static seedu.address.testutil.TypicalIndexes.INDEX_SECOND_PERSON;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
import static seedu.address.testutil.TypicalPersons.getTypicalTrackIter;

import org.junit.jupiter.api.Test;

import seedu.address.commons.core.Messages;
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.contact.ClearContactCommand;
import seedu.address.logic.commands.contact.EditContactCommand;
import seedu.address.logic.commands.contact.EditContactCommand.EditContactDescriptor;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
Expand All @@ -35,7 +33,7 @@
*/
public class EditContactCommandTest {

private final Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private final Model model = new ModelManager(getTypicalTrackIter(), new UserPrefs());

@Test
public void execute_allFieldsSpecifiedUnfilteredList_success() {
Expand Down
@@ -1,4 +1,4 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.contact;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down
@@ -1,4 +1,4 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.contact;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
Expand All @@ -8,14 +8,13 @@
import static seedu.address.testutil.TypicalPersons.CARL;
import static seedu.address.testutil.TypicalPersons.ELLE;
import static seedu.address.testutil.TypicalPersons.FIONA;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
import static seedu.address.testutil.TypicalPersons.getTypicalTrackIter;

import java.util.Arrays;
import java.util.Collections;

import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.contact.FindContactCommand;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
Expand All @@ -25,8 +24,8 @@
* Contains integration tests (interaction with the Model) for {@code FindContactCommand}.
*/
public class FindContactCommandTest {
private final Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private final Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
private final Model model = new ModelManager(getTypicalTrackIter(), new UserPrefs());
private final Model expectedModel = new ModelManager(getTypicalTrackIter(), new UserPrefs());

@Test
public void equals() {
Expand Down
@@ -1,14 +1,13 @@
package seedu.address.logic.commands;
package seedu.address.logic.commands.contact;

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.TypicalPersons.getTypicalTrackIter;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.contact.ListContactCommand;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
Expand All @@ -23,7 +22,7 @@ public class ListContactCommandTest {

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

Expand Down
Expand Up @@ -37,16 +37,16 @@ public class TrackIterParserTest {
public void parseCommand_add() throws Exception {
Contact contact = new PersonBuilder().build();
AddContactCommand command = (AddContactCommand) parser.parseCommand(Contact.TYPE
+ " " + ContactUtil.getAddCommand(contact));
+ " " + ContactUtil.getAddCommand(contact));
assertEquals(new AddContactCommand(contact), command);
}

@Test
public void parseCommand_clear() throws Exception {
assertTrue(parser.parseCommand(Contact.TYPE + " "
+ ClearContactCommand.COMMAND_WORD) instanceof ClearContactCommand);
+ ClearContactCommand.COMMAND_WORD) instanceof ClearContactCommand);
assertTrue(parser.parseCommand(Contact.TYPE + " "
+ ClearContactCommand.COMMAND_WORD + " 3") instanceof ClearContactCommand);
+ ClearContactCommand.COMMAND_WORD + " 3") instanceof ClearContactCommand);
}

@Test
Expand All @@ -61,8 +61,8 @@ public void parseCommand_edit() throws Exception {
Contact contact = new PersonBuilder().build();
EditContactDescriptor descriptor = new EditContactDescriptorBuilder(contact).build();
EditContactCommand command = (EditContactCommand) parser.parseCommand(Contact.TYPE + " "
+ EditContactCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased() + " "
+ ContactUtil.getEditContactDescriptorDetails(descriptor));
+ EditContactCommand.COMMAND_WORD + " " + INDEX_FIRST_PERSON.getOneBased() + " "
+ ContactUtil.getEditContactDescriptorDetails(descriptor));
assertEquals(new EditContactCommand(INDEX_FIRST_PERSON, descriptor), command);
}

Expand Down Expand Up @@ -90,9 +90,9 @@ public void parseCommand_help() throws Exception {
@Test
public void parseCommand_list() throws Exception {
assertTrue(parser.parseCommand(Contact.TYPE + " "
+ ListContactCommand.COMMAND_WORD) instanceof ListContactCommand);
+ ListContactCommand.COMMAND_WORD) instanceof ListContactCommand);
assertTrue(parser.parseCommand(Contact.TYPE + " "
+ ListContactCommand.COMMAND_WORD + " 3") instanceof ListContactCommand);
+ ListContactCommand.COMMAND_WORD + " 3") instanceof ListContactCommand);
}

@Test
Expand Down
@@ -1,4 +1,4 @@
package seedu.address.logic.parser;
package seedu.address.logic.parser.contact;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY;
Expand Down Expand Up @@ -32,7 +32,6 @@
import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.contact.AddContactCommand;
import seedu.address.logic.parser.contact.AddContactCommandParser;
import seedu.address.model.commons.Address;
import seedu.address.model.commons.Name;
import seedu.address.model.contact.Contact;
Expand Down
@@ -1,4 +1,4 @@
package seedu.address.logic.parser;
package seedu.address.logic.parser.contact;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
Expand All @@ -8,7 +8,6 @@
import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.contact.DeleteContactCommand;
import seedu.address.logic.parser.contact.DeleteContactCommandParser;

/**
* As we are only doing white-box testing, our test cases do not cover path variations
Expand All @@ -29,6 +28,6 @@ public void parse_validArgs_returnsDeleteCommand() {
@Test
public void parse_invalidArgs_throwsParseException() {
assertParseFailure(parser, "a",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteContactCommand.MESSAGE_USAGE));
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteContactCommand.MESSAGE_USAGE));
}
}
@@ -1,4 +1,4 @@
package seedu.address.logic.parser;
package seedu.address.logic.parser.contact;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.commands.CommandTestUtil.ADDRESS_DESC_AMY;
Expand Down Expand Up @@ -36,7 +36,6 @@
import seedu.address.commons.core.index.Index;
import seedu.address.logic.commands.contact.EditContactCommand;
import seedu.address.logic.commands.contact.EditContactCommand.EditContactDescriptor;
import seedu.address.logic.parser.contact.EditContactCommandParser;
import seedu.address.model.commons.Address;
import seedu.address.model.commons.Name;
import seedu.address.model.contact.Email;
Expand Down
@@ -1,4 +1,4 @@
package seedu.address.logic.parser;
package seedu.address.logic.parser.contact;

import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.CommandParserTestUtil.assertParseFailure;
Expand All @@ -9,7 +9,6 @@
import org.junit.jupiter.api.Test;

import seedu.address.logic.commands.contact.FindContactCommand;
import seedu.address.logic.parser.contact.FindContactCommandParser;
import seedu.address.model.contact.NameContainsKeywordsPredicate;

public class FindContactCommandParserTest {
Expand All @@ -19,7 +18,7 @@ public class FindContactCommandParserTest {
@Test
public void parse_emptyArg_throwsParseException() {
assertParseFailure(parser, " ",
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindContactCommand.MESSAGE_USAGE));
String.format(MESSAGE_INVALID_COMMAND_FORMAT, FindContactCommand.MESSAGE_USAGE));
}

@Test
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/model/TrackIterTest.java
Expand Up @@ -7,7 +7,7 @@
import static seedu.address.logic.commands.CommandTestUtil.VALID_TAG_HUSBAND;
import static seedu.address.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
import static seedu.address.testutil.TypicalPersons.getTypicalTrackIter;

import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -41,7 +41,7 @@ public void resetData_null_throwsNullPointerException() {

@Test
public void resetData_withValidReadOnlyAddressBook_replacesData() {
TrackIter newData = getTypicalAddressBook();
TrackIter newData = getTypicalTrackIter();
trackIter.resetData(newData);
assertEquals(newData, trackIter);
}
Expand Down
Expand Up @@ -25,7 +25,7 @@ public void toModelType_typicalPersonsFile_success() throws Exception {
JsonSerializableTrackIter dataFromFile = JsonUtil.readJsonFile(TYPICAL_PERSONS_FILE,
JsonSerializableTrackIter.class).get();
TrackIter trackIterFromFile = dataFromFile.toModelType();
TrackIter typicalPersonsTrackIter = TypicalPersons.getTypicalAddressBook();
TrackIter typicalPersonsTrackIter = TypicalPersons.getTypicalTrackIter();
assertEquals(trackIterFromFile, typicalPersonsTrackIter);
}

Expand Down
Expand Up @@ -6,7 +6,7 @@
import static seedu.address.testutil.TypicalPersons.ALICE;
import static seedu.address.testutil.TypicalPersons.HOON;
import static seedu.address.testutil.TypicalPersons.IDA;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
import static seedu.address.testutil.TypicalPersons.getTypicalTrackIter;

import java.io.IOException;
import java.nio.file.Path;
Expand Down Expand Up @@ -63,7 +63,7 @@ public void readAddressBook_invalidAndValidPersonAddressBook_throwDataConversion
@Test
public void readAndSaveAddressBook_allInOrder_success() throws Exception {
Path filePath = testFolder.resolve("TempAddressBook.json");
TrackIter original = getTypicalAddressBook();
TrackIter original = getTypicalTrackIter();
JsonTrackIterStorage jsonTrackIterStorage = new JsonTrackIterStorage(filePath);

// Save in new file and read back
Expand Down