5package io.flutter.util;
7import static io.flutter.Build.API_LEVELS;
8import static org.junit.Assert.assertEquals;
9import static org.junit.Assert.assertTrue;
10import static org.mockito.Mockito.mock;
11import static org.mockito.Mockito.when;
17import org.junit.runner.RunWith;
18import org.robolectric.RobolectricTestRunner;
19import org.robolectric.annotation.Config;
22@RunWith(RobolectricTestRunner.class)
25 private static final String APP_DATA_PATH =
"/data/data/package_name";
30 when(context.getFilesDir()).thenReturn(
new File(APP_DATA_PATH +
"/files"));
37 when(context.getFilesDir()).thenReturn(
null);
38 if (
Build.VERSION.SDK_INT >= API_LEVELS.API_24) {
39 when(context.getDataDir()).thenReturn(
new File(APP_DATA_PATH));
41 when(context.getApplicationInfo().dataDir).thenReturn(APP_DATA_PATH);
49 when(context.getDir(
"flutter",
Context.MODE_PRIVATE))
50 .thenReturn(
new File(APP_DATA_PATH +
"/app_flutter"));
57 when(context.getDir(
"flutter",
Context.MODE_PRIVATE)).thenReturn(
null);
58 if (
Build.VERSION.SDK_INT >= API_LEVELS.API_24) {
59 when(context.getDataDir()).thenReturn(
new File(APP_DATA_PATH));
61 when(context.getApplicationInfo().dataDir).thenReturn(APP_DATA_PATH);
69 when(context.getCacheDir()).thenReturn(
new File(APP_DATA_PATH +
"/cache"));
70 if (
Build.VERSION.SDK_INT >= API_LEVELS.API_21) {
71 when(context.getCodeCacheDir()).thenReturn(
new File(APP_DATA_PATH +
"/code_cache"));
79 when(context.getCacheDir()).thenReturn(
null);
80 if (
Build.VERSION.SDK_INT >= API_LEVELS.API_21) {
81 when(context.getCodeCacheDir()).thenReturn(
null);
83 if (
Build.VERSION.SDK_INT >= API_LEVELS.API_24) {
84 when(context.getDataDir()).thenReturn(
new File(APP_DATA_PATH));
86 when(context.getApplicationInfo().dataDir).thenReturn(APP_DATA_PATH);
void canOnlyGetFilesPathWhenDiskFullAndFilesDirNotCreated()
void canOnlyGetCachePathWhenDiskFullAndCacheDirNotCreated()
void canGetFlutterDataDir()
void canOnlyGetFlutterDataPathWhenDiskFullAndFlutterDataDirNotCreated()
static String getDataDirectory(@NonNull Context applicationContext)
static String getCacheDirectory(@NonNull Context applicationContext)
static String getFilesDir(@NonNull Context applicationContext)