/** * This is useful for fluently combining matchers that must both pass. For example: * <pre> * assertThat(string, both(containsString("a")).and(containsString("b"))); * </pre> * * @deprecated Please use {@link CoreMatchers#both(Matcher)} instead. */ @Deprecated public static <T> CombinableBothMatcher<T> both(Matcher<? super T> matcher) { return CoreMatchers.both(matcher); }
/** * This is useful for fluently combining matchers that must both pass. For example: * <pre> * assertThat(string, both(containsString("a")).and(containsString("b"))); * </pre> * * @deprecated Please use {@link CoreMatchers#both(Matcher)} instead. */ @Deprecated public static <T> CombinableBothMatcher<T> both(Matcher<? super T> matcher) { return CoreMatchers.both(matcher); }
/** * This is useful for fluently combining matchers that must both pass. For example: * <pre> * assertThat(string, both(containsString("a")).and(containsString("b"))); * </pre> * * @deprecated Please use {@link CoreMatchers#both(Matcher)} instead. */ @Deprecated public static <T> CombinableBothMatcher<T> both(Matcher<? super T> matcher) { return CoreMatchers.both(matcher); }
/** * This is useful for fluently combining matchers that must both pass. For example: * <pre> * assertThat(string, both(containsString("a")).and(containsString("b"))); * </pre> * * @deprecated Please use {@link CoreMatchers#both(Matcher)} instead. */ @Deprecated public static <T> CombinableBothMatcher<T> both(Matcher<? super T> matcher) { return CoreMatchers.both(matcher); }
/** * This is useful for fluently combining matchers that must both pass. For example: * <pre> * assertThat(string, both(containsString("a")).and(containsString("b"))); * </pre> * * @deprecated Please use {@link CoreMatchers#both(Matcher)} instead. */ @Deprecated public static <T> CombinableBothMatcher<T> both(Matcher<? super T> matcher) { return CoreMatchers.both(matcher); }
/** * This is useful for fluently combining matchers that must both pass. For example: * <pre> * assertThat(string, both(containsString("a")).and(containsString("b"))); * </pre> * * @deprecated Please use {@link CoreMatchers#both(Matcher)} instead. */ @Deprecated public static <T> CombinableBothMatcher<T> both(Matcher<? super T> matcher) { return CoreMatchers.both(matcher); }
/** * Adds {@code matcher} to the list of requirements for any thrown * exception. */ // Should be able to remove this suppression in some brave new hamcrest world. @SuppressWarnings("unchecked") public void expect(final Matcher<?> matcher) { if (fMatcher == null) fMatcher = (Matcher<Object>)matcher; else fMatcher = both(fMatcher).and((Matcher<? super Object>)matcher); }
@Test public void testAssertThatBothContainsString() { assertThat("albumen", both(containsString("a")).and(containsString("b"))); }
@Test public void unsubscribeAbsentSubscriptionShouldThrowSubscriptionNotFoundException() { final UnsubscribeRequest unsubscribeRequest = new UnsubscribeRequest(1L, CONNECTION_ID); thrown.expect( both(hasMessage(equalTo("Subscription not found (id=1)"))) .and(instanceOf(SubscriptionNotFoundException.class))); subscriptionManager.unsubscribe(unsubscribeRequest); }
@Test public void resolveURIBasic() throws RequestHandlerException { RequestMap foo = new RequestMap(dummyElement); RequestMap bar = new RequestMap(dummyElement); reqMaps.putSingle("foo", foo); reqMaps.putSingle("bar", bar); when(req.getPathInfo()).thenReturn("/foo"); assertThat(RequestHandler.resolveURI(ccfg, req), both(hasItem(foo)).and(not(hasItem(bar)))); assertThat(RequestHandler.resolveURI(ccfg, req).size(), is(1)); }
@Test public void mapRequestToUnsubscribeRequestMissingSubscriptionIdFails() { final JsonRpcRequest jsonRpcRequest = parseWebSocketRpcRequest("{\"id\": 1, \"method\": \"eth_unsubscribe\", \"params\": []}"); thrown.expect(InvalidSubscriptionRequestException.class); thrown.expectCause( both(hasMessage(equalTo("Missing required json rpc parameter at index 0"))) .and(instanceOf(InvalidJsonRpcParameters.class))); mapper.mapUnsubscribeRequest(jsonRpcRequest); }
@Test public void mapRequestToLogsWithInvalidSecondParam() { final JsonRpcRequest jsonRpcRequest = parseWebSocketRpcRequest( "{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"logs\", {\"foo\": \"bar\"}]}"); thrown.expect(InvalidSubscriptionRequestException.class); thrown.expectCause( both(hasMessage(equalTo("Invalid json rpc parameter at index 1"))) .and(instanceOf(InvalidJsonRpcParameters.class))); mapper.mapSubscribeRequest(jsonRpcRequest); }
@Test public void nightPeriod() { DateTime nightPeriod = new DateTime(faker.time.forward(1, Period.night)); assertThat(nightPeriod.getHourOfDay(), is(both(greaterThanOrEqualTo(18)).and(lessThanOrEqualTo(23)))); }
@Test public void morningPeriod() { DateTime morningPeriod = new DateTime(faker.time.forward(1, Period.morning)); assertThat(morningPeriod.getHourOfDay(), is(both(greaterThanOrEqualTo(6)).and(lessThanOrEqualTo(11)))); }
@Test public void eveningPeriod() { DateTime eveningPeriod = new DateTime(faker.time.forward(1, Period.evening)); assertThat(eveningPeriod.getHourOfDay(), is(both(greaterThanOrEqualTo(17)).and(lessThanOrEqualTo(21)))); }
@Test public void mapRequestToNewHeadsWithInvalidSecondParamFails() { final JsonRpcRequest jsonRpcRequest = parseWebSocketRpcRequest( "{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"newHeads\", {\"foo\": \"bar\"}]}"); thrown.expect(InvalidSubscriptionRequestException.class); thrown.expectCause( both(hasMessage(equalTo("Invalid json rpc parameter at index 1"))) .and(instanceOf(InvalidJsonRpcParameters.class))); mapper.mapSubscribeRequest(jsonRpcRequest); }
@Test public void mapAbsentSubscriptionTypeRequestFails() { final JsonRpcRequest jsonRpcRequest = parseWebSocketRpcRequest( "{\"id\": 1, \"method\": \"eth_subscribe\", \"params\": [\"foo\"]}"); thrown.expect(InvalidSubscriptionRequestException.class); thrown.expectCause( both(hasMessage(equalTo("Invalid json rpc parameter at index 0"))) .and(instanceOf(InvalidJsonRpcParameters.class))); mapper.mapSubscribeRequest(jsonRpcRequest); }
@Test public void shouldCreateRandomContainerNameAndPort() { when(cubeDroneConfiguration.isBrowserDockerfileDirectorySet()).thenReturn(false); when(cubeDroneConfiguration.isBrowserImageSet()).thenReturn(false); when(cubeDroneConfiguration.getContainerNameStrategy()).thenReturn(ContainerNameStrategy.RANDOM); final SeleniumContainers seleniumContainers = SeleniumContainers.create("firefox", cubeDroneConfiguration); assertThat(seleniumContainers.getSeleniumContainer().getPortBindings(), hasItem(SELENIUM_RANDOM_PORT_BINDING_MATCHER)); assertThat(seleniumContainers.getSeleniumContainerName(), both(UUID_CONTAINER_NAME_MATCHER).and(startsWith("browser"))); assertThat(seleniumContainers.getVncContainerName(), both(UUID_CONTAINER_NAME_MATCHER).and(startsWith("vnc"))); assertThat(seleniumContainers.getVideoConverterContainerName(), both(UUID_CONTAINER_NAME_MATCHER).and(startsWith("flv2mp4"))); }
@Test public void testErrorHandling() throws Exception { String roadSegments = getEncodedName(MockData.ROAD_SEGMENTS); DocumentContext json = getAsJSONPath("wfs3/collections/" + roadSegments + "/items?limit=abc", 400); assertEquals("InvalidParameterValue", json.read("code")); assertThat( json.read("description"), both(containsString("COUNT")).and(containsString("abc"))); }
@Test public void putSingleBasic() { m.putSingle("foo", 0); assertThat(m.get("foo"), hasItem(0)); m.putSingle("foo", 1); assertThat(m.get("foo"), both(hasItem(1)).and(not(hasItem(0)))); }