diff --git a/core/build.gradle b/core/build.gradle index 5b5b03d0e..17dcc002c 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -38,13 +38,13 @@ dependencies { exclude group: 'org.assertj' } testImplementation platform('org.junit:junit-bom') - testImplementation "org.junit.vintage:junit-vintage-engine" + testImplementation "org.junit.jupiter:junit-jupiter-api" + testImplementation "org.junit.jupiter:junit-jupiter-engine" testRuntimeOnly("org.junit.platform:junit-platform-launcher") - - testImplementation "junit:junit" testImplementation "commons-lang:commons-lang" testImplementation "gsbase:gsbase" testImplementation "org.mockito:mockito-core" + testImplementation "org.mockito:mockito-junit-jupiter:4.11.0" testImplementation "org.springframework:spring-test" testImplementation "org.assertj:assertj-core" testImplementation "com.unboundid:unboundid-ldapsdk" @@ -60,6 +60,7 @@ compileTestJava { test { jvmArgs '--add-exports', 'java.naming/com.sun.jndi.ldap=ALL-UNNAMED' + useJUnitPlatform() } checkFormatMain { diff --git a/core/src/test/java/org/springframework/ldap/NamingExceptionTests.java b/core/src/test/java/org/springframework/ldap/NamingExceptionTests.java index ff231a1b3..fba3e0dd3 100644 --- a/core/src/test/java/org/springframework/ldap/NamingExceptionTests.java +++ b/core/src/test/java/org/springframework/ldap/NamingExceptionTests.java @@ -24,7 +24,7 @@ import javax.naming.directory.InitialDirContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/aot/hint/LdapCoreRuntimeHintsTests.java b/core/src/test/java/org/springframework/ldap/aot/hint/LdapCoreRuntimeHintsTests.java index 4ebbf12f2..05072cbc6 100644 --- a/core/src/test/java/org/springframework/ldap/aot/hint/LdapCoreRuntimeHintsTests.java +++ b/core/src/test/java/org/springframework/ldap/aot/hint/LdapCoreRuntimeHintsTests.java @@ -22,8 +22,8 @@ import javax.naming.ldap.SortResponseControl; import javax.net.ssl.SSLSocketFactory; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.aot.hint.MemberCategory; import org.springframework.aot.hint.RuntimeHints; @@ -44,7 +44,7 @@ public class LdapCoreRuntimeHintsTests { private final RuntimeHints hints = new RuntimeHints(); - @Before + @BeforeEach public void setup() { SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories") .load(RuntimeHintsRegistrar.class) diff --git a/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTests.java b/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTests.java index a46236815..5e5f54b87 100644 --- a/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTests.java +++ b/core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTests.java @@ -16,8 +16,8 @@ package org.springframework.ldap.authentication; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.AuthenticationSource; @@ -36,7 +36,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTests { private AuthenticationSource authenticationSourceMock; - @Before + @BeforeEach public void setUp() throws Exception { this.authenticationSourceMock = mock(AuthenticationSource.class); this.tested = new DefaultValuesAuthenticationSourceDecorator(); diff --git a/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTests.java b/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTests.java index a528d91e0..10dd308ef 100644 --- a/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTests.java +++ b/core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTests.java @@ -28,7 +28,7 @@ import org.apache.commons.pool.impl.GenericKeyedObjectPool; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.beans.BeansException; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -97,19 +97,22 @@ public void verifyThatAnonymousReadOnlyContextWillNotBeWrappedInProxy() { assertThat(Boolean.TRUE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly")); } - @Test(expected = BeansException.class) + @Test public void verifyThatAnonymousReadOnlyAndTransactionalThrowsException() { - new ClassPathXmlApplicationContext("/ldap-namespace-config-anonymous-read-only-and-transactions.xml"); + assertThatExceptionOfType(BeansException.class).isThrownBy(() -> new ClassPathXmlApplicationContext( + "/ldap-namespace-config-anonymous-read-only-and-transactions.xml")); } - @Test(expected = BeansException.class) + @Test public void verifyThatMissingUsernameThrowsException() { - new ClassPathXmlApplicationContext("/ldap-namespace-config-missing-username.xml"); + assertThatExceptionOfType(BeansException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext("/ldap-namespace-config-missing-username.xml")); } - @Test(expected = BeansException.class) + @Test public void verifyThatMissingPasswordThrowsException() { - new ClassPathXmlApplicationContext("/ldap-namespace-config-missing-password.xml"); + assertThatExceptionOfType(BeansException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext("/ldap-namespace-config-missing-password.xml")); } @Test @@ -366,9 +369,10 @@ public void verifyParsePoolingValidationSet() { assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue(); } - @Test(expected = BeansException.class) + @Test public void verifyParseWithPoolingAndNativePoolingWillFail() { - new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-with-native.xml"); + assertThatExceptionOfType(BeansException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-with-native.xml")); } @Test @@ -494,14 +498,16 @@ public void verifyParsePool2ValidationSet() { assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue(); } - @Test(expected = BeansException.class) + @Test public void verifyParseWithPool2AndNativePoolingWillFail() { - new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-with-native.xml"); + assertThatExceptionOfType(BeansException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-with-native.xml")); } - @Test(expected = BeansException.class) + @Test public void verifyParseWithPool1AndPool2WillFail() { - new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-with-pool1.xml"); + assertThatExceptionOfType(BeansException.class) + .isThrownBy(() -> new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-with-pool1.xml")); } @Test diff --git a/core/src/test/java/org/springframework/ldap/control/PagedResultTests.java b/core/src/test/java/org/springframework/ldap/control/PagedResultTests.java index 86766f4ac..811f68f87 100644 --- a/core/src/test/java/org/springframework/ldap/control/PagedResultTests.java +++ b/core/src/test/java/org/springframework/ldap/control/PagedResultTests.java @@ -22,7 +22,7 @@ import javax.naming.ldap.PagedResultsControl; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * Unit tests for the PagedResult class. {@link PagedResultsControl} diff --git a/core/src/test/java/org/springframework/ldap/control/PagedResultsCookieTests.java b/core/src/test/java/org/springframework/ldap/control/PagedResultsCookieTests.java index ef9b19cde..03f4cc822 100644 --- a/core/src/test/java/org/springframework/ldap/control/PagedResultsCookieTests.java +++ b/core/src/test/java/org/springframework/ldap/control/PagedResultsCookieTests.java @@ -17,7 +17,7 @@ package org.springframework.ldap.control; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class PagedResultsCookieTests { diff --git a/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTests.java b/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTests.java index 7bad249f8..74fe5857d 100644 --- a/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTests.java +++ b/core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTests.java @@ -27,9 +27,9 @@ import com.sun.jndi.ldap.BerDecoder; import com.sun.jndi.ldap.BerEncoder; import com.sun.jndi.ldap.ctl.DirSyncResponseControl; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; @@ -41,7 +41,7 @@ public class PagedResultsDirContextProcessorTests { private PagedResultsDirContextProcessor tested; - @Before + @BeforeEach public void setUp() throws Exception { this.tested = new PagedResultsDirContextProcessor(20); @@ -50,7 +50,7 @@ public void setUp() throws Exception { this.ldapContextMock = mock(LdapContext.class); } - @After + @AfterEach public void tearDown() throws Exception { this.tested = null; diff --git a/core/src/test/java/org/springframework/ldap/control/RequestControlDirContextProcessorTests.java b/core/src/test/java/org/springframework/ldap/control/RequestControlDirContextProcessorTests.java index d4c6a1b83..de245284f 100644 --- a/core/src/test/java/org/springframework/ldap/control/RequestControlDirContextProcessorTests.java +++ b/core/src/test/java/org/springframework/ldap/control/RequestControlDirContextProcessorTests.java @@ -22,10 +22,11 @@ import javax.naming.ldap.LdapContext; import javax.naming.ldap.SortControl; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.mock; import static org.mockito.BDDMockito.verify; @@ -42,7 +43,7 @@ public class RequestControlDirContextProcessorTests { private DirContext dirContextMock; - @Before + @BeforeEach public void setUp() throws Exception { // Create requestControl mock this.requestControlMock = mock(Control.class); @@ -68,7 +69,7 @@ public void postProcess(DirContext ctx) throws NamingException { }; } - @After + @AfterEach public void tearDown() throws Exception { this.requestControlMock = null; this.requestControl2Mock = null; @@ -125,9 +126,10 @@ public void testPreProcessWithNullControlsShouldAdd() throws NamingException { verify(this.ldapContextMock).setRequestControls(new Control[] { this.requestControlMock }); } - @Test(expected = IllegalArgumentException.class) - public void testPreProcessWhenNotLdapContextShouldFail() throws Exception { - this.tested.preProcess(this.dirContextMock); + @Test + public void testPreProcessWhenNotLdapContextShouldFail() { + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> this.tested.preProcess(this.dirContextMock)); } } diff --git a/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTests.java b/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTests.java index 9c6ae6ae8..b83816b96 100644 --- a/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTests.java +++ b/core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTests.java @@ -27,8 +27,8 @@ import com.sun.jndi.ldap.BerDecoder; import com.sun.jndi.ldap.BerEncoder; import com.sun.jndi.ldap.ctl.DirSyncResponseControl; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; @@ -45,7 +45,7 @@ public class SortControlDirContextProcessorTests { private SortControlDirContextProcessor tested; - @Before + @BeforeEach public void setUp() throws Exception { this.tested = new SortControlDirContextProcessor("key"); diff --git a/core/src/test/java/org/springframework/ldap/core/CollectingNameClassPairCallbackHandlerTests.java b/core/src/test/java/org/springframework/ldap/core/CollectingNameClassPairCallbackHandlerTests.java index f999df231..38f038b3e 100644 --- a/core/src/test/java/org/springframework/ldap/core/CollectingNameClassPairCallbackHandlerTests.java +++ b/core/src/test/java/org/springframework/ldap/core/CollectingNameClassPairCallbackHandlerTests.java @@ -21,8 +21,8 @@ import javax.naming.NameClassPair; import javax.naming.NamingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -34,7 +34,7 @@ public class CollectingNameClassPairCallbackHandlerTests { private NameClassPair expectedNameClassPair; - @Before + @BeforeEach public void setUp() throws Exception { this.expectedResult = new Object(); this.expectedNameClassPair = new NameClassPair(null, null); diff --git a/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTests.java b/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTests.java index 598b081ff..f436fed40 100644 --- a/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTests.java +++ b/core/src/test/java/org/springframework/ldap/core/ContextMapperCallbackHandlerTests.java @@ -19,10 +19,11 @@ import javax.naming.Binding; import javax.naming.NamingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.mock; @@ -32,15 +33,16 @@ public class ContextMapperCallbackHandlerTests { private ContextMapperCallbackHandler tested; - @Before + @BeforeEach public void setUp() throws Exception { this.mapperMock = mock(ContextMapper.class); this.tested = new ContextMapperCallbackHandler(this.mapperMock); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorWithEmptyArgument() { - new ContextMapperCallbackHandler(null); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new ContextMapperCallbackHandler(null)); } @Test @@ -54,10 +56,12 @@ public void testGetObjectFromNameClassPair() throws NamingException { assertThat(actualResult).isEqualTo(expectedResult); } - @Test(expected = ObjectRetrievalException.class) - public void testGetObjectFromNameClassPairObjectRetrievalException() throws NamingException { - Binding expectedBinding = new Binding("some name", null); - this.tested.getObjectFromNameClassPair(expectedBinding); + @Test + public void testGetObjectFromNameClassPairObjectRetrievalException() { + assertThatExceptionOfType(ObjectRetrievalException.class).isThrownBy(() -> { + Binding expectedBinding = new Binding("some name", null); + this.tested.getObjectFromNameClassPair(expectedBinding); + }); } } diff --git a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientListTests.java b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientListTests.java index 5d82e7e28..da3e6ff92 100644 --- a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientListTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientListTests.java @@ -28,8 +28,8 @@ import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.LimitExceededException; import org.springframework.ldap.PartialResultException; @@ -64,7 +64,7 @@ public class DefaultLdapClientListTests { private DefaultLdapClient tested; - @Before + @BeforeEach public void setUp() throws Exception { // Setup ContextSource mock this.contextSourceMock = mock(ContextSource.class); diff --git a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientLookupTests.java b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientLookupTests.java index 5108dff5d..4bddd0e8d 100644 --- a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientLookupTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientLookupTests.java @@ -27,8 +27,8 @@ import javax.naming.directory.SearchResult; import javax.naming.ldap.LdapContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.BDDMockito; import org.springframework.LdapDataEntry; @@ -56,7 +56,7 @@ public class DefaultLdapClientLookupTests { private LdapClient tested; - @Before + @BeforeEach public void setUp() throws Exception { this.contextSourceMock = mock(ContextSource.class); this.dirContextMock = mock(LdapContext.class); diff --git a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientRenameTests.java b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientRenameTests.java index 678061a72..2de2d22ea 100644 --- a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientRenameTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientRenameTests.java @@ -20,8 +20,8 @@ import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.NameAlreadyBoundException; import org.springframework.ldap.UncategorizedLdapException; @@ -51,7 +51,7 @@ public class DefaultLdapClientRenameTests { private LdapClient tested; - @Before + @BeforeEach public void setUp() throws Exception { // Setup ContextSource mock this.contextSourceMock = mock(ContextSource.class); diff --git a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientTests.java b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientTests.java index 82d8b52bd..063869984 100644 --- a/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DefaultLdapClientTests.java @@ -30,8 +30,8 @@ import javax.naming.ldap.LdapContext; import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatcher; import org.springframework.dao.EmptyResultDataAccessException; @@ -102,7 +102,7 @@ public class DefaultLdapClientTests { private AuthenticatedLdapEntryContextMapper authContextMapperMock; - @Before + @BeforeEach public void setUp() throws Exception { // Setup ContextSource mock diff --git a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterBugTests.java b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterBugTests.java index 32e7423fa..71ab412bd 100644 --- a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterBugTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterBugTests.java @@ -20,7 +20,7 @@ import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttributes; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.support.LdapUtils; diff --git a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTests.java b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTests.java index f8ab26f3e..a73a2830a 100644 --- a/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DirContextAdapterTests.java @@ -30,8 +30,8 @@ import javax.naming.directory.ModificationItem; import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.support.LdapUtils; @@ -53,7 +53,7 @@ public class DirContextAdapterTests { private DirContextAdapter tested; - @Before + @BeforeEach public void setUp() throws Exception { this.tested = new DirContextAdapter(); } diff --git a/core/src/test/java/org/springframework/ldap/core/DistinguishedNameEditorTests.java b/core/src/test/java/org/springframework/ldap/core/DistinguishedNameEditorTests.java index 74532b5d0..5816ad564 100644 --- a/core/src/test/java/org/springframework/ldap/core/DistinguishedNameEditorTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DistinguishedNameEditorTests.java @@ -16,8 +16,8 @@ package org.springframework.ldap.core; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -31,7 +31,7 @@ public class DistinguishedNameEditorTests { private DistinguishedNameEditor tested; - @Before + @BeforeEach public void setUp() throws Exception { this.tested = new DistinguishedNameEditor(); } diff --git a/core/src/test/java/org/springframework/ldap/core/DistinguishedNameTests.java b/core/src/test/java/org/springframework/ldap/core/DistinguishedNameTests.java index 6bc526d31..d62b8a213 100644 --- a/core/src/test/java/org/springframework/ldap/core/DistinguishedNameTests.java +++ b/core/src/test/java/org/springframework/ldap/core/DistinguishedNameTests.java @@ -23,11 +23,12 @@ import javax.naming.Name; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.BadLdapGrammarException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.fail; /** @@ -469,10 +470,12 @@ public void testGetLdapRdnForKey() throws Exception { assertThat(ldapRdn).isEqualTo(new LdapRdn("ou=Some company")); } - @Test(expected = IllegalArgumentException.class) - public void testGetLdapRdnForKeyNoMatchingKeyThrowsException() throws Exception { - DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); - dn.getLdapRdn("nosuchkey"); + @Test + public void testGetLdapRdnForKeyNoMatchingKeyThrowsException() { + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); + dn.getLdapRdn("nosuchkey"); + }); } @Test @@ -482,10 +485,12 @@ public void testGetValue() throws Exception { assertThat(value).isEqualTo("Some company"); } - @Test(expected = IllegalArgumentException.class) - public void testGetValueNoMatchingKeyThrowsException() throws Exception { - DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); - dn.getValue("nosuchkey"); + @Test + public void testGetValueNoMatchingKeyThrowsException() { + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + DistinguishedName dn = new DistinguishedName("cn=john doe, ou=Some company, c=SE"); + dn.getValue("nosuchkey"); + }); } @Test @@ -515,9 +520,10 @@ public void testParseAtSign2() { /** * Test case to verify correct parsing for issue on forums. */ - @Test(expected = BadLdapGrammarException.class) + @Test public void testParseInvalidPlus() { - new DistinguishedName("cn=te+stname@example.com"); + assertThatExceptionOfType(BadLdapGrammarException.class) + .isThrownBy(() -> new DistinguishedName("cn=te+stname@example.com")); } /** @@ -537,34 +543,42 @@ public void testAppendChained() { assertThat(tested.toString()).isEqualTo("cn=john doe,ou=company1,dc=mycompany,dc=com"); } - @Test(expected = UnsupportedOperationException.class) - public void testUnmodifiableDistinguishedNameFailsToAddRdn() throws Exception { - DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); - result.add(new LdapRdn("somekey", "somevalue")); + @Test + public void testUnmodifiableDistinguishedNameFailsToAddRdn() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> { + DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); + result.add(new LdapRdn("somekey", "somevalue")); + }); } - @Test(expected = UnsupportedOperationException.class) - public void testUnmodifiableDistinguishedNameFailsToModifyRdn() throws Exception { - DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); - LdapRdn ldapRdn = result.getLdapRdn(0); + @Test + public void testUnmodifiableDistinguishedNameFailsToModifyRdn() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> { + DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); + LdapRdn ldapRdn = result.getLdapRdn(0); - ldapRdn.addComponent(new LdapRdnComponent("somekey", "somevalue")); + ldapRdn.addComponent(new LdapRdnComponent("somekey", "somevalue")); + }); } - @Test(expected = UnsupportedOperationException.class) - public void testUnmodifiableDistinguishedNameFailsToModifyRdnComponentKey() throws Exception { - DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); - LdapRdnComponent component = result.getLdapRdn(0).getComponent(); + @Test + public void testUnmodifiableDistinguishedNameFailsToModifyRdnComponentKey() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> { + DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); + LdapRdnComponent component = result.getLdapRdn(0).getComponent(); - component.setKey("somekey"); + component.setKey("somekey"); + }); } - @Test(expected = UnsupportedOperationException.class) - public void testUnmodifiableDistinguishedNameFailsToModifyRdnComponentValue() throws Exception { - DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); - LdapRdnComponent component = result.getLdapRdn(0).getComponent(); + @Test + public void testUnmodifiableDistinguishedNameFailsToModifyRdnComponentValue() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> { + DistinguishedName result = DistinguishedName.immutableDistinguishedName("cn=john doe"); + LdapRdnComponent component = result.getLdapRdn(0).getComponent(); - component.setValue("somevalue"); + component.setValue("somevalue"); + }); } @Test diff --git a/core/src/test/java/org/springframework/ldap/core/LdapRdnComponentTests.java b/core/src/test/java/org/springframework/ldap/core/LdapRdnComponentTests.java index b1b2fc253..69bc72cc0 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapRdnComponentTests.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapRdnComponentTests.java @@ -16,7 +16,7 @@ package org.springframework.ldap.core; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/core/LdapRdnTests.java b/core/src/test/java/org/springframework/ldap/core/LdapRdnTests.java index 30beaf0d8..da2a13862 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapRdnTests.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapRdnTests.java @@ -17,11 +17,12 @@ package org.springframework.ldap.core; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.BadLdapGrammarException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Unit test for the LdapRdn class. @@ -72,9 +73,9 @@ public void testLdapRdn_parse_hexEscape() { assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=bar\\0Dfum"); } - @Test(expected = BadLdapGrammarException.class) + @Test public void testLdapRdn_parse_trailingBackslash() { - new LdapRdn("foo=bar\\"); + assertThatExceptionOfType(BadLdapGrammarException.class).isThrownBy(() -> new LdapRdn("foo=bar\\")); } @Test @@ -86,9 +87,9 @@ public void testLdapRdn_parse_spaces_escape() { assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("foo=\\ bar \\ "); } - @Test(expected = BadLdapGrammarException.class) + @Test public void testLdapRdn_parse_tooMuchTrim() { - new LdapRdn("foo=bar\\"); + assertThatExceptionOfType(BadLdapGrammarException.class).isThrownBy(() -> new LdapRdn("foo=bar\\")); } @Test @@ -100,9 +101,9 @@ public void testLdapRdn_parse_slash() { assertThat(rdn.getComponent().getLdapEncoded()).isEqualTo("ou=Clerical / Secretarial Staff"); } - @Test(expected = BadLdapGrammarException.class) + @Test public void testLdapRdn_parse_quoteInKey() { - new LdapRdn("\"umanroleid=2583"); + assertThatExceptionOfType(BadLdapGrammarException.class).isThrownBy(() -> new LdapRdn("\"umanroleid=2583")); } @Test @@ -147,16 +148,20 @@ public void testLdapRdn_Parse_MultipleComponents() { assertThat(rdn.getValue("sn")).isEqualTo("Doe"); } - @Test(expected = IllegalArgumentException.class) + @Test public void testGetValueNoKeyWithCorrectValue() { - LdapRdn tested = new LdapRdn("cn=john doe"); - tested.getValue("sn"); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + LdapRdn tested = new LdapRdn("cn=john doe"); + tested.getValue("sn"); + }); } - @Test(expected = IllegalArgumentException.class) + @Test public void testGetValueNoComponents() { - LdapRdn tested = new LdapRdn(); - tested.getValue("sn"); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + LdapRdn tested = new LdapRdn(); + tested.getValue("sn"); + }); } @Test diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTests.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTests.java index 374954796..123507c27 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTests.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateListTests.java @@ -26,8 +26,8 @@ import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.LimitExceededException; import org.springframework.ldap.PartialResultException; @@ -63,7 +63,7 @@ public class LdapTemplateListTests { private LdapTemplate tested; - @Before + @BeforeEach public void setUp() throws Exception { // Setup ContextSource mock this.contextSourceMock = mock(ContextSource.class); diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTests.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTests.java index 63528d645..1d3ea4879 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTests.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateLookupTests.java @@ -25,8 +25,8 @@ import javax.naming.ldap.LdapContext; import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.NameNotFoundException; import org.springframework.ldap.odm.core.ObjectDirectoryMapper; @@ -56,7 +56,7 @@ public class LdapTemplateLookupTests { private ObjectDirectoryMapper odmMock; - @Before + @BeforeEach public void setUp() throws Exception { // Setup ContextSource mock this.contextSourceMock = mock(ContextSource.class); diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateOdmTests.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateOdmTests.java index 2e3a7071f..d7c6804d5 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateOdmTests.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateOdmTests.java @@ -16,8 +16,8 @@ package org.springframework.ldap.core; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.odm.core.ObjectDirectoryMapper; @@ -34,7 +34,7 @@ public class LdapTemplateOdmTests { private ObjectDirectoryMapper odmMock; - @Before + @BeforeEach public void prepareTestedClass() { this.tested = mock(LdapTemplate.class); diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTests.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTests.java index bff64add0..1aa9a218a 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTests.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateRenameTests.java @@ -20,8 +20,8 @@ import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.NameAlreadyBoundException; import org.springframework.ldap.UncategorizedLdapException; @@ -50,7 +50,7 @@ public class LdapTemplateRenameTests { private LdapTemplate tested; - @Before + @BeforeEach public void setUp() throws Exception { // Setup ContextSource mock this.contextSourceMock = mock(ContextSource.class); diff --git a/core/src/test/java/org/springframework/ldap/core/LdapTemplateTests.java b/core/src/test/java/org/springframework/ldap/core/LdapTemplateTests.java index 213b497fc..f22fc8cd6 100644 --- a/core/src/test/java/org/springframework/ldap/core/LdapTemplateTests.java +++ b/core/src/test/java/org/springframework/ldap/core/LdapTemplateTests.java @@ -32,8 +32,8 @@ import javax.naming.ldap.LdapContext; import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.ArgumentMatcher; @@ -109,7 +109,7 @@ public class LdapTemplateTests { private AuthenticatedLdapEntryContextMapper authContextMapperMock; - @Before + @BeforeEach public void setUp() throws Exception { // Setup ContextSource mock diff --git a/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTests.java b/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTests.java index 192b01a4c..2b45af34d 100644 --- a/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTests.java +++ b/core/src/test/java/org/springframework/ldap/core/NameAwareAttributeTests.java @@ -21,7 +21,7 @@ import javax.naming.NamingException; import javax.naming.ldap.LdapName; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.support.LdapUtils; diff --git a/core/src/test/java/org/springframework/ldap/core/NameAwareAttributesTests.java b/core/src/test/java/org/springframework/ldap/core/NameAwareAttributesTests.java index a682cc1d6..e9094ad00 100644 --- a/core/src/test/java/org/springframework/ldap/core/NameAwareAttributesTests.java +++ b/core/src/test/java/org/springframework/ldap/core/NameAwareAttributesTests.java @@ -19,7 +19,7 @@ import java.util.List; import java.util.stream.StreamSupport; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/core/support/AbstractContextSourceTests.java b/core/src/test/java/org/springframework/ldap/core/support/AbstractContextSourceTests.java index d1988a470..597ba8e4e 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/AbstractContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/AbstractContextSourceTests.java @@ -19,7 +19,7 @@ import javax.naming.InvalidNameException; import javax.naming.ldap.LdapName; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/core/support/AggregateDirContextProcessorTests.java b/core/src/test/java/org/springframework/ldap/core/support/AggregateDirContextProcessorTests.java index bc5d86dec..33933a298 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/AggregateDirContextProcessorTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/AggregateDirContextProcessorTests.java @@ -18,8 +18,8 @@ import javax.naming.NamingException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.DirContextProcessor; @@ -34,7 +34,7 @@ public class AggregateDirContextProcessorTests { private AggregateDirContextProcessor tested; - @Before + @BeforeEach public void setUp() throws Exception { // Create processor1 mock this.processor1Mock = mock(DirContextProcessor.class); diff --git a/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTests.java b/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTests.java index 3009ae447..550c2813c 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/BaseLdapPathBeanPostProcessorTests.java @@ -18,8 +18,8 @@ import java.util.HashMap; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.context.ApplicationContext; @@ -27,6 +27,7 @@ import org.springframework.ldap.support.LdapUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.mock; import static org.mockito.BDDMockito.verify; @@ -46,7 +47,7 @@ public class BaseLdapPathBeanPostProcessorTests { private BaseLdapNameAware ldapNameAwareMock; - @Before + @BeforeEach public void setUp() throws Exception { this.tested = new BaseLdapPathBeanPostProcessor(); @@ -138,18 +139,22 @@ public void testGetAbstractContextSourceFromApplicationContext() throws Exceptio assertThat(result).isSameAs(expectedContextSource); } - @Test(expected = NoSuchBeanDefinitionException.class) - public void testGetAbstractContextSourceFromApplicationContextNoContextSource() throws Exception { - given(this.applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)).willReturn(new String[0]); + @Test + public void testGetAbstractContextSourceFromApplicationContextNoContextSource() { + assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> { + given(this.applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)).willReturn(new String[0]); - this.tested.getBaseLdapPathSourceFromApplicationContext(); + this.tested.getBaseLdapPathSourceFromApplicationContext(); + }); } - @Test(expected = NoSuchBeanDefinitionException.class) - public void testGetAbstractContextSourceFromApplicationContextTwoContextSources() throws Exception { - given(this.applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)).willReturn(new String[2]); + @Test + public void testGetAbstractContextSourceFromApplicationContextTwoContextSources() { + assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() -> { + given(this.applicationContextMock.getBeanNamesForType(BaseLdapPathSource.class)).willReturn(new String[2]); - this.tested.getBaseLdapPathSourceFromApplicationContext(); + this.tested.getBaseLdapPathSourceFromApplicationContext(); + }); } @Test diff --git a/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTests.java b/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTests.java index 606755dec..b8f87ba09 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/ContextMapperCallbackHandlerWithControlsTests.java @@ -21,12 +21,13 @@ import javax.naming.ldap.Control; import javax.naming.ldap.HasControls; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.ObjectRetrievalException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.mock; @@ -41,15 +42,16 @@ public class ContextMapperCallbackHandlerWithControlsTests { private ContextMapperCallbackHandlerWithControls tested; @SuppressWarnings("unchecked") - @Before + @BeforeEach public void setUp() throws Exception { this.mapperMock = mock(ContextMapperWithControls.class); this.tested = new ContextMapperCallbackHandlerWithControls(this.mapperMock); } - @Test(expected = IllegalArgumentException.class) + @Test public void testConstructorWithEmptyArgument() { - new ContextMapperCallbackHandlerWithControls<>(null); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new ContextMapperCallbackHandlerWithControls<>(null)); } @Test @@ -78,11 +80,13 @@ public void testGetObjectFromNameClassPairImplementingHasControls() throws Namin assertThat(actualResult).isEqualTo(expectedResult); } - @Test(expected = ObjectRetrievalException.class) - public void testGetObjectFromNameClassPairObjectRetrievalException() throws NamingException { - Binding expectedBinding = new Binding("some name", null); + @Test + public void testGetObjectFromNameClassPairObjectRetrievalException() { + assertThatExceptionOfType(ObjectRetrievalException.class).isThrownBy(() -> { + Binding expectedBinding = new Binding("some name", null); - this.tested.getObjectFromNameClassPair(expectedBinding); + this.tested.getObjectFromNameClassPair(expectedBinding); + }); } private static class MyBindingThatHasControls extends Binding implements HasControls { diff --git a/core/src/test/java/org/springframework/ldap/core/support/CountNameClassPairResultCallbackHandlerTests.java b/core/src/test/java/org/springframework/ldap/core/support/CountNameClassPairResultCallbackHandlerTests.java index aef8fbcf7..af7ca0cd2 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/CountNameClassPairResultCallbackHandlerTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/CountNameClassPairResultCallbackHandlerTests.java @@ -18,8 +18,8 @@ import javax.naming.directory.SearchResult; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -27,7 +27,7 @@ public class CountNameClassPairResultCallbackHandlerTests { private CountNameClassPairCallbackHandler tested; - @Before + @BeforeEach public void setUp() throws Exception { this.tested = new CountNameClassPairCallbackHandler(); } diff --git a/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTests.java b/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTests.java index a0ea20bfb..1b7c661f9 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/DefaultDirObjectFactoryTests.java @@ -25,8 +25,8 @@ import javax.naming.directory.Attributes; import javax.naming.directory.BasicAttributes; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.NameAwareAttributes; @@ -49,7 +49,7 @@ public class DefaultDirObjectFactoryTests { private Context contextMock2; - @Before + @BeforeEach public void setUp() throws Exception { this.contextMock = mock(Context.class); this.contextMock2 = mock(Context.class); diff --git a/core/src/test/java/org/springframework/ldap/core/support/DefaultIncrementalAttributesMapperTests.java b/core/src/test/java/org/springframework/ldap/core/support/DefaultIncrementalAttributesMapperTests.java index 56b27cb8b..d1de42fc4 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/DefaultIncrementalAttributesMapperTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/DefaultIncrementalAttributesMapperTests.java @@ -21,8 +21,8 @@ import javax.naming.directory.BasicAttribute; import javax.naming.directory.BasicAttributes; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -36,7 +36,7 @@ public class DefaultIncrementalAttributesMapperTests { private DefaultIncrementalAttributesMapper tested; - @Before + @BeforeEach public void setUp() throws Exception { this.tested = new DefaultIncrementalAttributesMapper("member"); } diff --git a/core/src/test/java/org/springframework/ldap/core/support/DefaultTlsDirContextAuthenticationStrategyTests.java b/core/src/test/java/org/springframework/ldap/core/support/DefaultTlsDirContextAuthenticationStrategyTests.java index a8928f0ac..534b7acf3 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/DefaultTlsDirContextAuthenticationStrategyTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/DefaultTlsDirContextAuthenticationStrategyTests.java @@ -18,10 +18,12 @@ import javax.naming.ldap.LdapContext; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import static org.mockito.Mockito.verify; @@ -29,7 +31,8 @@ * @author Rob Winch * @since 5.0 */ -@RunWith(MockitoJUnitRunner.class) +@MockitoSettings(strictness = Strictness.WARN) +@ExtendWith(MockitoExtension.class) public class DefaultTlsDirContextAuthenticationStrategyTests { @Mock diff --git a/core/src/test/java/org/springframework/ldap/core/support/LdapContextSourceTests.java b/core/src/test/java/org/springframework/ldap/core/support/LdapContextSourceTests.java index 51382623a..c4cccf6ad 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/LdapContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/LdapContextSourceTests.java @@ -21,12 +21,13 @@ import javax.naming.Context; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.support.LdapUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Unit tests for the LdapContextSource class. @@ -38,23 +39,25 @@ public class LdapContextSourceTests { private LdapContextSource tested; - @Before + @BeforeEach public void setUp() throws Exception { this.tested = new LdapContextSource(); } - @Test(expected = IllegalArgumentException.class) - public void testAfterPropertiesSet_NoUrl() throws Exception { - this.tested.afterPropertiesSet(); + @Test + public void testAfterPropertiesSet_NoUrl() { + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> this.tested.afterPropertiesSet()); } // gh-538 - @Test(expected = IllegalArgumentException.class) + @Test public void testAfterPropertiesSet_NullPassword() { - this.tested.setUrl("ldap://ldap.example.com:389"); - this.tested.setUserDn("value"); - this.tested.setPassword(null); - this.tested.afterPropertiesSet(); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + this.tested.setUrl("ldap://ldap.example.com:389"); + this.tested.setUserDn("value"); + this.tested.setPassword(null); + this.tested.afterPropertiesSet(); + }); } @Test diff --git a/core/src/test/java/org/springframework/ldap/core/support/RangeOptionTests.java b/core/src/test/java/org/springframework/ldap/core/support/RangeOptionTests.java index 35295f3f4..aa2c36bd7 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/RangeOptionTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/RangeOptionTests.java @@ -16,7 +16,7 @@ package org.springframework.ldap.core.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/core/src/test/java/org/springframework/ldap/core/support/SimpleDirContextAuthenticationStrategyTests.java b/core/src/test/java/org/springframework/ldap/core/support/SimpleDirContextAuthenticationStrategyTests.java index db3ac0eee..670df7c8e 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/SimpleDirContextAuthenticationStrategyTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/SimpleDirContextAuthenticationStrategyTests.java @@ -20,8 +20,8 @@ import javax.naming.Context; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -29,7 +29,7 @@ public class SimpleDirContextAuthenticationStrategyTests { private SimpleDirContextAuthenticationStrategy tested; - @Before + @BeforeEach public void setUp() throws Exception { this.tested = new SimpleDirContextAuthenticationStrategy(); } diff --git a/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTests.java b/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTests.java index 71c408243..8e2c2280f 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/SingleContextSourceTests.java @@ -22,8 +22,8 @@ import javax.naming.NamingException; import javax.naming.directory.DirContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.ContextExecutor; import org.springframework.ldap.core.ContextSource; @@ -44,7 +44,7 @@ public class SingleContextSourceTests { private DirContext dirContextMock; - @Before + @BeforeEach public void prepareMocks() { this.contextSourceMock = mock(ContextSource.class); this.dirContextMock = mock(DirContext.class); diff --git a/core/src/test/java/org/springframework/ldap/core/support/ldap294/Ldap294Tests.java b/core/src/test/java/org/springframework/ldap/core/support/ldap294/Ldap294Tests.java index 6c14ccf83..878b59cc2 100644 --- a/core/src/test/java/org/springframework/ldap/core/support/ldap294/Ldap294Tests.java +++ b/core/src/test/java/org/springframework/ldap/core/support/ldap294/Ldap294Tests.java @@ -21,7 +21,7 @@ import javax.naming.NamingException; import javax.naming.directory.DirContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.support.AbstractContextSource; diff --git a/core/src/test/java/org/springframework/ldap/filter/AbstractFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/AbstractFilterTests.java index 2c074d21c..30e4d020a 100644 --- a/core/src/test/java/org/springframework/ldap/filter/AbstractFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/AbstractFilterTests.java @@ -16,7 +16,7 @@ package org.springframework.ldap.filter; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/AndFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/AndFilterTests.java index 357a485b4..66ee9938d 100644 --- a/core/src/test/java/org/springframework/ldap/filter/AndFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/AndFilterTests.java @@ -17,7 +17,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/EqualsFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/EqualsFilterTests.java index 41283a11f..a16970c3b 100644 --- a/core/src/test/java/org/springframework/ldap/filter/EqualsFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/EqualsFilterTests.java @@ -17,7 +17,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTests.java index d84d7f145..9960faba1 100644 --- a/core/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/GreaterThanOrEqualsFilterTests.java @@ -17,7 +17,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/HardcodedFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/HardcodedFilterTests.java index 4aa178df3..8051c9304 100644 --- a/core/src/test/java/org/springframework/ldap/filter/HardcodedFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/HardcodedFilterTests.java @@ -17,7 +17,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTests.java index 2273f304f..8762ae3cc 100644 --- a/core/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/LessThanOrEqualsFilterTests.java @@ -17,7 +17,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/LikeFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/LikeFilterTests.java index caf82f632..a1f88d156 100644 --- a/core/src/test/java/org/springframework/ldap/filter/LikeFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/LikeFilterTests.java @@ -17,7 +17,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/NotFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/NotFilterTests.java index e1af3b176..7feacce9a 100644 --- a/core/src/test/java/org/springframework/ldap/filter/NotFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/NotFilterTests.java @@ -17,7 +17,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/NotPresentFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/NotPresentFilterTests.java index d7929ceed..05d1fdf9a 100644 --- a/core/src/test/java/org/springframework/ldap/filter/NotPresentFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/NotPresentFilterTests.java @@ -17,7 +17,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/OrFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/OrFilterTests.java index c5b844219..7897498fe 100644 --- a/core/src/test/java/org/springframework/ldap/filter/OrFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/OrFilterTests.java @@ -16,7 +16,7 @@ package org.springframework.ldap.filter; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/PresentFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/PresentFilterTests.java index e7e22cc93..4dea47fa7 100644 --- a/core/src/test/java/org/springframework/ldap/filter/PresentFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/PresentFilterTests.java @@ -17,7 +17,7 @@ package org.springframework.ldap.filter; import com.gargoylesoftware.base.testing.EqualsTester; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/ProximityFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/ProximityFilterTests.java index b1842f76e..ceadbc23b 100644 --- a/core/src/test/java/org/springframework/ldap/filter/ProximityFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/ProximityFilterTests.java @@ -16,7 +16,7 @@ package org.springframework.ldap.filter; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTests.java b/core/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTests.java index 8f7ec813c..636f12f97 100644 --- a/core/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTests.java +++ b/core/src/test/java/org/springframework/ldap/filter/WhitespaceWildcardsFilterTests.java @@ -16,7 +16,7 @@ package org.springframework.ldap.filter; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java b/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java index 595b48c2b..a0a632d0b 100644 --- a/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java +++ b/core/src/test/java/org/springframework/ldap/odm/core/impl/DefaultObjectDirectoryMapperTests.java @@ -21,12 +21,14 @@ import javax.naming.Name; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.MockedStatic; import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.springframework.core.SpringVersion; import org.springframework.core.convert.ConversionService; @@ -38,6 +40,7 @@ import org.springframework.util.StringUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -45,12 +48,13 @@ /** * @author Mattias Hellborg Arthursson */ -@RunWith(MockitoJUnitRunner.class) +@MockitoSettings(strictness = Strictness.WARN) +@ExtendWith(MockitoExtension.class) public class DefaultObjectDirectoryMapperTests { private DefaultObjectDirectoryMapper tested; - @Before + @BeforeEach public void prepareTestedInstance() { this.tested = new DefaultObjectDirectoryMapper(); } @@ -127,9 +131,10 @@ public void testIndexedDnAttributes() { assertThat(calculatedId).isEqualTo(LdapUtils.newLdapName("cn=Some Person, ou=Some Company, c=Sweden")); } - @Test(expected = MetaDataException.class) + @Test public void testIndexedDnAttributesRequiresThatAllAreIndexed() { - this.tested.manageClass(UnitTestPersonWithIndexedAndUnindexedDnAttributes.class); + assertThatExceptionOfType(MetaDataException.class) + .isThrownBy(() -> this.tested.manageClass(UnitTestPersonWithIndexedAndUnindexedDnAttributes.class)); } @Test diff --git a/core/src/test/java/org/springframework/ldap/pool/AbstractPoolTestCase.java b/core/src/test/java/org/springframework/ldap/pool/AbstractPoolTestCase.java index 1239adbe8..9e3a42205 100644 --- a/core/src/test/java/org/springframework/ldap/pool/AbstractPoolTestCase.java +++ b/core/src/test/java/org/springframework/ldap/pool/AbstractPoolTestCase.java @@ -21,7 +21,7 @@ import javax.naming.ldap.LdapContext; import org.apache.commons.pool.KeyedObjectPool; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.pool.validation.DirContextValidator; @@ -47,7 +47,7 @@ public abstract class AbstractPoolTestCase { protected DirContextValidator dirContextValidatorMock; - @Before + @BeforeEach public void setUp() throws Exception { this.contextMock = mock(Context.class); this.dirContextMock = mock(DirContext.class); diff --git a/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTests.java b/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTests.java index ff22a6f07..ed33b6e9a 100644 --- a/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/DelegatingContextTests.java @@ -21,7 +21,7 @@ import javax.naming.NamingException; import org.apache.commons.pool.KeyedObjectPool; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/core/src/test/java/org/springframework/ldap/pool/DelegatingDirContextTests.java b/core/src/test/java/org/springframework/ldap/pool/DelegatingDirContextTests.java index f174f78e2..8569dcb74 100644 --- a/core/src/test/java/org/springframework/ldap/pool/DelegatingDirContextTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/DelegatingDirContextTests.java @@ -23,7 +23,7 @@ import javax.naming.directory.DirContext; import org.apache.commons.pool.KeyedObjectPool; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/core/src/test/java/org/springframework/ldap/pool/DelegatingLdapContextTests.java b/core/src/test/java/org/springframework/ldap/pool/DelegatingLdapContextTests.java index 028de096c..1a518b4e4 100644 --- a/core/src/test/java/org/springframework/ldap/pool/DelegatingLdapContextTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/DelegatingLdapContextTests.java @@ -21,7 +21,7 @@ import javax.naming.ldap.LdapContext; import org.apache.commons.pool.KeyedObjectPool; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/core/src/test/java/org/springframework/ldap/pool/MutableDelegatingLdapContextTests.java b/core/src/test/java/org/springframework/ldap/pool/MutableDelegatingLdapContextTests.java index 30da15d5d..99f7784cd 100644 --- a/core/src/test/java/org/springframework/ldap/pool/MutableDelegatingLdapContextTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/MutableDelegatingLdapContextTests.java @@ -16,7 +16,7 @@ package org.springframework.ldap.pool; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.mockito.Mockito.verify; diff --git a/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTests.java b/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTests.java index 6ebc9474f..3d1723626 100644 --- a/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/factory/DirContextPoolableObjectFactoryTests.java @@ -22,7 +22,7 @@ import javax.naming.directory.DirContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.springframework.ldap.core.ContextSource; diff --git a/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTests.java b/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTests.java index 7f82c0a70..251224a01 100644 --- a/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/factory/MutablePoolingContextSourceTests.java @@ -18,7 +18,7 @@ import javax.naming.directory.DirContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.pool.AbstractPoolTestCase; import org.springframework.ldap.pool.MutableDelegatingLdapContext; diff --git a/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTests.java b/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTests.java index 4babbe585..efc448f4a 100644 --- a/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/factory/PoolingContextSourceTests.java @@ -20,7 +20,7 @@ import javax.naming.ldap.LdapContext; import org.apache.commons.pool.impl.GenericKeyedObjectPool; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.ldap.core.ContextSource; diff --git a/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTests.java b/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTests.java index 02979b085..a6dbaaaa0 100644 --- a/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTests.java +++ b/core/src/test/java/org/springframework/ldap/pool/validation/DefaultDirContextValidatorTests.java @@ -21,8 +21,8 @@ import javax.naming.directory.DirContext; import javax.naming.directory.SearchControls; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.pool.DirContextType; @@ -41,7 +41,7 @@ public class DefaultDirContextValidatorTests { private DirContext dirContextMock; - @Before + @BeforeEach public void setUp() throws Exception { this.namingEnumerationMock = mock(NamingEnumeration.class); this.dirContextMock = mock(DirContext.class); diff --git a/core/src/test/java/org/springframework/ldap/pool2/AbstractPoolTestCase.java b/core/src/test/java/org/springframework/ldap/pool2/AbstractPoolTestCase.java index 1d71aa545..23c8329aa 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/AbstractPoolTestCase.java +++ b/core/src/test/java/org/springframework/ldap/pool2/AbstractPoolTestCase.java @@ -21,7 +21,7 @@ import javax.naming.ldap.LdapContext; import org.apache.commons.pool2.KeyedObjectPool; -import org.junit.Before; +import org.junit.jupiter.api.BeforeEach; import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.pool2.validation.DirContextValidator; @@ -47,7 +47,7 @@ public abstract class AbstractPoolTestCase { protected DirContextValidator dirContextValidatorMock; - @Before + @BeforeEach public void setUp() throws Exception { this.contextMock = mock(Context.class); this.dirContextMock = mock(DirContext.class); diff --git a/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTests.java b/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTests.java index 3833422c9..2d1860db3 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/DelegatingContextTests.java @@ -21,7 +21,7 @@ import javax.naming.NamingException; import org.apache.commons.pool2.KeyedObjectPool; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/core/src/test/java/org/springframework/ldap/pool2/DelegatingDirContextTests.java b/core/src/test/java/org/springframework/ldap/pool2/DelegatingDirContextTests.java index b6a9b442f..b82e0a80c 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/DelegatingDirContextTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/DelegatingDirContextTests.java @@ -23,7 +23,7 @@ import javax.naming.directory.DirContext; import org.apache.commons.pool2.KeyedObjectPool; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/core/src/test/java/org/springframework/ldap/pool2/DelegatingLdapContextTests.java b/core/src/test/java/org/springframework/ldap/pool2/DelegatingLdapContextTests.java index 247795384..c8e80f906 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/DelegatingLdapContextTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/DelegatingLdapContextTests.java @@ -21,7 +21,7 @@ import javax.naming.ldap.LdapContext; import org.apache.commons.pool2.KeyedObjectPool; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; diff --git a/core/src/test/java/org/springframework/ldap/pool2/MutableDelegatingLdapContextTests.java b/core/src/test/java/org/springframework/ldap/pool2/MutableDelegatingLdapContextTests.java index 4db7475e0..03a5e55d2 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/MutableDelegatingLdapContextTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/MutableDelegatingLdapContextTests.java @@ -16,7 +16,7 @@ package org.springframework.ldap.pool2; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.mockito.Mockito.verify; diff --git a/core/src/test/java/org/springframework/ldap/pool2/factory/DirContextPooledObjectFactoryTests.java b/core/src/test/java/org/springframework/ldap/pool2/factory/DirContextPooledObjectFactoryTests.java index 072a7a142..317b2ebd5 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/factory/DirContextPooledObjectFactoryTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/factory/DirContextPooledObjectFactoryTests.java @@ -24,7 +24,7 @@ import org.apache.commons.pool2.PooledObject; import org.apache.commons.pool2.impl.DefaultPooledObject; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.pool2.AbstractPoolTestCase; diff --git a/core/src/test/java/org/springframework/ldap/pool2/factory/MutablePooledContextSourceTests.java b/core/src/test/java/org/springframework/ldap/pool2/factory/MutablePooledContextSourceTests.java index 2db115398..08f9b6e12 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/factory/MutablePooledContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/factory/MutablePooledContextSourceTests.java @@ -18,7 +18,7 @@ import javax.naming.directory.DirContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.pool2.AbstractPoolTestCase; import org.springframework.ldap.pool2.MutableDelegatingLdapContext; diff --git a/core/src/test/java/org/springframework/ldap/pool2/factory/PoolConfigTests.java b/core/src/test/java/org/springframework/ldap/pool2/factory/PoolConfigTests.java index 579d98022..e7e33e3d4 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/factory/PoolConfigTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/factory/PoolConfigTests.java @@ -17,7 +17,7 @@ package org.springframework.ldap.pool2.factory; import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.pool2.AbstractPoolTestCase; diff --git a/core/src/test/java/org/springframework/ldap/pool2/factory/PooledContextSourceTests.java b/core/src/test/java/org/springframework/ldap/pool2/factory/PooledContextSourceTests.java index 185ddc7d6..a8a23ff92 100644 --- a/core/src/test/java/org/springframework/ldap/pool2/factory/PooledContextSourceTests.java +++ b/core/src/test/java/org/springframework/ldap/pool2/factory/PooledContextSourceTests.java @@ -19,7 +19,7 @@ import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.dao.DataAccessResourceFailureException; import org.springframework.ldap.core.ContextSource; diff --git a/core/src/test/java/org/springframework/ldap/query/LdapQueryBuilderTests.java b/core/src/test/java/org/springframework/ldap/query/LdapQueryBuilderTests.java index ce4f076e3..b43e2963c 100644 --- a/core/src/test/java/org/springframework/ldap/query/LdapQueryBuilderTests.java +++ b/core/src/test/java/org/springframework/ldap/query/LdapQueryBuilderTests.java @@ -16,12 +16,13 @@ package org.springframework.ldap.query; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.filter.ProximityFilter; import org.springframework.ldap.support.LdapUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * @author Mattias Hellborg Arthursson @@ -88,18 +89,22 @@ public void buildHardcodedFilter() { assertThat(result.filter().encode()).isEqualTo("(cn=Person*)"); } - @Test(expected = IllegalStateException.class) + @Test public void verifyThatHardcodedFilterFailsIfFilterAlreadySpecified() { - LdapQueryBuilder query = LdapQueryBuilder.query(); - query.where("sn").is("Doe"); - query.filter("(cn=Person*)"); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + LdapQueryBuilder query = LdapQueryBuilder.query(); + query.where("sn").is("Doe"); + query.filter("(cn=Person*)"); + }); } - @Test(expected = IllegalStateException.class) + @Test public void verifyThatFilterFormatFailsIfFilterAlreadySpecified() { - LdapQueryBuilder query = LdapQueryBuilder.query(); - query.where("sn").is("Doe"); - query.filter("(|(cn={0})(cn={1}))", "Person*", "Parson*"); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + LdapQueryBuilder query = LdapQueryBuilder.query(); + query.where("sn").is("Doe"); + query.filter("(|(cn={0})(cn={1}))", "Person*", "Parson*"); + }); } @Test @@ -162,28 +167,38 @@ public void buildNestedAnd() { assertThat(result.filter().encode()).isEqualTo("(&(objectclass=person)(|(sn=Doe)(sn=Die)))"); } - @Test(expected = IllegalStateException.class) + @Test public void verifyEmptyFilterThrowsIllegalState() { - LdapQueryBuilder.query().filter(); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> LdapQueryBuilder.query().filter()); } - @Test(expected = IllegalStateException.class) + @Test public void verifyThatNewAttemptToStartSpecifyingFilterThrowsIllegalState() { - LdapQueryBuilder query = LdapQueryBuilder.query(); - query.where("sn").is("Doe"); - query.where("cn").is("John Doe"); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + LdapQueryBuilder query = LdapQueryBuilder.query(); + query.where("sn").is("Doe"); + query.where("cn").is("John Doe"); + }); } - @Test(expected = IllegalStateException.class) + @Test public void verifyThatAttemptToStartSpecifyingBasePropertiesThrowsIllegalStateWhenFilterStarted() { - LdapQueryBuilder query = LdapQueryBuilder.query(); - query.where("sn").is("Doe"); - query.base("dc=261consulting,dc=com"); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> { + LdapQueryBuilder query = LdapQueryBuilder.query(); + query.where("sn").is("Doe"); + query.base("dc=261consulting,dc=com"); + }); } - @Test(expected = IllegalStateException.class) + @Test public void verifyThatOperatorChangeIsIllegal() { - LdapQueryBuilder.query().where("cn").is("John Doe").and("sn").is("Doe").or("objectclass").is("person"); + assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> LdapQueryBuilder.query() + .where("cn") + .is("John Doe") + .and("sn") + .is("Doe") + .or("objectclass") + .is("person")); } } diff --git a/core/src/test/java/org/springframework/ldap/support/LdapEncoderTests.java b/core/src/test/java/org/springframework/ldap/support/LdapEncoderTests.java index abcd2e6f3..1217e921b 100644 --- a/core/src/test/java/org/springframework/ldap/support/LdapEncoderTests.java +++ b/core/src/test/java/org/springframework/ldap/support/LdapEncoderTests.java @@ -16,11 +16,12 @@ package org.springframework.ldap.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.BadLdapGrammarException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; /** * Unit test for the LdapEncode class. @@ -52,9 +53,9 @@ public void testNameDecode() { assertThat(res).isEqualTo("# foo ,+\"\\<>; "); } - @Test(expected = BadLdapGrammarException.class) + @Test public void testNameDecode_slashlast() { - LdapEncoder.nameDecode("\\"); + assertThatExceptionOfType(BadLdapGrammarException.class).isThrownBy(() -> LdapEncoder.nameDecode("\\")); } // gh-413 diff --git a/core/src/test/java/org/springframework/ldap/support/LdapNameBuilderTests.java b/core/src/test/java/org/springframework/ldap/support/LdapNameBuilderTests.java index dde503da9..cb938ec96 100644 --- a/core/src/test/java/org/springframework/ldap/support/LdapNameBuilderTests.java +++ b/core/src/test/java/org/springframework/ldap/support/LdapNameBuilderTests.java @@ -16,7 +16,7 @@ package org.springframework.ldap.support; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core/src/test/java/org/springframework/ldap/support/LdapUtilsTests.java b/core/src/test/java/org/springframework/ldap/support/LdapUtilsTests.java index 0037d70a3..a05a55e65 100644 --- a/core/src/test/java/org/springframework/ldap/support/LdapUtilsTests.java +++ b/core/src/test/java/org/springframework/ldap/support/LdapUtilsTests.java @@ -25,8 +25,8 @@ import javax.naming.ldap.LdapName; import org.apache.commons.lang.ArrayUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.NoSuchAttributeException; @@ -43,7 +43,7 @@ public class LdapUtilsTests { private AttributeValueCallbackHandler handlerMock; - @Before + @BeforeEach public void setUp() throws Exception { this.handlerMock = mock(AttributeValueCallbackHandler.class); } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationExecutorTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationExecutorTests.java index b183b08af..8edeb4585 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationExecutorTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationExecutorTests.java @@ -19,8 +19,8 @@ import javax.naming.directory.BasicAttributes; import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.support.LdapUtils; @@ -33,7 +33,7 @@ public class BindOperationExecutorTests { private LdapOperations ldapOperationsMock; - @Before + @BeforeEach public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTests.java index b42e9c6be..a9f853836 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/BindOperationRecorderTests.java @@ -19,21 +19,22 @@ import javax.naming.directory.BasicAttributes; import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.support.LdapUtils; import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.Mockito.mock; public class BindOperationRecorderTests { private LdapOperations ldapOperationsMock; - @Before + @BeforeEach public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); @@ -75,13 +76,15 @@ public void testPerformOperation_String() { assertThat(rollbackOperation.getLdapOperations()).isSameAs(this.ldapOperationsMock); } - @Test(expected = IllegalArgumentException.class) + @Test public void testPerformOperation_Invalid() { - BindOperationRecorder tested = new BindOperationRecorder(this.ldapOperationsMock); - Object expectedDn = new Object(); + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> { + BindOperationRecorder tested = new BindOperationRecorder(this.ldapOperationsMock); + Object expectedDn = new Object(); - // Perform test. - tested.recordOperation(new Object[] { expectedDn }); + // Perform test. + tested.recordOperation(new Object[] { expectedDn }); + }); } } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapCompensatingTransactionOperationFactoryTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapCompensatingTransactionOperationFactoryTests.java index f82e1becd..15eab75c3 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapCompensatingTransactionOperationFactoryTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapCompensatingTransactionOperationFactoryTests.java @@ -18,8 +18,8 @@ import javax.naming.directory.DirContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.LdapOperations; import org.springframework.transaction.compensating.CompensatingTransactionOperationRecorder; @@ -37,7 +37,7 @@ public class LdapCompensatingTransactionOperationFactoryTests { private LdapCompensatingTransactionOperationFactory tested; - @Before + @BeforeEach public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); this.renamingStrategyMock = mock(TempEntryRenamingStrategy.class); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapTransactionUtilsTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapTransactionUtilsTests.java index dcb396cc2..fba3a56ea 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapTransactionUtilsTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/LdapTransactionUtilsTests.java @@ -19,8 +19,8 @@ import javax.naming.NamingException; import javax.naming.directory.DirContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.support.LdapUtils; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -33,7 +33,7 @@ public class LdapTransactionUtilsTests { private DirContext dirContextMock; - @Before + @BeforeEach public void setUp() throws Exception { this.dirContextMock = mock(DirContext.class); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutorTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutorTests.java index 18c225489..4d6b491b5 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutorTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationExecutorTests.java @@ -19,8 +19,8 @@ import javax.naming.Name; import javax.naming.directory.ModificationItem; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.support.LdapUtils; @@ -33,7 +33,7 @@ public class ModifyAttributesOperationExecutorTests { private LdapOperations ldapOperationsMock; - @Before + @BeforeEach public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTests.java index 7e886309a..4f0bf1dbc 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/ModifyAttributesOperationRecorderTests.java @@ -25,8 +25,8 @@ import javax.naming.directory.ModificationItem; import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.IncrementalAttributesMapper; import org.springframework.ldap.core.LdapOperations; @@ -45,7 +45,7 @@ public class ModifyAttributesOperationRecorderTests { private ModifyAttributesOperationRecorder tested; - @Before + @BeforeEach public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); this.attributesMapperMock = mock(IncrementalAttributesMapper.class); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationExecutorTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationExecutorTests.java index bfab43c9b..1eed6cd39 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationExecutorTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationExecutorTests.java @@ -19,8 +19,8 @@ import javax.naming.directory.BasicAttributes; import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.support.LdapUtils; @@ -32,7 +32,7 @@ public class RebindOperationExecutorTests { private LdapOperations ldapOperationsMock; - @Before + @BeforeEach public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTests.java index 6424e5f14..ac7bcff4d 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/RebindOperationRecorderTests.java @@ -19,8 +19,8 @@ import javax.naming.directory.BasicAttributes; import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.support.LdapUtils; @@ -36,7 +36,7 @@ public class RebindOperationRecorderTests { private TempEntryRenamingStrategy renamingStrategyMock; - @Before + @BeforeEach public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); this.renamingStrategyMock = mock(TempEntryRenamingStrategy.class); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationExecutorTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationExecutorTests.java index d2118053b..e6441037f 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationExecutorTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationExecutorTests.java @@ -18,8 +18,8 @@ import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.support.LdapUtils; @@ -32,7 +32,7 @@ public class RenameOperationExecutorTests { private LdapOperations ldapOperationsMock; - @Before + @BeforeEach public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTests.java index a89abf7bb..2f6b2fffb 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/RenameOperationRecorderTests.java @@ -16,8 +16,8 @@ package org.springframework.ldap.transaction.compensating; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.LdapOperations; import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor; @@ -29,7 +29,7 @@ public class RenameOperationRecorderTests { private LdapOperations ldapOperationsMock; - @Before + @BeforeEach public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationExecutorTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationExecutorTests.java index 2dc956ca1..ff0a4e0aa 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationExecutorTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationExecutorTests.java @@ -18,8 +18,8 @@ import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.support.LdapUtils; @@ -31,7 +31,7 @@ public class UnbindOperationExecutorTests { private LdapOperations ldapOperationsMock; - @Before + @BeforeEach public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); } diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTests.java index ef42f7a12..9b9b5cb00 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/UnbindOperationRecorderTests.java @@ -18,8 +18,8 @@ import javax.naming.ldap.LdapName; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.LdapOperations; import org.springframework.ldap.support.LdapUtils; @@ -35,7 +35,7 @@ public class UnbindOperationRecorderTests { private TempEntryRenamingStrategy renamingStrategyMock; - @Before + @BeforeEach public void setUp() throws Exception { this.ldapOperationsMock = mock(LdapOperations.class); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/CompensatingTransactionUtilsTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/CompensatingTransactionUtilsTests.java index e1443ae4c..da991871c 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/CompensatingTransactionUtilsTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/CompensatingTransactionUtilsTests.java @@ -20,8 +20,8 @@ import javax.naming.directory.DirContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.ContextSource; import org.springframework.transaction.compensating.CompensatingTransactionOperationManager; @@ -40,7 +40,7 @@ public class CompensatingTransactionUtilsTests { private CompensatingTransactionOperationManager operationManagerMock; - @Before + @BeforeEach public void setUp() throws Exception { this.dirContextMock = mock(DirContext.class); this.contextSourceMock = mock(ContextSource.class); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTests.java index c6b9ae774..fcf5d3d81 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/ContextSourceTransactionManagerTests.java @@ -21,8 +21,8 @@ import javax.naming.directory.DirContext; import javax.sql.DataSource; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.ldap.UncategorizedLdapException; @@ -59,7 +59,7 @@ public class ContextSourceTransactionManagerTests { private TempEntryRenamingStrategy renamingStrategyMock; - @Before + @BeforeEach public void setUp() throws Exception { if (TransactionSynchronizationManager.isSynchronizationActive()) { TransactionSynchronizationManager.clearSynchronization(); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTests.java index d0033a7b5..031b9d485 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareContextSourceProxyTests.java @@ -19,8 +19,8 @@ import javax.naming.directory.DirContext; import javax.naming.ldap.LdapContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.ContextSource; import org.springframework.ldap.core.DirContextProxy; @@ -44,7 +44,7 @@ public class TransactionAwareContextSourceProxyTests { private DirContext dirContextMock; - @Before + @BeforeEach public void setUp() throws Exception { this.contextSourceMock = mock(ContextSource.class); this.ldapContextMock = mock(LdapContext.class); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareDirContextInvocationHandlerTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareDirContextInvocationHandlerTests.java index 4c3b472d6..dceb5a3df 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareDirContextInvocationHandlerTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/manager/TransactionAwareDirContextInvocationHandlerTests.java @@ -19,8 +19,8 @@ import javax.naming.NamingException; import javax.naming.directory.DirContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.core.ContextSource; import org.springframework.transaction.support.TransactionSynchronizationManager; @@ -39,7 +39,7 @@ public class TransactionAwareDirContextInvocationHandlerTests { private DirContextHolder holder; - @Before + @BeforeEach public void setUp() throws Exception { this.dirContextMock = mock(DirContext.class); this.contextSourceMock = mock(ContextSource.class); diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DefaultTempEntryRenamingStrategyTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DefaultTempEntryRenamingStrategyTests.java index 3f85065cc..6a1689f41 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DefaultTempEntryRenamingStrategyTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DefaultTempEntryRenamingStrategyTests.java @@ -19,7 +19,7 @@ import javax.naming.Name; import javax.naming.ldap.LdapName; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.support.LdapUtils; diff --git a/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DifferentSubtreeTempEntryRenamingStrategyTests.java b/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DifferentSubtreeTempEntryRenamingStrategyTests.java index f71da758b..026b4f372 100644 --- a/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DifferentSubtreeTempEntryRenamingStrategyTests.java +++ b/core/src/test/java/org/springframework/ldap/transaction/compensating/support/DifferentSubtreeTempEntryRenamingStrategyTests.java @@ -19,7 +19,7 @@ import javax.naming.Name; import javax.naming.ldap.LdapName; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.support.LdapUtils; diff --git a/core/src/test/java/org/springframework/ldap/util/ListComparatorTests.java b/core/src/test/java/org/springframework/ldap/util/ListComparatorTests.java index c53d2fc24..11fc002b8 100644 --- a/core/src/test/java/org/springframework/ldap/util/ListComparatorTests.java +++ b/core/src/test/java/org/springframework/ldap/util/ListComparatorTests.java @@ -19,8 +19,8 @@ import java.util.Arrays; import java.util.List; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.support.ListComparator; @@ -35,7 +35,7 @@ public class ListComparatorTests { private ListComparator tested; - @Before + @BeforeEach public void setUp() throws Exception { this.tested = new ListComparator(); } diff --git a/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTests.java b/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTests.java index c89f0f93d..ee2e1948b 100644 --- a/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTests.java +++ b/core/src/test/java/org/springframework/transaction/compensating/support/DefaultCompensatingTransactionOperationManagerTests.java @@ -18,8 +18,8 @@ import java.util.Stack; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.transaction.TransactionSystemException; import org.springframework.transaction.compensating.CompensatingTransactionOperationExecutor; @@ -27,6 +27,7 @@ import org.springframework.transaction.compensating.CompensatingTransactionOperationRecorder; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.mock; import static org.mockito.BDDMockito.verify; @@ -40,7 +41,7 @@ public class DefaultCompensatingTransactionOperationManagerTests { private CompensatingTransactionOperationRecorder operationRecorderMock; - @Before + @BeforeEach public void setUp() throws Exception { this.operationExecutorMock = mock(CompensatingTransactionOperationExecutor.class); this.operationFactoryMock = mock(CompensatingTransactionOperationFactory.class); @@ -77,15 +78,17 @@ public void testRollback() { verify(this.operationExecutorMock).rollback(); } - @Test(expected = TransactionSystemException.class) + @Test public void testRollback_Exception() { - DefaultCompensatingTransactionOperationManager tested = new DefaultCompensatingTransactionOperationManager( - this.operationFactoryMock); - tested.getOperationExecutors().push(this.operationExecutorMock); + assertThatExceptionOfType(TransactionSystemException.class).isThrownBy(() -> { + DefaultCompensatingTransactionOperationManager tested = new DefaultCompensatingTransactionOperationManager( + this.operationFactoryMock); + tested.getOperationExecutors().push(this.operationExecutorMock); - willThrow(new RuntimeException()).given(this.operationExecutorMock).rollback(); + willThrow(new RuntimeException()).given(this.operationExecutorMock).rollback(); - tested.rollback(); + tested.rollback(); + }); } @Test @@ -98,15 +101,17 @@ public void testCommit() { verify(this.operationExecutorMock).commit(); } - @Test(expected = TransactionSystemException.class) + @Test public void testCommit_Exception() { - DefaultCompensatingTransactionOperationManager tested = new DefaultCompensatingTransactionOperationManager( - this.operationFactoryMock); - tested.getOperationExecutors().push(this.operationExecutorMock); + assertThatExceptionOfType(TransactionSystemException.class).isThrownBy(() -> { + DefaultCompensatingTransactionOperationManager tested = new DefaultCompensatingTransactionOperationManager( + this.operationFactoryMock); + tested.getOperationExecutors().push(this.operationExecutorMock); - willThrow(new RuntimeException()).given(this.operationExecutorMock).commit(); + willThrow(new RuntimeException()).given(this.operationExecutorMock).commit(); - tested.commit(); + tested.commit(); + }); } } diff --git a/dependencies/build.gradle b/dependencies/build.gradle index 40326cb69..402fd5aaa 100644 --- a/dependencies/build.gradle +++ b/dependencies/build.gradle @@ -26,7 +26,7 @@ dependencies { api platform("org.springframework.security:spring-security-bom:6.4.6") api platform('com.fasterxml.jackson:jackson-bom:2.19.1') api platform("io.micrometer:micrometer-bom:1.14.8") - api platform("io.micrometer:micrometer-tracing-bom:1.4.7") + api platform("io.micrometer:micrometer-tracing-bom:1.5.2") api platform("org.junit:junit-bom:5.12.2") constraints { api "com.querydsl:querydsl-core:$queryDslVersion" diff --git a/ldif/ldif-core/build.gradle b/ldif/ldif-core/build.gradle index b0aed199c..86ef8518a 100644 --- a/ldif/ldif-core/build.gradle +++ b/ldif/ldif-core/build.gradle @@ -6,13 +6,20 @@ dependencies { management platform(project(":spring-ldap-dependencies")) api project(":spring-ldap-core") + testImplementation platform('org.junit:junit-bom') - testImplementation "org.junit.vintage:junit-vintage-engine" - testImplementation "junit:junit" testImplementation "org.assertj:assertj-core" + testImplementation "org.junit.jupiter:junit-jupiter-api" + testImplementation "org.junit.jupiter:junit-jupiter-engine" + testImplementation "org.junit.jupiter:junit-jupiter-params" + testRuntimeOnly("org.junit.platform:junit-platform-launcher") testImplementation ("log4j:log4j:1.2.17") { exclude group: 'javax.jms' exclude group: 'com.sun.jdmk' exclude group: 'com.sun.jmx' } } + +tasks.withType(Test).configureEach { + useJUnitPlatform() +} diff --git a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/DefaultAttributeValidationPolicyTests.java b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/DefaultAttributeValidationPolicyTests.java index ce42b737b..5aa797413 100644 --- a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/DefaultAttributeValidationPolicyTests.java +++ b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/DefaultAttributeValidationPolicyTests.java @@ -21,10 +21,8 @@ import java.util.Collection; import java.util.List; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -44,7 +42,6 @@ * @author Keith Barlow * */ -@RunWith(Parameterized.class) public class DefaultAttributeValidationPolicyTests { private static Logger log = LoggerFactory.getLogger(DefaultAttributeValidationPolicyTests.class); @@ -75,7 +72,6 @@ private enum AttributeType { * The data set to parse. * @return */ - @Parameters public static Collection data() { return Arrays.asList(new Object[][] { // Format: line, id, options, value, type @@ -146,7 +142,7 @@ public static Collection data() { * @param value The value expected from successful parsing. * @param type The attribute type: one of enum AttributeType. */ - public DefaultAttributeValidationPolicyTests(String line, String id, String options, String value, + public void initDefaultAttributeValidationPolicyTests(String line, String id, String options, String value, AttributeType type) { this.line = line; this.id = id; @@ -159,8 +155,10 @@ public DefaultAttributeValidationPolicyTests(String line, String id, String opti * The test case: parses passed in parameters and validates the outcome against the * expected results. */ - @Test - public void parseAttribute() { + @MethodSource("data") + @ParameterizedTest + public void parseAttribute(String line, String id, String options, String value, AttributeType type) { + initDefaultAttributeValidationPolicyTests(line, id, options, value, type); try { LdapAttribute attribute = (LdapAttribute) policy.parse(this.line); diff --git a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/Ldap233LdifParserTests.java b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/Ldap233LdifParserTests.java index c8f8739f3..afa06eb9c 100644 --- a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/Ldap233LdifParserTests.java +++ b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/Ldap233LdifParserTests.java @@ -20,7 +20,7 @@ import java.io.IOException; import java.nio.file.Files; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.ldif.parser.LdifParser; import org.springframework.ldap.schema.BasicSchemaSpecification; diff --git a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/LdifParserTests.java b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/LdifParserTests.java index 464ee1acd..d52934e26 100644 --- a/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/LdifParserTests.java +++ b/ldif/ldif-core/src/test/java/org/springframework/ldap/ldif/LdifParserTests.java @@ -18,9 +18,9 @@ import java.io.IOException; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,7 +66,7 @@ public LdifParserTests() { /** * Setup: opens file. */ - @Before + @BeforeEach public void openLdif() { try { this.parser.open(); @@ -122,7 +122,7 @@ public void parseLdif() { /** * Cleanup: closes file. */ - @After + @AfterEach public void closeLdif() { try { this.parser.close(); diff --git a/odm/build.gradle b/odm/build.gradle index ad3be5be0..111f7ffa7 100644 --- a/odm/build.gradle +++ b/odm/build.gradle @@ -34,5 +34,11 @@ dependencies { testImplementation "org.apache.directory.shared:shared-ldap" testImplementation "org.assertj:assertj-core" testImplementation platform('org.junit:junit-bom') - testImplementation "org.junit.vintage:junit-vintage-engine" + testImplementation "org.junit.jupiter:junit-jupiter-api" + testImplementation "org.junit.jupiter:junit-jupiter-engine" + testRuntimeOnly("org.junit.platform:junit-platform-launcher") +} + +tasks.withType(Test).configureEach { + useJUnitPlatform() } \ No newline at end of file diff --git a/odm/src/test/java/org/springframework/ldap/odm/test/ConverterFactoryTests.java b/odm/src/test/java/org/springframework/ldap/odm/test/ConverterFactoryTests.java index 20315c307..c6adbbd18 100755 --- a/odm/src/test/java/org/springframework/ldap/odm/test/ConverterFactoryTests.java +++ b/odm/src/test/java/org/springframework/ldap/odm/test/ConverterFactoryTests.java @@ -20,7 +20,7 @@ import java.util.HashSet; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.ldap.odm.test.utils.ExecuteRunnable; import org.springframework.ldap.odm.test.utils.RunnableTests; diff --git a/odm/src/test/java/org/springframework/ldap/odm/test/ConverterManagerTests.java b/odm/src/test/java/org/springframework/ldap/odm/test/ConverterManagerTests.java index be25c68ad..1051f5aa5 100755 --- a/odm/src/test/java/org/springframework/ldap/odm/test/ConverterManagerTests.java +++ b/odm/src/test/java/org/springframework/ldap/odm/test/ConverterManagerTests.java @@ -19,9 +19,9 @@ import java.net.URI; import java.util.BitSet; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.odm.test.utils.ExecuteRunnable; import org.springframework.ldap.odm.test.utils.RunnableTests; @@ -32,12 +32,13 @@ import org.springframework.ldap.odm.typeconversion.impl.converters.ToStringConverter; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; public final class ConverterManagerTests { private ConverterManagerImpl converterManager; - @Before + @BeforeEach public void setUp() { this.converterManager = new ConverterManagerImpl(); @@ -64,7 +65,7 @@ public void setUp() { this.converterManager.addConverter(String.class, "", URI.class, uric); } - @After + @AfterEach public void tearDown() { this.converterManager = null; } @@ -141,15 +142,17 @@ public void runTest(ConverterTestData testData) { } // No converter for classes - @Test(expected = ConverterException.class) - public void noClassConverter() throws Exception { - this.converterManager.convert(BitSet.class, "", Integer.class); + @Test + public void noClassConverter() { + assertThatExceptionOfType(ConverterException.class) + .isThrownBy(() -> this.converterManager.convert(BitSet.class, "", Integer.class)); } // Invalid syntax so converter fails - @Test(expected = ConverterException.class) - public void invalidSyntax() throws Exception { - this.converterManager.convert(String.class, "not a uri", URI.class); + @Test + public void invalidSyntax() { + assertThatExceptionOfType(ConverterException.class) + .isThrownBy(() -> this.converterManager.convert(String.class, "not a uri", URI.class)); } private static final class ConverterTestData { diff --git a/odm/src/test/java/org/springframework/ldap/odm/test/JDependTests.java b/odm/src/test/java/org/springframework/ldap/odm/test/JDependTests.java index 713ccce75..e973aa390 100755 --- a/odm/src/test/java/org/springframework/ldap/odm/test/JDependTests.java +++ b/odm/src/test/java/org/springframework/ldap/odm/test/JDependTests.java @@ -19,8 +19,8 @@ import java.io.IOException; import jdepend.framework.JDepend; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; @@ -28,7 +28,7 @@ public class JDependTests { private JDepend jdepend; - @Before + @BeforeEach public void setUp() throws IOException { this.jdepend = new JDepend(); this.jdepend.addDirectory("build/classes/java/main"); diff --git a/odm/src/test/java/org/springframework/ldap/odm/test/LdapTests.java b/odm/src/test/java/org/springframework/ldap/odm/test/LdapTests.java index 1285219fb..f18c5a201 100755 --- a/odm/src/test/java/org/springframework/ldap/odm/test/LdapTests.java +++ b/odm/src/test/java/org/springframework/ldap/odm/test/LdapTests.java @@ -35,11 +35,11 @@ import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.cli.PosixParser; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,6 +68,7 @@ import org.springframework.util.CollectionUtils; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; // Tests all OdmManager functions public final class LdapTests { @@ -128,7 +129,7 @@ public final class LdapTests { } } - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { // Added because the close down of Apache DS on Linux does // not seem to free up its port. @@ -138,7 +139,7 @@ public static void setUpClass() throws Exception { LdapTestUtils.startEmbeddedServer(port, baseName.toString(), "odm-test"); } - @AfterClass + @AfterAll public static void tearDownClass() throws Exception { LdapTestUtils.shutdownEmbeddedServer(); } @@ -192,12 +193,12 @@ public void setUp(String url, String username, String password) throws Exception this.odmManager = new OdmManagerImpl(this.converterManager, this.contextSource, managedClasses); } - @Before + @BeforeEach public void setUp() throws Exception { setUp("ldap://127.0.0.1:" + port, "", ""); } - @After + @AfterEach public void tearDown() throws Exception { LdapTestUtils.clearSubContexts(this.contextSource, baseName); @@ -437,70 +438,81 @@ public void delete() throws Exception { } // Trying to read a non-existant entry should be flagged as an error - @Test(expected = NameNotFoundException.class) - public void readNonExistant() throws Exception { - this.odmManager.read(Person.class, LdapUtils.newLdapName("cn=Hili Harvey,ou=Doctors,o=Whoniverse")); + @Test + public void readNonExistant() { + assertThatExceptionOfType(NameNotFoundException.class).isThrownBy(() -> this.odmManager.read(Person.class, + LdapUtils.newLdapName("cn=Hili Harvey,ou=Doctors,o=Whoniverse"))); } // Read an entry with classes in addition to those supported by the Entry - @Test(expected = OdmException.class) - public void readNonMatchingObjectclasses() throws Exception { - this.odmManager.read(Person.class, LdapUtils.newLdapName("ou=Doctors,o=Whoniverse")); + @Test + public void readNonMatchingObjectclasses() { + assertThatExceptionOfType(OdmException.class) + .isThrownBy(() -> this.odmManager.read(Person.class, LdapUtils.newLdapName("ou=Doctors,o=Whoniverse"))); } // Every class to be managed must be annotated @Entry - @Test(expected = MetaDataException.class) + @Test public void noEntryAnnotation() { - ((OdmManagerImpl) this.odmManager).addManagedClass(NoEntry.class); + assertThatExceptionOfType(MetaDataException.class) + .isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(NoEntry.class)); } // There must be a field with the @Id annotation - @Test(expected = MetaDataException.class) + @Test public void noId() { - ((OdmManagerImpl) this.odmManager).addManagedClass(NoId.class); + assertThatExceptionOfType(MetaDataException.class) + .isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(NoId.class)); } // Only one field may be annotated @Id - @Test(expected = MetaDataException.class) + @Test public void twoIds() { - ((OdmManagerImpl) this.odmManager).addManagedClass(TwoIds.class); + assertThatExceptionOfType(MetaDataException.class) + .isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(TwoIds.class)); } // All Entry annotated classes must have a zero argument public constructor - @Test(expected = InvalidEntryException.class) + @Test public void noConstructor() { - ((OdmManagerImpl) this.odmManager).addManagedClass(NoConstructor.class); + assertThatExceptionOfType(InvalidEntryException.class) + .isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(NoConstructor.class)); } // It is illegal put put both the Id and the Attribute annotation on the same field - @Test(expected = MetaDataException.class) + @Test public void attributeOnId() { - ((OdmManagerImpl) this.odmManager).addManagedClass(AttributeOnId.class); + assertThatExceptionOfType(MetaDataException.class) + .isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(AttributeOnId.class)); } // The field annotation with @Id must be of type javax.naming.Name - @Test(expected = MetaDataException.class) + @Test public void idIsNotAName() { - ((OdmManagerImpl) this.odmManager).addManagedClass(IdIsNotAName.class); + assertThatExceptionOfType(MetaDataException.class) + .isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(IdIsNotAName.class)); } // The OdmManager should flag any missing converters when it is instantiated - @Test(expected = InvalidEntryException.class) + @Test public void missingConverter() { - ((OdmManagerImpl) this.odmManager).addManagedClass(MissingConverter.class); + assertThatExceptionOfType(InvalidEntryException.class) + .isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(MissingConverter.class)); } // The OdmManager should flag if the objectClass attribute is not of the appropriate // type - @Test(expected = MetaDataException.class) + @Test public void wrongClassForOc() { - ((OdmManagerImpl) this.odmManager).addManagedClass(WrongClassForOc.class); + assertThatExceptionOfType(MetaDataException.class) + .isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(WrongClassForOc.class)); } // The OdmManager should flag any attempt to use a "unmanaged" class - @Test(expected = MetaDataException.class) + @Test public void unManagedClass() { - this.odmManager.read(Integer.class, baseName); + assertThatExceptionOfType(MetaDataException.class) + .isThrownBy(() -> this.odmManager.read(Integer.class, baseName)); } @Test diff --git a/odm/src/test/java/org/springframework/ldap/odm/test/SchemaToJavaTests.java b/odm/src/test/java/org/springframework/ldap/odm/test/SchemaToJavaTests.java index 0cd884001..aaf03d8d9 100755 --- a/odm/src/test/java/org/springframework/ldap/odm/test/SchemaToJavaTests.java +++ b/odm/src/test/java/org/springframework/ldap/odm/test/SchemaToJavaTests.java @@ -30,11 +30,11 @@ import javax.naming.ldap.LdapName; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,7 +69,7 @@ public final class SchemaToJavaTests { private LdapContextSource contextSource; - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { // Added because the close down of Apache DS on Linux does // not seem to free up its port. @@ -79,13 +79,13 @@ public static void setUpClass() throws Exception { LdapTestUtils.startEmbeddedServer(port, baseName.toString(), "odm-test"); } - @AfterClass + @AfterAll public static void tearDownClass() throws Exception { // Stop the in process LDAP server LdapTestUtils.shutdownEmbeddedServer(); } - @Before + @BeforeEach public void setUp() throws Exception { // Create some basic converters and a converter manager this.converterManager = new ConverterManagerImpl(); @@ -120,7 +120,7 @@ public void setUp() throws Exception { LdapTestUtils.cleanAndSetup(this.contextSource, baseName, new ClassPathResource("testdata.ldif")); } - @After + @AfterEach public void tearDown() throws Exception { LdapTestUtils.shutdownEmbeddedServer(); diff --git a/odm/src/test/java/org/springframework/ldap/odm/test/SchemaViewerTests.java b/odm/src/test/java/org/springframework/ldap/odm/test/SchemaViewerTests.java index d1b4bb1d3..d0916b493 100755 --- a/odm/src/test/java/org/springframework/ldap/odm/test/SchemaViewerTests.java +++ b/odm/src/test/java/org/springframework/ldap/odm/test/SchemaViewerTests.java @@ -24,11 +24,11 @@ import javax.naming.ldap.LdapName; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.odm.test.utils.ExecuteRunnable; import org.springframework.ldap.odm.test.utils.GetFreePort; @@ -50,7 +50,7 @@ public final class SchemaViewerTests { private static String[] commonFlags; - @BeforeClass + @BeforeAll public static void setUpClass() throws Exception { // Added because the close down of Apache DS on Linux does // not seem to free up its port. @@ -63,16 +63,16 @@ public static void setUpClass() throws Exception { LdapTestUtils.startEmbeddedServer(port, baseName.toString(), "odm-test"); } - @AfterClass + @AfterAll public static void tearDownClass() throws Exception { LdapTestUtils.shutdownEmbeddedServer(); } - @Before + @BeforeEach public void setUp() throws Exception { } - @After + @AfterEach public void tearDown() throws Exception { } diff --git a/sandbox/build.gradle b/sandbox/build.gradle index 1a2f9a7f1..5933ba8f2 100644 --- a/sandbox/build.gradle +++ b/sandbox/build.gradle @@ -9,8 +9,9 @@ dependencies { provided "com.sun:ldapbp:1.0" testImplementation platform('org.junit:junit-bom') - testImplementation "org.junit.vintage:junit-vintage-engine" - testImplementation "junit:junit" + testImplementation "org.junit.jupiter:junit-jupiter-api" + testImplementation "org.junit.jupiter:junit-jupiter-engine" + testRuntimeOnly("org.junit.platform:junit-platform-launcher") testImplementation "org.mockito:mockito-core" testImplementation "gsbase:gsbase" testImplementation "org.assertj:assertj-core" @@ -26,4 +27,5 @@ compileTestJava { test { jvmArgs '--add-exports', 'java.naming/com.sun.jndi.ldap=ALL-UNNAMED' + useJUnitPlatform() } diff --git a/sandbox/src/test/java/org/springframework/ldap/control/VirtualListViewControlDirContextProcessorTests.java b/sandbox/src/test/java/org/springframework/ldap/control/VirtualListViewControlDirContextProcessorTests.java index d0b481f52..236f394a3 100644 --- a/sandbox/src/test/java/org/springframework/ldap/control/VirtualListViewControlDirContextProcessorTests.java +++ b/sandbox/src/test/java/org/springframework/ldap/control/VirtualListViewControlDirContextProcessorTests.java @@ -27,8 +27,8 @@ import com.sun.jndi.ldap.ctl.VirtualListViewControl; import com.sun.jndi.ldap.ctl.VirtualListViewResponseControl; import junit.framework.AssertionFailedError; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.ldap.OperationNotSupportedException; @@ -50,7 +50,7 @@ public class VirtualListViewControlDirContextProcessorTests { private LdapContext ldapContextMock; - @Before + @BeforeEach public void setUp() throws Exception { // Create ldapContext mock this.ldapContextMock = mock(LdapContext.class);