mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-11 17:41:57 +01:00
File external files dir creation, add test
This commit is contained in:
parent
7d73ca3df2
commit
6244bdd745
@ -1,5 +0,0 @@
|
|||||||
package nodomain.freeyourgadget.gadgetbridge.devices.qhybrid;
|
|
||||||
|
|
||||||
public class FossilConstants {
|
|
||||||
public static String QFILES_DIR = "qFiles";
|
|
||||||
}
|
|
@ -195,7 +195,8 @@ public class FileUtils {
|
|||||||
*/
|
*/
|
||||||
public static File getExternalFile(String child) throws IOException {
|
public static File getExternalFile(String child) throws IOException {
|
||||||
File file = new File(getExternalFilesDir(), child);
|
File file = new File(getExternalFilesDir(), child);
|
||||||
if (!file.getParentFile().mkdirs()) {
|
File dir = file.getParentFile();
|
||||||
|
if (!dir.exists() && !dir.mkdirs()) {
|
||||||
throw new IOException("Unable to create directory " + file.getParent());
|
throw new IOException("Unable to create directory " + file.getParent());
|
||||||
}
|
}
|
||||||
return file;
|
return file;
|
||||||
|
@ -2,9 +2,14 @@ package nodomain.freeyourgadget.gadgetbridge.test;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
public class FileUtilsTest extends TestBase {
|
public class FileUtilsTest extends TestBase {
|
||||||
|
|
||||||
@ -16,4 +21,24 @@ public class FileUtilsTest extends TestBase {
|
|||||||
tempName = "fo\no::bar";
|
tempName = "fo\no::bar";
|
||||||
assertEquals("fo_o__bar", FileUtils.makeValidFileName(tempName));
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user