Java 类org.hamcrest.core.AnyOf 实例源码

项目:retromock    文件:MockClient.java   
@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())
    );
}
项目:cortado    文件:Linker_Tests.java   
@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);
}
项目:mrgeo    文件:ModeAggregatorTest.java   
@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);

}
项目:mrgeo    文件:ModeAggregatorTest.java   
@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);

}
项目:mule-module-hamcrest    文件:PropertyMatcher.java   
@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);
}
项目:mule-module-hamcrest    文件:PropertyMatcher.java   
@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);
}
项目:pdb    文件:EngineCreateTest.java   
/**
 * 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();
    }
}
项目:dynunit    文件:ClassReflectionTest.java   
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));
}
项目:flink-spector    文件:OutputMatchers.java   
/**
 * 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));
}
项目:moxiemocks    文件:MoxieMatchers.java   
@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    文件:Detective.java   
/**
  * 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));
}
项目:moxiemocks    文件:MoxieMatchers.java   
/**
 * 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()));
}
项目:moxiemocks    文件:MoxieMatchers.java   
/**
 * 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))));
}