public static Matcher<View> componentHost() { return componentHost(any(ComponentHost.class)); }
@Override public ResultValidator<T> expectScheduledDeadlineOfType(Instant scheduledTime, Class<?> deadlineType) { return expectScheduledDeadlineMatching(scheduledTime, messageWithPayload(any(deadlineType))); }
@Override public ResultValidator<T> expectScheduledDeadlineOfType(Duration duration, Class<?> deadlineType) { return expectScheduledDeadlineMatching(duration, messageWithPayload(any(deadlineType))); }
@Override public FixtureExecutionResult expectScheduledEventOfType(Duration duration, Class<?> eventType) { return expectScheduledEventMatching(duration, messageWithPayload(any(eventType))); }
@Override public FixtureExecutionResult expectScheduledEventOfType(Instant scheduledTime, Class<?> eventType) { return expectScheduledEventMatching(scheduledTime, messageWithPayload(any(eventType))); }
@Override public FixtureExecutionResult expectScheduledDeadlineOfType(Instant scheduledTime, Class<?> deadlineType) { return expectScheduledDeadlineMatching(scheduledTime, messageWithPayload(any(deadlineType))); }
@Override public FixtureExecutionResult expectScheduledDeadlineOfType(Duration duration, Class<?> deadlineType) { return expectScheduledDeadlineMatching(duration, messageWithPayload(any(deadlineType))); }
@Test public void processNextBatchShouldCloseConnectionOnFatalAuthenticationError() { BoltConnection connection = newConnection(); connection.enqueue( machine -> { throw new BoltConnectionAuthFatality( "auth failure", new RuntimeException( "inner error" ) ); } ); connection.processNextBatch(); verify( stateMachine ).close(); logProvider.assertNone( AssertableLogProvider.inLog( containsString( BoltServer.class.getPackage().getName() ) ).warn( any( String.class ) ) ); }
@Test public void testWithBoundService() throws TimeoutException { // Create the service Intent. Intent serviceIntent = new Intent(getApplicationContext(), LocalService.class); // Data can be passed to the service via the Intent. serviceIntent.putExtra(LocalService.SEED_KEY, 42L); // Bind the service and grab a reference to the binder. IBinder binder = mServiceRule.bindService(serviceIntent); // Get the reference to the service, or you can call public methods on the binder directly. LocalService service = ((LocalService.LocalBinder) binder).getService(); // Verify that the service is working correctly. assertThat(service.getRandomInt(), is(any(Integer.class))); } }
@Test @SuppressWarnings("unchecked") public void shouldPrintResultsForListOrShowCommands() { assertRunListCommand( "topics", Matchers.hasItems( Matchers.contains( equalTo(orderDataProvider.topicName()), equalTo("true"), equalTo("1"), equalTo("1"), any(String.class), any(String.class)))); assertRunListCommand( "registered topics", hasItems( new TestResult.Builder() .addRow(orderDataProvider.kstreamName(), orderDataProvider.topicName(), "JSON") .addRow(COMMANDS_KSQL_TOPIC_NAME, commandTopicName, "JSON") .build() ) ); assertRunListCommand( "streams", contains( new TestResult(orderDataProvider.kstreamName(), orderDataProvider.topicName(), "JSON"))); assertRunListCommand("tables", is(EMPTY_RESULT)); assertRunListCommand("queries", is(EMPTY_RESULT)); }
@Test public void checkTokenKeyReturnETag() throws Exception { mockMvc.perform( get("/token_key") .with(new SetServerNameRequestPostProcessor(testZone.getSubdomain() + ".localhost")) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(header().string("ETag", any(String.class))) .andReturn(); }
@Test public void checkTokenKeysReturnETag() throws Exception { mockMvc.perform( get("/token_keys") .with(new SetServerNameRequestPostProcessor(testZone.getSubdomain() + ".localhost")) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(header().string("ETag", any(String.class))) .andReturn(); }
@Test public void valueInjected() throws Exception { interceptable.initialise(); verify(injector).inject(value); if (connectionProvider.isPresent()) { verify(injector).inject(connectionProvider.get()); } else { verify(injector, never()).inject(any(ConnectionProvider.class)); } }
@Test public void hasExpirationDate_() throws Exception { Matcher<Long> anyMatcher = any(Long.class); assertThat(message, not(hasExpirationDate(anyMatcher))); Date expirationDate = new Date(System.currentTimeMillis() + 10000); message = MessageBuilder.fromMessage(message).setExpirationDate(expirationDate).build(); assertThat(message, hasExpirationDate(expirationDate)); assertThat(message, hasExpirationDate(not(is((System.currentTimeMillis()))))); }
/** * A matcher for any property change. * * @return {@code true} if any property can be matched; {@code false} otherwise */ public static Matcher<PropertyChangeEvent> anyProperty() { return any(PropertyChangeEvent.class); }
@Test @DirtiesContext public void checkFlow() throws Exception { this.requests.subscribe(handlerExpecting(any(Message.class))); MockHttpServletRequest request = new MockHttpServletRequest(); request.setMethod("GET"); request.addHeader("Accept", "application/my-serialized"); request.setParameter("foo", "bar"); MockHttpServletResponse response = new MockHttpServletResponse(); List<HttpMessageConverter<?>> converters = new ArrayList<>(); SerializingHttpMessageConverter serializingHttpMessageConverter = new SerializingHttpMessageConverter(); serializingHttpMessageConverter.setSupportedMediaTypes( Collections.singletonList(new MediaType("application", "my-serialized"))); converters.add(serializingHttpMessageConverter); this.gateway.setMessageConverters(converters); this.gateway.afterPropertiesSet(); this.gateway.start(); this.gateway.handleRequest(request, response); assertThat(response.getStatus(), is(HttpServletResponse.SC_OK)); assertEquals(response.getContentType(), "application/my-serialized"); }
@Test public void hasNodeCanBeCombinedWithNot() throws Exception { // GIVEN MockNode node = new MockNode("test"); // WHEN node.addNode("subnode"); // THEN HamcrestTestUtil.assertMismatchDescription(node, not(hasNode("other-subnode")), true, equalTo("not a child node named 'other-subnode'"), any(String.class /*TODO: better mismatch descriptions*/)); HamcrestTestUtil.assertMismatchDescription(node, not(hasNode("subnode")), false, equalTo("not a child node named 'subnode'"), any(String.class /*TODO: better mismatch descriptions*/)); }
public static Matcher<AssertingPeriodicReporter> hasReportedNodes(final String... paths) { final List<Matcher<? super AssertingPeriodicReporter>> matchers = new ArrayList<Matcher<? super AssertingPeriodicReporter>>(); for (final String path : paths) { matchers.add(hasReports(typesafeHasEntry(any(Long.class), equalTo(path)), whatever())); } return allOf(matchers); }
@Test public void testHasNode() throws Exception { // GIVEN MockNode node = new MockNode("test"); // WHEN node.addNode("subnode"); // THEN assertThat(node, hasNode("subnode")); HamcrestTestUtil.assertMismatchDescription(node, hasNode("subnode"), true, equalTo("a child node named 'subnode'"), any(String.class /*TODO: better mismatch descriptions*/)); }