Hi.
I'm creating a File mock object with Mockito that will be used as the directory to store a new File.
Folder folder = Mockito.mock(File.class);
File file = new Agent().createNewFile(folder, "fileName");
and inside my Agent class:
public File createNewFile(File folder, String filename){
return new File(folder, "testfile");
}
But I'm getting a NullPointerException at the initialization block of File when creating the new file inside createNewFile
method:
java.lang.NullPointerException at java.io.File.<init>(File.java:308)
I think it happens because File doesn't have any empty constructor, so when mocking the object some internal state remains null.
Am I taking the wrong approach mocking the File folder
object? My goal is to check some constraints before creating the new file, but I don't want to depend on an existing real folder on the file system.
Thank you.