我是 Java 中的 JUnit 和 Mockito 测试的新手,有人可以给我一个示例或想法,说明如何测试基本上读取路径并验证文件是否存在的方法,该方法无论如何都会接收一个日期作为参数
这里是我要测试的方法:
public String getFileAE(String fecha) {
String fileName = null;
String filePath = null;
File file = null;
try {
logger.info("Leyendo archivo ejecutivos facultados");
fileName = ConstantsFiles.FILE_NAME_AE + fecha + ConstantsFiles.FILE_EXTENSION;
filePath = ConstantsFiles.FILE_PATH_AE + fileName;
logger.info(filePath);
file = new File(filePath);
if (!file.exists()) {
logger.error("Error, el archivo no existe: " + filePath);
return "";
}
return filePath;
} catch (Exception ex) {
logger.error("Error, el archivo no se pudo leer: " + ex.getMessage(), ex);
}
return filePath;
}