Java Code Examples for org.assertj.core.api.ThrowableAssertAlternative#satisfies()

The following examples show how to use org.assertj.core.api.ThrowableAssertAlternative#satisfies() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ThingsConditionalHeadersValidatorTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void assertThrowingNotModifiedWhenSelectedFieldDoesNotContainPolicy() {
    final String ifNoneMatchHeaderValue = "\"rev:1\"";
    final EntityTag actualEntityTag = EntityTag.fromString("\"rev:1\"");
    final String expectedMessage =
            format(IF_NONE_MATCH_NOT_MODIFIED_MESSAGE_PATTERN, ifNoneMatchHeaderValue, actualEntityTag);

    final RetrieveThing retrieveThing = createRetrieveThingCommand(ifNoneMatchHeaderValue, "_revision");

    final ThrowableAssertAlternative<ThingPreconditionNotModifiedException> assertion =
            assertThatExceptionOfType(ThingPreconditionNotModifiedException.class)
                    .isThrownBy(() -> SUT.checkConditionalHeaders(retrieveThing, actualEntityTag))
                    .withMessage(expectedMessage);

    assertion.satisfies(exception -> assertETagHeaderInDre(exception, actualEntityTag));
}
 
Example 2
Source File: ThingsConditionalHeadersValidatorTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private void assertPreconditionFailed(final String ifMatchHeaderValue,
        final String ifNoneMatchHeaderValue, @Nullable final EntityTag actualEntityTag,
        final Category commandCategory, final String expectedMessage) {
    final Command commandMock =
            createCommandMock(commandCategory, ifMatchHeaderValue, ifNoneMatchHeaderValue);

    final ThrowableAssertAlternative<ThingPreconditionFailedException> assertion =
            assertThatExceptionOfType(ThingPreconditionFailedException.class)
                    .isThrownBy(() -> SUT.checkConditionalHeaders(commandMock, actualEntityTag))
                    .withMessage(expectedMessage);

    if (actualEntityTag == null) {
        assertion.satisfies(exception -> assertThat(exception.getDittoHeaders().getETag()).isNotPresent());
    } else {
        assertion.satisfies(exception -> assertETagHeaderInDre(exception, actualEntityTag));
    }
}
 
Example 3
Source File: ThingsConditionalHeadersValidatorTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private void assertNotModified(final String ifMatchHeaderValue,
        final String ifNoneMatchHeaderValue, @Nullable final EntityTag actualEntityTag,
        final String expectedMessage) {
    final Command commandMock =
            createCommandMock(QUERY, ifMatchHeaderValue, ifNoneMatchHeaderValue);

    final ThrowableAssertAlternative<ThingPreconditionNotModifiedException> assertion =
            assertThatExceptionOfType(ThingPreconditionNotModifiedException.class)
                    .isThrownBy(() -> SUT.checkConditionalHeaders(commandMock, actualEntityTag))
                    .withMessage(expectedMessage);

    if (actualEntityTag == null) {
        assertion.satisfies(exception -> assertThat(exception.getDittoHeaders().getETag()).isNotPresent());
    } else {
        assertion.satisfies(exception -> assertETagHeaderInDre(exception, actualEntityTag));
    }
}
 
Example 4
Source File: PoliciesConditionalHeadersValidatorTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private void assertPreconditionFailed(final String ifMatchHeaderValue,
        final String ifNoneMatchHeaderValue, @Nullable final EntityTag actualEntityTag,
        final Category commandCategory, final String expectedMessage) {
    final Command commandMock =
            createCommandMock(commandCategory, ifMatchHeaderValue, ifNoneMatchHeaderValue, null);

    final ThrowableAssertAlternative<PolicyPreconditionFailedException> assertion =
            assertThatExceptionOfType(PolicyPreconditionFailedException.class)
                    .isThrownBy(() -> SUT.checkConditionalHeaders(commandMock, actualEntityTag))
                    .withMessage(expectedMessage);

    if (actualEntityTag == null) {
        assertion.satisfies(exception -> assertThat(exception.getDittoHeaders().getETag()).isNotPresent());
    } else {
        assertion.satisfies(exception -> assertETagHeaderInDre(exception, actualEntityTag));
    }
}
 
Example 5
Source File: PoliciesConditionalHeadersValidatorTest.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
private void assertNotModified(final String ifMatchHeaderValue,
        final String ifNoneMatchHeaderValue, @Nullable final EntityTag actualEntityTag,
        final String expectedMessage, final @Nullable JsonObject selectedFields) {
    final Command commandMock =
            createCommandMock(QUERY, ifMatchHeaderValue, ifNoneMatchHeaderValue, selectedFields);

    final ThrowableAssertAlternative<PolicyPreconditionNotModifiedException> assertion =
            assertThatExceptionOfType(PolicyPreconditionNotModifiedException.class)
                    .isThrownBy(() -> SUT.checkConditionalHeaders(commandMock, actualEntityTag))
                    .withMessage(expectedMessage);

    if (actualEntityTag == null) {
        assertion.satisfies(exception -> assertThat(exception.getDittoHeaders().getETag()).isNotPresent());
    } else {
        assertion.satisfies(exception -> assertETagHeaderInDre(exception, actualEntityTag));
    }
}