Skip to content

Commit

Permalink
Merge pull request #207 from ys112/improve-code-quality
Browse files Browse the repository at this point in the history
Improve code quality
  • Loading branch information
ys112 authored Apr 12, 2024
2 parents 87e6aba + 6c714e8 commit 93206c7
Show file tree
Hide file tree
Showing 8 changed files with 175 additions and 50 deletions.
7 changes: 5 additions & 2 deletions src/main/java/seedu/address/logic/commands/ImportCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public class ImportCommand extends Command {
+ "accessible and is a json file for HRConnect";

public static final String MESSAGE_SUCCESS = "Successfully added new contacts.";
public static final String FILE_NOT_LOADED = "Data file could not be loaded.";
public static final String EMPTY_FILE = "Data file is empty";


private static final Logger logger = LogsCenter.getLogger(ImportCommand.class);
private final Path filePath;
Expand All @@ -54,13 +57,13 @@ public CommandResult execute(Model model) throws CommandException {
Optional<ReadOnlyAddressBook> addressBookOptional = addressBookStorage.readAddressBook();
if (!addressBookOptional.isPresent()) {
logger.info("Selected data file is empty");
throw new CommandException("Data file is empty");
throw new CommandException(EMPTY_FILE);
}

ReadOnlyAddressBook newData = addressBookOptional.get();
addNewData(model, newData);
} catch (DataLoadingException e) {
throw new CommandException("Data file could not be loaded.", e.getCause());
throw new CommandException(FILE_NOT_LOADED, e.getCause());
}

return new CommandResult(MESSAGE_SUCCESS);
Expand Down
23 changes: 1 addition & 22 deletions src/main/java/seedu/address/model/applicant/Applicant.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public boolean equals(Object other) {
}

// instanceof handles nulls
if (!(other instanceof seedu.address.model.applicant.Applicant)) {
if (!(other instanceof Applicant)) {
return false;
}

Expand All @@ -73,25 +73,4 @@ public boolean equals(Object other) {
&& role.equals(otherApplicant.role)
&& stage.equals(otherApplicant.stage);
}

/**
* Returns true if both persons have the same name.
* This defines a weaker notion of equality between two applicants.
*/
public boolean isSameApplicant(Applicant otherApplicant) {
if (otherApplicant == this) {
return true;
}

return otherApplicant != null
&& otherApplicant.getName().equals(getName())
&& otherApplicant.getPhone().equals(getPhone())
&& otherApplicant.getEmail().equals(getEmail())
&& otherApplicant.getAddress().equals(getAddress())
&& otherApplicant.getRole().equals(getRole())
&& otherApplicant.getStage().equals(getStage())
&& otherApplicant.getTags().equals(getTags())
&& otherApplicant.getNote().equals(getNote());
}

}
21 changes: 0 additions & 21 deletions src/main/java/seedu/address/model/applicant/Application.java

This file was deleted.

4 changes: 4 additions & 0 deletions src/main/java/seedu/address/model/applicant/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
public class Role {
public final String roleName;

/**
* Constructs a role object with given role string.
* @param roleName role input string
*/
public Role(String roleName) {
this.roleName = roleName;
}
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/seedu/address/model/applicant/Stage.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class Stage {
public static final String TECHNICAL_ASSESSMENT = "Technical Assessment";
public static final String INTERVIEW = "Interview";
public static final String DECISION_AND_OFFER = "Decision & Offer";


public static final String MESSAGE_CONSTRAINTS = "Stage must be one of the following four options:"
+ "\n" + "1. " + INITIAL_APPLICATION + "\n"
+ "2. " + TECHNICAL_ASSESSMENT + "\n"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"persons" : [ {
"@type" : "JsonAdaptedApplicant",
"name" : "Xiao Li",
"phone" : "92456721",
"email" : "[email protected]",
"address" : "Blk 685 Rangoon road 3, #12-09",
"role" : "SWE",
"stage" : "Interview",
"tags" : [ ],
"note" : "Forbes 30 under 30",
"noteDate" : "",
"img" : null
}, {
"@type" : "JsonAdaptedApplicant",
"name" : "Alex Yeoh",
"phone" : "87438807",
"email" : "[email protected]",
"address" : "Blk 30 Geylang Street 29, #06-40",
"role" : "Frontend Engineer",
"stage" : "Initial Application",
"tags" : [ "friends" ],
"note" : "",
"noteDate" : "",
"img" : null
}, {
"@type" : "JsonAdaptedApplicant",
"name" : "Bernice Yu",
"phone" : "99272758",
"email" : "[email protected]",
"address" : "Blk 30 Lorong 3 Serangoon Gardens, #07-18",
"role" : "SWE",
"stage" : "Technical Assessment",
"tags" : [ "colleagues", "friends" ],
"note" : "",
"noteDate" : "",
"img" : null
}, {
"@type" : "JsonAdaptedApplicant",
"name" : "Charlotte Oliveiro",
"phone" : "93210283",
"email" : "[email protected]",
"address" : "Blk 11 Ang Mo Kio Street 74, #11-04",
"role" : "SWE",
"stage" : "Interview",
"tags" : [ "neighbours" ],
"note" : "",
"noteDate" : "",
"img" : null
}, {
"@type" : "JsonAdaptedApplicant",
"name" : "David Li",
"phone" : "91031282",
"email" : "[email protected]",
"address" : "Blk 436 Serangoon Gardens Street 26, #16-43",
"role" : "SWE",
"stage" : "Decision & Offer",
"tags" : [ "family" ],
"note" : "",
"noteDate" : "",
"img" : null
}, {
"@type" : "JsonAdaptedApplicant",
"name" : "Irfan Ibrahim",
"phone" : "92492021",
"email" : "[email protected]",
"address" : "Blk 47 Tampines Street 20, #17-35",
"role" : "SWE",
"stage" : "Decision & Offer",
"tags" : [ "classmates" ],
"note" : "",
"noteDate" : "",
"img" : null
}, {
"@type" : "JsonAdaptedApplicant",
"name" : "Roy Balakrishnan",
"phone" : "92624417",
"email" : "[email protected]",
"address" : "Blk 45 Aljunied Street 85, #11-31",
"role" : "SWE",
"stage" : "Initial Application",
"tags" : [ "colleagues" ],
"note" : "",
"noteDate" : "",
"img" : null
} ]
}
73 changes: 73 additions & 0 deletions src/test/java/seedu/address/logic/commands/ImportCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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.testutil.Assert.assertThrows;
import static seedu.address.testutil.TypicalApplicants.getTypicalApplicantsAddressBook;

import java.nio.file.Path;
import java.nio.file.Paths;

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

import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;

class ImportCommandTest {

private static final Path TEST_DATA_FOLDER = Paths.get("src", "test", "data", "JsonAddressBookStorageTest");

private Model model;

private static String getFilePathString(String fileName) {
return TEST_DATA_FOLDER.resolve(fileName).toString();
}

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

@Test
void execute_importValidFile_successful() throws Exception {
CommandResult commandResult = new ImportCommand(
getFilePathString("validApplicantHRConnect.json")).execute(model);

assertEquals(ImportCommand.MESSAGE_SUCCESS,
commandResult.getFeedbackToUser());
}

@Test
void execute_importInvalidFile_successful() throws Exception {
ImportCommand importCommand = new ImportCommand(
getFilePathString("invalidPersonAddressBook.json"));

assertThrows(CommandException.class, ImportCommand.FILE_NOT_LOADED, () -> importCommand.execute(model));
}

@Test
public void equals() {
String validFilePath = getFilePathString("validApplicantHRConnect.json");
ImportCommand importValidCommand = new ImportCommand(validFilePath);
ImportCommand importInvalidCommand = new ImportCommand(getFilePathString("invalidPersonAddressBook.json"));

// same object -> returns true
assertEquals(importValidCommand, importValidCommand);

// same values -> returns true
ImportCommand importValidCommandCopy = new ImportCommand(validFilePath);
assertEquals(importValidCommand, importValidCommandCopy);

// different types -> returns false
assertNotEquals(1, importValidCommand);

// null -> returns false
assertNotEquals(null, importValidCommand);

// different file path -> returns false
assertNotEquals(importValidCommand, importInvalidCommand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

public class ImportCommandParserTest {

private static final String VALID_FILEPATH = "C:\\tp\\data\\interesting.json";
private static final String INVALID_FILEPATH = "C:\\tp\\data\\interesting.txt";
private final ImportCommandParser parser = new ImportCommandParser();

@Test
Expand All @@ -22,7 +24,7 @@ public void parse_emptyArg_throwsParseException() {
@Test
public void parse_invalidPath_throwsParseException() {
// not json extension
assertParseFailure(parser, "C:\\tp\\data\\interesting.txt",
assertParseFailure(parser, INVALID_FILEPATH,
String.format(MESSAGE_INVALID_FILE_PATH, ImportCommand.MESSAGE_FILE_PATH));

// not a file path
Expand All @@ -34,8 +36,8 @@ public void parse_invalidPath_throwsParseException() {
public void parse_validArgs_returnsImportCommand() {
// no leading and trailing whitespaces
ImportCommand expectedImportCommand =
new ImportCommand("C:\\tp\\data\\interesting.json");
assertParseSuccess(parser, "C:\\tp\\data\\interesting.json", expectedImportCommand);
new ImportCommand(VALID_FILEPATH);
assertParseSuccess(parser, VALID_FILEPATH, expectedImportCommand);
}

}

0 comments on commit 93206c7

Please sign in to comment.