org.assertj.core.api.AbstractThrowableAssert Java Examples

The following examples show how to use org.assertj.core.api.AbstractThrowableAssert. 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: AssertableCallback.java    From brave with Apache License 2.0 6 votes vote down vote up
public AbstractThrowableAssert<?, ? extends Throwable> assertThatError() {
  awaitUninterruptably();

  if (onErrorCount.get() > 0) {
    assertThat(onErrorCount)
      .withFailMessage("onError signaled multiple times")
      .hasValueLessThan(2);

    assertThat(onSuccessCount)
      .withFailMessage("Both onSuccess and onError were signaled")
      .hasValue(0);

    return assertThat(result == NULL_SENTINEL ? null : (Throwable) result);
  } else if (onSuccessCount.get() > 0) {
    throw new AssertionError("expected onError, but received onSuccess(" + result + ")");
  }
  throw new AssertionError(); // unexpected as we only have two callbacks to handle!
}
 
Example #2
Source File: ProfilesTest.java    From liiklus with MIT License 5 votes vote down vote up
@SafeVarargs
protected final AbstractThrowableAssert<?, ? extends Throwable> assertThatAppWithProps(Set<String>... props) {
    if (lastApplicationContext != null) {
        lastApplicationContext.close();
    }

    return assertThatCode(() -> {
        var args = Stream.of(props)
                .flatMap(Collection::stream)
                .map(it -> "--" + it)
                .toArray(String[]::new);

        lastApplicationContext = Application.start(args);
    });
}
 
Example #3
Source File: JUnitPlatformDynamicIntegrationTest.java    From BlockHound with Apache License 2.0 5 votes vote down vote up
private AbstractThrowableAssert<?, ? extends Throwable> assertThatBlockingCall() {
    return Assertions.assertThatCode(() -> {
        Mono
                .fromCallable(() -> {
                    Thread.sleep(1);
                    return "";
                })
                .subscribeOn(Schedulers.parallel())
                .block();
    });
}
 
Example #4
Source File: JUnitPlatformIntegrationTest.java    From BlockHound with Apache License 2.0 5 votes vote down vote up
private AbstractThrowableAssert<?, ? extends Throwable> assertThatBlockingCall() {
    return Assertions.assertThatCode(() -> {
        Mono
                .fromCallable(() -> {
                    Thread.sleep(1);
                    return "";
                })
                .subscribeOn(Schedulers.parallel())
                .block();
    });
}
 
Example #5
Source File: ExpectedExceptionAppender.java    From centraldogma with Apache License 2.0 5 votes vote down vote up
/**
 * Adds {@code "(expected exception)"} to the log message and lower its logging level to
 * {@link Level#DEBUG} if the exception occurred from the {@code shouldRaiseThrowable} matches
 * {@code throwable} and contains {@code message}.
 */
public static AbstractThrowableAssert<?, ? extends Throwable> assertThatThrownByWithExpectedException(
        Class<?> throwable, String message, ThrowingCallable shouldRaiseThrowable) throws Exception {
    requireNonNull(throwable, "throwable");
    requireNonNull(message, "message");
    requireNonNull(shouldRaiseThrowable, "shouldRaiseThrowable");
    exceptionAndMessage.put(throwable.getName(), message);
    try {
        return assertThatThrownBy(shouldRaiseThrowable);
    } finally {
        exceptionAndMessage.remove(throwable.getName());
    }
}
 
Example #6
Source File: DeploymentTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeploymentToInactiveEnvironment() throws Exception {
    Environment inactiveEnvironment = createAndSubmitEnvironment(apolloTestClient, false);
    Service service = createAndSubmitService(apolloTestClient);
    DeployableVersion deployableVersion = createAndSubmitDeployableVersion(apolloTestClient, service);

    AbstractThrowableAssert<?, ? extends Throwable> throwableAssert = assertThatThrownBy(
            () -> createAndSubmitDeployment(apolloTestClient, inactiveEnvironment, service, deployableVersion)
    );

    throwableAssert.isInstanceOf(Exception.class);
    throwableAssert.hasMessage("Cannot deploy. Target environment is not active.");
}