Reputation: 475
I have method in Java class that takes a file path and creates a new file. How do I write a Junit test for this method?
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);
}
}
Upvotes: 0
Views: 827
Reputation: 374
@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);
Upvotes: 1