forked from nus-cs2103-AY1920S1/addressbook-level3
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
157 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...est/java/seedu/weme/logic/parser/templatecommandparser/TemplateEditCommandParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package seedu.weme.logic.parser.templatecommandparser; | ||
|
||
import static seedu.weme.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.weme.logic.commands.CommandTestUtil.NAME_DESC_DOGE; | ||
import static seedu.weme.logic.commands.CommandTestUtil.NAME_DESC_DRAKE; | ||
import static seedu.weme.logic.commands.CommandTestUtil.VALID_NAME_DOGE; | ||
import static seedu.weme.logic.commands.CommandTestUtil.VALID_NAME_DRAKE; | ||
import static seedu.weme.logic.parser.CommandParserTestUtil.assertParseFailure; | ||
import static seedu.weme.logic.parser.CommandParserTestUtil.assertParseSuccess; | ||
import static seedu.weme.testutil.TypicalIndexes.INDEX_FIRST; | ||
import static seedu.weme.testutil.TypicalIndexes.INDEX_SECOND; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.weme.commons.core.index.Index; | ||
import seedu.weme.logic.commands.templatecommand.TemplateEditCommand; | ||
import seedu.weme.logic.parser.commandparser.templatecommandparser.TemplateEditCommandParser; | ||
import seedu.weme.model.template.Name; | ||
|
||
public class TemplateEditCommandParserTest { | ||
|
||
private static final String MESSAGE_INVALID_FORMAT = | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, TemplateEditCommand.MESSAGE_USAGE); | ||
|
||
private TemplateEditCommandParser parser = new TemplateEditCommandParser(); | ||
|
||
@Test | ||
public void parse_missingParts_failure() { | ||
// no index specified | ||
assertParseFailure(parser, NAME_DESC_DRAKE, MESSAGE_INVALID_FORMAT); | ||
|
||
// no field specified | ||
assertParseFailure(parser, "1", TemplateEditCommand.MESSAGE_NOT_EDITED); | ||
|
||
// no index and no field specified | ||
assertParseFailure(parser, "", MESSAGE_INVALID_FORMAT); | ||
} | ||
|
||
@Test | ||
public void parse_invalidPreamble_failure() { | ||
// negative index | ||
assertParseFailure(parser, "-5" + NAME_DESC_DRAKE, MESSAGE_INVALID_FORMAT); | ||
|
||
// zero index | ||
assertParseFailure(parser, "0" + NAME_DESC_DRAKE, MESSAGE_INVALID_FORMAT); | ||
|
||
// invalid arguments being parsed as preamble | ||
assertParseFailure(parser, "1 some random string" + NAME_DESC_DRAKE, MESSAGE_INVALID_FORMAT); | ||
|
||
// invalid prefix being parsed as preamble | ||
assertParseFailure(parser, "1 i/ string", MESSAGE_INVALID_FORMAT); | ||
} | ||
|
||
@Test | ||
public void parse_nameSpecified_success() { | ||
Index targetIndex = INDEX_SECOND; | ||
String userInput = targetIndex.getOneBased() + NAME_DESC_DRAKE; | ||
|
||
Name expectedName = new Name(VALID_NAME_DRAKE); | ||
TemplateEditCommand expectedCommand = new TemplateEditCommand(targetIndex, expectedName); | ||
|
||
assertParseSuccess(parser, userInput, expectedCommand); | ||
} | ||
|
||
@Test | ||
public void parse_multipleNamesSpecified_acceptsLast() { | ||
Index targetIndex = INDEX_FIRST; | ||
String userInput = targetIndex.getOneBased() + NAME_DESC_DRAKE + NAME_DESC_DOGE; | ||
|
||
Name expectedName = new Name(VALID_NAME_DOGE); | ||
TemplateEditCommand expectedCommand = new TemplateEditCommand(targetIndex, expectedName); | ||
|
||
assertParseSuccess(parser, userInput, expectedCommand); | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
src/test/java/seedu/weme/model/templates/MemeTextColorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package seedu.weme.model.templates; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotEquals; | ||
import static seedu.weme.testutil.Assert.assertThrows; | ||
|
||
import java.awt.Color; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import seedu.weme.model.template.MemeTextColor; | ||
|
||
public class MemeTextColorTest { | ||
|
||
private static String ERROR_MESSAGE = MemeTextColor.MESSAGE_CONSTRAINTS; | ||
|
||
@Test | ||
public void constructor_validColorName_success() { | ||
assertEquals(Color.BLACK, new MemeTextColor("black").getColor()); | ||
assertEquals(Color.BLUE, new MemeTextColor("blue").getColor()); | ||
assertEquals(Color.GRAY, new MemeTextColor("gray").getColor()); | ||
assertEquals(Color.MAGENTA, new MemeTextColor("magenta").getColor()); | ||
assertEquals(Color.WHITE, new MemeTextColor("white").getColor()); | ||
assertEquals(Color.YELLOW, new MemeTextColor("yellow").getColor()); | ||
} | ||
|
||
@Test | ||
public void constructor_invalidString_throwsIllegalArgumentException() { | ||
assertThrows(IllegalArgumentException.class, ERROR_MESSAGE, () -> new MemeTextColor("not a color")); | ||
assertThrows(IllegalArgumentException.class, ERROR_MESSAGE, () -> new MemeTextColor("str1ng and numb3r")); | ||
assertThrows(IllegalArgumentException.class, ERROR_MESSAGE, () -> new MemeTextColor("")); | ||
} | ||
|
||
@Test | ||
public void constructor_validHexValue_success() { | ||
assertEquals(new Color(0, 0, 0), new MemeTextColor("#000000").getColor()); | ||
assertEquals(new Color(255, 255, 255), new MemeTextColor("#FFFFFF").getColor()); | ||
assertEquals(new Color(200, 100, 50), new MemeTextColor("#C86432").getColor()); | ||
} | ||
|
||
@Test | ||
public void constructor_invalidHexValue_throwsIllegalArgumentException() { | ||
assertThrows(IllegalArgumentException.class, ERROR_MESSAGE, () -> new MemeTextColor("#GGGGGG")); | ||
assertThrows(IllegalArgumentException.class, ERROR_MESSAGE, () -> new MemeTextColor("#GG0000")); | ||
assertThrows(IllegalArgumentException.class, ERROR_MESSAGE, () -> new MemeTextColor("#00GG00")); | ||
assertThrows(IllegalArgumentException.class, ERROR_MESSAGE, () -> new MemeTextColor("#0000GG")); | ||
assertThrows(IllegalArgumentException.class, ERROR_MESSAGE, () -> new MemeTextColor("#123GHJ")); | ||
} | ||
|
||
@Test | ||
public void equals() { | ||
// same color name -> true | ||
assertEquals(new MemeTextColor("black"), new MemeTextColor("black")); | ||
assertEquals(new MemeTextColor("white"), new MemeTextColor("white")); | ||
// different color name -> false | ||
assertNotEquals(new MemeTextColor("blue"), new MemeTextColor("yellow")); | ||
assertNotEquals(new MemeTextColor("red"), new MemeTextColor("brown")); | ||
// same hex values -> true | ||
assertEquals(new MemeTextColor("#123456"), new MemeTextColor("#123456")); | ||
assertEquals(new MemeTextColor("#EFD987"), new MemeTextColor("#EFD987")); | ||
// different hex values -> false | ||
assertNotEquals(new MemeTextColor("#876EAB"), new MemeTextColor("#12D45F")); | ||
assertNotEquals(new MemeTextColor("#812BAC"), new MemeTextColor("#1F29E7")); | ||
// equivalent color name and hex value -> true | ||
assertEquals(new MemeTextColor("red"), new MemeTextColor("#FF0000")); | ||
assertEquals(new MemeTextColor("yellow"), new MemeTextColor("#FFFF00")); | ||
assertEquals(new MemeTextColor("blue"), new MemeTextColor("#0000FF")); | ||
// in-equivalent color name and hex value -> false | ||
assertNotEquals(new MemeTextColor("red"), new MemeTextColor("#123EDA")); | ||
assertNotEquals(new MemeTextColor("yellow"), new MemeTextColor("#ACE987")); | ||
assertNotEquals(new MemeTextColor("blue"), new MemeTextColor("#0123DE")); | ||
} | ||
} | ||
|