Skip to content

Commit 3d4f74a

Browse files
committed
Update Core Tests to JUnit 5
Issue gh-1058
1 parent 8734656 commit 3d4f74a

File tree

98 files changed

+409
-333
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+409
-333
lines changed

core/build.gradle

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ dependencies {
3838
exclude group: 'org.assertj'
3939
}
4040
testImplementation platform('org.junit:junit-bom')
41-
testImplementation "org.junit.vintage:junit-vintage-engine"
41+
testImplementation "org.junit.jupiter:junit-jupiter-api"
42+
testImplementation "org.junit.jupiter:junit-jupiter-engine"
4243
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
43-
44-
testImplementation "junit:junit"
4544
testImplementation "commons-lang:commons-lang"
4645
testImplementation "gsbase:gsbase"
4746
testImplementation "org.mockito:mockito-core"
47+
testImplementation "org.mockito:mockito-junit-jupiter:4.11.0"
4848
testImplementation "org.springframework:spring-test"
4949
testImplementation "org.assertj:assertj-core"
5050
testImplementation "com.unboundid:unboundid-ldapsdk"
@@ -60,6 +60,7 @@ compileTestJava {
6060

6161
test {
6262
jvmArgs '--add-exports', 'java.naming/com.sun.jndi.ldap=ALL-UNNAMED'
63+
useJUnitPlatform()
6364
}
6465

6566
checkFormatMain {

core/src/test/java/org/springframework/ldap/NamingExceptionTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
import javax.naming.directory.InitialDirContext;
2626

27-
import org.junit.Test;
27+
import org.junit.jupiter.api.Test;
2828

2929
import static org.assertj.core.api.Assertions.assertThat;
3030

core/src/test/java/org/springframework/ldap/aot/hint/LdapCoreRuntimeHintsTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import javax.naming.ldap.SortResponseControl;
2323
import javax.net.ssl.SSLSocketFactory;
2424

25-
import org.junit.Before;
26-
import org.junit.Test;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2727

2828
import org.springframework.aot.hint.MemberCategory;
2929
import org.springframework.aot.hint.RuntimeHints;
@@ -44,7 +44,7 @@ public class LdapCoreRuntimeHintsTests {
4444

4545
private final RuntimeHints hints = new RuntimeHints();
4646

47-
@Before
47+
@BeforeEach
4848
public void setup() {
4949
SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
5050
.load(RuntimeHintsRegistrar.class)

core/src/test/java/org/springframework/ldap/authentication/DefaultValuesAuthenticationSourceDecoratorTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.ldap.authentication;
1818

19-
import org.junit.Before;
20-
import org.junit.Test;
19+
import org.junit.jupiter.api.BeforeEach;
20+
import org.junit.jupiter.api.Test;
2121

2222
import org.springframework.ldap.core.AuthenticationSource;
2323

@@ -36,7 +36,7 @@ public class DefaultValuesAuthenticationSourceDecoratorTests {
3636

3737
private AuthenticationSource authenticationSourceMock;
3838

39-
@Before
39+
@BeforeEach
4040
public void setUp() throws Exception {
4141
this.authenticationSourceMock = mock(AuthenticationSource.class);
4242
this.tested = new DefaultValuesAuthenticationSourceDecorator();

core/src/test/java/org/springframework/ldap/config/LdapTemplateNamespaceHandlerTests.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
3030
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
31-
import org.junit.Test;
31+
import org.junit.jupiter.api.Test;
3232

3333
import org.springframework.beans.BeansException;
3434
import org.springframework.context.support.ClassPathXmlApplicationContext;
@@ -97,19 +97,22 @@ public void verifyThatAnonymousReadOnlyContextWillNotBeWrappedInProxy() {
9797
assertThat(Boolean.TRUE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly"));
9898
}
9999

100-
@Test(expected = BeansException.class)
100+
@Test
101101
public void verifyThatAnonymousReadOnlyAndTransactionalThrowsException() {
102-
new ClassPathXmlApplicationContext("/ldap-namespace-config-anonymous-read-only-and-transactions.xml");
102+
assertThatExceptionOfType(BeansException.class).isThrownBy(() -> new ClassPathXmlApplicationContext(
103+
"/ldap-namespace-config-anonymous-read-only-and-transactions.xml"));
103104
}
104105

105-
@Test(expected = BeansException.class)
106+
@Test
106107
public void verifyThatMissingUsernameThrowsException() {
107-
new ClassPathXmlApplicationContext("/ldap-namespace-config-missing-username.xml");
108+
assertThatExceptionOfType(BeansException.class)
109+
.isThrownBy(() -> new ClassPathXmlApplicationContext("/ldap-namespace-config-missing-username.xml"));
108110
}
109111

110-
@Test(expected = BeansException.class)
112+
@Test
111113
public void verifyThatMissingPasswordThrowsException() {
112-
new ClassPathXmlApplicationContext("/ldap-namespace-config-missing-password.xml");
114+
assertThatExceptionOfType(BeansException.class)
115+
.isThrownBy(() -> new ClassPathXmlApplicationContext("/ldap-namespace-config-missing-password.xml"));
113116
}
114117

115118
@Test
@@ -366,9 +369,10 @@ public void verifyParsePoolingValidationSet() {
366369
assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue();
367370
}
368371

369-
@Test(expected = BeansException.class)
372+
@Test
370373
public void verifyParseWithPoolingAndNativePoolingWillFail() {
371-
new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-with-native.xml");
374+
assertThatExceptionOfType(BeansException.class)
375+
.isThrownBy(() -> new ClassPathXmlApplicationContext("/ldap-namespace-config-pooling-with-native.xml"));
372376
}
373377

374378
@Test
@@ -494,14 +498,16 @@ public void verifyParsePool2ValidationSet() {
494498
assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue();
495499
}
496500

497-
@Test(expected = BeansException.class)
501+
@Test
498502
public void verifyParseWithPool2AndNativePoolingWillFail() {
499-
new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-with-native.xml");
503+
assertThatExceptionOfType(BeansException.class)
504+
.isThrownBy(() -> new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-with-native.xml"));
500505
}
501506

502-
@Test(expected = BeansException.class)
507+
@Test
503508
public void verifyParseWithPool1AndPool2WillFail() {
504-
new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-with-pool1.xml");
509+
assertThatExceptionOfType(BeansException.class)
510+
.isThrownBy(() -> new ClassPathXmlApplicationContext("/ldap-namespace-config-pool2-with-pool1.xml"));
505511
}
506512

507513
@Test

core/src/test/java/org/springframework/ldap/control/PagedResultTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import javax.naming.ldap.PagedResultsControl;
2323

2424
import com.gargoylesoftware.base.testing.EqualsTester;
25-
import org.junit.Test;
25+
import org.junit.jupiter.api.Test;
2626

2727
/**
2828
* Unit tests for the PagedResult class. {@link PagedResultsControl}

core/src/test/java/org/springframework/ldap/control/PagedResultsCookieTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.springframework.ldap.control;
1818

1919
import com.gargoylesoftware.base.testing.EqualsTester;
20-
import org.junit.Test;
20+
import org.junit.jupiter.api.Test;
2121

2222
public class PagedResultsCookieTests {
2323

core/src/test/java/org/springframework/ldap/control/PagedResultsDirContextProcessorTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
import com.sun.jndi.ldap.BerDecoder;
2828
import com.sun.jndi.ldap.BerEncoder;
2929
import com.sun.jndi.ldap.ctl.DirSyncResponseControl;
30-
import org.junit.After;
31-
import org.junit.Before;
32-
import org.junit.Test;
30+
import org.junit.jupiter.api.AfterEach;
31+
import org.junit.jupiter.api.BeforeEach;
32+
import org.junit.jupiter.api.Test;
3333

3434
import static org.assertj.core.api.Assertions.assertThat;
3535
import static org.mockito.BDDMockito.given;
@@ -41,7 +41,7 @@ public class PagedResultsDirContextProcessorTests {
4141

4242
private PagedResultsDirContextProcessor tested;
4343

44-
@Before
44+
@BeforeEach
4545
public void setUp() throws Exception {
4646

4747
this.tested = new PagedResultsDirContextProcessor(20);
@@ -50,7 +50,7 @@ public void setUp() throws Exception {
5050
this.ldapContextMock = mock(LdapContext.class);
5151
}
5252

53-
@After
53+
@AfterEach
5454
public void tearDown() throws Exception {
5555

5656
this.tested = null;

core/src/test/java/org/springframework/ldap/control/RequestControlDirContextProcessorTests.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
2222
import javax.naming.ldap.LdapContext;
2323
import javax.naming.ldap.SortControl;
2424

25-
import org.junit.After;
26-
import org.junit.Before;
27-
import org.junit.Test;
25+
import org.junit.jupiter.api.AfterEach;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
2828

29+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2930
import static org.mockito.BDDMockito.given;
3031
import static org.mockito.BDDMockito.mock;
3132
import static org.mockito.BDDMockito.verify;
@@ -42,7 +43,7 @@ public class RequestControlDirContextProcessorTests {
4243

4344
private DirContext dirContextMock;
4445

45-
@Before
46+
@BeforeEach
4647
public void setUp() throws Exception {
4748
// Create requestControl mock
4849
this.requestControlMock = mock(Control.class);
@@ -68,7 +69,7 @@ public void postProcess(DirContext ctx) throws NamingException {
6869
};
6970
}
7071

71-
@After
72+
@AfterEach
7273
public void tearDown() throws Exception {
7374
this.requestControlMock = null;
7475
this.requestControl2Mock = null;
@@ -125,9 +126,10 @@ public void testPreProcessWithNullControlsShouldAdd() throws NamingException {
125126
verify(this.ldapContextMock).setRequestControls(new Control[] { this.requestControlMock });
126127
}
127128

128-
@Test(expected = IllegalArgumentException.class)
129-
public void testPreProcessWhenNotLdapContextShouldFail() throws Exception {
130-
this.tested.preProcess(this.dirContextMock);
129+
@Test
130+
public void testPreProcessWhenNotLdapContextShouldFail() {
131+
assertThatExceptionOfType(IllegalArgumentException.class)
132+
.isThrownBy(() -> this.tested.preProcess(this.dirContextMock));
131133
}
132134

133135
}

core/src/test/java/org/springframework/ldap/control/SortControlDirContextProcessorTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import com.sun.jndi.ldap.BerDecoder;
2828
import com.sun.jndi.ldap.BerEncoder;
2929
import com.sun.jndi.ldap.ctl.DirSyncResponseControl;
30-
import org.junit.Before;
31-
import org.junit.Test;
30+
import org.junit.jupiter.api.BeforeEach;
31+
import org.junit.jupiter.api.Test;
3232

3333
import static org.assertj.core.api.Assertions.assertThat;
3434
import static org.mockito.BDDMockito.given;
@@ -45,7 +45,7 @@ public class SortControlDirContextProcessorTests {
4545

4646
private SortControlDirContextProcessor tested;
4747

48-
@Before
48+
@BeforeEach
4949
public void setUp() throws Exception {
5050
this.tested = new SortControlDirContextProcessor("key");
5151

0 commit comments

Comments
 (0)