-
Notifications
You must be signed in to change notification settings - Fork 0
/
SeekBarMatchers.java
59 lines (51 loc) · 1.76 KB
/
SeekBarMatchers.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
package ch.teleboy.matchers;
import android.view.View;
import android.widget.SeekBar;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
/**
* Small set of matchers for asserting SeekBar states.
*/
public class SeekBarMatchers {
/**
* Matches does SeekBar has set position (progress) at desired position.
* @param position The value we want to validate against
*/
public static Matcher<View> isAtPosition(final int position) {
return new TypeSafeMatcher<View>() {
@Override
protected boolean matchesSafely(View view) {
if (!(view instanceof SeekBar)) {
return false;
}
SeekBar seekBar = (SeekBar) view;
return seekBar.getProgress() == position;
}
@Override
public void describeTo(Description description) {
description.appendText("expected to be at position: " + position);
}
};
}
/**
* Matches does SeekBar has set max value at desired value.
* @param maxValue The value we want to validate against
*/
public static Matcher<View> hasMaxValue(final int maxValue) {
return new TypeSafeMatcher<View>() {
@Override
protected boolean matchesSafely(View view) {
if (!(view instanceof SeekBar)) {
return false;
}
SeekBar seekBar = (SeekBar) view;
return seekBar.getMax() == maxValue;
}
@Override
public void describeTo(Description description) {
description.appendText("expected to have max value: " + maxValue);
}
};
}
}