/** * Evaluates to true only if ALL of the passed in matchers evaluate to true. * @param matchers the matchers */ @SafeVarargs public final void allOf(Matcher<? super T>... matchers) { verifyUsingMatcher(CoreMatchers.allOf(matchers)); }
private Matcher<Throwable> allOfTheMatchers() { if (matchers.size() == 1) { return cast(matchers.get(0)); } return allOf(castedMatchers()); }
private Matcher<Throwable> allOfTheMatchers() { if (fMatchers.size() == 1) { return cast(fMatchers.get(0)); } return allOf(castedMatchers()); }
private synchronized void doTest() { if (!doTest) { return; } assertThat(logs, hasItem(allOf( containsString(" has been blocked for "), containsString(" time limit is " + maxExecuteTimeUnit.toMillis(maxExecuteTime) + " ms"), containsString("Thread[" + poolName + "-")) )); } }
@Test public void serializerSnapshotIsSuccessfullyRead() { TypeSerializerSnapshot<ElementT> snapshot = snapshotUnderTest(); assertThat(snapshot, allOf( notNullValue(), instanceOf(TypeSerializerSnapshot.class) )); }
private Matcher<String> messageMatcher( @Nonnull String message ) { return allOf( startsWith( "[AsyncLog @ " ), endsWith( "] " + message ) ); } }
@Test public void testPrintHelpWithMissingParams() { RequiredParameters required = new RequiredParameters(); String helpText = required.getHelp(Arrays.asList("param1", "param2", "paramN")); Assert.assertThat(helpText, CoreMatchers.allOf( containsString("Missing arguments for:"), containsString("param1 "), containsString("param2 "), containsString("paramN "))); } }
@SuppressWarnings("deprecation") @Test public void movingForward() throws IOException { TypeSerializerSnapshot<ElementT> previousSnapshot = snapshotUnderTest(); TypeSerializer<ElementT> restoredSerializer = previousSnapshot.restoreSerializer(); TypeSerializerSnapshot<ElementT> nextSnapshot = restoredSerializer.snapshotConfiguration(); assertThat(nextSnapshot, instanceOf(testSpecification.snapshotClass)); TypeSerializerSnapshot<ElementT> nextSnapshotDeserialized = writeAndThenReadTheSnapshot(restoredSerializer, nextSnapshot); assertThat(nextSnapshotDeserialized, allOf( notNullValue(), not(instanceOf(TypeSerializerConfigSnapshot.class)) )); }
@Test public void maxAge() { Duration maxAge = Duration.ofDays(365); String expires = HttpHeaders.formatDate(System.currentTimeMillis() + maxAge.toMillis()); expires = expires.substring(0, expires.indexOf(":") + 1); assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge).build().toString(), allOf( startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires), endsWith(" GMT"))); assertThat(ResponseCookie.from("id", "1fWa").maxAge(maxAge.getSeconds()).build().toString(), allOf( startsWith("id=1fWa; Max-Age=31536000; Expires=" + expires), endsWith(" GMT"))); }
@Test public void shouldForceUserToCallWith() { expected.expectCause( allOf( instanceOf( IllegalArgumentException.class ), hasProperty( "message", is( "You need to call 'with(GraphDatabaseService)' on the template in order to use it" ) ) ) ); TransactionTemplate transactionTemplate = new TransactionTemplate(); transactionTemplate.execute( transaction -> null ); }
@Test public void shouldRespondWithMetadataToDiscardAll() throws Throwable { // When negotiateBoltV3(); connection.send( util.chunk( new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ), DiscardAllMessage.INSTANCE ) ); // Then Matcher<Map<? extends String,?>> entryTypeMatcher = hasEntry( is( "type" ), equalTo( "r" ) ); Matcher<Map<? extends String,?>> entryFieldsMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess( allOf( entryFieldsMatcher, hasKey( "t_first" ) ) ), msgSuccess( allOf( entryTypeMatcher, hasKey( "t_last" ), hasKey( "bookmark" ) ) ) ) ); }
@Test public void testApplyToWithMissingParameters() throws RequiredParametersException { expectedException.expect(RequiredParametersException.class); expectedException.expectMessage(CoreMatchers.allOf( containsString("Missing arguments for:"), containsString("munich "))); ParameterTool parameter = ParameterTool.fromArgs(new String[]{}); RequiredParameters required = new RequiredParameters(); required.add(new Option("munich")); required.applyTo(parameter); }
@Test public void testPrintHelpForFullySetOption() { RequiredParameters required = new RequiredParameters(); try { required.add(new Option("option").defaultValue("some").help("help").alt("o").choices("some", "options")); String helpText = required.getHelp(); Assert.assertThat(helpText, CoreMatchers.allOf( containsString("Required Parameters:"), containsString("-o, --option"), containsString("default: some"), containsString("choices: "), containsString("some"), containsString("options"))); } catch (RequiredParametersException e) { fail("Exception thrown " + e.getMessage()); } }
@Test public void shouldCloseConnectionInStreaming() throws Throwable { // Given negotiateBoltV3(); // When connection.send( util.chunk( new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ) ) ); Matcher<Map<? extends String,?>> entryFieldMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess( allOf( entryFieldMatcher, hasKey( "t_first" ) ) ) ) ); // you shall be in the streaming state now connection.send( util.chunk( GOODBYE_MESSAGE ) ); // Then assertThat( connection, serverImmediatelyDisconnects() ); assertThat( server, eventuallyClosesTransaction() ); }
@Test public void shouldRunSimpleStatement() throws Throwable { // When negotiateBoltV3(); connection.send( util.chunk( new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ), PullAllMessage.INSTANCE ) ); // Then Matcher<Map<? extends String,?>> entryFieldMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); Matcher<Map<? extends String,?>> entryTypeMatcher = hasEntry( is( "type" ), equalTo( "r" ) ); assertThat( connection, util.eventuallyReceives( msgSuccess( allOf( entryFieldMatcher, hasKey( "t_first" ) ) ), msgRecord( eqRecord( equalTo( longValue( 1L ) ), equalTo( longValue( 1L ) ) ) ), msgRecord( eqRecord( equalTo( longValue( 2L ) ), equalTo( longValue( 4L ) ) ) ), msgRecord( eqRecord( equalTo( longValue( 3L ) ), equalTo( longValue( 9L ) ) ) ), msgSuccess( allOf( entryTypeMatcher, hasKey( "t_last" ), hasKey( "bookmark" ) ) ) ) ); }
@Test public void shouldCloseConnectionInTxStreaming() throws Throwable { // Given negotiateBoltV3(); // When connection.send( util.chunk( new BeginMessage(), new RunMessage( "UNWIND [1,2,3] AS a RETURN a, a * a AS a_squared" ) ) ); Matcher<Map<? extends String,?>> entryFieldMatcher = hasEntry( is( "fields" ), equalTo( asList( "a", "a_squared" ) ) ); assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess( allOf( entryFieldMatcher, hasKey( "t_first" ) ) ) ) ); // you shall be in the tx_streaming state now connection.send( util.chunk( GOODBYE_MESSAGE ) ); // Then assertThat( connection, serverImmediatelyDisconnects() ); assertThat( server, eventuallyClosesTransaction() ); }
allOf(startsWith("<MyBean"), endsWith("><string>foo</string></MyBean>")));
@Test public void shouldNegotiateProtocolV3() throws Exception { connection.connect( address ).send( util.acceptedVersions( 3, 0, 0, 0 ) ).send( util.chunk( new HelloMessage( map( "user_agent", USER_AGENT ) ) ) ); assertThat( connection, eventuallyReceives( new byte[]{0, 0, 0, 3} ) ); assertThat( connection, util.eventuallyReceives( msgSuccess( allOf( hasKey( "server" ), hasKey( "connection_id" ) ) ) ) ); }
@Test public void shouldReturnUpdatedBookmarkAfterAutoCommitTransaction() throws Throwable { negotiateBoltV3(); // bookmark is expected to advance once the auto-commit transaction is committed long lastClosedTransactionId = getLastClosedTransactionId(); String expectedBookmark = new Bookmark( lastClosedTransactionId + 1 ).toString(); connection.send( util.chunk( new RunMessage( "CREATE ()" ), PullAllMessage.INSTANCE ) ); assertThat( connection, util.eventuallyReceives( msgSuccess(), msgSuccess( allOf( hasEntry( "bookmark", expectedBookmark ) ) ) ) ); }