// Path: src/com/atsebak/embeddedlinuxjvm/runner/conf/EmbeddedLinuxJVMRunConfiguration.java
// public class EmbeddedLinuxJVMRunConfiguration extends LocatableConfigurationBase implements RunProfileWithCompileBeforeLaunchOption {
//     private EmbeddedLinuxJVMRunConfigurationRunnerParameters embeddedLinuxJVMRunConfigurationRunnerParameters = new EmbeddedLinuxJVMRunConfigurationRunnerParameters();
// 
//     /**
//      * Run Configurations To Run App
//      *
//      * @param project
//      * @param factory
//      */
//     protected EmbeddedLinuxJVMRunConfiguration(final Project project, final ConfigurationFactory factory, String name) {
//         super(project, factory, name);
//     }
// 
//     /**
//      * Settings Editor
//      * @return
//      */
//     @NotNull
//     @Override
//     public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
//         return new RunConfigurationEditor(getProject());
//     }
// 
//     /**
//      * Creates new running paramters instance
//      * @return
//      */
//     protected EmbeddedLinuxJVMRunConfigurationRunnerParameters createRunnerParametersInstance() {
//         return new EmbeddedLinuxJVMRunConfigurationRunnerParameters();
//     }
// 
// 
//     /**
//      * Read External
//      * @param element
//      * @throws InvalidDataException
//      */
//     @Override
//     public void readExternal(Element element) throws InvalidDataException {
//         super.readExternal(element);
//         embeddedLinuxJVMRunConfigurationRunnerParameters = createRunnerParametersInstance();
//         XmlSerializer.deserializeInto(embeddedLinuxJVMRunConfigurationRunnerParameters, element);
//     }
// 
//     /**
//      * Write External
//      * @param element
//      * @throws WriteExternalException
//      */
//     @Override
//     public void writeExternal(Element element) throws WriteExternalException {
//         super.writeExternal(element);
//         if (embeddedLinuxJVMRunConfigurationRunnerParameters != null) {
//             XmlSerializer.serializeInto(embeddedLinuxJVMRunConfigurationRunnerParameters, element);
//         }
//     }
// 
//     /**
//      * Gets the state of the execution environment
//      * @param executor
//      * @param env
//      * @return
//      * @throws ExecutionException
//      */
//     @Override
//     public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
//         return new AppCommandLineState(env, this);
//     }
// 
// 
//     /**
//      * Checks weather all the supplied paramters from the user are correct
//      * @throws RuntimeConfigurationException
//      */
//     @Override
//     public void checkConfiguration() throws RuntimeConfigurationException {
//         EmbeddedLinuxJVMRunnerValidator.checkJavaSettings(this);
//         EmbeddedLinuxJVMRunnerValidator.checkEmbeddedSettings(getRunnerParameters());
//     }
// 
//     /**
//      * Gets runner paramters instance
//      * @return
//      */
//     public EmbeddedLinuxJVMRunConfigurationRunnerParameters getRunnerParameters() {
//         return embeddedLinuxJVMRunConfigurationRunnerParameters;
//     }
// 
//     /**
//      * Gets modules
//      *
//      * @return
//      */
//     @NotNull
//     @Override
//     public Module[] getModules() {
//         return new Module[0];
//     }
// }
// 
// Path: src/com/atsebak/embeddedlinuxjvm/runner/data/EmbeddedLinuxJVMRunConfigurationRunnerParameters.java
// @Data
// public class EmbeddedLinuxJVMRunConfigurationRunnerParameters implements Cloneable {
// 	public String moduleName;
//     public String mainclass;
//     private String hostname;
//     private boolean runAsRoot;
//     private boolean usingKey;
//     @Nullable
//     private String keyPath;
//     @NotNull
//     private String port = "1234";
//     @NotNull
//     private int sshPort = 22;
//     private String username;
//     @Nullable
//     private String password;
//     private String classesDirectory;
//     private String vmParameters;
//     private String programArguments;
// 
//     /**
//      * Clones members
//      *
//      * @return
//      */
//     @Override
//     public EmbeddedLinuxJVMRunConfigurationRunnerParameters clone() {
//         try {
//             return (EmbeddedLinuxJVMRunConfigurationRunnerParameters) super.clone();
//         } catch (CloneNotSupportedException e) {
//             return null;
//         }
//     }
// 
// }


import com.atsebak.embeddedlinuxjvm.runner.conf.EmbeddedLinuxJVMRunConfiguration;
import com.atsebak.embeddedlinuxjvm.runner.data.EmbeddedLinuxJVMRunConfigurationRunnerParameters;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.configurations.ParametersList;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
        when(javaParameters.getProgramParametersList().getParameters()).thenReturn(new ArrayList<String>());
        when(javaParameters.getVMParametersList()).thenReturn(jvmParametersList);
        when(javaParameters.getModuleName()).thenReturn(parameters.getModuleName());
        when(javaParameters.getMainClass()).thenReturn(parameters.getMainclass());
    }

    @Test
    public void testRunCommand() {
        when(javaParameters.getVMParametersList().getParameters()).thenReturn(new ArrayList<String>());
        String runCommand = CommandLineTarget.builder()
                .isDebugging(false)
                .parameters(javaParameters)
                .embeddedLinuxJVMRunConfiguration(piRunConfiguration)
                .build().toString();
        assertTrue(runCommand.contains(String.format("sudo java -cp classes:lib/'*' %s", parameters.getMainclass())));
    }

    @Test
    public void testDebugCommand() {
        JavaParameters params = Mockito.mock(JavaParameters.class);
        String debugCommand = CommandLineTarget.builder()
                .isDebugging(true)
                .parameters(javaParameters)
                .embeddedLinuxJVMRunConfiguration(piRunConfiguration)
                .build().toString();
        assertTrue(debugCommand.contains("sudo java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + parameters.getPort()));
    }

    @Test
    public void testAddingArguments() {
// Path: src/com/atsebak/embeddedlinuxjvm/runner/conf/EmbeddedLinuxJVMRunConfiguration.java
// public class EmbeddedLinuxJVMRunConfiguration extends LocatableConfigurationBase implements RunProfileWithCompileBeforeLaunchOption {
//     private EmbeddedLinuxJVMRunConfigurationRunnerParameters embeddedLinuxJVMRunConfigurationRunnerParameters = new EmbeddedLinuxJVMRunConfigurationRunnerParameters();
// 
//     /**
//      * Run Configurations To Run App
//      *
//      * @param project
//      * @param factory
//      */
//     protected EmbeddedLinuxJVMRunConfiguration(final Project project, final ConfigurationFactory factory, String name) {
//         super(project, factory, name);
//     }
// 
//     /**
//      * Settings Editor
//      * @return
//      */
//     @NotNull
//     @Override
//     public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
//         return new RunConfigurationEditor(getProject());
//     }
// 
//     /**
//      * Creates new running paramters instance
//      * @return
//      */
//     protected EmbeddedLinuxJVMRunConfigurationRunnerParameters createRunnerParametersInstance() {
//         return new EmbeddedLinuxJVMRunConfigurationRunnerParameters();
//     }
// 
// 
//     /**
//      * Read External
//      * @param element
//      * @throws InvalidDataException
//      */
//     @Override
//     public void readExternal(Element element) throws InvalidDataException {
//         super.readExternal(element);
//         embeddedLinuxJVMRunConfigurationRunnerParameters = createRunnerParametersInstance();
//         XmlSerializer.deserializeInto(embeddedLinuxJVMRunConfigurationRunnerParameters, element);
//     }
// 
//     /**
//      * Write External
//      * @param element
//      * @throws WriteExternalException
//      */
//     @Override
//     public void writeExternal(Element element) throws WriteExternalException {
//         super.writeExternal(element);
//         if (embeddedLinuxJVMRunConfigurationRunnerParameters != null) {
//             XmlSerializer.serializeInto(embeddedLinuxJVMRunConfigurationRunnerParameters, element);
//         }
//     }
// 
//     /**
//      * Gets the state of the execution environment
//      * @param executor
//      * @param env
//      * @return
//      * @throws ExecutionException
//      */
//     @Override
//     public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) throws ExecutionException {
//         return new AppCommandLineState(env, this);
//     }
// 
// 
//     /**
//      * Checks weather all the supplied paramters from the user are correct
//      * @throws RuntimeConfigurationException
//      */
//     @Override
//     public void checkConfiguration() throws RuntimeConfigurationException {
//         EmbeddedLinuxJVMRunnerValidator.checkJavaSettings(this);
//         EmbeddedLinuxJVMRunnerValidator.checkEmbeddedSettings(getRunnerParameters());
//     }
// 
//     /**
//      * Gets runner paramters instance
//      * @return
//      */
//     public EmbeddedLinuxJVMRunConfigurationRunnerParameters getRunnerParameters() {
//         return embeddedLinuxJVMRunConfigurationRunnerParameters;
//     }
// 
//     /**
//      * Gets modules
//      *
//      * @return
//      */
//     @NotNull
//     @Override
//     public Module[] getModules() {
//         return new Module[0];
//     }
// }
// 
// Path: src/com/atsebak/embeddedlinuxjvm/runner/data/EmbeddedLinuxJVMRunConfigurationRunnerParameters.java
// @Data
// public class EmbeddedLinuxJVMRunConfigurationRunnerParameters implements Cloneable {
// 	public String moduleName;
//     public String mainclass;
//     private String hostname;
//     private boolean runAsRoot;
//     private boolean usingKey;
//     @Nullable
//     private String keyPath;
//     @NotNull
//     private String port = "1234";
//     @NotNull
//     private int sshPort = 22;
//     private String username;
//     @Nullable
//     private String password;
//     private String classesDirectory;
//     private String vmParameters;
//     private String programArguments;
// 
//     /**
//      * Clones members
//      *
//      * @return
//      */
//     @Override
//     public EmbeddedLinuxJVMRunConfigurationRunnerParameters clone() {
//         try {
//             return (EmbeddedLinuxJVMRunConfigurationRunnerParameters) super.clone();
//         } catch (CloneNotSupportedException e) {
//             return null;
//         }
//     }
// 
// }


// Path: test/com/atsebak/embeddedlinuxjvm/commandline/CommandLineTargetTest.java
import com.atsebak.embeddedlinuxjvm.runner.conf.EmbeddedLinuxJVMRunConfiguration;
import com.atsebak.embeddedlinuxjvm.runner.data.EmbeddedLinuxJVMRunConfigurationRunnerParameters;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.configurations.ParametersList;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import java.util.ArrayList;
import java.util.Arrays;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;

        when(javaParameters.getProgramParametersList().getParameters()).thenReturn(new ArrayList<String>());
        when(javaParameters.getVMParametersList()).thenReturn(jvmParametersList);
        when(javaParameters.getModuleName()).thenReturn(parameters.getModuleName());
        when(javaParameters.getMainClass()).thenReturn(parameters.getMainclass());
    }

    @Test
    public void testRunCommand() {
        when(javaParameters.getVMParametersList().getParameters()).thenReturn(new ArrayList<String>());
        String runCommand = CommandLineTarget.builder()
                .isDebugging(false)
                .parameters(javaParameters)
                .embeddedLinuxJVMRunConfiguration(piRunConfiguration)
                .build().toString();
        assertTrue(runCommand.contains(String.format("sudo java -cp classes:lib/'*' %s", parameters.getMainclass())));
    }

    @Test
    public void testDebugCommand() {
        JavaParameters params = Mockito.mock(JavaParameters.class);
        String debugCommand = CommandLineTarget.builder()
                .isDebugging(true)
                .parameters(javaParameters)
                .embeddedLinuxJVMRunConfiguration(piRunConfiguration)
                .build().toString();
        assertTrue(debugCommand.contains("sudo java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + parameters.getPort()));
    }

    @Test
    public void testAddingArguments() {
        when(javaParameters.getProgramParametersList().getParameters()).thenReturn(Arrays.asList("1", "2", "3"));