package guitests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;

import java.util.ArrayList;

import org.junit.Before;
import org.junit.Test;

import seedu.doit.ui.CommandBox;

public class CommandBoxTest extends TaskManagerGuiTest {

    private static final String COMMAND_THAT_SUCCEEDS = "select 1";
    private static final String COMMAND_THAT_FAILS = "invalid command";

    private ArrayList<String> defaultStyleOfCommandBox;
    private ArrayList<String> errorStyleOfCommandBox;

    @Before
    public void setUp() {
        this.defaultStyleOfCommandBox = new ArrayList<>(this.commandBox.getStyleClass());
        assertFalse("CommandBox default style classes should not contain error style class.",
                this.defaultStyleOfCommandBox.contains(CommandBox.ERROR_STYLE_CLASS));

        // build style class for error
        this.errorStyleOfCommandBox = new ArrayList<>(this.defaultStyleOfCommandBox);
        this.errorStyleOfCommandBox.add(CommandBox.ERROR_STYLE_CLASS);
    }

    @Test
    public void commandBox_commandSucceeds_textClearedAndStyleClassRemainsTheSame() {
        this.commandBox.runCommand(COMMAND_THAT_SUCCEEDS);

        assertEquals("", this.commandBox.getCommandInput());
        assertEquals(this.defaultStyleOfCommandBox, this.commandBox.getStyleClass());
    }

    @Test
    public void commandBox_commandFails_textStaysAndErrorStyleClassAdded() {
        this.commandBox.runCommand(COMMAND_THAT_FAILS);

        assertEquals(COMMAND_THAT_FAILS, this.commandBox.getCommandInput());
        assertEquals(this.errorStyleOfCommandBox, this.commandBox.getStyleClass());
    }

    @Test
    public void commandBox_commandSucceedsAfterFailedCommand_textClearedAndErrorStyleClassRemoved() {
        // add error style to simulate a failed command
        this.commandBox.getStyleClass().add(CommandBox.ERROR_STYLE_CLASS);

        this.commandBox.runCommand(COMMAND_THAT_SUCCEEDS);

        assertEquals("", this.commandBox.getCommandInput());
        assertEquals(this.defaultStyleOfCommandBox, this.commandBox.getStyleClass());
    }

}

@@ -272,16 +272,66 @@
 Test %7B%0A%0A
+    public static final String EMPTY_STRING = %22%22;%0A
     priv
@@ -1256,34 +1256,44 @@
    assertEquals(
-%22%22
+EMPTY_STRING
 , this.commandBo
@@ -1572,34 +1572,28 @@
 tEquals(
-COMMAND_THAT_FAILS
+EMPTY_STRING
 , this.c
@@ -2038,18 +2038,28 @@
 tEquals(
-%22%22
+EMPTY_STRING
 , this.c

Fix Test case for command box