1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.utils;
19
20 import java.io.File;
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
25 import org.junit.Test;
26
27
28
29
30
31 public class FileUtilsTest extends BaseTest {
32
33
34
35
36 @Test
37 public void testGetFileExtension() {
38 String[] fileName = {"something-0.9.5.jar", "lib2-1.1.js", "dir.tmp/noext"};
39 String[] expResult = {"jar", "js", null};
40
41 for (int i = 0; i < fileName.length; i++) {
42 String result = FileUtils.getFileExtension(fileName[i]);
43 assertEquals("Failed extraction on \"" + fileName[i] + "\".", expResult[i], result);
44 }
45 }
46
47
48
49
50 @Test
51 public void testDelete() throws Exception {
52
53 File file = File.createTempFile("tmp", "deleteme", Settings.getTempDirectory());
54 if (!file.exists()) {
55 fail("Unable to create a temporary file.");
56 }
57 boolean status = FileUtils.delete(file);
58 assertTrue("delete returned a failed status", status);
59 assertFalse("Temporary file exists after attempting deletion", file.exists());
60 }
61 }