Skip to content

Commit

Permalink
Merge pull request #327 from ngswbryan/update-tests
Browse files Browse the repository at this point in the history
Updated more tests
  • Loading branch information
caesarpjz committed Nov 9, 2019
2 parents b1b6134 + c6a55f6 commit f8b34c9
Show file tree
Hide file tree
Showing 9 changed files with 370 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/model/classid/ClassId.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ClassId {
public static final String MESSAGE_CONSTRAINTS = "Class IDs can take any values, and it should not be blank";

/**
* The first character of the address must not be a whitespace,
* The first character of the classId must not be a whitespace,
* otherwise " " (a blank string) becomes a valid input.
*/
public static final String VALIDATION_REGEX = "[^\\s].*";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import seedu.address.model.commands.commandsexceptions.CommandNotFoundException;
import seedu.address.model.earnings.earningsexception.DuplicateEarningsException;
import seedu.address.model.earnings.earningsexception.EarningsNotFoundException;
import seedu.address.model.commands.commandsexceptions.DuplicateCommandException;

/**
* A list of CommandObjects that enforces uniqueness between its elements and does not allow nulls.
Expand Down Expand Up @@ -47,7 +46,7 @@ public boolean contains(CommandObject toCheck) {
public void add(CommandObject toAdd) {
requireNonNull(toAdd);
if (contains(toAdd)) {
throw new DuplicateEarningsException();
throw new DuplicateCommandException();
}
internalList.add(toAdd);
}
Expand All @@ -63,11 +62,11 @@ public void setCommands(CommandObject target, CommandObject editedCommand) {

int index = internalList.indexOf(target);
if (index == -1) {
throw new EarningsNotFoundException();
throw new CommandNotFoundException();
}

if (!target.isSameCommand(editedCommand) && contains(editedCommand)) {
throw new DuplicateEarningsException();
throw new DuplicateCommandException();
}

internalList.set(index, editedCommand);
Expand All @@ -85,7 +84,7 @@ public void setCommands(UniqueCommandsList replacement) {
public void setCommands(List<CommandObject> commands) {
requireAllNonNull(commands);
if (!commandsAreUnique(commands)) {
throw new DuplicateEarningsException();
throw new DuplicateCommandException();
}

internalList.setAll(commands);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package seedu.address.model.commands.commandsexceptions;

/**
* Signals that the operation will result in duplicate Earnings
* (Earnings are considered duplicates if they have the same
* classId, date, amount and type).
*/
public class DuplicateCommandException extends RuntimeException {
public DuplicateCommandException() {
super("Operation would result in duplicate command");
}
}
23 changes: 23 additions & 0 deletions src/test/java/seedu/address/logic/commands/CancelCommandTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package seedu.address.logic.commands;

import static seedu.address.logic.commands.CancelCommand.SHOWING_CANCEL_MESSAGE;
import static seedu.address.logic.commands.CommandTestUtil.assertCommandSuccess;

import org.junit.jupiter.api.Test;

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

public class CancelCommandTest {
private Model model = new ModelManager();
private Model expectedModel = new ModelManager();

@Test
public void execute_help_success() {
CommandResult expectedCommandResult = new CommandResult(SHOWING_CANCEL_MESSAGE,
false, false, false, false,
false, false, false, false);

assertCommandSuccess(new CancelCommand(), model, expectedCommandResult, expectedModel);
}
}
37 changes: 37 additions & 0 deletions src/test/java/seedu/address/model/classid/ClassIdTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package seedu.address.model.classid;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;

import org.junit.jupiter.api.Test;

public class ClassIdTest {

@Test
public void constructor_null_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new ClassId(null));
}

@Test
public void constructor_invalidClassId_throwsIllegalArgumentException() {
String invalidClassId = "";
assertThrows(IllegalArgumentException.class, () -> new ClassId(invalidClassId));
}

@Test
public void isValidClassId() {
// null classId
assertThrows(NullPointerException.class, () -> ClassId.isValidClassId(null));

// invalid classId
assertFalse(ClassId.isValidClassId("")); // empty string
assertFalse(ClassId.isValidClassId(" ")); // spaces only

assertTrue(ClassId.isValidClassId("CS2030"));
assertTrue(ClassId.isValidClassId("CS1231"));
assertTrue(ClassId.isValidClassId("CS2030 Tut 7"));
assertTrue(ClassId.isValidClassId("CS40000000"));
assertTrue(ClassId.isValidClassId("random class"));
}
}
38 changes: 38 additions & 0 deletions src/test/java/seedu/address/model/commands/CommandActionTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package seedu.address.model.classid;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;

import org.junit.jupiter.api.Test;

import seedu.address.model.commands.CommandAction;

public class CommandActionTest {

@Test
public void constructor_null_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new CommandAction(null));
}

@Test
public void constructor_invalidCommandAction_throwsIllegalArgumentException() {
String invalidCommandAction = "";
assertThrows(IllegalArgumentException.class, () -> new CommandAction(invalidCommandAction));
}

@Test
public void isValidCommandAction() {

assertThrows(NullPointerException.class, () -> CommandAction.isValidAction(null));

assertFalse(CommandAction.isValidAction("")); // empty string
assertFalse(CommandAction.isValidAction(" ")); // spaces only

assertTrue(CommandAction.isValidAction("add"));
assertTrue(CommandAction.isValidAction("delete"));
assertTrue(CommandAction.isValidAction("plus multiply"));
assertTrue(CommandAction.isValidAction("randomize"));
assertTrue(CommandAction.isValidAction("random"));
}
}
55 changes: 55 additions & 0 deletions src/test/java/seedu/address/model/commands/CommandObjectTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package seedu.address.model.person;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.TypicalTutorAid.ADDER;
import static seedu.address.testutil.TypicalTutorAid.DELETER;

import org.junit.jupiter.api.Test;

import seedu.address.model.commands.CommandObject;
import seedu.address.testutil.CommandObjectBuilder;

public class CommandObjectTest {

public static final String VALID_COMMAND_ACTION_MUL = "multiply";
public static final String VALID_WORD_MUL = "mul";

@Test
public void isSameCommandObject() {
// same object -> returns true
assertTrue(ADDER.isSameCommand(ADDER));

// null -> returns false
assertFalse(ADDER.isSameCommand(null));
}

@Test
public void equals() {
// same values -> returns true
CommandObject adderCopy = new CommandObjectBuilder(ADDER).build();
assertTrue(ADDER.equals(adderCopy));

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

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

// different type -> returns false
assertFalse(ADDER.equals(5));

// different command -> returns false
assertFalse(ADDER.equals(DELETER));

// different action -> returns false
CommandObject editedAdder = new CommandObjectBuilder(ADDER)
.withCommandAction(VALID_COMMAND_ACTION_MUL).build();
assertFalse(ADDER.equals(editedAdder));

// different commandword -> returns false
editedAdder = new CommandObjectBuilder(ADDER).withCommandWord(VALID_WORD_MUL).build();
assertFalse(ADDER.equals(editedAdder));
}

}
38 changes: 38 additions & 0 deletions src/test/java/seedu/address/model/commands/CommandWordTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package seedu.address.model.classid;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static seedu.address.testutil.Assert.assertThrows;

import org.junit.jupiter.api.Test;

import seedu.address.model.commands.CommandWord;

public class CommandWordTest {

@Test
public void constructor_null_throwsNullPointerException() {
assertThrows(NullPointerException.class, () -> new CommandWord(null));
}

@Test
public void constructor_invalidCommandWord_throwsIllegalArgumentException() {
String invalidCommandWord = "";
assertThrows(IllegalArgumentException.class, () -> new CommandWord(invalidCommandWord));
}

@Test
public void isValidCommandWord() {

assertThrows(NullPointerException.class, () -> CommandWord.isValidWord(null));

assertFalse(CommandWord.isValidWord("")); // empty string
assertFalse(CommandWord.isValidWord(" ")); // spaces only

assertTrue(CommandWord.isValidWord("test"));
assertTrue(CommandWord.isValidWord("test test"));
assertTrue(CommandWord.isValidWord("accepted!"));
assertTrue(CommandWord.isValidWord("okay123"));
assertTrue(CommandWord.isValidWord("random"));
}
}

0 comments on commit f8b34c9

Please sign in to comment.