package net.raymanoz.util;
import net.raymanoz.io.File;
import org.junit.Test;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
public class ScriptExecuterCommandLineParserImplTests {
@Test(expected=IllegalArgumentException.class)
public void throwsIlliegalArgumentExceptionIfNoScriptHolderInCmdLine(){
new ScriptExecuterCommandLineParserImpl("Invalid {script} holder");
}
@Test(expected=IllegalArgumentException.class)
public void throwsIlliegalArgumentExceptionIfNullCmdLine(){
new ScriptExecuterCommandLineParserImpl(null);
}
private void checkParser(String cmdLine, String absolutePath, String ... expectedArguments){
File executeFile = mock(File.class);
when(executeFile.getAbsolutePath()).thenReturn(absolutePath);
ScriptExecuterCommandLineParser parser = new ScriptExecuterCommandLineParserImpl(cmdLine);
assertArrayEquals(expectedArguments, parser.processBuilderArgs(executeFile));
}
@Test
public void checkParsing(){
checkParser("\"S:\\One\\Hellp\\Out\\..\\There\" ${script} -p" , "A Path of Absolute", "S:\\One\\Hellp\\Out\\..\\There", "A Path of Absolute", "-p");
checkParser("'One' -p '${script}'" , "Different Path", "One", "-p", "Different Path");
checkParser("One -p ${script}" , "Different Path", "One", "-p", "Different Path");
checkParser("One -p${script}" , "Different Path", "One", "-pDifferent Path");
checkParser("Two ${script}" , "Different Path", "Two", "Different Path");
checkParser("Two ${script} -x${script}" , "Different Path", "Two", "Different Path", "-xDifferent Path");
}
}