### Question:
ActionBar extends RelativeLayout { @VisibleForTesting @Nullable View getViewAt(int rowIdx, int colIdx) { if (rowIdx < 0 || rowIdx > mRowsContainer.getChildCount()) { throw new IllegalArgumentException(String.format((Locale) null, "Row index out of range (requested: %d, max: %d)", rowIdx, mRowsContainer.getChildCount())); } if (colIdx < 0 || colIdx > mNumColumns) { throw new IllegalArgumentException(String.format((Locale) null, "Column index out of range (requested: %d, max: %d)", colIdx, mNumColumns)); } FrameLayout slot = (FrameLayout) ((LinearLayout) mRowsContainer.getChildAt(rowIdx)) .getChildAt(colIdx + 1); return slot.getChildCount() > 0 ? slot.getChildAt(0) : null; } ActionBar(Context context);  ActionBar(Context context, AttributeSet attrs);  ActionBar(Context context, AttributeSet attrs, int defStyleAttrs);  ActionBar(Context context, AttributeSet attrs, int defStyleAttrs, int defStyleRes); void setView(@Nullable View view, @SlotPosition int slotPosition); void setExpandCollapseView(@NonNull View view); void setViews(@Nullable View[] views); static final int SLOT_MAIN; static final int SLOT_LEFT; static final int SLOT_RIGHT; static final int SLOT_EXPAND_COLLAPSE; }### Answer:
@Test public void testNormalSlotUsage() { for (int items = 1; items < NUM_COLS - 1; items++) { setUpActionBarItems(items); final int numItems = items; onView(withId(androidx.car.test.R.id.action_bar)) .check((view, noViewFoundException) -> { Preconditions.checkNotNull(view); assertLeftItemsNotEmpty(TOP_ROW_IDX, 0); assertNull("Expand/collapse should be empty" , mActionBar.getViewAt(BOTTOM_ROW_IDX, NUM_COLS - 1)); assertLeftItemsNotEmpty(BOTTOM_ROW_IDX, numItems); }); } }
@Test public void testReservingNamedSlots() { View mainView = createButton(mActivity); setViewInPosition(mainView, ActionBar.SLOT_MAIN); View leftView = new Space(mActivity); setViewInPosition(leftView, ActionBar.SLOT_LEFT); setUpActionBarItems(NUM_COLS + 1); onView(withContentDescription(R.string.action_bar_expand_collapse_button)) .check((view, noViewFoundException) -> { Preconditions.checkNotNull(view); assertLeftItemsNotEmpty(TOP_ROW_IDX, 4); assertLeftItemsNotEmpty(BOTTOM_ROW_IDX, NUM_COLS); assertRowVisibility(TOP_ROW_IDX, View.GONE); assertEquals(mainView, mActionBar.getViewAt(BOTTOM_ROW_IDX, 2)); assertEquals(leftView, mActionBar.getViewAt(BOTTOM_ROW_IDX, 1)); }) .perform(click()) .check((view, noViewFoundException) -> { assertRowVisibility(TOP_ROW_IDX, View.VISIBLE); }); }
@Test public void testCustomExpandCollapseView() { View customExpandCollapse = new ToggleButton(mActivity); customExpandCollapse.setContentDescription(mActivity.getString( R.string.action_bar_expand_collapse_button)); setExpandCollapseCustomView(customExpandCollapse); setUpActionBarItems(NUM_COLS + 1); onView(withContentDescription(R.string.action_bar_expand_collapse_button)) .check((view, noViewFoundException) -> { Preconditions.checkNotNull(view); assertEquals(customExpandCollapse, mActionBar.getViewAt(BOTTOM_ROW_IDX, NUM_COLS - 1)); }); }