Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gary-lgy committed Nov 10, 2019
1 parent 1401320 commit 73f790b
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ public TemplateEditCommand parse(String args) throws ParseException {
}

if (!argMultimap.arePrefixesPresent(PREFIX_NAME) || argMultimap.getValue(PREFIX_NAME).get().isEmpty()) {
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT,
TemplateEditCommand.MESSAGE_NOT_EDITED));
throw new ParseException(TemplateEditCommand.MESSAGE_NOT_EDITED);
}

Name editedName = new Name(argMultimap.getValue(PREFIX_NAME).get());
Expand Down
7 changes: 7 additions & 0 deletions src/test/java/seedu/weme/logic/commands/CommandTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static seedu.weme.logic.commands.memecommand.MemeDeleteCommand.MESSAGE_DELETE_MEME_SUCCESS;
import static seedu.weme.logic.parser.util.CliSyntax.PREFIX_DESCRIPTION;
import static seedu.weme.logic.parser.util.CliSyntax.PREFIX_FILEPATH;
import static seedu.weme.logic.parser.util.CliSyntax.PREFIX_NAME_STRING;
import static seedu.weme.logic.parser.util.CliSyntax.PREFIX_TAG;
import static seedu.weme.testutil.Assert.assertThrows;
import static seedu.weme.testutil.MemeUtil.isSameMemeImage;
Expand Down Expand Up @@ -37,13 +38,19 @@ public class CommandTestUtil {
public static final String VALID_TAG_CHARMANDER = "charmander";
public static final String VALID_TAG_JOKER = "joker";

public static final String VALID_NAME_DRAKE = "Drake Reaction";
public static final String VALID_NAME_DOGE = "Doge";

public static final String DESCRIPTION_DESC_CHARMANDER = " " + PREFIX_DESCRIPTION + VALID_DESCRIPTION_CHARMANDER;
public static final String DESCRIPTION_DESC_JOKER = " " + PREFIX_DESCRIPTION + VALID_DESCRIPTION_JOKER;
public static final String FILEPATH_DESC_CHARMANDER = " " + PREFIX_FILEPATH + VALID_FILEPATH_CHARMANDER;
public static final String FILEPATH_DESC_JOKER = " " + PREFIX_FILEPATH + VALID_FILEPATH_JOKER;
public static final String TAG_DESC_CHARMANDER = " " + PREFIX_TAG + VALID_TAG_CHARMANDER;
public static final String TAG_DESC_JOKER = " " + PREFIX_TAG + VALID_TAG_JOKER;

public static final String NAME_DESC_DRAKE = " " + PREFIX_NAME_STRING + VALID_NAME_DRAKE;
public static final String NAME_DESC_DOGE = " " + PREFIX_NAME_STRING + VALID_NAME_DOGE;

public static final String INVALID_FILEPATH_DESC = " " + PREFIX_FILEPATH; // empty string not allowed for file path
public static final String INVALID_TAG_DESC = " " + PREFIX_TAG + "hubby*"; // '*' not allowed in tags

Expand Down
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 src/test/java/seedu/weme/model/templates/MemeTextColorTest.java
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"));
}
}

0 comments on commit 73f790b

Please sign in to comment.