org.mockito.hamcrest.MockitoHamcrest#org.hamcrest.TypeSafeMatcher源码实例Demo

下面列出了org.mockito.hamcrest.MockitoHamcrest#org.hamcrest.TypeSafeMatcher 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android-test   文件: IntentMatchers.java
public static Matcher<Intent> hasExtras(final Matcher<Bundle> bundleMatcher) {
  checkNotNull(bundleMatcher);

  return new TypeSafeMatcher<Intent>() {
    @Override
    public void describeTo(Description description) {
      description.appendText("has extras: ");
      description.appendDescriptionOf(bundleMatcher);
    }

    @Override
    public boolean matchesSafely(Intent intent) {
      return bundleMatcher.matches(intent.getExtras());
    }
  };
}
 
源代码2 项目: Kore   文件: Matchers.java
public static Matcher<View> withOnlyMatchingDataItems(final Matcher<View> dataMatcher) {
    return new TypeSafeMatcher<View>() {
        @Override
        protected boolean matchesSafely(View view) {
            if (!(view instanceof RecyclerView))
                return false;

            RecyclerView recyclerView = (RecyclerView) view;
            for (int i = 0; i < recyclerView.getChildCount(); i++) {
                RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(i);
                if (! dataMatcher.matches(viewHolder.itemView)) {
                    return false;
                }
            }
            return true;
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("withOnlyMatchingDataItems: ");
            dataMatcher.describeTo(description);
        }
    };
}
 
源代码3 项目: go-bees   文件: ViewRecordingTest.java
private static Matcher<View> childAtPosition(
        final Matcher<View> parentMatcher, final int position) {

    return new TypeSafeMatcher<View>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent)
                    && view.equals(((ViewGroup) parent).getChildAt(position));
        }
    };
}
 
源代码4 项目: cukes   文件: ResponseMatcher.java
public static Matcher<Response> aHeader(final String header, final Matcher<?> matcher) {
        return new TypeSafeMatcher<Response>() {

            @Override
            protected boolean matchesSafely(Response response) {
                String actualHeaderValue = response.getHeader(header);
                return matcher.matches(actualHeaderValue);
            }

            @Override
            public void describeTo(Description description) {
//                description.appendText("has statusCode").appendDescriptionOf(statusCodeMatches);
            }

            @Override
            protected void describeMismatchSafely(Response item, Description mismatchDescription) {
//                mismatchDescription.appendText("statusCode<").appendValue(item.statusCode()+"").appendText(">");
            }
        };
    }
 
源代码5 项目: c5-replicator   文件: LogMatchers.java
static Matcher<OLogHeader> equalToHeader(OLogHeader header) {
  return new TypeSafeMatcher<OLogHeader>() {
    @Override
    protected boolean matchesSafely(OLogHeader item) {
      return item.getBaseSeqNum() == header.getBaseSeqNum()
          && item.getBaseTerm() == header.getBaseTerm()
          && QuorumConfiguration.fromProtostuff(item.getBaseConfiguration())
          .equals(QuorumConfiguration.fromProtostuff(header.getBaseConfiguration()));
    }

    @Override
    public void describeTo(Description description) {
      description.appendText(" equal to ").appendValue(header);
    }
  };
}
 
源代码6 项目: heroic   文件: Matchers.java
public static Matcher<QueryTrace> hasIdentifier(final Matcher<QueryTrace.Identifier> inner) {
    return new TypeSafeMatcher<QueryTrace>() {
        @Override
        protected boolean matchesSafely(final QueryTrace queryTrace) {
            return inner.matches(queryTrace.what());
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText("has identifier that is ").appendDescriptionOf(inner);
        }

        @Override
        public void describeMismatchSafely(QueryTrace item, Description mismatchDescription) {
            inner.describeMismatch(item, mismatchDescription);
        }
    };
}
 
/** Returns a matcher that matches TextInputLayouts with non-displayed end icons. */
public static Matcher<View> doesNotShowEndIcon() {
  return new TypeSafeMatcher<View>(TextInputLayout.class) {
    @Override
    public void describeTo(Description description) {
      description.appendText("TextInputLayout doesn't show end icon.");
    }

    @Override
    protected boolean matchesSafely(View item) {
      // Reach in and find the end icon since we don't have a public API
      // to get a reference to it
      View endIcon = item.findViewById(R.id.text_input_end_icon);
      return endIcon.getVisibility() != View.VISIBLE;
    }
  };
}
 
源代码8 项目: Flink-CEPplus   文件: BucketTest.java
private static TypeSafeMatcher<Bucket<String, String>> hasNullInProgressFile(final boolean isNull) {

		return new TypeSafeMatcher<Bucket<String, String>>() {
			@Override
			protected boolean matchesSafely(Bucket<String, String> bucket) {
				final PartFileWriter<String, String> inProgressPart = bucket.getInProgressPart();
				return isNull == (inProgressPart == null);
			}

			@Override
			public void describeTo(Description description) {
				description.appendText("a Bucket with its inProgressPart being ")
						.appendText(isNull ? " null." : " not null.");
			}
		};
	}
 
源代码9 项目: bowman   文件: RestOperationsFactoryTest.java
private static Matcher<JsonDeserializer> anInlineAssociationDeserializerMatching(
		Matcher<RestOperations> restOperations, Matcher<ClientProxyFactory> proxyFactory) {
	return new TypeSafeMatcher<JsonDeserializer>() {

		@Override
		public boolean matchesSafely(JsonDeserializer item) {
			if (!(item instanceof InlineAssociationDeserializer)) {
				return false;
			}
			
			InlineAssociationDeserializer other = (InlineAssociationDeserializer) item;
			
			return restOperations.matches(other.getRestOperations())
					&& proxyFactory.matches(other.getProxyFactory());
		}

		@Override
		public void describeTo(Description description) {
			description.appendText("instanceof ").appendValue(InlineAssociationDeserializer.class)
				.appendText(", restOperations ").appendValue(restOperations)
				.appendText(", proxyFactory ").appendValue(proxyFactory);
		}
	};
}
 
源代码10 项目: android-test   文件: UriMatchers.java
public static Matcher<Uri> hasScheme(final Matcher<String> schemeMatcher) {
  checkNotNull(schemeMatcher);

  return new TypeSafeMatcher<Uri>() {

    @Override
    public boolean matchesSafely(Uri uri) {
      return schemeMatcher.matches(uri.getScheme());
    }

    @Override
    public void describeTo(Description description) {
      description.appendText("has scheme: ");
      description.appendDescriptionOf(schemeMatcher);
    }
  };
}
 
源代码11 项目: elasticsearch   文件: SystemTestMatchers.java
public static Matcher<? super String> isValidDateTime() {
    return new TypeSafeMatcher<String>() {
        @Override
        protected boolean matchesSafely(String item) {
            try {
                ZonedDateTime.parse(item);
                return true;
            } catch (DateTimeException e) {
                return false;
            }
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("Valid ISO zoned date time");
        }
    };
}
 
源代码12 项目: android-test   文件: DomMatchersTest.java
@Test
public void testWithBody_NormalDocument() {
  Matcher<Element> hasAttributes =
      new TypeSafeMatcher<Element>() {
        @Override
        public void describeTo(Description description) {
          description.appendText("has attributes");
        }

        @Override
        public boolean matchesSafely(Element element) {
          return element.hasAttributes();
        }
      };

  assertTrue(withBody(not(hasAttributes)).matches(document));
}
 
源代码13 项目: android-mvvm-with-tests   文件: MatcherEx.java
/**
 * Returns a matcher that matches {@link MyTextView}s resourceId
 */
public static Matcher<View> hasResId(int resId) {
    return new TypeSafeMatcher<View>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("has resId");
        }

        @Override
        public boolean matchesSafely(View view) {
            try {
                return ((MyTextView) view).getBackgroundResource() == resId;
            } catch (Exception exception) {
                return false;
            }
        }
    };
}
 
源代码14 项目: fullstop   文件: MatcherHelper.java
public static <T> TypeSafeMatcher<? extends T> meetsAssertions(final Assertable<? super T> assertions) {
    return new TypeSafeMatcher<T>() {
        private final Logger log = getLogger(getClass());

        @Override
        protected boolean matchesSafely(final T item) {
            try {
                assertions.doAssertions(item);
                return true;
            }
            catch (final AssertionError e) {
                log.error("Assertions failed", e);
                return false;
            }
        }

        @Override
        public void describeTo(final Description description) {
            description.appendText("object that meets all assertions");
        }
    };
}
 
源代码15 项目: flink   文件: BucketTest.java
private static TypeSafeMatcher<Bucket<String, String>> hasNullInProgressFile(final boolean isNull) {

		return new TypeSafeMatcher<Bucket<String, String>>() {
			@Override
			protected boolean matchesSafely(Bucket<String, String> bucket) {
				final PartFileWriter<String, String> inProgressPart = bucket.getInProgressPart();
				return isNull == (inProgressPart == null);
			}

			@Override
			public void describeTo(Description description) {
				description.appendText("a Bucket with its inProgressPart being ")
						.appendText(isNull ? " null." : " not null.");
			}
		};
	}
 
源代码16 项目: japicmp   文件: Helper.java
public static Matcher<JApiClass> hasJApiMethodWithName(final String methodName) {
	return new TypeSafeMatcher<JApiClass>() {

		@Override
		public void describeTo(Description description) {
			description.appendText("JApiClass should have a method with name '").appendValue(methodName)
				.appendText("'.");
		}

		@Override
		protected boolean matchesSafely(JApiClass jApiClass) {
			List<JApiMethod> jApiMethods = jApiClass.getMethods();
			boolean found = false;
			for (JApiMethod jApiMethod : jApiMethods) {
				if (methodName.equals(jApiMethod.getName())) {
					found = true;
					break;
				}
			}
			return found;
		}
	};
}
 
源代码17 项目: gocd   文件: PersistentObjectMatchers.java
public static Matcher<PersistentObject> hasSameId(final PersistentObject expected) {
    return new TypeSafeMatcher<PersistentObject>() {
        public String message;

        @Override
        public boolean matchesSafely(PersistentObject item) {
            message = "should have same database id. Expected " + expected.getId() + " but was " + item.getId();
            return expected.getId() == item.getId();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(message);
        }
    };

}
 
源代码18 项目: querqy   文件: TermSubQueryBuilderTest.java
@Override
protected boolean matchesSafely(PRMSQuery query) {
    PRMSDisjunctionMaxQuery prmsDmq = ((PRMSDisjunctionMaxQuery) query);
    
    for (TypeSafeMatcher<PRMSQuery> disjunct : disjuncts) {
        boolean found = false;
        for (PRMSQuery q : prmsDmq.getDisjuncts()) {
            found = disjunct.matches(q);
            if (found) {
                break;
            }
        }
        if (!found) {
            return false;
        }

    }
    return true;
    
    
}
 
源代码19 项目: keycloak   文件: AssertAdminEvents.java
public static Matcher<String> isExpectedPrefixFollowedByUuid(final String prefix) {
    return new TypeSafeMatcher<String>() {

        @Override
        protected boolean matchesSafely(String item) {
            int expectedLength = prefix.length() + 1 + org.keycloak.models.utils.KeycloakModelUtils.generateId().length();
            return item.startsWith(prefix) && expectedLength == item.length();
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("resourcePath in the format like \"" + prefix + "/<UUID>\"");
        }

    };
}
 
源代码20 项目: android-test   文件: LayoutMatchers.java
/**
 * Matches TextView elements having ellipsized text. If text is too long to fit into a TextView,
 * it can be either ellipsized ('Too long' shown as 'Too l…' or '… long') or cut off ('Too long'
 * shown as 'Too l'). Though acceptable in some cases, usually indicates bad user experience.
 */
public static Matcher<View> hasEllipsizedText() {
  return new TypeSafeMatcher<View>(TextView.class) {
    @Override
    public void describeTo(Description description) {
      description.appendText("has ellipsized text");
    }

    @Override
    public boolean matchesSafely(View tv) {
      Layout layout = ((TextView) tv).getLayout();
      if (layout != null) {
        int lines = layout.getLineCount();
        return lines > 0 && layout.getEllipsisCount(lines - 1) > 0;
      }
      return false;
    }
  };
}
 
private static Matcher<View> orderMatcher() {
    return new TypeSafeMatcher<View>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("with correct position order");
        }

        @Override
        public boolean matchesSafely(View v) {
            RecyclerView view = (RecyclerView) v;
            if (view.getLayoutManager() == null) return false;
            ChildViewsIterable childViews = new ChildViewsIterable(view.getLayoutManager());
            int pos = view.getChildAdapterPosition(childViews.iterator().next());
            for (View child : childViews) {
                if (pos != view.getChildAdapterPosition(child)) {
                    return false;
                }
                pos ++;
            }
            return true;
        }
    };
}
 
源代码22 项目: android-test   文件: UriMatchers.java
private static Matcher<QueryParamEntry> queryParamEntry(
    final Matcher<String> paramName, final Matcher<String> paramVal) {
  final Matcher<Iterable<? super String>> valMatcher = hasItem(paramVal);

  return new TypeSafeMatcher<QueryParamEntry>(QueryParamEntry.class) {

    @Override
    public boolean matchesSafely(QueryParamEntry qpe) {
      return paramName.matches(qpe.paramName) && valMatcher.matches(qpe.paramVals);
    }

    @Override
    public void describeTo(Description description) {
      description.appendDescriptionOf(paramName);
      description.appendDescriptionOf(paramVal);
    }
  };
}
 
源代码23 项目: ETHWallet   文件: ScreengrabTest.java
private static Matcher<View> childAtPosition(
        final Matcher<View> parentMatcher, final int position) {

    return new TypeSafeMatcher<View>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + position + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent)
                    && view.equals(((ViewGroup) parent).getChildAt(position));
        }
    };
}
 
源代码24 项目: android-test-demo   文件: CustomMatchers.java
public static Matcher<View> withError(final String expected) {
    return new TypeSafeMatcher<View>() {

        @Override
        public boolean matchesSafely(View view) {
            if (!(view instanceof EditText)) {
                return false;
            }
            EditText editText = (EditText) view;
            return editText.getError().toString().equals(expected);
        }

        @Override
        public void describeTo(Description description) {

        }
    };
}
 
private static Matcher<View> childAtPosition(
        final Matcher<View> parentMatcher) {

    return new TypeSafeMatcher<View>() {
        @Override
        public void describeTo(Description description) {
            description.appendText("Child at position " + 0 + " in parent ");
            parentMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            ViewParent parent = view.getParent();
            return parent instanceof ViewGroup && parentMatcher.matches(parent)
                    && view.equals(((ViewGroup) parent).getChildAt(0));
        }
    };
}
 
源代码26 项目: hamcrest-junit   文件: EventCollector.java
static Matcher<EventCollector> failureIs(final Matcher<? super Throwable> exceptionMatcher) {
    return new TypeSafeMatcher<EventCollector>() {
        @Override
        public boolean matchesSafely(EventCollector item) {
            for (Failure f : item.fFailures) {
                return exceptionMatcher.matches(f.getException());
            }
            return false;
        }

        public void describeTo(org.hamcrest.Description description) {
            description.appendText("failure is ");
            exceptionMatcher.describeTo(description);
        }
    };
}
 
源代码27 项目: querqy   文件: AbstractLuceneQueryTest.java
protected boolean matchDisjunctionMaxQuery(DisjunctionMaxQuery dmq) {

            if (tieBreaker != dmq.getTieBreakerMultiplier()) {
                return false;
            }

            List<Query> dmqDisjuncts = dmq.getDisjuncts();
            if (dmqDisjuncts == null || dmqDisjuncts.size() != disjuncts.length) {
                return false;
            }

            for (TypeSafeMatcher<? extends Query> disjunct : disjuncts) {
                boolean found = false;
                for (Query q : dmqDisjuncts) {
                    found = disjunct.matches(q);
                    if (found) {
                        break;
                    }
                }
                if (!found) {
                    return false;
                }

            }
            return true;
        }
 
源代码28 项目: hamcrest-junit   文件: EventCollector.java
static Matcher<EventCollector> failureIs(final Matcher<? super Throwable> exceptionMatcher) {
    return new TypeSafeMatcher<EventCollector>() {
        @Override
        public boolean matchesSafely(EventCollector item) {
            for (Failure f : item.fFailures) {
                return exceptionMatcher.matches(f.getException());
            }
            return false;
        }

        public void describeTo(org.hamcrest.Description description) {
            description.appendText("failure is ");
            exceptionMatcher.describeTo(description);
        }
    };
}
 
源代码29 项目: raml-java-tools   文件: TypeNameMatcher.java
public static Matcher<TypeName> typeName(final Matcher<? super ClassName> matcher) {

        final Matcher<? super ClassName> subMatcher = matcher;
        return new TypeSafeMatcher<TypeName>() {
            @Override
            protected boolean matchesSafely(TypeName item) {
                return subMatcher.matches(item);
            }

            @Override
            public void describeTo(Description description) {

                description.appendText("typename ").appendDescriptionOf(subMatcher);
            }
        };
    }
 
/**
 * This helps "find" the lists in the activity, since there is more than 1.
 *
 * @param tag
 * @return
 */
private static Matcher<View> withTag(final Object tag) {
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(final Description description) {
            description.appendText("has tag equals to: " + tag);
        }

        @Override
        protected boolean matchesSafely(final View view) {
            Object viewTag = view.getTag();
            if (viewTag == null) {
                return tag == null;
            }

            return viewTag.equals(tag);
        }
    };
}