Skip to content

Commit

Permalink
Fix coding quality and failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JJtan2002 committed Oct 18, 2024
1 parent a1b7874 commit c9fb3ad
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public String toString() {
.add("showHelp", showHelp)
.add("exit", exit)
.add("save", save)
.add("load", load)
.toString();
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/seedu/address/logic/commands/LoadCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

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

public class LoadCommand extends Command{
/**
* Load command that will set address book to the saved file.
*/
public class LoadCommand extends Command {
public static final String COMMAND_WORD = "load";
public static final String MESSAGE_SUCCESS = "The saved address book has been loaded!";
public CommandResult execute(Model model) throws CommandException {
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/seedu/address/logic/commands/SaveCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.Model;

public class SaveCommand extends Command{
/**
* Save command that saves the address book state to a save file.
*/
public class SaveCommand extends Command {
public static final String COMMAND_WORD = "save";
public static final String MESSAGE_SUCCESS = "Address book has been saved!";
public CommandResult execute(Model model) throws CommandException {
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/seedu/address/logic/parser/AddressBookParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,18 @@
import java.util.regex.Pattern;

import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.commands.*;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
import seedu.address.logic.commands.EditGameCommand;
import seedu.address.logic.commands.ExitCommand;
import seedu.address.logic.commands.FindCommand;
import seedu.address.logic.commands.HelpCommand;
import seedu.address.logic.commands.ListCommand;
import seedu.address.logic.commands.LoadCommand;
import seedu.address.logic.commands.SaveCommand;
import seedu.address.logic.parser.exceptions.ParseException;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public class JsonAddressBookStorage implements AddressBookStorage {
private Path filePath;
private Path manualSaveFilePath;

/**
* Creates a new JsonAddressBookStorage object.
*
* @param filePath The path to the JSON file where the address book data will be stored.
* @param manualSaveFilePath The path to the JSON file where the address book data will be manually saved.
*/
public JsonAddressBookStorage(Path filePath, Path manualSaveFilePath) {
this.filePath = filePath;
this.manualSaveFilePath = manualSaveFilePath;
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/seedu/address/logic/LogicManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ private void assertCommandFailureForExceptionFromStorage(IOException e, String e
Path prefPath = temporaryFolder.resolve("ExceptionUserPrefs.json");

// Inject LogicManager with an AddressBookStorage that throws the IOException e when saving
JsonAddressBookStorage addressBookStorage = new JsonAddressBookStorage(prefPath, temporaryFolder.resolve("save.json")) {
JsonAddressBookStorage addressBookStorage = new JsonAddressBookStorage(prefPath,
temporaryFolder.resolve("save.json")) {
@Override
public void saveAddressBook(ReadOnlyAddressBook addressBook, Path filePath)
throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void equals() {

// same values -> returns true
assertTrue(commandResult.equals(new CommandResult("feedback")));
assertTrue(commandResult.equals(new CommandResult("feedback", false, false)));
assertTrue(commandResult.equals(new CommandResult("feedback", false, false, false, false)));

// same object -> returns true
assertTrue(commandResult.equals(commandResult));
Expand All @@ -29,10 +29,10 @@ public void equals() {
assertFalse(commandResult.equals(new CommandResult("different")));

// different showHelp value -> returns false
assertFalse(commandResult.equals(new CommandResult("feedback", true, false)));
assertFalse(commandResult.equals(new CommandResult("feedback", true, false, false, false)));

// different exit value -> returns false
assertFalse(commandResult.equals(new CommandResult("feedback", false, true)));
assertFalse(commandResult.equals(new CommandResult("feedback", false, true, false, false)));
}

@Test
Expand All @@ -46,18 +46,19 @@ public void hashcode() {
assertNotEquals(commandResult.hashCode(), new CommandResult("different").hashCode());

// different showHelp value -> returns different hashcode
assertNotEquals(commandResult.hashCode(), new CommandResult("feedback", true, false).hashCode());
assertNotEquals(commandResult.hashCode(), new CommandResult("feedback", true, false, false, false).hashCode());

// different exit value -> returns different hashcode
assertNotEquals(commandResult.hashCode(), new CommandResult("feedback", false, true).hashCode());
assertNotEquals(commandResult.hashCode(), new CommandResult("feedback", false, true, false, false).hashCode());
}

@Test
public void toStringMethod() {
CommandResult commandResult = new CommandResult("feedback");
String expected = CommandResult.class.getCanonicalName() + "{feedbackToUser="
+ commandResult.getFeedbackToUser() + ", showHelp=" + commandResult.isShowHelp()
+ ", exit=" + commandResult.isExit() + "}";
+ ", exit=" + commandResult.isExit() + ", save=" + commandResult.isSave()
+ ", load=" + commandResult.isLoad() + "}";
assertEquals(expected, commandResult.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class ExitCommandTest {

@Test
public void execute_exit_success() {
CommandResult expectedCommandResult = new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true);
CommandResult expectedCommandResult =
new CommandResult(MESSAGE_EXIT_ACKNOWLEDGEMENT, false, true, false, false);
assertCommandSuccess(new ExitCommand(), model, expectedCommandResult, expectedModel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class HelpCommandTest {

@Test
public void execute_help_success() {
CommandResult expectedCommandResult = new CommandResult(SHOWING_HELP_MESSAGE, true, false);
CommandResult expectedCommandResult = new CommandResult(SHOWING_HELP_MESSAGE, true, false, false, false);
assertCommandSuccess(new HelpCommand(), model, expectedCommandResult, expectedModel);
}
}
8 changes: 4 additions & 4 deletions src/test/java/seedu/address/model/preferredtime/DayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public void constructor_null_throwsNullPointerException() {

@Test
public void constructor_invalidName_throwsIllegalArgumentException() {
String invalid_empty = "";
assertThrows(IllegalArgumentException.class, () -> new Day(invalid_empty));
String invalidEmpty = "";
assertThrows(IllegalArgumentException.class, () -> new Day(invalidEmpty));

String invalid_out_of_range = "Wednes";
assertThrows(IllegalArgumentException.class, () -> new Time(invalid_out_of_range));
String invalidOutOfRange = "Wednes";
assertThrows(IllegalArgumentException.class, () -> new Time(invalidOutOfRange));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public void constructor_null_throwsNullPointerException() {

@Test
public void constructor_invalidName_throwsIllegalArgumentException() {
String invalid_empty = "";
assertThrows(IllegalArgumentException.class, () -> new PreferredTime(invalid_empty));
String invalidEmpty = "";
assertThrows(IllegalArgumentException.class, () -> new PreferredTime(invalidEmpty));

String invalid_out_of_range = "Monday 4500";
assertThrows(IllegalArgumentException.class, () -> new PreferredTime(invalid_out_of_range));
String invalidOutOfRange = "Monday 4500";
assertThrows(IllegalArgumentException.class, () -> new PreferredTime(invalidOutOfRange));

String invalid_day = "weekday 1200";
assertThrows(IllegalArgumentException.class, () -> new PreferredTime(invalid_day));
String invalidDay = "weekday 1200";
assertThrows(IllegalArgumentException.class, () -> new PreferredTime(invalidDay));
}

@Test
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/seedu/address/model/preferredtime/TimeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public void constructor_null_throwsNullPointerException() {

@Test
public void constructor_invalidName_throwsIllegalArgumentException() {
String invalidTime_empty = "";
assertThrows(IllegalArgumentException.class, () -> new Time(invalidTime_empty));
String invalidTimeEmpty = "";
assertThrows(IllegalArgumentException.class, () -> new Time(invalidTimeEmpty));

String invalidTime_out_of_range = "4500";
assertThrows(IllegalArgumentException.class, () -> new Time(invalidTime_out_of_range));
String invalidTimeOutOfRange = "4500";
assertThrows(IllegalArgumentException.class, () -> new Time(invalidTimeOutOfRange));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public void readAddressBook_nullFilePath_throwsNullPointerException() {
}

private java.util.Optional<ReadOnlyAddressBook> readAddressBook(String filePath) throws Exception {
return new JsonAddressBookStorage(Paths.get(filePath), Paths.get("save.json")).readAddressBook(addToTestDataPathIfNotNull(filePath));
return new JsonAddressBookStorage(Paths.get(filePath), Paths.get("save.json"))
.readAddressBook(addToTestDataPathIfNotNull(filePath));
}

private Path addToTestDataPathIfNotNull(String prefsFileInTestDataFolder) {
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/seedu/address/storage/StorageManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class StorageManagerTest {

@BeforeEach
public void setUp() {
JsonAddressBookStorage addressBookStorage = new JsonAddressBookStorage(getTempFilePath("ab"), getTempFilePath("save"));
JsonAddressBookStorage addressBookStorage =
new JsonAddressBookStorage(getTempFilePath("ab"), getTempFilePath("save"));
JsonUserPrefsStorage userPrefsStorage = new JsonUserPrefsStorage(getTempFilePath("prefs"));
storageManager = new StorageManager(addressBookStorage, userPrefsStorage);
}
Expand Down

0 comments on commit c9fb3ad

Please sign in to comment.