-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextViewMatchers.java
executable file
·68 lines (57 loc) · 1.83 KB
/
TextViewMatchers.java
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
package com.eutechpro.matchers;
import android.graphics.Typeface;
import android.support.annotation.ColorInt;
import android.view.View;
import android.widget.TextView;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
/**
* Created by Kursulla on 14/01/16.
*/
public class TextViewMatchers {
/**
* Match does target {@link TextView} has {@link Typeface#BOLD} style set
* @return Does it match or not.
*/
public static Matcher<View> isBold() {
return new TypeSafeMatcher<View>() {
@Override
public boolean matchesSafely(View view) {
if (!(view instanceof TextView)) {
return false;
}
TextView textView = (TextView)view;
if (textView.getTypeface() != null) {
return textView.getTypeface().getStyle() == Typeface.BOLD;
}
return false;
}
@Override
public void describeTo(Description description) {
}
};
}
/**
* Match does target {@link TextView} has desired color set.
* <br/>
* @see ColorInt
* @param colorInt {@link ColorInt} int we want to math.
* @return Does it match or not.
*/
public static Matcher<View> hasColor(@ColorInt final int colorInt) {
return new TypeSafeMatcher<View>() {
@Override
public boolean matchesSafely(View view) {
if (!(view instanceof TextView)) {
return false;
}
TextView textView = (TextView) view;
return textView.getCurrentTextColor()== colorInt;
}
@Override
public void describeTo(Description description) {
}
};
}
}