@@ -4,6 +4,8 @@ import kotlin.test.*
44
55class FileTests {
66
7+ private val localSeparator = ' /'
8+
79 @Test
810 fun testNonexistentRootFile () {
911 val testFile = File (" testNonexistentRootFile.txt" )
@@ -17,6 +19,18 @@ class FileTests {
1719 assertEquals(" testNonexistentRootFile" , testFile.nameWithoutExtension)
1820 }
1921
22+ @Test
23+ fun testExistentRootFile () {
24+ val testFile = File (" testFileRoot/testExistentRootFile.txt" )
25+ println (testFile.getAbsolutePath())
26+
27+ assertFalse(testFile.exists(), " file should not exist" )
28+ assertFalse(testFile.getParentFile()?.exists() == true , " file should not have parent file" )
29+ assertNotNull(testFile.getParentFileUnsafe(), " file should not have parent file" )
30+
31+ assertEquals(" testFileRoot" , testFile.getParentFileUnsafe().getName(), " couldn't get parent file name" )
32+ }
33+
2034 @Test
2135 fun testFileCreateAndDelete () {
2236 val testFolder = File (" build/testNewDirectoryCreation" )
@@ -70,4 +84,51 @@ class FileTests {
7084 assertEquals(" gradle-wrapper.properties" , listedFileNames[1 ])
7185 assertEquals(" gradle-wrapper.properties" , listedFiles[1 ].getName())
7286 }
87+
88+ @Test
89+ fun testFileCopyMethod () {
90+ val testFile = File (" gradle/wrapper/gradle-wrapper.properties" )
91+ val testDestFolder = File (" build/testCopyFolder" )
92+ val testDestFile = File (" build/testCopyFolder/gradle-wrapper.properties" )
93+
94+ assertTrue(testFile.exists(), " file have to exist" )
95+ assertFalse(testDestFolder.exists(), " folder shouldn't be created yet" )
96+
97+ testDestFolder.mkdirs()
98+ assertTrue(testDestFolder.exists(), " now folder have to exists" )
99+
100+ assertFalse(testDestFile.exists(), " file should not exists yet" )
101+ testFile.copyTo(testDestFile, overwrite = false )
102+ assertTrue(testDestFile.exists(), " file have to exist after coping" )
103+
104+ assertTrue(testDestFile.delete(), " failed to cleanup test file" )
105+ assertTrue(testDestFolder.delete(), " failed to cleanup directory" )
106+ }
107+
108+ @Test
109+ fun testFileMoveMethod () {
110+ val testFolder = File (" build/testMoveFolder" )
111+ val testDestFolder = File (" build/testMoveFolder2" )
112+ val testFile = File (" build/testMoveFolder/test_move_file.properties" )
113+ val testDestFile = File (" build/testMoveFolder2/test_move_file.properties" )
114+
115+ assertFalse(testFile.exists(), " file have not to exist" )
116+ assertFalse(testFolder.exists(), " folder shouldn't be created yet" )
117+ assertFalse(testDestFolder.exists(), " folder shouldn't be created yet" )
118+
119+ assertTrue(testFolder.mkdirs() && testFolder.exists(), " now folder1 have to exists" )
120+ assertTrue(testDestFolder.mkdirs() && testDestFolder.exists(), " now folder2 have to exists" )
121+
122+ assertTrue(testFile.createNewFile(), " file should be created" )
123+ testFile.writeText(" moving=true" )
124+
125+ testFile.moveTo(testDestFile, overwrite = false )
126+ assertTrue(testDestFile.exists(), " file have to exist after coping" )
127+ assertEquals(" moving=true" , testDestFile.readText(), " moved file should have the same content" )
128+ assertFalse(testFile.exists(), " file should not exists on previous place after moving" )
129+
130+ assertTrue(testFolder.delete(), " failed to cleanup test file" )
131+ assertTrue(testDestFile.delete(), " failed to cleanup test file" )
132+ assertTrue(testDestFolder.delete(), " failed to cleanup directory" )
133+ }
73134}
0 commit comments