Skip to content

Commit

Permalink
Merge pull request #115 from iamdiluxedbutcooler/add-close-split-command
Browse files Browse the repository at this point in the history
Add close command
  • Loading branch information
iamdiluxedbutcooler authored Oct 22, 2024
2 parents 8ca6273 + 62fb739 commit 9074ba2
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 8 deletions.
36 changes: 36 additions & 0 deletions src/main/java/seedu/address/logic/commands/CloseCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CommandCommons.EMPTY_PERSON;

import seedu.address.model.Model;

/**
* Closes the detail view in the address book.
*/
public class CloseCommand extends Command {

public static final String COMMAND_WORD = "close";

public static final String MESSAGE_SUCCESS = "Detailed view closed.";

@Override
public CommandResult execute(Model model) {
return new CommandResult(
MESSAGE_SUCCESS,
false,
false,
false,
EMPTY_PERSON,
false
);
}
@Override
public boolean equals(Object obj) {
return obj == this || obj instanceof CloseCommand;
}

@Override
public String toString() {
return COMMAND_WORD;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package seedu.address.logic.commands;

import seedu.address.model.person.Person;

/**
* Contains common values used in different command classes, including default command values.
*/
public final class CommandCommons {
public static final String DEFAULT_TIER = "";
public static final String DEFAULT_REMARK = "NA";
public static final Person EMPTY_PERSON = null;

}
4 changes: 3 additions & 1 deletion src/main/java/seedu/address/logic/commands/HelpCommand.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CommandCommons.EMPTY_PERSON;

import seedu.address.model.Model;

/**
Expand All @@ -16,6 +18,6 @@ public class HelpCommand extends Command {

@Override
public CommandResult execute(Model model) {
return new CommandResult(SHOWING_HELP_MESSAGE, true, false, false, null, false);
return new CommandResult(SHOWING_HELP_MESSAGE, true, false, false, EMPTY_PERSON, false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import seedu.address.commons.core.LogsCenter;
import seedu.address.logic.commands.AddCommand;
import seedu.address.logic.commands.ClearCommand;
import seedu.address.logic.commands.CloseCommand;
import seedu.address.logic.commands.Command;
import seedu.address.logic.commands.DeleteCommand;
import seedu.address.logic.commands.EditCommand;
Expand Down Expand Up @@ -82,6 +83,9 @@ public Command parseCommand(String userInput) throws ParseException {
case ViewCommand.COMMAND_WORD:
return new ViewCommandParser().parse(arguments);

case CloseCommand.COMMAND_WORD:
return new CloseCommand();

default:
logger.finer("This user input caused a ParseException: " + userInput);
throw new ParseException(MESSAGE_UNKNOWN_COMMAND);
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ private void handleViewCommand(String commandText) {
}
}

private void handleCloseCommand() {
splitPane.getItems().remove(personDetailsPanelPlaceholder);
}

/**
* Executes the command and returns the result.
*
Expand All @@ -222,6 +226,8 @@ private CommandResult executeCommand(String commandText) throws CommandException

if (commandResult.isShowPerson()) {
handleViewCommand(commandText);
} else {
handleCloseCommand();
}

if (commandResult.isShowHelp()) {
Expand Down
47 changes: 47 additions & 0 deletions src/test/java/seedu/address/logic/commands/CloseCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package seedu.address.logic.commands;

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 org.junit.jupiter.api.Test;

import seedu.address.model.Model;
import seedu.address.model.ModelManager;

public class CloseCommandTest {

private Model model = new ModelManager();
@Test
public void execute_close_success() {
CloseCommand closeCommand = new CloseCommand();
CommandResult commandResult = closeCommand.execute(model);

assertEquals(CloseCommand.MESSAGE_SUCCESS, commandResult.getFeedbackToUser());
assertFalse(commandResult.isShowHelp());
assertFalse(commandResult.isExit());
}

@Test
public void equals() {
CloseCommand closeCommand = new CloseCommand();

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

// same type -> returns true
assertTrue(closeCommand.equals(new CloseCommand()));

// null -> returns false
assertFalse(closeCommand.equals(null));

// different types -> returns false
assertFalse(closeCommand.equals(1));
}

@Test
public void toStringMethod() {
CloseCommand closeCommand = new CloseCommand();
assertEquals(CloseCommand.COMMAND_WORD, closeCommand.toString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.logic.commands.CommandCommons.EMPTY_PERSON;

import org.junit.jupiter.api.Test;

Expand All @@ -14,8 +15,7 @@ public void equals() {

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

// same object -> returns true
assertTrue(commandResult.equals(commandResult));
Expand All @@ -31,11 +31,11 @@ public void equals() {

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

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

@Test
Expand All @@ -50,11 +50,11 @@ public void hashcode() {

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

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

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CommandCommons.EMPTY_PERSON;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.logic.commands.HelpCommand.SHOWING_HELP_MESSAGE;

Expand All @@ -14,7 +15,8 @@ public class HelpCommandTest {

@Test
public void execute_help_success() {
CommandResult expectedCommandResult = new CommandResult(SHOWING_HELP_MESSAGE, true, false, false, null, false);
CommandResult expectedCommandResult = new CommandResult(SHOWING_HELP_MESSAGE,
true, false, false, EMPTY_PERSON, false);
assertCommandSuccess(new HelpCommand(), model, expectedCommandResult, expectedModel);
}
}

0 comments on commit 9074ba2

Please sign in to comment.