blob: ad461fbe7a611618896e7234ee9c2b28377d3477 [file] [log] [blame]
Cole Faustd4e193b2019-10-03 09:49:26 -07001/*
2 * Copyright 2019 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.car.ui.toolbar;
18
19import static com.google.common.truth.Truth.assertThat;
20
Ram Parameswaran05fec072019-10-17 13:24:27 -070021import static org.mockito.Mockito.spy;
22import static org.mockito.Mockito.when;
23
Cole Faustd4e193b2019-10-03 09:49:26 -070024import android.content.Context;
Ram Parameswaran05fec072019-10-17 13:24:27 -070025import android.content.res.Resources;
Cole Faustd4e193b2019-10-03 09:49:26 -070026import android.view.View;
27import android.view.ViewGroup;
28
Cole Faustd4e193b2019-10-03 09:49:26 -070029import com.android.car.ui.R;
30
31import org.junit.Before;
32import org.junit.Test;
33import org.junit.runner.RunWith;
34import org.robolectric.Robolectric;
Ram Parameswaran39020e42020-01-23 17:50:54 -080035import org.robolectric.RobolectricTestRunner;
Cole Faustd4e193b2019-10-03 09:49:26 -070036import org.robolectric.RuntimeEnvironment;
37import org.robolectric.android.controller.ActivityController;
38import org.robolectric.annotation.Config;
39
40import java.util.Arrays;
41import java.util.Collections;
42import java.util.List;
43
Ram Parameswaran39020e42020-01-23 17:50:54 -080044@RunWith(RobolectricTestRunner.class)
Cole Faustd4e193b2019-10-03 09:49:26 -070045@Config(qualifiers = "land")
46public class ToolbarTest {
47
48 private Context mContext;
Ram Parameswaran05fec072019-10-17 13:24:27 -070049 private Resources mResources;
Cole Faustd4e193b2019-10-03 09:49:26 -070050 private ActivityController<TestActivity> mActivityController;
51 private TestActivity mActivity;
52 private Toolbar mToolbar;
53
54 @Before
55 public void setUp() {
56 mContext = RuntimeEnvironment.application;
Ram Parameswaran05fec072019-10-17 13:24:27 -070057 mResources = mContext.getResources();
Cole Faustd4e193b2019-10-03 09:49:26 -070058 mActivityController = Robolectric.buildActivity(TestActivity.class);
59 mActivityController.setup();
Cole Faustd4e193b2019-10-03 09:49:26 -070060 mActivity = mActivityController.get();
61 mToolbar = mActivity.findViewById(R.id.toolbar);
62 }
63
64 @Test
65 public void getters_nochanges_shouldReturnDefaults() {
66 assertThat(mToolbar.getBackgroundShown()).isEqualTo(true);
67 assertThat(mToolbar.getShowMenuItemsWhileSearching()).isEqualTo(false);
68 assertThat(mToolbar.getState()).isEquivalentAccordingToCompareTo(Toolbar.State.HOME);
69 assertThat(mToolbar.getNavButtonMode()).isEquivalentAccordingToCompareTo(
70 Toolbar.NavButtonMode.BACK);
71 }
72
73 @Test
74 public void setState_subpage_shouldCauseGetStateToReturnSubpage() {
75 mToolbar.setState(Toolbar.State.SUBPAGE);
76
77 assertThat(mToolbar.getState()).isEquivalentAccordingToCompareTo(Toolbar.State.SUBPAGE);
78 }
79
80 @Test
Cole Faustcffd5ba2020-01-02 15:25:55 -080081 public void setters_and_getters_test() {
Cole Faustd4e193b2019-10-03 09:49:26 -070082 mToolbar.setTitle("Foo");
83 mToolbar.setSearchHint("Foo2");
84 mToolbar.setBackgroundShown(false);
85 mToolbar.setShowMenuItemsWhileSearching(true);
86 mToolbar.setState(Toolbar.State.SUBPAGE);
87 mToolbar.setNavButtonMode(Toolbar.NavButtonMode.CLOSE);
88
Cole Faustd4e193b2019-10-03 09:49:26 -070089 assertThat(mToolbar.getTitle().toString()).isEqualTo("Foo");
90 assertThat(mToolbar.getSearchHint().toString()).isEqualTo("Foo2");
91 assertThat(mToolbar.getBackgroundShown()).isEqualTo(false);
92 assertThat(mToolbar.getShowMenuItemsWhileSearching()).isEqualTo(true);
93 assertThat(mToolbar.getState()).isEquivalentAccordingToCompareTo(Toolbar.State.SUBPAGE);
94 assertThat(mToolbar.getNavButtonMode()).isEquivalentAccordingToCompareTo(
95 Toolbar.NavButtonMode.CLOSE);
96 }
97
98 @Test
Cole Faustd4e193b2019-10-03 09:49:26 -070099 public void showLogo_whenSet_andStateIsHome() {
100 mToolbar.setState(Toolbar.State.HOME);
101 mToolbar.setLogo(R.drawable.test_ic_launcher);
102
Cole Faustdb6866c2019-10-09 15:56:07 -0700103 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_logo).isShown()).isTrue();
Roberto Perez90c45bb2019-10-21 17:30:48 -0700104 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_title_logo).isShown()).isFalse();
Cole Faustd4e193b2019-10-03 09:49:26 -0700105 }
106
107 @Test
Roberto Pereze5d8e682019-12-12 06:39:16 -0800108 public void hideLogo_andTitleLogo_whenSet_andStateIsHome_andLogoIsDisabled() {
109 mockResources();
110 when(mResources.getBoolean(R.bool.car_ui_toolbar_show_logo)).thenReturn(false);
111
112 Toolbar toolbar = new Toolbar(mContext);
113 toolbar.setState(Toolbar.State.HOME);
114 toolbar.setLogo(R.drawable.test_ic_launcher);
115
116 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_logo).isShown()).isFalse();
117 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title_logo).isShown()).isFalse();
118 }
119
120 @Test
Roberto Perez90c45bb2019-10-21 17:30:48 -0700121 public void showTitleLogo_whenSet_andStateIsNotHome() {
Cole Faustd4e193b2019-10-03 09:49:26 -0700122 mToolbar.setState(Toolbar.State.SUBPAGE);
123 mToolbar.setLogo(R.drawable.test_ic_launcher);
124
Cole Faustdb6866c2019-10-09 15:56:07 -0700125 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_logo).isShown()).isFalse();
Roberto Perez90c45bb2019-10-21 17:30:48 -0700126 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_title_logo).isShown()).isTrue();
Cole Faustd4e193b2019-10-03 09:49:26 -0700127 }
128
129 @Test
Roberto Perez90c45bb2019-10-21 17:30:48 -0700130 public void hideLogo_andTitleLogo_whenNotSet_andStateIsHome() {
Cole Faustd4e193b2019-10-03 09:49:26 -0700131 mToolbar.setState(Toolbar.State.HOME);
132 mToolbar.setLogo(0);
133
Cole Faustdb6866c2019-10-09 15:56:07 -0700134 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_logo).isShown()).isFalse();
Roberto Perez90c45bb2019-10-21 17:30:48 -0700135 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_title_logo).isShown()).isFalse();
Cole Faustd4e193b2019-10-03 09:49:26 -0700136 }
137
138 @Test
Roberto Perez90c45bb2019-10-21 17:30:48 -0700139 public void hideLogo_andTitleLogo_whenNotSet_andStateIsNotHome() {
Cole Faustd4e193b2019-10-03 09:49:26 -0700140 mToolbar.setState(Toolbar.State.SUBPAGE);
141 mToolbar.setLogo(0);
142
Cole Faustdb6866c2019-10-09 15:56:07 -0700143 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_logo).isShown()).isFalse();
Roberto Perez90c45bb2019-10-21 17:30:48 -0700144 assertThat(mToolbar.findViewById(R.id.car_ui_toolbar_title_logo).isShown()).isFalse();
Cole Faustd4e193b2019-10-03 09:49:26 -0700145 }
146
147 @Test
148 public void registerOnBackListener_whenBackIsPressed_shouldCallListener() {
149 mToolbar.setState(Toolbar.State.SUBPAGE);
150 Mutable<Integer> timesBackPressed = new Mutable<>(0);
151 Toolbar.OnBackListener listener = () -> {
152 timesBackPressed.value++;
153 return false;
154 };
155
156 mToolbar.registerOnBackListener(listener);
157 pressBack();
158
159 assertThat(timesBackPressed.value).isEqualTo(1);
160 assertThat(mActivity.getTimesBackPressed()).isEqualTo(1);
161 }
162
163 @Test
164 public void registerOnBackListener_whenAListenerReturnsTrue_shouldSuppressBack() {
165 mToolbar.setState(Toolbar.State.SUBPAGE);
166
167 mToolbar.registerOnBackListener(() -> true);
168 pressBack();
169 mToolbar.registerOnBackListener(() -> false);
170 pressBack();
171
172 assertThat(mActivity.getTimesBackPressed()).isEqualTo(0);
173 }
174
175 @Test
Ram Parameswaran05fec072019-10-17 13:24:27 -0700176 public void testState_twoRow_withTitle_withTabs() {
177 mockResources();
178 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(true);
179
180 Toolbar toolbar = new Toolbar(mContext);
181 assertThat(toolbar.isTabsInSecondRow()).isTrue();
182
183 // Set title and tabs for toolbar.
184 toolbar.setTitle("Test title");
185 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
186 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
187
188 // Toolbar should display two rows, showing both title and tabs.
189 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isEqualTo(
190 View.VISIBLE);
191 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isEqualTo(
192 View.VISIBLE);
193 }
194
195 @Test
196 public void testState_twoRow_withTitle() {
197 mockResources();
198 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(true);
199
200 Toolbar toolbar = new Toolbar(mContext);
201 assertThat(toolbar.isTabsInSecondRow()).isTrue();
202
203 toolbar.setTitle("Test title");
204
205 // Toolbar should display two rows, but no tabs are set so they should not be visible.
206 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isEqualTo(
207 View.VISIBLE);
208 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isNotEqualTo(
209 View.VISIBLE);
210 }
211
212 @Test
213 public void testState_twoRow_withTabs() {
214 mockResources();
215 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(true);
216
217 Toolbar toolbar = new Toolbar(mContext);
218 assertThat(toolbar.isTabsInSecondRow()).isTrue();
219 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
220 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
221
222 // Toolbar should display two rows with an empty title and tabs.
223 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isEqualTo(
224 View.VISIBLE);
225 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isEqualTo(
226 View.VISIBLE);
227 }
228
229 @Test
230 public void testState_oneRow_withTitle_withTabs() {
231 mockResources();
232 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(false);
233
234 Toolbar toolbar = new Toolbar(mContext);
235 assertThat(toolbar.isTabsInSecondRow()).isFalse();
236
237 // Set title and tabs for toolbar.
238 toolbar.setTitle("Test title");
239 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
240 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
241
242 // With only one row available, toolbar will only show tabs and not the title.
243 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isEqualTo(
244 View.VISIBLE);
245 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isNotEqualTo(
246 View.VISIBLE);
247 }
248
249 @Test
250 public void testState_oneRow_withTitle() {
251 mockResources();
252 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(false);
253
254
255 Toolbar toolbar = new Toolbar(mContext);
256 assertThat(toolbar.isTabsInSecondRow()).isFalse();
257
258 toolbar.setTitle("Test title");
259
260 // Toolbar should display one row with the title and no tabs.
261 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isNotEqualTo(
262 View.VISIBLE);
263 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isEqualTo(
264 View.VISIBLE);
265 }
266
267 @Test
268 public void testState_oneRow_withTabs() {
269 mockResources();
270 when(mResources.getBoolean(R.bool.car_ui_toolbar_tabs_on_second_row)).thenReturn(false);
271
272
273 Toolbar toolbar = new Toolbar(mContext);
274 assertThat(toolbar.isTabsInSecondRow()).isFalse();
275
276 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
277 toolbar.addTab(new TabLayout.Tab(mContext.getDrawable(R.drawable.test_ic_launcher), "Foo"));
278
279 // Toolbar should display one row with only tabs.
280 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_tabs).getVisibility()).isEqualTo(
281 View.VISIBLE);
282 assertThat(toolbar.findViewById(R.id.car_ui_toolbar_title).getVisibility()).isNotEqualTo(
283 View.VISIBLE);
284 }
285
286 @Test
Cole Faustd4e193b2019-10-03 09:49:26 -0700287 public void registerOnBackListener_whenListenerRegisteredTwice_shouldntCallListenerTwice() {
288 mToolbar.setState(Toolbar.State.SUBPAGE);
289 Mutable<Integer> timesBackPressed = new Mutable<>(0);
290 Toolbar.OnBackListener listener = () -> {
291 timesBackPressed.value++;
292 return false;
293 };
294
295 // Registering a second time shouldn't do anything
296 mToolbar.registerOnBackListener(listener);
297 mToolbar.registerOnBackListener(listener);
298 pressBack();
299
300 assertThat(timesBackPressed.value).isEqualTo(1);
301 }
302
303 @Test
304 public void unregisterOnBackListener_previouslyRegisteredListener_shouldUnregister() {
305 mToolbar.setState(Toolbar.State.SUBPAGE);
306 Mutable<Integer> timesBackPressed = new Mutable<>(0);
307 Toolbar.OnBackListener listener = () -> {
308 timesBackPressed.value++;
309 return false;
310 };
311
312 mToolbar.registerOnBackListener(listener);
313 mToolbar.unregisterOnBackListener(listener);
314 pressBack();
315
316 assertThat(timesBackPressed.value).isEqualTo(0);
317 }
318
319 @Test
Cole Faust4ad34c82019-11-19 17:55:11 -0800320 public void menuItems_builder_id() {
321 MenuItem item = MenuItem.builder(mContext)
322 .setId(5)
323 .build();
324
325 assertThat(item.getId()).isEqualTo(5);
326 }
327
328 @Test
329 public void menuItems_setId_shouldWork() {
330 MenuItem item = MenuItem.builder(mContext).build();
331
Cole Faust9ed740e2019-12-06 17:36:20 -0800332 assertThat(item.getId()).isEqualTo(View.NO_ID);
Cole Faust4ad34c82019-11-19 17:55:11 -0800333
334 item.setId(7);
335
336 assertThat(item.getId()).isEqualTo(7);
337 }
338
339 @Test
Cole Faustd4e193b2019-10-03 09:49:26 -0700340 public void menuItems_whenClicked_shouldCallListener() {
Cole Faust9de21992019-11-22 10:45:25 -0800341 assertThat(getMenuItemCount()).isEqualTo(0);
Cole Faustd4e193b2019-10-03 09:49:26 -0700342
343 Mutable<Boolean> button1Clicked = new Mutable<>(false);
344 Mutable<Boolean> button2Clicked = new Mutable<>(false);
345 mToolbar.setMenuItems(Arrays.asList(
346 createMenuItem(i -> button1Clicked.value = true),
347 createMenuItem(i -> button2Clicked.value = true)));
348
Cole Faust9de21992019-11-22 10:45:25 -0800349 assertThat(getMenuItemCount()).isEqualTo(2);
Cole Faustd4e193b2019-10-03 09:49:26 -0700350
Cole Faustdb6866c2019-10-09 15:56:07 -0700351 getMenuItemView(0).performClick();
Cole Faustd4e193b2019-10-03 09:49:26 -0700352
353 assertThat(button1Clicked.value).isTrue();
354
Cole Faustdb6866c2019-10-09 15:56:07 -0700355 getMenuItemView(1).performClick();
Cole Faustd4e193b2019-10-03 09:49:26 -0700356
357 assertThat(button2Clicked.value).isTrue();
358 }
359
360 @Test
361 public void menuItems_null_shouldRemoveExistingMenuItems() {
362 mToolbar.setMenuItems(Arrays.asList(
Ram Parameswaran05fec072019-10-17 13:24:27 -0700363 createMenuItem(i -> {
364 }),
365 createMenuItem(i -> {
366 })));
Cole Faustd4e193b2019-10-03 09:49:26 -0700367
Cole Faust9de21992019-11-22 10:45:25 -0800368 assertThat(getMenuItemCount()).isEqualTo(2);
Cole Faustd4e193b2019-10-03 09:49:26 -0700369
370 mToolbar.setMenuItems(null);
371
Cole Faust9de21992019-11-22 10:45:25 -0800372 assertThat(getMenuItemCount()).isEqualTo(0);
Cole Faustd4e193b2019-10-03 09:49:26 -0700373 }
374
375 @Test
376 public void menuItems_setVisibility_shouldDefaultToShown() {
Ram Parameswaran05fec072019-10-17 13:24:27 -0700377 MenuItem item = createMenuItem(i -> {
378 });
Cole Faustd4e193b2019-10-03 09:49:26 -0700379 mToolbar.setMenuItems(Collections.singletonList(item));
380
Cole Faustdb6866c2019-10-09 15:56:07 -0700381 assertThat(getMenuItemView(0).isShown()).isTrue();
Cole Faustd4e193b2019-10-03 09:49:26 -0700382 }
383
384 @Test
385 public void menuItems_setVisibility_shouldHide() {
Ram Parameswaran05fec072019-10-17 13:24:27 -0700386 MenuItem item = createMenuItem(i -> {
387 });
Cole Faustd4e193b2019-10-03 09:49:26 -0700388 mToolbar.setMenuItems(Collections.singletonList(item));
389
Cole Faustd4e193b2019-10-03 09:49:26 -0700390 item.setVisible(false);
Cole Faustdb6866c2019-10-09 15:56:07 -0700391 assertThat(getMenuItemView(0).isShown()).isFalse();
Cole Faustd4e193b2019-10-03 09:49:26 -0700392 }
393
394 @Test
395 public void menuItems_setVisibility_shouldReshowAfterHiding() {
Ram Parameswaran05fec072019-10-17 13:24:27 -0700396 MenuItem item = createMenuItem(i -> {
397 });
Cole Faustd4e193b2019-10-03 09:49:26 -0700398 mToolbar.setMenuItems(Collections.singletonList(item));
399
Cole Faustd4e193b2019-10-03 09:49:26 -0700400 item.setVisible(false);
401 item.setVisible(true);
Cole Faustdb6866c2019-10-09 15:56:07 -0700402 assertThat(getMenuItemView(0).isShown()).isTrue();
Cole Faustd4e193b2019-10-03 09:49:26 -0700403 }
404
405 @Test
406 public void menuItems_equalItems_shouldntRecreateViews() {
407 List<MenuItem> menuItems = Arrays.asList(
Ram Parameswaran05fec072019-10-17 13:24:27 -0700408 createMenuItem(i -> {
409 }),
410 createMenuItem(i -> {
411 }));
Cole Faustd4e193b2019-10-03 09:49:26 -0700412 mToolbar.setMenuItems(menuItems);
413
Cole Faust9de21992019-11-22 10:45:25 -0800414 assertThat(getMenuItemCount()).isEqualTo(2);
Cole Faustd4e193b2019-10-03 09:49:26 -0700415
Cole Faustdb6866c2019-10-09 15:56:07 -0700416 View firstMenuItemView = getMenuItemView(0);
Cole Faustd4e193b2019-10-03 09:49:26 -0700417
418 mToolbar.setMenuItems(menuItems);
419
Cole Faustdb6866c2019-10-09 15:56:07 -0700420 assertThat(firstMenuItemView).isSameAs(getMenuItemView(0));
Cole Faustd4e193b2019-10-03 09:49:26 -0700421 }
422
423 @Test
424 public void menuItems_searchScreen_shouldHideMenuItems() {
425 mToolbar.setMenuItems(Arrays.asList(
Cole Faust042a8a62019-11-22 14:11:58 -0800426 MenuItem.builder(mContext).setToSearch().build(),
Ram Parameswaran05fec072019-10-17 13:24:27 -0700427 createMenuItem(i -> {
428 })));
Cole Faustd4e193b2019-10-03 09:49:26 -0700429
430 mToolbar.setShowMenuItemsWhileSearching(false);
431 mToolbar.setState(Toolbar.State.SEARCH);
432
Cole Faustdb6866c2019-10-09 15:56:07 -0700433 assertThat(getMenuItemView(0).isShown()).isFalse();
434 assertThat(getMenuItemView(1).isShown()).isFalse();
Cole Faustd4e193b2019-10-03 09:49:26 -0700435 }
436
437 @Test
438 public void menuItems_showMenuItemsWhileSearching() {
439 mToolbar.setMenuItems(Arrays.asList(
Cole Faust042a8a62019-11-22 14:11:58 -0800440 MenuItem.builder(mContext).setToSearch().build(),
Ram Parameswaran05fec072019-10-17 13:24:27 -0700441 createMenuItem(i -> {
442 })));
Cole Faustd4e193b2019-10-03 09:49:26 -0700443
444 mToolbar.setShowMenuItemsWhileSearching(true);
445 mToolbar.setState(Toolbar.State.SEARCH);
446
Cole Faustdb6866c2019-10-09 15:56:07 -0700447 assertThat(getMenuItemView(0).isShown()).isFalse();
448 assertThat(getMenuItemView(1).isShown()).isTrue();
Cole Faustd4e193b2019-10-03 09:49:26 -0700449 }
450
451 private MenuItem createMenuItem(MenuItem.OnClickListener listener) {
Cole Faust042a8a62019-11-22 14:11:58 -0800452 return MenuItem.builder(mContext)
Cole Faustd4e193b2019-10-03 09:49:26 -0700453 .setTitle("Button!")
454 .setOnClickListener(listener)
455 .build();
456 }
457
Ram Parameswaran05fec072019-10-17 13:24:27 -0700458 private void mockResources() {
459 mContext = spy(RuntimeEnvironment.application);
460 mResources = spy(mContext.getResources());
461 when(mContext.getResources()).thenReturn(mResources);
462 }
463
Cole Faust9de21992019-11-22 10:45:25 -0800464 private int getMenuItemCount() {
465 return mToolbar.getMenuItems().size();
Cole Faustdb6866c2019-10-09 15:56:07 -0700466 }
467
468 private View getMenuItemView(int index) {
469 return ((ViewGroup) mToolbar
470 .findViewById(R.id.car_ui_toolbar_menu_items_container))
471 .getChildAt(index);
472 }
473
Cole Faustd4e193b2019-10-03 09:49:26 -0700474 private void pressBack() {
Cole Faustdb6866c2019-10-09 15:56:07 -0700475 mToolbar.findViewById(R.id.car_ui_toolbar_nav_icon_container).performClick();
Cole Faustd4e193b2019-10-03 09:49:26 -0700476 }
477
478 private static class Mutable<T> {
479 public T value;
480
481 Mutable(T value) {
482 this.value = value;
483 }
484 }
485
486}