-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathMatches.java
More file actions
75 lines (66 loc) · 2.13 KB
/
Matches.java
File metadata and controls
75 lines (66 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package de.dotwee.micropinner.tools;
import android.graphics.drawable.ColorDrawable;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.test.espresso.Root;
import androidx.test.espresso.intent.Checks;
import androidx.test.espresso.matcher.BoundedMatcher;
import android.view.View;
import android.widget.TextView;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
/**
* Created by Lukas Wolfsteiner on 06.11.2015.
*/
public final class Matches {
@NonNull
public static Matcher<Root> isToast() {
return new ToastMatcher();
}
@NonNull
public static Matcher<Root> isToast(int maxRetries) {
return new ToastMatcher(maxRetries);
}
/**
* This matcher checks if a TextView displays its text in
* a specific color.
*
* @param color The color to verify.
* @return Corresponding matcher.
*/
@NonNull
public static Matcher<View> withTextColor(@ColorInt final int color) {
Checks.checkNotNull(color);
return new BoundedMatcher<View, TextView>(TextView.class) {
@Override
public boolean matchesSafely(TextView warning) {
return color == warning.getCurrentTextColor();
}
@Override
public void describeTo(Description description) {
description.appendText("with text color: ");
}
};
}
/**
* This matcher checks if a View displays its background in
* a specific color.
*
* @param color The color to verify.
* @return Corresponding matcher.
*/
@NonNull
public static Matcher<View> withBackgroundColor(@ColorInt final int color) {
Checks.checkNotNull(color);
return new BoundedMatcher<View, View>(View.class) {
@Override
public boolean matchesSafely(View warning) {
return color == ((ColorDrawable) warning.getBackground()).getColor();
}
@Override
public void describeTo(Description description) {
description.appendText("with text color: ");
}
};
}
}