1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/test/groovy/FileUtilsTest.groovy

94 lines
2.2 KiB
Groovy
Raw Normal View History

2017-07-11 15:12:03 +02:00
import org.junit.Rule
import org.junit.Before
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.TemporaryFolder
import hudson.AbortException
import com.sap.piper.FileUtils
class FileUtilsTest {
@Rule
public ExpectedException thrown = new ExpectedException().none()
@Rule
public TemporaryFolder tmp = new TemporaryFolder()
private File emptyDir
private File notEmptyDir
private File notDir
@Before
2017-11-21 15:27:05 +02:00
void setUp() {
2017-07-11 15:12:03 +02:00
emptyDir = tmp.newFolder('emptyDir')
notEmptyDir = tmp.newFolder('notEmptyDir')
File file = new File("${notEmptyDir.getAbsolutePath()}${File.separator}test.txt")
file.createNewFile()
notDir = tmp.newFile('noDir')
}
@Test
void nullValidateDirectoryTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'dir' can not be null or empty.")
FileUtils.validateDirectory(null)
}
@Test
void emptyValidateDirectoryTest() {
thrown.expect(IllegalArgumentException)
thrown.expectMessage("The parameter 'dir' can not be null or empty.")
FileUtils.validateDirectory('')
}
@Test
void doestNotExistValidateDirectoryTest() {
def path = "${emptyDir.getAbsolutePath()}${File.separator}test"
thrown.expect(AbortException)
thrown.expectMessage("'$path' does not exist.")
FileUtils.validateDirectory(path)
}
@Test
void isNotDirectoryValidateDirectoryTest() {
thrown.expect(AbortException)
thrown.expectMessage("'${notDir.getAbsolutePath()}' is not a directory.")
FileUtils.validateDirectory(notDir.getAbsolutePath())
}
@Test
void validateDirectoryTest() {
FileUtils.validateDirectory(notEmptyDir.getAbsolutePath())
}
@Test
void emptyDirValidateDirectoryIsNotEmptyTest() {
thrown.expect(AbortException)
thrown.expectMessage("'${emptyDir.getAbsolutePath()}' is empty.")
FileUtils.validateDirectoryIsNotEmpty(emptyDir.getAbsolutePath())
}
@Test
void validateDirectoryIsNotEmptyTest() {
FileUtils.validateDirectoryIsNotEmpty(notEmptyDir.getAbsolutePath())
}
}