wangzhibo
2026-08-16 ae6f40460dcd56af6c5f60ba52c883854c3bac55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package nodomain.freeyourgadget.gadgetbridge.test;
 
import org.junit.Test;
 
import java.io.File;
import java.io.IOException;
 
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
 
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
 
public class FileUtilsTest extends TestBase {
 
    @Test
    public void testValidFileName() {
        String tempName = "foo:bar";
        assertEquals("foo_bar", FileUtils.makeValidFileName(tempName));
 
        tempName = "fo\no::bar";
        assertEquals("fo_o__bar", FileUtils.makeValidFileName(tempName));
    }
 
    @Test
    public void testExternalFilesDir() throws IOException {
        File dir = FileUtils.getExternalFilesDir();
        assertTrue(dir.exists());
    }
 
    @Test
    public void testExternalFile() throws IOException {
        File extDir = FileUtils.getExternalFilesDir();
        File dir = FileUtils.getExternalFile("qfiles");
        assertFalse(dir.exists());
 
        File file = FileUtils.getExternalFile("qfiles/test");
        assertTrue(file.getParentFile().exists());
        assertFalse(file.exists());
 
        File expectedFile = new File(extDir + "/qfiles/test");
        assertEquals(expectedFile.getPath(), file.getPath());
    }
}