Replace try/catch with AssertJ
Replace manual try/catch/fail blocks with AssertJ calls.
This commit is contained in:
committed by
Josh Cummings
parent
d9276ed8f3
commit
910b81928f
+4
-10
@@ -29,8 +29,7 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.security.saml2.provider.service.authentication.Saml2AuthenticationException;
|
||||
import org.springframework.security.saml2.provider.service.registration.RelyingPartyRegistrationRepository;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
@@ -85,14 +84,9 @@ public class Saml2WebSsoAuthenticationFilterTests {
|
||||
this.filter = new Saml2WebSsoAuthenticationFilter(this.repository, "/some/other/path/{registrationId}");
|
||||
this.request.setPathInfo("/some/other/path/non-existent-id");
|
||||
this.request.setParameter("SAMLResponse", "response");
|
||||
try {
|
||||
this.filter.attemptAuthentication(this.request, this.response);
|
||||
failBecauseExceptionWasNotThrown(Saml2AuthenticationException.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
assertThat(ex).isInstanceOf(Saml2AuthenticationException.class);
|
||||
assertThat(ex.getMessage()).isEqualTo("No relying party registration found");
|
||||
}
|
||||
assertThatExceptionOfType(Saml2AuthenticationException.class)
|
||||
.isThrownBy(() -> this.filter.attemptAuthentication(this.request, this.response))
|
||||
.withMessage("No relying party registration found");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user