1
0
mirror of synced 2026-05-22 13:23:17 +00:00

Replace try/catch with AssertJ

Replace manual try/catch/fail blocks with AssertJ calls.
This commit is contained in:
Phillip Webb
2020-09-10 12:06:07 -07:00
committed by Josh Cummings
parent d9276ed8f3
commit 910b81928f
98 changed files with 717 additions and 2122 deletions
@@ -30,7 +30,7 @@ import org.springframework.security.util.SimpleMethodInvocation;
import org.springframework.test.util.ReflectionTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests {@link ContextPropagatingRemoteInvocation} and
@@ -59,15 +59,10 @@ public class ContextPropagatingRemoteInvocationTests {
Authentication clientSideAuthentication = new UsernamePasswordAuthenticationToken("rod", "koala");
SecurityContextHolder.getContext().setAuthentication(clientSideAuthentication);
ContextPropagatingRemoteInvocation remoteInvocation = getRemoteInvocation();
try {
// Set up the wrong arguments.
remoteInvocation.setArguments(new Object[] {});
remoteInvocation.invoke(TargetObject.class.newInstance());
fail("Expected IllegalArgumentException");
}
catch (IllegalArgumentException ex) {
// expected
}
// Set up the wrong arguments.
remoteInvocation.setArguments(new Object[] {});
assertThatIllegalArgumentException()
.isThrownBy(() -> remoteInvocation.invoke(TargetObject.class.newInstance()));
assertThat(SecurityContextHolder.getContext().getAuthentication())
.withFailMessage("Authentication must be null").isNull();
}