package tars.logic;

import org.junit.Test;

import tars.logic.commands.CdCommand;

/**
 * Logic command test for cd
 * 
 * @@author A0124333U
 */
public class CdLogicCommandTest extends LogicCommandTest {
    @Test
    public void execute_cd_incorrectArgsFormatErrorMessageShown()
            throws Exception {
        assertCommandBehavior("cd ", CdCommand.MESSAGE_INVALID_FILEPATH);
    }

    @Test
    public void execute_cd_invalidFileTypeErrorMessageShown() throws Exception {
        assertCommandBehavior("cd invalidFileType",
                CdCommand.MESSAGE_INVALID_FILEPATH);
    }

    @Test
    public void execute_cd_success() throws Exception {
        String tempTestTarsFilePath =
                saveFolder.getRoot().getPath() + "TempTestTars.xml";
        assertCommandBehavior("cd " + tempTestTarsFilePath,
                String.format(CdCommand.MESSAGE_SUCCESS_NEW_FILE, tempTestTarsFilePath));
    }
}

@@ -14,16 +14,38 @@
 logic;%0A%0A
+import java.io.File;%0A%0A
 import o
@@ -76,32 +76,160 @@
 ars.
-logic.commands.CdCommand
+commons.util.FileUtil;%0Aimport tars.logic.commands.CdCommand;%0Aimport tars.model.Tars;%0Aimport tars.storage.TarsStorage;%0Aimport tars.storage.XmlTarsStorage
 ;%0A%0A/
@@ -349,26 +349,24 @@
 dTest %7B%0A
-  
   @Test%0A
     publ
@@ -349,34 +349,32 @@
 dTest %7B%0A  @Test%0A
-  
   public void ex
@@ -420,28 +420,16 @@
 eShown()
-%0A           
  throws 
@@ -432,36 +432,32 @@
 ows Exception %7B%0A
-    
     assertComman
@@ -508,39 +508,35 @@
 ILEPATH);%0A  
- 
- 
 %7D%0A%0A
-  
   @Test%0A
     public v
@@ -515,34 +515,32 @@
 );%0A  %7D%0A%0A  @Test%0A
-  
   public void ex
@@ -598,28 +598,24 @@
 Exception %7B%0A
-    
     assertCo
@@ -649,32 +649,16 @@
 leType%22,
-%0A               
  CdComma
@@ -691,27 +691,21 @@
 H);%0A
-  
   %7D%0A%0A  
- 
- 
 @Test%0A
-  
   pu
@@ -725,16 +725,25 @@
 cute_cd_
+new_file_
 success(
@@ -771,57 +771,357 @@
     
-    String tempTestTarsFilePath =%0A               
+String tempTestTarsFilePath = saveFolder.getRoot().getPath() + %22TempTestTars.xml%22;%0A    assertCommandBehavior(%22cd %22 + tempTestTarsFilePath,%0A        String.format(CdCommand.MESSAGE_SUCCESS_NEW_FILE, tempTestTarsFilePath));%0A  %7D%0A%0A  @Test%0A  public void execute_cd_existing_file_failureToReadExistingFile() throws Exception %7B%0A    String existingFilePath =
  sav
@@ -1148,36 +1148,32 @@
 tPath() + %22TempT
-estT
 ars.xml%22;%0A      
@@ -1174,62 +1174,415 @@
     
-    assertCommandBehavior(%22cd %22 + tempTestTars
+File existingFile = new File(existingFilePath);%0A    FileUtil.createIfMissing(existingFile);%0A    assertCommandBehavior(%22cd %22 + existingFilePath, CdCommand.MESSAGE_FAILURE_READ_FILE);%0A  %7D%0A%0A  @Test%0A  public void execute_cd_existing_file_success() throws Exception %7B%0A    String existingFilePath = saveFolder.getRoot().getPath() + %22TempTars.xml%22;%0A    TarsStorage testStorage = new XmlTarsStorage(existing
 FilePath
 ,%0A  
@@ -1577,26 +1577,118 @@
 FilePath
-,
+);
 %0A    
-    
+testStorage.saveTars(Tars.getEmptyTars());%0A    assertCommandBehavior(%22cd %22 + existingFilePath,%0A
         
@@ -1727,38 +1727,39 @@
 SUCCESS_
-NEW_FILE, tempTestTars
+EXISTING_FILE, existing
 FilePath
@@ -1762,16 +1762,14 @@
 Path));%0A
-  
   %7D%0A%7D%0A

Add logic tests for CdCommand