Skip to content

Commit

Permalink
Merge pull request #168 from tristyxxnana/GradebookDeleteCommand
Browse files Browse the repository at this point in the history
Updated Gradebook Delete Command
  • Loading branch information
harriuscai committed Oct 25, 2018
2 parents df5b4be + 123e51b commit 8ad062e
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
public class GradebookDeleteCommand extends Command {
public static final String COMMAND_WORD = "gradebook delete";
private static final String MESSAGE_DELETE_SUCCESS = "\nModule Code: %1$s \nGradebook Component: %2$s \n"
public static final String MESSAGE_DELETE_SUCCESS = "\nModule Code: %1$s \nGradebook Component: %2$s \n"
+ "Successfully deleted!";
private static final String MESSAGE_DELETE_FAIL = "\nUnsuccessful Deletion";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Deletes a gradebook component to Trajectory. "
Expand Down Expand Up @@ -46,8 +46,6 @@ public CommandResult execute (Model model, CommandHistory history) throws Comman
return new CommandResult(String.format(
MESSAGE_DELETE_SUCCESS,
toDeleteGradebookComponent.getModuleCode(),
toDeleteGradebookComponent.getGradeComponentName(),
toDeleteGradebookComponent.getGradeComponentMaxMarks(),
toDeleteGradebookComponent.getGradeComponentWeightage()));
toDeleteGradebookComponent.getGradeComponentName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Parses input arguments and creates a new GradebookDeleteCommand object
*/
public class GradebookDeleteCommandParser {
private static final String MESSAGE_EMPTY_INPUTS = "Module code and gradebook component name cannot be empty";
public static final String MESSAGE_EMPTY_INPUTS = "Module code and gradebook component name cannot be empty";
/**
* Parses the given {@code String args} of arguments in the context of the GradebookDeleteCommand
* and returns a GradebookDeleteCommand object for execution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public GradebookEditCommand parse(String args) throws ParseException {

String moduleCodeArg = argMultimap.getValue(PREFIX_MODULE_CODE).get();
String gradeComponentNameArg = argMultimap.getValue(PREFIX_GRADEBOOK_ITEM).get();
boolean isEmpty = Gradebook.hasEmptyParams(moduleCodeArg, gradeComponentNameArg);
boolean isEmpty = gradebookManager.isEmpty(moduleCodeArg, gradeComponentNameArg);
if (isEmpty) {
throw new ParseException(MESSAGE_ERROR_EMPTY);
}
Expand Down
11 changes: 0 additions & 11 deletions src/main/java/seedu/address/model/gradebook/Gradebook.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,6 @@ public Gradebook(String moduleCode, String gradebookComponentName) {
this.gradebookComponentName = gradebookComponentName;
}

/**
This method checks if user inputs empty values for module code or gradebook component name.
*/
public static boolean hasEmptyParams(String moduleCode, String gradebookComponentName) {
boolean empty = false;
if (moduleCode.equals("") || gradebookComponentName.equals("")) {
empty = true;
}
return empty;
}

public String getModuleCode() {
return this.moduleCode;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public void saveGradebookList() {
StorageController.storeData();
}

public void clearGradebook() {
gradebooks.clear();
}

/**
This method adds gradebook component to a module in Trajectory.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,6 @@ public XmlAdaptedGradebook() {

}

/**
* Constructs an {@code XmlAdaptedGradebook} with the given gradebook component details
*/
public XmlAdaptedGradebook(String moduleCode, String gradeComponentName, int gradeComponentMaxMarks,
int gradeComponentWeightage) {
this.moduleCode = moduleCode;
this.gradeComponentName = gradeComponentName;
this.gradeComponentMaxMarks = gradeComponentMaxMarks;
this.gradeComponentWeightage = gradeComponentWeightage;
}

/**
* Constructs an {@code XmlAdaptedGradebook} with the given gradebook component details
*/
Expand All @@ -51,14 +40,6 @@ public XmlAdaptedGradebook(Gradebook gradebook) {
this.gradeComponentWeightage = gradebook.getGradeComponentWeightage();
}

/**
* Constructs an {@code XmlAdaptedGradebook} with the given gradebook componenet details
*/
public XmlAdaptedGradebook(String moduleCode, String gradeComponentName) {
this.moduleCode = moduleCode;
this.gradeComponentName = gradeComponentName;
}

/**
* Converts this XmlAdaptedGradebook into the model's Gradebook object
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package seedu.address.logic.commands;

import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import seedu.address.logic.CommandHistory;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.model.ModelManager;
import seedu.address.model.gradebook.GradebookManager;
import seedu.address.testutil.GradebookBuilder;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static seedu.address.logic.commands.GradebookDeleteCommand.MESSAGE_DELETE_SUCCESS;


public class GradebookDeleteCommandTest {
private static GradebookManager gradebookManager = new GradebookManager();

private static GradebookBuilder dummyGradebookComponent = new GradebookBuilder();

@Rule
public ExpectedException thrown = ExpectedException.none();

@Before
public void setUp() {
gradebookManager.clearGradebook();
gradebookManager.saveGradebookList();
}

@Test
public void execute_gradebookDelete_success() throws CommandException {
String moduleCode = "CS2113";
String gradebookComponentName = "Finals";
String expectedMessage = String.format(MESSAGE_DELETE_SUCCESS, moduleCode, gradebookComponentName);

gradebookManager.addGradebookComponent(dummyGradebookComponent.build());
gradebookManager.saveGradebookList();

GradebookDeleteCommand gradebookDeleteCommand = new GradebookDeleteCommand(moduleCode, gradebookComponentName);
CommandResult result = gradebookDeleteCommand.execute(new ModelManager(), new CommandHistory());

assertEquals(expectedMessage, result.feedbackToUser);
}

@AfterClass
public static void tearDown() {
gradebookManager.clearGradebook();
gradebookManager.saveGradebookList();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,59 @@
package seedu.address.logic.parser;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import seedu.address.logic.commands.GradebookDeleteCommand;
import seedu.address.logic.parser.exceptions.ParseException;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
import static seedu.address.logic.parser.GradebookDeleteCommandParser.MESSAGE_EMPTY_INPUTS;

public class GradebookDeleteCommandParserTest {
private GradebookDeleteCommandParser parser = new GradebookDeleteCommandParser();

@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void parse_invalidFormat_throwsParseException() throws ParseException {
String expectedMessage = String.format(MESSAGE_INVALID_COMMAND_FORMAT, GradebookDeleteCommand.MESSAGE_USAGE);

//invalid arguments found
String arg = "this is an invalid format";

thrown.expect(ParseException.class);
thrown.expectMessage(expectedMessage);
parser.parse(arg);
}

@Test
public void parse_validArgs_success() throws ParseException {
//valid arguments without optional arguments
String args = " mc/CS2113 i/Finals";
GradebookDeleteCommand gradebookDeleteCommand = parser.parse(args);
assertNotNull(gradebookDeleteCommand);
}

@Test
public void parse_emptyModuleCodeArgs_throwsParseException() throws ParseException {
String expectedMessage = String.format(MESSAGE_EMPTY_INPUTS);
//module code empty
String args = " mc/ i/Finals";
thrown.expect(ParseException.class);
thrown.expectMessage(expectedMessage);
parser.parse(args);
}

@Test
public void parse_emptyComponentNameArgs_throwsParseException() throws ParseException {
String expectedMessage = String.format(MESSAGE_EMPTY_INPUTS);
//component name empty
String arg = " mc/CS2113 i/";
thrown.expect(ParseException.class);
thrown.expectMessage(expectedMessage);
parser.parse(arg);
}
}

0 comments on commit 8ad062e

Please sign in to comment.