I am new to JUnit and I do not know how to test this kind of code.
package input.commandline;
import java.util.InputMismatchException;
import java.util.regex.Pattern;
public class ReadFilePath extends CommandLineInput{
public String perform(){
String path = scanner.nextLine();
String regularExpression = "([a-zA-Z]:)?(\\[a-zA-Z0-9_-]+)+\\?";
boolean isMatched = Pattern.matches(regularExpression,path);
if(isMatched){
return path;
}else {
throw new InputMismatchException();
}
}
}
this is my test class
package input.commandline;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.*;
public class ReadFilePathTest {
@Test
public void sampleTest() throws Exception{
// ReadFilePath readFile = new ReadFilePath();
//
// readFile.perform();
Assert.assertEquals("sam","sam");
}
}
I do not know how to pass data to String path = scanner.nextLine(); this line