ScreenController

public class ScreenController


ScreenController provides API that allows testing of a Screen.

This controller will allows:

Summary

Public constructors

Creates a ScreenController to control a Screen for testing.

Public methods

@NonNull Screen

Returns the Screen being controlled.

@Nullable Object

Returns the result that was set via setResult, or null if one was not set.

@NonNull List<Template>

Returns all the Templates returned from onGetTemplate for the being controlled.

@NonNull ScreenController

Moves the Screen being controlled to the input state.

void

Resets values tracked by this ScreenController.

Public constructors

ScreenController

Added in 1.1.0
public ScreenController(@NonNull Screen screen)

Creates a ScreenController to control a Screen for testing.

Throws
java.lang.NullPointerException

if screen is null

java.lang.IllegalArgumentException

if screen was not created with a TestCarContext

Public methods

getScreen

Added in 1.1.0
public @NonNull Screen getScreen()

Returns the Screen being controlled.

getScreenResult

Added in 1.1.0
public @Nullable Object getScreenResult()

Returns the result that was set via setResult, or null if one was not set.

getTemplatesReturned

Added in 1.1.0
public @NonNull List<TemplategetTemplatesReturned()

Returns all the Templates returned from onGetTemplate for the being controlled.

The templates 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 templates will be stored until reset is called.

moveToState

Added in 1.1.0
public @NonNull ScreenController moveToState(@NonNull Lifecycle.State state)

Moves the Screen being controlled to the input state.

Note that moving the Screen up a state will also push the Screen onto the androidx.car.app.ScreenManager's screen stack if it isn't the current top.

DESTROYED is a terminal state, and you cannot move to any other state after the Screen reaches that state.

See also
getLifecycle

reset

Added in 1.1.0
public void reset()

Resets values tracked by this ScreenController.