1/*
2 * Copyright (C) 2017 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 android.support.v17.leanback.widget;
18
19import android.content.Context;
20import android.graphics.drawable.GradientDrawable;
21import android.support.test.InstrumentationRegistry;
22import android.support.test.filters.SmallTest;
23import android.support.test.runner.AndroidJUnit4;
24import android.util.AttributeSet;
25import android.view.View;
26import android.widget.LinearLayout;
27
28import org.junit.Test;
29import org.junit.runner.RunWith;
30import org.mockito.Mockito;
31
32@SmallTest
33@RunWith(AndroidJUnit4.class)
34public class TitleViewAdapterTest {
35
36
37    public static class CustomTitle extends LinearLayout implements TitleViewAdapter.Provider {
38
39        final View mSearchOrbView;
40
41        public CustomTitle(Context context, AttributeSet set) {
42            this(context, set, 0);
43        }
44
45        public CustomTitle(Context context, AttributeSet set, int s) {
46            super(context, set, s);
47            mSearchOrbView = new View(context);
48            addView(mSearchOrbView, 10, 10);
49        }
50
51        TitleViewAdapter mTitleViewAdapter = new TitleViewAdapter() {
52            @Override
53            public View getSearchAffordanceView() {
54                return mSearchOrbView;
55            }
56        };
57
58        @Override
59        public TitleViewAdapter getTitleViewAdapter() {
60            return mTitleViewAdapter;
61        }
62    }
63
64    @Test
65    public void customTitle() {
66        CustomTitle t = new CustomTitle(InstrumentationRegistry.getTargetContext(), null);
67        TitleViewAdapter adapter = t.getTitleViewAdapter();
68        adapter.setTitle("title");
69        adapter.setBadgeDrawable(new GradientDrawable());
70        View.OnClickListener listener = Mockito.mock(View.OnClickListener.class);
71        adapter.setOnSearchClickedListener(listener);
72        adapter.getSearchAffordanceView().performClick();
73        Mockito.verify(listener).onClick(Mockito.any(View.class));
74    }
75}
76