當前位置: 首頁>>代碼示例>>Java>>正文


Java Factory類代碼示例

本文整理匯總了Java中org.hamcrest.Factory的典型用法代碼示例。如果您正苦於以下問題:Java Factory類的具體用法?Java Factory怎麽用?Java Factory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Factory類屬於org.hamcrest包,在下文中一共展示了Factory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: matches

import org.hamcrest.Factory; //導入依賴的package包/類
@Factory
@Deprecated
/**
 * Please avoid using as the hamcrest way of reporting error wraps a multi-line
 * text into a single line and makes hard to understand the problem.
 * Instead, please try to use the spock/groovy assert and {@link #containsLine(String, String)}
 */
public static Matcher<String> containsLine(final String line) {
    return new BaseMatcher<String>() {
        public boolean matches(Object o) {
            return containsLine(equalTo(line)).matches(o);
        }

        public void describeTo(Description description) {
            description.appendText("a String that contains line ").appendValue(line);
        }
    };
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:19,代碼來源:Matchers.java

示例2: hasData

import org.hamcrest.Factory; //導入依賴的package包/類
/**
 * Matches the set of entries against the given set of values. The full combinatorial of values passed in is expected in the output set.
 *
 * @param rows
 *          Rows to check for.
 * @param colFs
 *          Column families to check for.
 * @param colQs
 *          Column qualifiers to check for.
 * @param colVs
 *          Column visibilities to check for.
 * @param values
 *          Values to check for.
 * @return Hamcrest matcher.
 */
@Factory
@SuppressWarnings("unchecked")
public static Matcher<Iterable<Entry<Key,Value>>> hasData(Collection<String> rows, Collection<String> colFs, Collection<String> colQs,
    Collection<String> colVs, Collection<String> values) {
  int size = rows.size() * colFs.size() * colQs.size() * colVs.size() * values.size();
  ArrayList<Matcher<? super Iterable<Entry<Key,Value>>>> matchers = new ArrayList<>(size + 1);

  matchers.add(IsIterableWithSize.iterableWithSize(size));

  for (String row : rows) {
    for (String colF : colFs) {
      for (String colQ : colQs) {
        for (String colV : colVs) {
          for (String value : values) {
            matchers.add(hasItems(equalToRow(row, colF, colQ, colV, value)));
          }
        }
      }
    }
  }

  return allOf(matchers);
}
 
開發者ID:mit-ll,項目名稱:PACE,代碼行數:39,代碼來源:Matchers.java

示例3: equalsVertex

import org.hamcrest.Factory; //導入依賴的package包/類
/**
 * @param v The expected vertex.
 * @return A matcher that compares an actual vertex with the expected
 * vertex. Two vertices are considered equal if all their fields are equal.
 */
@Factory
public static Matcher equalsVertex(Vertex v) {
    return new TypeSafeMatcher<Vertex>() {
        @Override
        protected boolean matchesSafely(Vertex w) {
            return v.label.equals(w.label)
                && Double.doubleToLongBits(v.radius) == Double.doubleToLongBits(w.radius)
                && v.fillColor.equals(w.fillColor)
                && v.strokeWidth == w.strokeWidth
                && v.textHeight == w.textHeight
                && v.strokeColor.equals(w.strokeColor)
                && v.coordinates.equals(w.coordinates);
        }

        @Override
        public void describeTo(Description d) {
            d.appendText("Vertex equality");
        }
    };
}
 
開發者ID:gralog,項目名稱:gralog,代碼行數:26,代碼來源:StructureMatchers.java

示例4: matchesSafely

import org.hamcrest.Factory; //導入依賴的package包/類
@Factory
public static <T> Matcher<Node> cellWithValue(final Matcher<T> contentsMatcher) {
    return new TypeSafeMatcher<Node>(Cell.class) {
        @Override
        protected boolean matchesSafely(Node item) {
            return contentsMatcher.matches(((Cell) item).getItem());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText(Cell.class.getSimpleName())
                    .appendText(" ")
                    .appendText("with value")
                    .appendDescriptionOf(contentsMatcher);
        }
    };
}
 
開發者ID:republique-et-canton-de-geneve,項目名稱:chvote-1-0,代碼行數:18,代碼來源:AdditionalTableViewMatchers.java

示例5: describeTo

import org.hamcrest.Factory; //導入依賴的package包/類
@Factory
private static DiagnosingMatcher<Object> translateTo(HttpStatus status) {
    return new DiagnosingMatcher<Object>() {
        private static final String EXCEPTION = "EXCEPTION";

        @Override
        public void describeTo(final Description description) {
            description.appendText("does not translate to ").appendText(status.toString());
        }

        @SuppressWarnings("unchecked")
        protected boolean matches(final Object item, final Description mismatch) {

            if (item instanceof Class) {
                if (((Class) item).getClass().isInstance(Throwable.class)) {
                    Class<? extends Throwable> type = (Class<? extends Throwable>) item;
                    try {
                        Throwable exception = type.getConstructor(String.class).newInstance(EXCEPTION);
                        Mono.just(exception).transform(ThrowableTranslator::translate).subscribe(translator -> {
                            assertThat(translator.getMessage(), is(EXCEPTION));
                            assertThat(translator.getHttpStatus(), is(status));
                        });
                    } catch (InstantiationException | IllegalAccessException |
                            InvocationTargetException | NoSuchMethodException cause) {
                        throw new AssertionError("This exception class has not constructor with a String", cause);
                    }
                    return true;
                }
            }
            mismatch.appendText(item.toString());
            return false;
        }
    };
}
 
開發者ID:LearningByExample,項目名稱:reactive-ms-example,代碼行數:35,代碼來源:ThrowableTranslatorTest.java

示例6: absentBackReferences

import org.hamcrest.Factory; //導入依賴的package包/類
@Factory
public static Matcher<Predicate> absentBackReferences(int noOfPredicateArguments)
{
    Matcher[] matchers = new Matcher[noOfPredicateArguments];
    Arrays.fill(matchers, isAbsent());
    return new ArgumentBackReferences(Absent.<TransactionContext>absent(), matchers);
}
 
開發者ID:dmfs,項目名稱:ContentPal,代碼行數:8,代碼來源:PredicateMatcher.java

示例7: ringBufferWithEvents

import org.hamcrest.Factory; //導入依賴的package包/類
@Factory
public static RingBufferEventMatcher ringBufferWithEvents(final Object... values)
{
    Matcher<?>[] valueMatchers = new Matcher[values.length];
    for (int i = 0; i < values.length; i++)
    {
        final Object value = values[i];
        valueMatchers[i] = is(value);
    }
    return new RingBufferEventMatcher(valueMatchers);
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:12,代碼來源:RingBufferEventMatcher.java

示例8: featureValueOf

import org.hamcrest.Factory; //導入依賴的package包/類
@Factory
public static Matcher<BattleModel> monsterIsAlive() {
    return new FeatureMatcher<BattleModel, Boolean>( is( true ), "monster alive", "monster alive" ) {
        @Override
        protected Boolean featureValueOf(BattleModel actual) {
            return actual.monsterAlive();
        }
    };
}
 
開發者ID:jaahay,項目名稱:harenacapsa,代碼行數:10,代碼來源:BattleModelMatchers.java

示例9: hasAttributes

import org.hamcrest.Factory; //導入依賴的package包/類
@Factory
public static Matcher<HtmlElement> hasAttributes(String... nameValues) {
    if (nameValues.length % 2 != 0) throw new RuntimeException("The last attr was missing a value");

    List<Attribute> expectedAttrs = new ArrayList<Attribute>();
    for (int i = 0; i < nameValues.length; i += 2) {
        expectedAttrs.add(new Attribute(nameValues[i], nameValues[i + 1]));
    }

    return new HasAttribute(expectedAttrs);
}
 
開發者ID:CanFactory,項目名稱:canfactory-html,代碼行數:12,代碼來源:HasAttribute.java

示例10: matches

import org.hamcrest.Factory; //導入依賴的package包/類
/**
 * A reimplementation of hamcrest's isA() but without the broken generics.
 */
@Factory
public static Matcher<Object> isA(final Class<?> type) {
    return new BaseMatcher<Object>() {
        public boolean matches(Object item) {
            return type.isInstance(item);
        }

        public void describeTo(Description description) {
            description.appendText("instanceof ").appendValue(type);
        }
    };
}
 
開發者ID:Pushjet,項目名稱:Pushjet-Android,代碼行數:16,代碼來源:Matchers.java

示例11: assetsWithIds

import org.hamcrest.Factory; //導入依賴的package包/類
@Factory
public static Collection<Matcher<? super Asset>> assetsWithIds(Asset... assets) {
    ArrayList<Matcher<? super Asset>> matchers = new ArrayList<>();
    for (Asset asset : assets) {
        matchers.add(hasId(asset));
    }
    return matchers;
}
 
開發者ID:WASdev,項目名稱:tool.lars,代碼行數:9,代碼來源:ServerAssetByIdMatcher.java

示例12: reflectionEquals

import org.hamcrest.Factory; //導入依賴的package包/類
@Factory
public static <T> Matcher<T> reflectionEquals(T equalsTo) {
    return new ReflectionEqualsMatcher<T>(equalsTo);
}
 
開發者ID:lxxlxx888,項目名稱:Reer,代碼行數:5,代碼來源:Matchers.java

示例13: closeTo

import org.hamcrest.Factory; //導入依賴的package包/類
@Factory
public static Matcher<AspectRatio> closeTo(AspectRatio ratio) {
    return new AspectRatioIsCloseTo(ratio);
}
 
開發者ID:vshkl,項目名稱:PXLSRT,代碼行數:5,代碼來源:AspectRatioIsCloseTo.java

示例14: closeToOrInverse

import org.hamcrest.Factory; //導入依賴的package包/類
@Factory
public static Matcher<AspectRatio> closeToOrInverse(AspectRatio ratio) {
    return either(closeTo(ratio)).or(closeTo(ratio.inverse()));
}
 
開發者ID:vshkl,項目名稱:PXLSRT,代碼行數:5,代碼來源:AspectRatioIsCloseTo.java

示例15: matchesSafely

import org.hamcrest.Factory; //導入依賴的package包/類
/**
 * Gets a hamcrest matcher that tests whether two Ini objects are equal.
 *
 * @param expectedValue
 *          The expected value to core against.
 * @return Method safe matcher that will core field equality.
 */
@Factory
public static TypeSafeMatcher<Ini> equalTo(final Ini expectedValue) {
  return new TypeSafeMatcher<Ini>() {
    @Override
    protected boolean matchesSafely(Ini actualValue) {
      if (expectedValue.size() != actualValue.size()) {
        return false;
      }

      for (Section expectedSection : expectedValue.values()) {
        Section actualSection = actualValue.get(expectedSection.getName());
        if (actualSection == null) {
          return false;
        }

        if (expectedSection.size() != actualSection.size()) {
          return false;
        }

        for (Entry<String,String> expectedEntry : expectedSection.entrySet()) {
          if (!actualSection.containsKey(expectedEntry.getKey())) {
            return false;
          }

          String actual = actualSection.get(expectedEntry.getKey());
          String expected = expectedEntry.getValue();
          if ((actual == null && expected != null) || (actual != null && !actual.equals(expected))) {
            return false;
          }

        }
      }

      return true;
    }

    @Override
    public void describeTo(Description description) {
      description.appendValue(expectedValue);
    }
  };
}
 
開發者ID:mit-ll,項目名稱:PACE,代碼行數:50,代碼來源:Matchers.java


注:本文中的org.hamcrest.Factory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。