• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2020 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 
17 package com.android.car.ui.matchers;
18 
19 import static androidx.test.espresso.assertion.ViewAssertions.matches;
20 import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
21 
22 import static org.hamcrest.Matchers.allOf;
23 import static org.hamcrest.Matchers.not;
24 
25 import android.content.Context;
26 import android.view.View;
27 
28 import androidx.annotation.DrawableRes;
29 import androidx.annotation.NonNull;
30 import androidx.test.espresso.ViewAssertion;
31 
32 import com.android.car.ui.matchers.PaddingMatcher.Side;
33 
34 import org.hamcrest.Matcher;
35 
36 public class ViewMatchers {
withDrawable( @onNull Context context, @DrawableRes int drawableId)37     public static Matcher<View> withDrawable(
38             @NonNull Context context, @DrawableRes int drawableId) {
39         return new DrawableMatcher(context, drawableId);
40     }
41 
nthChildOfView(Matcher<View> parentMatcher, int n)42     public static Matcher<View> nthChildOfView(Matcher<View> parentMatcher, int n) {
43         return new NthChildMatcher(parentMatcher, n);
44     }
45 
withIndex(Matcher<View> matcher, int index)46     public static Matcher<View> withIndex(Matcher<View> matcher, int index) {
47         return new IndexMatcher(matcher, index);
48     }
49 
withPadding(Side side, int exactly)50     public static Matcher<View> withPadding(Side side, int exactly) {
51         return new PaddingMatcher(side, exactly, exactly);
52     }
53 
withPaddingAtLeast(Side side, int min)54     public static Matcher<View> withPaddingAtLeast(Side side, int min) {
55         return new PaddingMatcher(side, min, -1);
56     }
57 
isActivated()58     public static Matcher<View> isActivated() {
59         return new IsActivatedMatcher();
60     }
61 
doesNotExistOrIsNotDisplayed()62     public static ViewAssertion doesNotExistOrIsNotDisplayed() {
63         return (view, noViewFoundException) -> {
64             if (view != null) {
65                 matches(not(isDisplayed())).check(view, noViewFoundException);
66             }
67         };
68     }
69 
70     public static Matcher<View> isDisplayedAnd(Matcher<View> another) {
71         return allOf(isDisplayed(), another);
72     }
73 
74 
75     public static Matcher<View> hasIndeterminateProgress() {
76         return new ProgressBarIndeterminateMatcher();
77     }
78 }
79