I have a java method checking File Existence..
public String checkFileExistance(String arg) throws IOException {
String FolderPath = SomePath
File file = new File(FolderPath);
if (file.exists() && file.isDirectory()) {
//Do something here
}
}
i want to mock the file.exist() and file.isDirectory() to make it return true always
i tried below method:
public void test_checkFileExistance1() throws IOException {
/**Mock*/
File mockedFile = Mockito.mock(File.class);
Mockito.when(mockedFile.exists()).thenReturn(true);
Mockito.when(mockedFile.isDirectory()).thenReturn(true);
/**Actual Call*/
ProcessClass.checkFileExistance("arg");
}
but it always returns false