-
Notifications
You must be signed in to change notification settings - Fork 384
Expand file tree
/
Copy pathTokenMatchers.java
More file actions
48 lines (41 loc) · 1.8 KB
/
TokenMatchers.java
File metadata and controls
48 lines (41 loc) · 1.8 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
package com.tokenautocomplete;
import android.support.test.espresso.matcher.BoundedMatcher;
import android.view.View;
import org.hamcrest.Description;
import org.hamcrest.Matcher;
import java.util.Locale;
import static android.support.test.espresso.core.deps.guava.base.Preconditions.checkNotNull;
/** Convenience matchers to make it easier to check token view contents
* Created by mgod on 8/25/17.
*/
class TokenMatchers {
static Matcher<View> emailForPerson(final int position, final Matcher<String> stringMatcher) {
checkNotNull(stringMatcher);
return new BoundedMatcher<View, ContactsCompletionView>(ContactsCompletionView.class) {
@Override
public void describeTo(Description description) {
description.appendText(String.format(Locale.US, "email for person %d: ", position));
stringMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(ContactsCompletionView view) {
if (view.getObjects().size() <= position) { return stringMatcher.matches(null); }
return stringMatcher.matches(view.getObjects().get(position).getEmail());
}
};
}
static Matcher<View> tokenCount(final Matcher<Integer> intMatcher) {
checkNotNull(intMatcher);
return new BoundedMatcher<View, ContactsCompletionView>(ContactsCompletionView.class) {
@Override
public void describeTo(Description description) {
description.appendText("token count: ");
intMatcher.describeTo(description);
}
@Override
public boolean matchesSafely(ContactsCompletionView view) {
return intMatcher.matches(view.getObjects().size());
}
};
}
}