Package org.robolectric.shadows
Class ShadowEnvironment
java.lang.Object
org.robolectric.shadows.ShadowEnvironment
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic FileaddExternalDir(String path) Adds a directory to list returned byShadowEnvironment.ShadowUserEnvironment.getExternalDirs().protected static File[]buildExternalStorageAppCacheDirs(String packageName) protected static FilegetExternalStorageAppCacheDirectory(String packageName) protected static Fileprotected static Fileprotected static Stringprotected static StringgetExternalStorageState(File directory) protected static Fileprotected static StringgetStorageState(File directory) protected static booleanprotected static booleanprotected static booleanprotected static booleanisExternalStorageLegacy(File path) protected static booleanprotected static booleanstatic voidreset()static voidsetExternalStorageDirectory(Path directory) Sets the return value ofgetExternalStorageDirectory().static voidsetExternalStorageEmulated(File file, boolean isEmulated) Sets the "isEmulated" flag of a particular file.static voidsetExternalStorageRemovable(File file, boolean isRemovable) Sets the "isRemovable" flag of a particular file.static voidsetExternalStorageState(File directory, String state) Sets thegetExternalStorageState(File)for given directory.static voidsetExternalStorageState(String externalStorageState) Sets the return value ofgetExternalStorageState().static voidsetIsExternalStorageEmulated(boolean emulated) Sets the return value ofisExternalStorageEmulated().static voidsetIsExternalStorageLegacy(boolean legacy) Sets the return value ofisExternalStorageLegacy()()}.static voidsetStorageDirectory(Path directory) Sets the return value ofgetStorageDirectory().
-
Constructor Details
-
ShadowEnvironment
public ShadowEnvironment()
-
-
Method Details
-
getExternalStorageState
-
setExternalStorageState
Sets the return value ofgetExternalStorageState().- Parameters:
externalStorageState- Value to return fromgetExternalStorageState().
-
setIsExternalStorageEmulated
public static void setIsExternalStorageEmulated(boolean emulated) Sets the return value ofisExternalStorageEmulated().- Parameters:
emulated- Value to return fromisExternalStorageEmulated().
-
setIsExternalStorageLegacy
public static void setIsExternalStorageLegacy(boolean legacy) Sets the return value ofisExternalStorageLegacy()()}.- Parameters:
legacy- Value to return fromisExternalStorageLegacy().
-
setStorageDirectory
Sets the return value ofgetStorageDirectory(). This can be used for example, when testing code paths that need to perform regex matching on this directory.Note that the default value provides a directory that is usable in the test environment. If the test app uses this method to override that default directory, please clean up any files written to that directory, as the Robolectric environment will not purge that directory when the test ends.
- Parameters:
directory- Path to return fromgetStorageDirectory().
-
getStorageDirectory
-
setExternalStorageDirectory
Sets the return value ofgetExternalStorageDirectory(). Note that the default value provides a directory that is usable in the test environment. If the test app uses this method to override that default directory, please clean up any files written to that directory, as the Robolectric environment will not purge that directory when the test ends.- Parameters:
directory- Path to return fromgetExternalStorageDirectory().
-
getExternalStorageDirectory
-
buildExternalStorageAppCacheDirs
@Implementation(minSdk=19) protected static File[] buildExternalStorageAppCacheDirs(String packageName) -
getExternalStorageAppCacheDirectory
@Implementation(maxSdk=18) protected static File getExternalStorageAppCacheDirectory(String packageName) -
getExternalStoragePublicDirectory
-
reset
-
isExternalStorageRemovable
-
getStorageState
-
getExternalStorageState
-
isExternalStorageRemovable
-
isExternalStorageEmulated
-
isExternalStorageEmulated
-
isExternalStorageLegacy
-
isExternalStorageLegacy
-
setExternalStorageRemovable
Sets the "isRemovable" flag of a particular file.- Parameters:
file- Target file.isRemovable- True if the filesystem is removable.
-
setExternalStorageEmulated
Sets the "isEmulated" flag of a particular file.- Parameters:
file- Target file.isEmulated- True if the filesystem is emulated.
-
addExternalDir
Adds a directory to list returned byShadowEnvironment.ShadowUserEnvironment.getExternalDirs().- Parameters:
path- the external dir to add
-
setExternalStorageState
Sets thegetExternalStorageState(File)for given directory.- Parameters:
externalStorageState- Value to return fromgetExternalStorageState(File).
-