public class TestUtils
extends java.lang.Object
Constructor and Description |
---|
TestUtils() |
Modifier and Type | Method and Description |
---|---|
static java.io.File |
createTempDirDeletedOnExit() |
static void |
deleteFile(java.io.File dir) |
static void |
eventually(java.lang.Runnable runnable)
Asserts that a runnable will eventually not throw an assertion exception.
|
static void |
eventually(java.lang.Runnable runnable,
java.time.Duration duration)
Asserts that a runnable will eventually not throw
AssertionError before
timeoutMs milliseconds have ellapsed |
static java.lang.String |
getDiff(java.lang.String[] before,
java.lang.String[] after) |
static java.lang.String |
getDiff(java.lang.String before,
java.lang.String after) |
static java.lang.String |
getLatestAndroidPlatform() |
static java.io.File |
getNdk()
Returns the path to checked-in NDK.
|
static java.io.File |
getPlatformFile(java.lang.String path)
Returns a file at
path relative to the root for getLatestAndroidPlatform() . |
static java.io.File |
getRoot(java.lang.String... names)
Deprecated.
Use
getWorkspaceRoot() or getWorkspaceFile(String) instead. |
static java.io.File |
getSdk()
Returns the SDK directory.
|
static java.io.File |
getWorkspaceFile(java.lang.String path)
Given a full path to a file from the base of the current workspace, return the file.
|
static java.io.File |
getWorkspaceRoot()
Returns the root of the entire Android Studio codebase.
|
static boolean |
runningFromBazel()
Checks if tests were started by Bazel.
|
static void |
waitForFileSystemTick()
Sleeps the current thread for enough time to ensure that the local file system had enough
time to notice a "tick".
|
static void |
waitForFileSystemTick(long currentTimestamp)
Sleeps the current thread for enough time to ensure that the local file system had enough
time to notice a "tick".
|
@Deprecated @NonNull public static java.io.File getRoot(java.lang.String... names)
getWorkspaceRoot()
or getWorkspaceFile(String)
instead.public static void deleteFile(java.io.File dir)
public static java.io.File createTempDirDeletedOnExit()
@NonNull public static java.io.File getWorkspaceRoot()
getWorkspaceFile(String)
as it
is more resilient to cross-platform testing.java.lang.IllegalStateException
- if the current directory of the test is not a subdirectory of
the workspace directory when this method is called. This shouldn't happen if the test is run
by Bazel or run by IntelliJ with default configuration settings (where the working directory
is initialized to the module root).@NonNull public static java.io.File getWorkspaceFile(@NonNull java.lang.String path)
java.lang.IllegalArgumentException
- if the path results in a file that's not found.@NonNull public static java.io.File getPlatformFile(java.lang.String path)
path
relative to the root for getLatestAndroidPlatform()
.java.lang.IllegalStateException
- if the current OS is not supported.java.lang.IllegalArgumentException
- if the path results in a file not found.public static boolean runningFromBazel()
@NonNull public static java.io.File getSdk()
java.lang.IllegalStateException
- if the current OS is not supported.java.lang.IllegalArgumentException
- if the path results in a file not found.@NonNull public static java.io.File getNdk()
getSdk()
@NonNull public static java.lang.String getLatestAndroidPlatform()
public static void waitForFileSystemTick() throws java.lang.InterruptedException, java.io.IOException
java.lang.InterruptedException
- waiting interruptedjava.io.IOException
- issues creating a temporary filepublic static void waitForFileSystemTick(long currentTimestamp) throws java.lang.InterruptedException, java.io.IOException
currentTimestamp
- last timestamp read from diskjava.lang.InterruptedException
- waiting interruptedjava.io.IOException
- issues creating a temporary file@NonNull public static java.lang.String getDiff(@NonNull java.lang.String before, @NonNull java.lang.String after)
@NonNull public static java.lang.String getDiff(@NonNull java.lang.String[] before, @NonNull java.lang.String[] after)
public static void eventually(@NonNull java.lang.Runnable runnable)
eventually(Runnable, Duration)
, but using a default timeoutrunnable
- a description of the failure, if the condition never becomes true
public static void eventually(@NonNull java.lang.Runnable runnable, java.time.Duration duration)
AssertionError
before
timeoutMs
milliseconds have ellapsedrunnable
- a description of the failure, if the condition never becomes true
duration
- the timeout for the predicate to become true