@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()) ); }
@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); }
@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); }
@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); }
@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); }
@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); }
/** * 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(); } }
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)); }
/** * 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)); }
@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)); }
/** * 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)); }
/** * 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())); }
/** * 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)))); }