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

Fix test cases #192

Merged
merged 16 commits into from
Nov 10, 2023
14 changes: 9 additions & 5 deletions docs/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ Clears all entries from the system upon confirmation in the pop-up.
![result for 'clear' GUI](images/clearUI.png)

#### Expected Output(Failure or Cancellation):
If the clear command fails, or you press `cancel` on the confirmation pop-up:
* GUI: All students' details remain on the student list.
* Case: Clear command fails.
* Case: You press `cancel` on the confirmation pop-up.
GUI: All students' details remain on the student list.
![result for cancelled 'clear' GUI](images/clearCancel.png)

### Exiting the program : `exit`
Expand Down Expand Up @@ -381,8 +382,10 @@ Deletes a specific student and all personal details based on email.
![Delete feature](images/delete.png)

#### Expected Output (Failure):
* Message: `Student with the provided email not found.`
* Message: `Invalid command format!`<br>
* Case: Provided email not registered in system.
Message: `Student with the provided email not found.`
* Case: Invalid command format e.g. `delete 02`.
Message: `Invalid command format!`<br>
`delete: Deletes the student identified by the email address.`<br>
`Parameters: EMAIL`<br>
`Example: delete [email protected]`
Expand Down Expand Up @@ -448,7 +451,8 @@ Deletes a group from the system, based on group number.
![result for 'deleteGroup gr/3'](images/deleteGroup.png)

#### Expected Output(Failure):
* Message: `Group with the provided group number not found.`
* Case: Group with specified number is not in the system.
Message: `Group with the provided group number not found.`

### Joining a group : `join`

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/seedu/address/logic/commands/ClearCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,13 @@ public CommandResult execute(Model model) throws CommandException {
return new CommandResult(SHOWING_CONFIRMATION_MESSAGE, false, false, false, false);
}
}

/**
* Sets the confirmation status of the popup.
*
* @param isConfirmed The confirmation status to be set. True if confirmed, false otherwise.
*/
public void setConfirmed(boolean isConfirmed) {
this.isConfirmed = isConfirmed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,13 @@ public CommandResult execute(Model model) throws CommandException {
return new CommandResult(String.format(MESSAGE_DELETE_GROUP_SUCCESS, groupToDelete.getNumber()),
false, false, true, false);
}

/**
* Gets the group number of the group to be deleted.
*
* @return The group number.
*/
public int getGroupNumber() {
return groupNumber;
}
}
45 changes: 44 additions & 1 deletion src/main/java/seedu/address/ui/ConfirmationPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ public ConfirmationPopup() {
initialize();
}

/**
* Sets the callback to be executed when the confirmation is received.
*
* @param callback The callback to be executed.
*/
public void setConfirmationCallback(Consumer<Boolean> callback) {
this.confirmationCallback = callback;
}
Expand All @@ -60,6 +65,9 @@ public void show() {
getRoot().centerOnScreen();
}

/**
* Initializes the confirmation popup, setting up event handlers for the "Yes" and "Cancel" buttons.
*/
@FXML
private void initialize() {
yesButton.setOnAction(event -> {
Expand All @@ -73,12 +81,19 @@ private void initialize() {
cancelButton.setOnAction(event -> getRoot().close());
}

/**
* Gets the logger for the ConfirmationPopup class.
*
* @return The logger for the ConfirmationPopup class.
*/
private static Logger getLogger() {
return LogsCenter.getLogger(ConfirmationPopup.class);
}

/**
* Returns true if the confirmation popup is currently being shown.
* Checks if the confirmation popup is currently being shown.
*
* @return True if the confirmation popup is showing, false otherwise.
*/
public boolean isShowing() {
return getRoot().isShowing();
Expand All @@ -90,4 +105,32 @@ public boolean isShowing() {
public void focus() {
getRoot().requestFocus();
}

/**
* Checks if the confirmation was confirmed.
*
* @return True if the confirmation was confirmed, false otherwise.
*/
public boolean isConfirmed() {
return isConfirmed;
}

/**
* Gets the "Yes" button of the confirmation popup.
*
* @return The "Yes" button.
*/
public Button getYesButton() {
return yesButton;
}

/**
* Gets the "Cancel" button of the confirmation popup.
*
* @return The "Cancel" button.
*/
public Button getCancelButton() {
return cancelButton;
}

}
226 changes: 211 additions & 15 deletions src/test/java/seedu/address/logic/commands/ClearCommandTest.java
Original file line number Diff line number Diff line change
@@ -1,34 +1,230 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;
import static seedu.address.testutil.TypicalPersons.getTypicalAddressBook;
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 java.nio.file.Path;
import java.util.Optional;
import java.util.function.Predicate;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import javafx.application.Platform;
import javafx.collections.ObservableList;
import seedu.address.commons.core.GuiSettings;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.AddressBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.UserPrefs;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.group.Group;
import seedu.address.model.group.tasks.TaskList;
import seedu.address.model.person.Email;
import seedu.address.model.person.Person;
import seedu.address.ui.JavaFxInitializer;


public class ClearCommandTest {

@BeforeAll
public static void init() {
JavaFxInitializer.initialize();
}

@AfterAll
public static void cleanup() {
JavaFxInitializer.cleanup();
}

@Test
public void execute_emptyAddressBook_success() {
Model model = new ModelManager();
Model expectedModel = new ModelManager();
public void execute_clearCommandConfirmed_success() throws CommandException {
// Arrange
ModelStub modelStub = new ModelStub();
ClearCommand clearCommand = new ClearCommand();
clearCommand.setConfirmed(true);

// Act
Platform.runLater(() -> {
try {
CommandResult commandResult = clearCommand.execute(modelStub);

assertCommandSuccess(new ClearCommand(), model, ClearCommand.SHOWING_CONFIRMATION_MESSAGE, expectedModel,
false);
// Assert
assertEquals(ClearCommand.SHOWING_CONFIRMATION_MESSAGE, commandResult.getFeedbackToUser());
assertFalse(commandResult.isShowHelp());
assertFalse(commandResult.isExit());
assertFalse(commandResult.isGroupCommand());
assertTrue(commandResult.isClear());
assertEquals(0, modelStub.getAddressBook().getPersonList().size());
} catch (CommandException e) {
// Handle exception
}
});
}

@Test
public void execute_nonEmptyAddressBook_success() {
Model model = new ModelManager(getTypicalAddressBook(), new UserPrefs());
Model expectedModel = new ModelManager(getTypicalAddressBook(), new UserPrefs());
expectedModel.setAddressBook(new AddressBook());
public void execute_clearCommandNotConfirmed_success() throws CommandException {
// Arrange
ModelStub modelStub = new ModelStub();
ClearCommand clearCommand = new ClearCommand();
clearCommand.setConfirmed(false);

// Act
Platform.runLater(() -> {
try {
CommandResult commandResult = clearCommand.execute(modelStub);

assertCommandSuccess(new ClearCommand(), model, ClearCommand.SHOWING_CONFIRMATION_MESSAGE, expectedModel,
false);
// Assert
assertEquals(ClearCommand.SHOWING_CONFIRMATION_MESSAGE, commandResult.getFeedbackToUser());
assertFalse(commandResult.isShowHelp());
assertFalse(commandResult.isExit());
assertFalse(commandResult.isGroupCommand());
assertFalse(commandResult.isClear());
assertEquals(0, modelStub.getAddressBook().getPersonList().size());
} catch (CommandException e) {
// Handle exception if needed
}
});
}

// Rest of the class remains unchanged
private static class ModelStub implements Model {
private final AddressBook addressBook = new AddressBook();

@Override
public void setUserPrefs(ReadOnlyUserPrefs userPrefs) {
throw new AssertionError("This method should not be called.");
}

@Override
public ReadOnlyUserPrefs getUserPrefs() {
return null;
}

@Override
public GuiSettings getGuiSettings() {
return null;
}

@Override
public void setGuiSettings(GuiSettings guiSettings) {

}

@Override
public Path getAddressBookFilePath() {
// Implement if needed
return null;
}

@Override
public void setAddressBookFilePath(Path addressBookFilePath) {
throw new AssertionError("This method should not be called.");
}

@Override
public void setAddressBook(ReadOnlyAddressBook addressBook) {
throw new AssertionError("This method should not be called.");
}

@Override
public ReadOnlyAddressBook getAddressBook() {
return addressBook;
}

@Override
public boolean hasPerson(Person person) {
return addressBook.hasPerson(person);
}

@Override
public void deletePerson(Person target) {
addressBook.removePerson(target);
}

@Override
public void addPerson(Person person) {
addressBook.addPerson(person);
}

@Override
public void setPerson(Person target, Person editedPerson) {
addressBook.setPerson(target, editedPerson);
}

@Override
public ObservableList<Person> getFilteredPersonList() {
return null;
}

@Override
public void updateFilteredPersonList(Predicate<Person> predicate) {
throw new AssertionError("This method should not be called.");
}


@Override
public void addGroup(Group group) {
throw new AssertionError("This method should not be called.");
}

@Override
public void addPersonToGroup(Person person, Group group) {
throw new AssertionError("This method should not be called.");
}

@Override
public ObservableList<Group> getFilteredGroupList() {
return null;
}

@Override
public void updateFilteredGroupList(Predicate<Group> predicate) {
throw new AssertionError("This method should not be called.");
}

@Override
public Optional<Person> getPersonWithEmail(Email email) {
return Optional.empty();
}

@Override
public Optional<Group> getGroupWithNumber(int number) {
return Optional.empty();
}


@Override
public boolean personIsInAGroup(Person person) {
// Implement if needed
return false;
}

@Override
public Group getGroupThatPersonIsIn(Person person) {
return null;
}

@Override
public void removePersonFromGroup(Person person, Group group) {
throw new AssertionError("This method should not be called.");
}

@Override
public void addTasksToGroup(TaskList taskList, Group group) {
throw new AssertionError("This method should not be called.");
}

@Override
public boolean hasGroup(Group group) {
return false;
}

@Override
public void deleteGroup(Group group) {
throw new AssertionError("This method should not be called.");
}
}
}
Loading