package guitests;

import static org.mockito.Matchers.any;
import static seedu.ezdo.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;

import java.io.File;
import java.io.IOException;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import seedu.ezdo.commons.util.FileUtil;
import seedu.ezdo.logic.commands.SaveCommand;

@RunWith(PowerMockRunner.class)
@PrepareForTest({FileUtil.class})
public class SaveCommandTest extends EzDoGuiTest {

    private final String validDirectory = "./";
    private final String inexistentDirectory = "data/COWABUNGA";

    @Test
    public void save_validDirectory_success() {
        commandBox.runCommand("save " + validDirectory);
        assertResultMessage(String.format(SaveCommand.MESSAGE_SAVE_TASK_SUCCESS,
                validDirectory + SaveCommand.DATA_FILE_NAME));
    }

    @Test
    public void save_invalidFormat_failure() {
        commandBox.runCommand("save");
        assertResultMessage(String.format(MESSAGE_INVALID_COMMAND_FORMAT, SaveCommand.MESSAGE_USAGE));
    }

    @Test
    public void save_inexistentDirectory_failure() {
        commandBox.runCommand("save " + inexistentDirectory);
        assertResultMessage(String.format(SaveCommand.MESSAGE_DIRECTORY_PATH_DOES_NOT_EXIST));
    }

    @Test
    public void save_validDirectory_noAdminPermissions_failure() throws Exception {
        PowerMockito.spy(FileUtil.class);
        PowerMockito.doThrow(new IOException()).when(FileUtil.class, "createIfMissing", any(File.class));
        commandBox.runCommand("save " + validDirectory);
        assertResultMessage(String.format(SaveCommand.MESSAGE_DIRECTORY_PATH_INVALID));
    }
}

@@ -16,48 +16,8 @@
 s;%0A%0A
-import static org.mockito.Matchers.any;%0A
 impo
@@ -202,53 +202,27 @@
 th;%0A
+%0A
 import 
-org.powermock.api.mockito.Power
+mockit.
 Mock
-ito
 ;%0Aim
@@ -230,120 +230,64 @@
 ort 
-org.powermock.core.classloader.annotations.PrepareForTest;%0Aimport org.powermock.modules.junit4.PowerMockRunner;%0A
+mockit.MockUp;%0Aimport mockit.integration.junit4.JMockit;
 %0Aimp
@@ -384,63 +384,21 @@
 ith(
-PowerMockRunner.class)%0A@PrepareForTest(%7BFileUtil
+JMockit
 .class
-%7D
 )%0Apu
@@ -1366,146 +1366,296 @@
     
-PowerMockito.spy(FileUtil.class);%0A        PowerMockito.doThrow(new IOException()).when(FileUtil.class, %22createIfMissing%22, any(File.class))
+new MockUp%3CFileUtil%3E()%0A        %7B%0A            @Mock%0A            public void createIfMissing(File file) throws IOException // this method is static in SwingUtilities%0A            %7B%0A                throw new IOException(); // so that everything executes on this thread%0A            %7D%0A        %7D
 ;%0A  
@@ -1797,16 +1797,17 @@
 ALID));%0A
-
     %7D%0A
+%0A
 %7D%0A

Fix testing bug related to PowerMock and .dlls being loaded in another classloader already Switch to JMockit