我在Java类中有一个采用文件路径并创建新文件的方法。如何为此方法编写Junit测试?
public String sendToECM(String filePath) {
String ecmDocId = StringUtils.EMPTY;
try {
File file = new File(filePath);
if(file.exists()) {
DocumentPropertiesVO documentPropertiesVO = UploadFileToContentManagement.uploadDocument(file);
ecmDocId = documentPropertiesVO.getDocumentID();
}
return ecmDocId;
} catch (SomeException cee) {
log.error("There was an error adding the document", cee);
}
}
@Test
void testValidFilePath() {
String filePath = "path.txt";
String str = sendToECM(filePath);
Assertions.assertNotEquals(str, ""); // or null, depending on what your StringUtils.EMPTY is doing
@Test
void testInvalidFilePath() {
String filePath = "invalidPath.txt";
String str = sendtoECM(filePath);
Assertions.assertEquals(str, StringUtils.EMPTY);