Google is committed to advancing racial equity for Black communities. See how.

ItemListController

public class ItemListController
extends Object

java.lang.Object
   ↳ com.google.android.libraries.car.app.testing.model.ItemListController


A controller that allows testing of an ItemList.

This controller allows:

Summary

Public methods

ItemList get()

Retrieves the ItemList that this controller is controlling.

<T extends ItemController<? extends Item>> T getItemByTitle(String title, Class<T> itemClass)

Retrieves the first ItemController in the list that has the given title as its title, or null if none are found.

List<ItemController<? extends Item>> getItems()

Retrieves all ItemControllers in the ItemList.

String getNoItemsMessage()

Retrieves the noItemsMessage set via ItemList.Builder.setNoItemsMessage(CharSequence), or null if it is not present.

int getSelectedIndex()

Retrieves index of the currently selected Item.

static ItemListController of(ItemList itemList)

Creates an ItemListController to control an ItemList for testing.

void scrollDown()

Performs callbacks as if the user scrolled down the ItemList on the actual car screen.

void scrollUp()

Performs callbacks as if the user scrolled up the ItemList on the actual car screen.

void select(Item item)

Performs the expected callback given a user selection on the provided Item.

void select(int index)

Performs the expected callback given a user selection on the Item at index.

Inherited methods

Public methods

get

public ItemList get ()

Retrieves the ItemList that this controller is controlling.

Returns
ItemList

getItemByTitle

public T getItemByTitle (String title, 
                Class<T> itemClass)

Retrieves the first ItemController in the list that has the given title as its title, or null if none are found.

Parameters
title String

itemClass Class

Returns
T

getItems

public List<ItemController<? extends Item>> getItems ()

Retrieves all ItemControllers in the ItemList.

Returns
List<ItemController<? extends Item>>

getNoItemsMessage

public String getNoItemsMessage ()

Retrieves the noItemsMessage set via ItemList.Builder.setNoItemsMessage(CharSequence), or null if it is not present.

The value returned is the CharSequence.toString() for the text provided.

Returns
String

getSelectedIndex

public int getSelectedIndex ()

Retrieves index of the currently selected Item.

Returns
int

of

public static ItemListController of (ItemList itemList)

Creates an ItemListController to control an ItemList for testing.

Parameters
itemList ItemList

Returns
ItemListController

scrollDown

public void scrollDown ()

Performs callbacks as if the user scrolled down the ItemList on the actual car screen.

This will generate a callback to the ItemList.OnItemVisibilityChangedListener provided via ItemList.Builder.setOnItemsVisibilityChangeListener(ItemList.OnItemVisibilityChangedListener).

If the ItemList is already scrolled to the bottom, nothing will happen.

For testing purposes, the virtual car screen fits two Items per page.

scrollUp

public void scrollUp ()

Performs callbacks as if the user scrolled up the ItemList on the actual car screen.

This will generate a callback to the ItemList.OnItemVisibilityChangedListener provided via ItemList.Builder.setOnItemsVisibilityChangeListener(ItemList.OnItemVisibilityChangedListener).

If the ItemList is already scrolled to the top, nothing will happen.

For testing purposes, the virtual car screen fits two Items per page.

select

public void select (Item item)

Performs the expected callback given a user selection on the provided Item.

This will generate a callback to the ItemList.OnSelectedListener provided via ItemList.Builder.setSelectable(ItemList.OnSelectedListener). *

Parameters
item Item

Throws
IllegalArgumentException if item is not in the ItemList.
IllegalStateException if the ItemList does not have an ItemList.OnSelectedListener, or is not selectable.

select

public void select (int index)

Performs the expected callback given a user selection on the Item at index.

This will generate a callback to the ItemList.OnSelectedListener provided via ItemList.Builder.setSelectable(ItemList.OnSelectedListener).

Parameters
index int

Throws
IllegalArgumentException if no Item exists at index index in the ItemList.
IllegalStateException if the ItemList does not have an ItemList.OnSelectedListener, or is not selectable.