Use new AssertJ exception assertions

This commit is contained in:
Sam Brannen
2022-05-31 14:08:28 +02:00
parent 9d324e59a0
commit 1beb7068f6
45 changed files with 554 additions and 803 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,9 +25,11 @@ import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatException;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatRuntimeException;
import static org.mockito.Mockito.mock;
/**
@@ -71,8 +73,8 @@ public class InvocableHandlerMethodTests {
@Test
public void cannotResolveArg() throws Exception {
Method method = ResolvableMethod.on(Handler.class).mockCall(c -> c.handle(0, "")).method();
assertThatExceptionOfType(MethodArgumentResolutionException.class).isThrownBy(() ->
invoke(new Handler(), method))
assertThatExceptionOfType(MethodArgumentResolutionException.class)
.isThrownBy(() -> invoke(new Handler(), method))
.withMessageContaining("Could not resolve parameter [0]");
}
@@ -125,20 +127,20 @@ public class InvocableHandlerMethodTests {
Handler handler = new Handler();
Method method = ResolvableMethod.on(Handler.class).argTypes(Throwable.class).resolveMethod();
RuntimeException runtimeException = new RuntimeException("error");
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() ->
invoke(handler, method, runtimeException))
assertThatRuntimeException()
.isThrownBy(() -> invoke(handler, method, runtimeException))
.isSameAs(runtimeException);
Error error = new Error("error");
assertThatExceptionOfType(Error.class).isThrownBy(() ->
invoke(handler, method, error))
assertThatExceptionOfType(Error.class)
.isThrownBy(() -> invoke(handler, method, error))
.isSameAs(error);
Exception exception = new Exception("error");
assertThatExceptionOfType(Exception.class).isThrownBy(() ->
invoke(handler, method, exception))
assertThatException()
.isThrownBy(() -> invoke(handler, method, exception))
.isSameAs(exception);
Throwable throwable = new Throwable("error", exception);
assertThatIllegalStateException().isThrownBy(() ->
invoke(handler, method, throwable))
assertThatIllegalStateException()
.isThrownBy(() -> invoke(handler, method, throwable))
.withCause(throwable)
.withMessageContaining("Invocation failure");
}