org.hamcrest.Factory类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(135)

本文整理了Java中org.hamcrest.Factory类的一些代码示例,展示了Factory类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Factory类的具体详情如下:
包路径:org.hamcrest.Factory
类名称:Factory

Factory介绍

暂无

代码示例

代码示例来源:origin: org.hamcrest/hamcrest-all

/**
 * Creates a matcher of {@link String} that matches when the examined string has zero length.
 * <p/>
 * For example:
 * <pre>assertThat("", isEmptyString())</pre>
 * 
 */
@Factory
public static Matcher<String> isEmptyString() {
  return INSTANCE;
}

代码示例来源:origin: google/j2objc

/**
 * A shortcut to the frequently used <code>is(equalTo(x))</code>.
 * <p/>
 * For example:
 * <pre>assertThat(cheese, is(smelly))</pre>
 * instead of:
 * <pre>assertThat(cheese, is(equalTo(smelly)))</pre>
 * 
 */
@Factory
public static <T> Matcher<T> is(T value) {
  return is(equalTo(value));
}

代码示例来源:origin: google/j2objc

/**
 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.
 * <p/>
 * For example:
 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
 */
@Factory
public static <T> Matcher<T> allOf(Matcher<? super T>... matchers) {
  return allOf(Arrays.asList(matchers));
}

代码示例来源:origin: google/j2objc

/**
 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.
 * <p/>
 * For example:
 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
 */
@Factory
public static <T> Matcher<T> allOf(Iterable<Matcher<? super T>> matchers) {
  return new AllOf<T>(matchers);
}

代码示例来源:origin: org.hamcrest/hamcrest-all

/**
 * A shortcut to the frequently used <code>is(equalTo(x))</code>.
 * <p/>
 * For example:
 * <pre>assertThat(cheese, is(smelly))</pre>
 * instead of:
 * <pre>assertThat(cheese, is(equalTo(smelly)))</pre>
 * 
 */
@Factory
public static <T> Matcher<T> is(T value) {
  return is(equalTo(value));
}

代码示例来源:origin: org.hamcrest/hamcrest-all

/**
 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.
 * <p/>
 * For example:
 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
 */
@Factory
public static <T> Matcher<T> allOf(Matcher<? super T>... matchers) {
  return allOf(Arrays.asList(matchers));
}

代码示例来源:origin: org.hamcrest/hamcrest-all

/**
 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.
 * <p/>
 * For example:
 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
 */
@Factory
public static <T> Matcher<T> allOf(Iterable<Matcher<? super T>> matchers) {
  return new AllOf<T>(matchers);
}

代码示例来源:origin: org.hamcrest/hamcrest-all

/**
   * Creates a matcher of {@link String} that matches when the examined string is <code>null</code>, or
   * has zero length.
   * <p/>
   * For example:
   * <pre>assertThat(((String)null), isEmptyString())</pre>
   * 
   */
  @Factory
  public static Matcher<String> isEmptyOrNullString() {
    return NULL_OR_EMPTY_INSTANCE;
  }
}

代码示例来源:origin: json-path/JsonPath

/**
   * This is a shortcut to the frequently used hasSize(equalTo(x)).
   *
   * For example,  assertThat(hasSize(equal_to(x)))
   *          vs.  assertThat(hasSize(x))
   */
  @Factory
  public static <E> Matcher<? super Collection<? extends E>> hasSize(int size) {
    Matcher<? super Integer> matcher = equalTo(size);
    return IsCollectionWithSize.<E>hasSize(matcher);
  }
}

代码示例来源:origin: google/j2objc

/**
 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.
 * <p/>
 * For example:
 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
 */
@Factory
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second) {
  List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(2);
  matchers.add(first);
  matchers.add(second);
  return allOf(matchers);
}

代码示例来源:origin: junit-team/junit4

/**
   * Returns a matcher that verifies that the outer exception has a cause for which the supplied matcher
   * evaluates to true.
   *
   * @param matcher to apply to the cause of the outer exception
   * @param <T> type of the outer exception
   */
  @Factory
  public static <T extends Throwable> Matcher<T> hasCause(final Matcher<?> matcher) {
    return new ThrowableCauseMatcher<T>(matcher);
  }
}

代码示例来源:origin: json-path/JsonPath

@Factory
public static <K> Matcher<Map<K,?>> hasKey(K key) {
  return hasKey(equalTo(key));
}

代码示例来源:origin: org.hamcrest/hamcrest-all

/**
 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.
 * <p/>
 * For example:
 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
 */
@Factory
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second) {
  List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(2);
  matchers.add(first);
  matchers.add(second);
  return allOf(matchers);
}

代码示例来源:origin: junit-team/junit4

@Factory
public static <T extends Throwable> Matcher<T> isThrowable(
    Matcher<T> throwableMatcher) {
  return new StacktracePrintingMatcher<T>(throwableMatcher);
}

代码示例来源:origin: json-path/JsonPath

@Factory
public static <V> Matcher<? super Map<?,V>> hasValue(V value) {
  return IsMapContainingValue.<V>hasValue(equalTo(value));
}

代码示例来源:origin: google/j2objc

/**
 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.
 * <p/>
 * For example:
 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
 */
@Factory
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third) {
  List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(3);
  matchers.add(first);
  matchers.add(second);
  matchers.add(third);
  return allOf(matchers);
}

代码示例来源:origin: junit-team/junit4

@Factory
  public static <T extends Exception> Matcher<T> isException(
      Matcher<T> exceptionMatcher) {
    return new StacktracePrintingMatcher<T>(exceptionMatcher);
  }
}

代码示例来源:origin: org.hamcrest/hamcrest-all

/**
 * Creates a matcher for arrays that matches when the <code>length</code> of the array
 * equals the specified <code>size</code>.
 * <p/>
 * For example:
 * <pre>assertThat(new String[]{"foo", "bar"}, arrayWithSize(2))</pre>
 * 
 * @param size
 *     the length that an examined array must have for a positive match
 */
@Factory
public static <E> Matcher<E[]> arrayWithSize(int size) {
  return arrayWithSize(equalTo(size));
}

代码示例来源:origin: org.hamcrest/hamcrest-all

/**
 * Creates a matcher that matches if the examined object matches <b>ALL</b> of the specified matchers.
 * <p/>
 * For example:
 * <pre>assertThat("myValue", allOf(startsWith("my"), containsString("Val")))</pre>
 */
@Factory
public static <T> Matcher<T> allOf(Matcher<? super T> first, Matcher<? super T> second, Matcher<? super T> third) {
  List<Matcher<? super T>> matchers = new ArrayList<Matcher<? super T>>(3);
  matchers.add(first);
  matchers.add(second);
  matchers.add(third);
  return allOf(matchers);
}

代码示例来源:origin: junit-team/junit4

@Factory
  public static <T extends Throwable> Matcher<T> hasMessage(final Matcher<String> matcher) {
    return new ThrowableMessageMatcher<T>(matcher);
  }
}

相关文章

Factory类方法