java类org.hamcrest.core.AnyOf的实例源码

MockClient.java 文件源码 项目:retromock 阅读 31 收藏 0 点赞 0 评论 0
@Override
public Response execute(Request request) throws IOException {
    List<Matcher<? super Request>> unmatchedRoutes = new LinkedList<>();
    for (Route route : routes) {
        if (route.requestMatcher.matches(request)) return route.response.createFrom(request);
        unmatchedRoutes.add(route.requestMatcher);
    }
    StringDescription description = new StringDescription();
    AnyOf.anyOf(unmatchedRoutes).describeTo(description);
    return new Response(
            request.getUrl(),
            404,
            "No route matched",
            Collections.<Header>emptyList(), 
            new TypedString("No matching route found. expected:\n" + description.toString())
    );
}
Linker_Tests.java 文件源码 项目:cortado 阅读 25 收藏 0 点赞 0 评论 0
@Test
public void or_returns_instanceOf_AnyOf() {
    //given
    List<Matcher<? super View>> matchers = new ArrayList<>();
    Matcher<View> matcher = new SimpleWrappingViewMatcher<>(null);
    matchers.add(matcher);

    //when
    Matcher<? super View> link = OR.link(matchers);

    //then
    assertThat(link).isInstanceOf(AnyOf.class);
}
ModeAggregatorTest.java 文件源码 项目:mrgeo 阅读 28 收藏 0 点赞 0 评论 0
@Test
@Category(UnitTest.class)
public void testDouble()
{
  double[] values = {0.21, 0.32, 0.32, 0.54};
  double nodata = Double.NaN;
  double result;
  Aggregator agg = new ModeAggregator();

  //Test normal case
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  //Test nodata cases
  values[0] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  values[1] = nodata;
  result = agg.aggregate(values, nodata);
  assertThat((double) result, AnyOf.anyOf(IsCloseTo.closeTo(0.32f, epsilon), IsCloseTo.closeTo(0.54f, epsilon)));

  values[2] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.54, result, epsilon);

  values[3] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(nodata, result, epsilon);

}
ModeAggregatorTest.java 文件源码 项目:mrgeo 阅读 24 收藏 0 点赞 0 评论 0
@Test
@Category(UnitTest.class)
public void testFloat()
{
  float[] values = {0.21f, 0.32f, 0.32f, 0.54f};
  float nodata = -9999.0f;
  float result;
  Aggregator agg = new ModeAggregator();

  //Test normal case
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  //Test nodata cases
  values[0] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.32, result, epsilon);

  values[1] = nodata;
  result = agg.aggregate(values, nodata);
  //assertEquals(0.54, result, epsilon);
  assertThat((double) result, AnyOf.anyOf(IsCloseTo.closeTo(0.32f, epsilon), IsCloseTo.closeTo(0.54f, epsilon)));

  values[2] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(0.54, result, epsilon);

  values[3] = nodata;
  result = agg.aggregate(values, nodata);
  assertEquals(nodata, result, epsilon);

}
PropertyMatcher.java 文件源码 项目:mule-module-hamcrest 阅读 29 收藏 0 点赞 0 评论 0
@Factory
public static <T> Matcher<MuleMessage> hasPropertyInAnyScope(String key) {

    List<Matcher<? super MuleMessage>> allScopeMatchers = new ArrayList<Matcher<? super MuleMessage>>(4);

    allScopeMatchers.add(new PropertyMatcher(PropertyScope.INBOUND, key, IsNull.notNullValue()));
    allScopeMatchers.add(new PropertyMatcher(PropertyScope.OUTBOUND, key, IsNull.notNullValue()));
    allScopeMatchers.add(new PropertyMatcher(PropertyScope.INVOCATION, key, IsNull.notNullValue()));
    allScopeMatchers.add(new PropertyMatcher(PropertyScope.SESSION, key, IsNull.notNullValue()));

    return new AnyOf<MuleMessage>(allScopeMatchers);
}
PropertyMatcher.java 文件源码 项目:mule-module-hamcrest 阅读 25 收藏 0 点赞 0 评论 0
@Factory
public static <T> Matcher<MuleMessage> hasPropertyInAnyScope(String key, Matcher<? super T> matcher) {
    List<Matcher<? super MuleMessage>> allScopeMatchers = new ArrayList<Matcher<? super MuleMessage>>(4);

    allScopeMatchers.add(new PropertyMatcher(PropertyScope.INBOUND, key, matcher));
    allScopeMatchers.add(new PropertyMatcher(PropertyScope.OUTBOUND, key, matcher));
    allScopeMatchers.add(new PropertyMatcher(PropertyScope.INVOCATION, key, matcher));
    allScopeMatchers.add(new PropertyMatcher(PropertyScope.SESSION, key, matcher));

    return new AnyOf<MuleMessage>(allScopeMatchers);
}
EngineCreateTest.java 文件源码 项目:pdb 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Tests the error thrown when an entity is loaded and it doesn't exist in the database.
 *
 * @throws Exception If something goes wrong with the test.
 * @since 2.1.2
 */
@Test
public void testLoadEntityTableDoesNotExist() throws Exception {
    DatabaseEngine engine = DatabaseFactory.getConnection(properties);

    // make sure that entity doesn't exist
    silentTableDrop(engine, "TEST");

    try {

        DbEntity entity = dbEntity()
                .name("TEST")
                .addColumn("COL1", INT)
                .pkFields("COL1")
                .build();

        expected.expect(DatabaseEngineException.class);
        expected.expectMessage(AnyOf.anyOf(IsEqual.equalTo("Something went wrong persisting the entity"),
                IsEqual.equalTo("Something went wrong handling statement")));
        engine.loadEntity(entity);

        // some of the databases will throw the error on loadEntity, the others only on persist
        engine.persist(entity.getName(), new EntityEntry.Builder().set("COL1", 1).build());
    } finally {
        engine.close();
    }
}
ClassReflectionTest.java 文件源码 项目:dynunit 阅读 25 收藏 0 点赞 0 评论 0
private void assertAnnotationIsAnyOf(final Annotation annotation, final Class<?>... types) {
    final List<Matcher<? super Class<?>>> matchers = new ArrayList<Matcher<? super Class<?>>>(types.length);
    for (Class<?> type : types) {
        matchers.add(typeCompatibleWith(type));
    }
    final AnyOf<Class<?>> anyAnnotation = new AnyOf<Class<?>>(matchers);
    assertThat(annotation.annotationType(), is(anyAnnotation));
}
OutputMatchers.java 文件源码 项目:flink-spector 阅读 38 收藏 0 点赞 0 评论 0
/**
 * Creates a matcher that matches if the examined object matches <b>ANY</b> of the specified matchers.
 */
@SafeVarargs
public static <T> OutputMatcher<T> anyOf(OutputMatcher<T>... matchers) {
    return OutputMatcherFactory.create(AnyOf.anyOf(matchers));
}
MoxieMatchers.java 文件源码 项目:moxiemocks 阅读 27 收藏 0 点赞 0 评论 0
@SuppressWarnings("unchecked")
private static <T> T reportOr(Object matchValuesArray, Class<T> clazz) {
    List<Matcher> matchers = MatcherSyntax.matcherListFragment(clazz, matchValuesArray);
    return (T) argThat(clazz, new AnyOf(matchers));
}
Detective.java 文件源码 项目:detective 阅读 23 收藏 0 点赞 0 评论 0
/**
  * Creates a matcher that matches if the examined object matches <b>Any</b> of the specified matchers.
  * <p></p>
  * For example:
  * <pre>assertThat("myValue", anyOf(startsWith("my"), containsString("Val")))</pre>
  */
 public static <T> Matcher<T> anyOf(Matcher<? super T>... matchers) {
   return AnyOf.anyOf(Arrays.asList(matchers));
}
MoxieMatchers.java 文件源码 项目:moxiemocks 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Matches any array.
 *
 * @param <T> element type of the array
 * @return <code>null</code>
 */
@SuppressWarnings("unchecked")
static public <T> T[] anyArray() {
    return (T[]) argThat(Object[].class, AnyOf.anyOf(new IsNull(), IsInstanceOfArray.instanceOfArray()));
}
MoxieMatchers.java 文件源码 项目:moxiemocks 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Matches any value assignable to the given class, or <code>null</code>.
 *
 * @return <code>null</code> if the given class is an object, or the primitive's default value if the given class is a primitive
 */
@SuppressWarnings("unchecked")
static public <T> T any(Class<T> clazz) {
    return (T) argThat(clazz, AnyOf.anyOf(new IsNull(), new IsInstanceOf(MoxieUtils.toNonPrimitive(clazz))));
}


问题


面经


文章

微信
公众号

扫码关注公众号