Replace ExpectedException @Rules with AssertJ
Replace JUnit ExpectedException @Rules with AssertJ calls.
This commit is contained in:
committed by
Josh Cummings
parent
910b81928f
commit
20baa7d409
+4
-32
@@ -30,14 +30,8 @@ import javax.naming.directory.SearchControls;
|
||||
import javax.naming.directory.SearchResult;
|
||||
|
||||
import org.apache.directory.shared.ldap.util.EmptyEnumeration;
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import org.springframework.dao.IncorrectResultSizeDataAccessException;
|
||||
@@ -71,9 +65,6 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
|
||||
public static final String NON_EXISTING_LDAP_PROVIDER = "ldap://192.168.1.201/";
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
ActiveDirectoryLdapAuthenticationProvider provider;
|
||||
|
||||
UsernamePasswordAuthenticationToken joe = new UsernamePasswordAuthenticationToken("joe", "password");
|
||||
@@ -245,29 +236,10 @@ public class ActiveDirectoryLdapAuthenticationProviderTests {
|
||||
this.provider.contextFactory = createContextFactoryThrowing(
|
||||
new AuthenticationException(msg + dataCode + ", xxxx]"));
|
||||
this.provider.setConvertSubErrorCodesToExceptions(true);
|
||||
this.thrown.expect(BadCredentialsException.class);
|
||||
this.thrown.expect(new BaseMatcher<BadCredentialsException>() {
|
||||
private Matcher<Object> causeInstance = CoreMatchers
|
||||
.instanceOf(ActiveDirectoryAuthenticationException.class);
|
||||
|
||||
private Matcher<String> causeDataCode = CoreMatchers.equalTo(dataCode);
|
||||
|
||||
@Override
|
||||
public boolean matches(Object that) {
|
||||
Throwable t = (Throwable) that;
|
||||
ActiveDirectoryAuthenticationException cause = (ActiveDirectoryAuthenticationException) t.getCause();
|
||||
return this.causeInstance.matches(cause) && this.causeDataCode.matches(cause.getDataCode());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void describeTo(Description desc) {
|
||||
desc.appendText("getCause() ");
|
||||
this.causeInstance.describeTo(desc);
|
||||
desc.appendText("getCause().getDataCode() ");
|
||||
this.causeDataCode.describeTo(desc);
|
||||
}
|
||||
});
|
||||
this.provider.authenticate(this.joe);
|
||||
assertThatExceptionOfType(BadCredentialsException.class).isThrownBy(() -> this.provider.authenticate(this.joe))
|
||||
.withCauseInstanceOf(ActiveDirectoryAuthenticationException.class)
|
||||
.satisfies((ex) -> assertThat(((ActiveDirectoryAuthenticationException) ex.getCause()).getDataCode())
|
||||
.isEqualTo(dataCode));
|
||||
}
|
||||
|
||||
@Test(expected = CredentialsExpiredException.class)
|
||||
|
||||
Reference in New Issue
Block a user