TestAppManager
public class TestAppManager extends AppManager
The AppManager that is used for testing.
This class will track the following usages of the AppManager throughout your test:
- All
SurfaceCallbacks set via callingsetSurfaceCallback. - The
Templates returned fromonGetTemplatedue to invalidate calls viainvalidate. - All toasts shown via calling
showToast.
Summary
Public methods |
|
|---|---|
@Nullable SurfaceCallback |
Returns the callback set via |
@NonNull List<Pair<Screen, Template>> |
Returns all the |
@NonNull List<CharSequence> |
Returns all the toasts shown via |
void |
reset()Resets the values tracked by this |
void |
setSurfaceCallback(@Nullable SurfaceCallback surfaceCallback)Sets the |
void |
showToast(@NonNull CharSequence text, int duration)Shows a toast on the car screen. |
Inherited methods |
||||||
|---|---|---|---|---|---|---|
|
Public methods
getSurfaceCallback
public @Nullable SurfaceCallback getSurfaceCallback()
Returns the callback set via setSurfaceCallback, or null if not set.
getTemplatesReturned
public @NonNull List<Pair<Screen, Template>> getTemplatesReturned()
Returns all the Templates returned from onGetTemplate due to a call to invalidate, and the respective Screen instance that returned it. The results are stored in the order in which they were returned from onGetTemplate, where the first template in the list, is the first template returned.
The results will be stored until reset is called.
getToastsShown
public @NonNull List<CharSequence> getToastsShown()
Returns all the toasts shown via showToast.
The toasts are stored in the order in which they are sent via showToast, where the first toast in the list is the first toast that was sent.
The toasts will be stored until reset is called.
reset
public void reset()
Resets the values tracked by this TestAppManager and all ScreenControllers.
setSurfaceCallback
public void setSurfaceCallback(@Nullable SurfaceCallback surfaceCallback)
Sets the SurfaceCallback to get changes and updates to the surface on which the app can draw custom content, or null to reset the listener.
This call requires the androidx.car.app.ACCESS_SURFACE permission to be declared.
The Surface can be used to draw custom content such as a navigation app's map.
Note that the listener relates to UI events and will be executed on the main thread using getMainLooper.
| Throws | |
|---|---|
java.lang.SecurityException |
if the app does not have the required permissions to access the surface |
androidx.car.app.HostException |
if the remote call fails |
showToast
public void showToast(@NonNull CharSequence text, int duration)
Shows a toast on the car screen.
| Parameters | |
|---|---|
@NonNull CharSequence text |
the text to show |
int duration |
how long to display the message |
| Throws | |
|---|---|
androidx.car.app.HostException |
if the remote call fails |
java.lang.NullPointerException |
if |