下面列出了org.hamcrest.Matchers#allOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void textView_returnsProperMatcher() {
//given
final Cortado.OrAnd.Matcher matcher = Cortado.textView().withText("test");
final Matcher<View> expectedEspressoMatcher = Matchers.allOf(
ViewMatchers.isAssignableFrom(TextView.class),
matcher.getCortado().matchers.get(0));
//when
//then
Utils.assertThat(matcher).isEqualTo(expectedEspressoMatcher);
}
@Test
public void button_returnsProperMatcher() {
//given
final Cortado.OrAnd.Matcher matcher = Cortado.button().withText("test");
final Matcher<View> expectedEspressoMatcher = Matchers.allOf(
ViewMatchers.isAssignableFrom(Button.class),
matcher.getCortado().matchers.get(0));
//when
//then
Utils.assertThat(matcher).isEqualTo(expectedEspressoMatcher);
}
@Test
public void imageView_returnsProperMatcher() {
//given
final Cortado.OrAnd.Matcher matcher = Cortado.imageView().withText("test");
final Matcher<View> expectedEspressoMatcher = Matchers.allOf(
ViewMatchers.isAssignableFrom(ImageView.class),
matcher.getCortado().matchers.get(0));
//when
//then
Utils.assertThat(matcher).isEqualTo(expectedEspressoMatcher);
}
@Test
public void imageButton_returnsProperMatcher() {
//given
final Cortado.OrAnd.Matcher matcher = Cortado.imageButton().withText("test");
final Matcher<View> expectedEspressoMatcher = Matchers.allOf(
ViewMatchers.isAssignableFrom(ImageButton.class),
matcher.getCortado().matchers.get(0));
//when
//then
Utils.assertThat(matcher).isEqualTo(expectedEspressoMatcher);
}
@Test
public void onTextView_returnsProperViewInteraction() {
//given
final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onTextView().withText("test");
final Matcher<View> expectedEspressoMatcher = Matchers.allOf(
ViewMatchers.isAssignableFrom(TextView.class),
viewInteraction.getCortado().matchers.get(0));
//when
final Matcher<View> rawMatcher = viewInteraction.getCortado().get();
//then
Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);
}
@Test
public void onEditText_returnsProperViewInteraction() {
//given
final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onEditText().withText("test");
final Matcher<View> expectedEspressoMatcher = Matchers.allOf(
ViewMatchers.isAssignableFrom(EditText.class),
viewInteraction.getCortado().matchers.get(0));
//when
final Matcher<View> rawMatcher = viewInteraction.getCortado().get();
//then
Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);
}
@Test
public void onButton_returnsProperViewInteraction() {
//given
final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onButton().withText("test");
final Matcher<View> expectedEspressoMatcher = Matchers.allOf(
ViewMatchers.isAssignableFrom(Button.class),
viewInteraction.getCortado().matchers.get(0));
//when
final Matcher<View> rawMatcher = viewInteraction.getCortado().get();
//then
Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);
}
@Test
public void onImageView_returnsProperViewInteraction() {
//given
final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onImageView().withText("test");
final Matcher<View> expectedEspressoMatcher = Matchers.allOf(
ViewMatchers.isAssignableFrom(ImageView.class),
viewInteraction.getCortado().matchers.get(0));
//when
final Matcher<View> rawMatcher = viewInteraction.getCortado().get();
//then
Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);
}
@Test
public void onImageButton_returnsProperViewInteraction() {
//given
final Cortado.OrAnd.ViewInteraction viewInteraction = Cortado.onImageButton().withText("test");
final Matcher<View> expectedEspressoMatcher = Matchers.allOf(
ViewMatchers.isAssignableFrom(ImageButton.class),
viewInteraction.getCortado().matchers.get(0));
//when
final Matcher<View> rawMatcher = viewInteraction.getCortado().get();
//then
Utils.assertThat(rawMatcher).isEqualTo(expectedEspressoMatcher);
}
private Matcher<Map<String, Object>> ruleOutputToMatchers(RuleOutput ruleOutput) {
Matcher<Map<? extends String, ? extends Object>> targetMatcher =
Matchers.hasEntry("target", ruleOutput.target);
Matcher<Map<? extends String, ? extends Object>> valMatcher =
Matchers.hasEntry("val", ruleOutput.val);
Matcher<Object> srcs = createEndOfPathMatcher(ruleOutput.srcs);
Matcher<Object> deps =
(Matcher<Object>)
(Matcher<? extends Object>)
Matchers.containsInAnyOrder(
Collections2.transform(
ruleOutput.deps,
d -> (Matcher<? super Object>) (Matcher<?>) ruleOutputToMatchers(d)));
Matcher<Object> outputs = createEndOfPathMatcher(ruleOutput.outputs);
Matcher<Map<? extends String, ? extends Object>> srcsMatcher =
Matchers.hasEntry(Matchers.is("srcs"), srcs);
Matcher<Map<? extends String, ? extends Object>> depMatcher =
Matchers.hasEntry(Matchers.is("dep"), deps);
Matcher<Map<? extends String, ? extends Object>> outputsMatcher =
Matchers.hasEntry(Matchers.is("outputs"), outputs);
Matcher<? extends Map<? extends String, ? extends Object>> matcher =
Matchers.allOf(targetMatcher, valMatcher, srcsMatcher, depMatcher, outputsMatcher);
return (Matcher<Map<String, Object>>) matcher;
}
private static Matcher<? super View> viewNameMatcher(String viewName) {
Matcher<View> subMatchers = Matchers.allOf(ImmutableList.of(
propertyMatcher(View::getName, "name", viewNameEqualTo(viewName))
));
return Matchers.describedAs("%0", subMatchers, viewName);
}
private static Matcher<? super Index> indexMatcher(Index index) {
Matcher<Index> subMatchers = Matchers.allOf(ImmutableList.of(
propertyMatcher(Index::getName, "name", indexNameEqualTo(index.getName())),
propertyMatcher(Index::columnNames, "columns", contains(indexColumnNamesEqualTo(index.columnNames()))),
propertyMatcher(Index::isUnique, "unique", equalTo(index.isUnique()))
));
return Matchers.describedAs("%0", subMatchers, index.toString());
}
public static <T> Matcher<T[]> hasItemsInArray(Matcher<T>... items) {
Collection<Matcher<? super T[]>> matchers = new ArrayList<Matcher<? super T[]>>(items.length);
for (Matcher<T> item : items) {
matchers.add(hasItemInArray(item));
}
return Matchers.allOf(matchers);
}
public Matcher<View> getConstraints() {
return Matchers.allOf(new Matcher[] {
ViewMatchers.isAssignableFrom(RecyclerView.class), ViewMatchers.isDisplayed()
});
}
public Matcher<View> getConstraints() {
return Matchers.allOf(new Matcher[] {
ViewMatchers.isAssignableFrom(RecyclerView.class), ViewMatchers.isDisplayed()
});
}
public Matcher<View> getConstraints() {
return Matchers.allOf(new Matcher[] {
ViewMatchers.isAssignableFrom(RecyclerView.class), ViewMatchers.isDisplayed()
});
}
@Override
Matcher<? super View> link(List<Matcher<? super View>> matchers) {
return Matchers.allOf(matchers);
}
public static Matcher<Result<?>> isResult(Matcher<?> valueMatcher, Iterable<String> warnings) {
return Matchers.allOf(
hasProperty("value", valueMatcher),
hasWarnings(warnings));
}
public ViewGroupInteraction onChildView(Matcher<View> matcher) {
//noinspection unchecked
return new ViewGroupInteraction(Matchers.allOf(withParent(groupMatcher), matcher));
}
public Matcher<View> getConstraints() {
return Matchers.allOf(new Matcher[]{
ViewMatchers.isAssignableFrom(RecyclerView.class), ViewMatchers.isDisplayed()
});
}