I am new to jUnit. Can not figure out how to test handled exception.
public File inputProcessor(String filePath){
File file = null;
try {
file = new File(filePath);
Scanner input = new Scanner(file);
} catch (FileNotFoundException e) {
System.out.print("Check your input file path");
e.printStackTrace();
}
return file;
}
Now, want to test with a invalid file path to check whether exception is thrown and caught properly. I wrote this
@Test (expected = java.io.FileNotFoundException.class)
public void Input_CheckOnInvalidPath_ExceptionThrown() {
Driver driver = new Driver();
String filePath = "wrong path";
File file = driver.inputProcessor(filePath);
}
But as I have already caught my exception its not working. Test is failing . Any help will be great!! thnx
public).