Skip to content

Commit be8c30e

Browse files
committed
Update Odm Tests to JUnit 5
Issue gh-1058
1 parent cc178e2 commit be8c30e

File tree

7 files changed

+88
-67
lines changed

7 files changed

+88
-67
lines changed

odm/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,11 @@ dependencies {
3434
testImplementation "org.apache.directory.shared:shared-ldap"
3535
testImplementation "org.assertj:assertj-core"
3636
testImplementation platform('org.junit:junit-bom')
37-
testImplementation "org.junit.vintage:junit-vintage-engine"
37+
testImplementation "org.junit.jupiter:junit-jupiter-api"
38+
testImplementation "org.junit.jupiter:junit-jupiter-engine"
39+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
40+
}
41+
42+
tasks.withType(Test).configureEach {
43+
useJUnitPlatform()
3844
}

odm/src/test/java/org/springframework/ldap/odm/test/ConverterFactoryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.HashSet;
2121
import java.util.Set;
2222

23-
import org.junit.Test;
23+
import org.junit.jupiter.api.Test;
2424

2525
import org.springframework.ldap.odm.test.utils.ExecuteRunnable;
2626
import org.springframework.ldap.odm.test.utils.RunnableTests;

odm/src/test/java/org/springframework/ldap/odm/test/ConverterManagerTests.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
import java.net.URI;
2020
import java.util.BitSet;
2121

22-
import org.junit.After;
23-
import org.junit.Before;
24-
import org.junit.Test;
22+
import org.junit.jupiter.api.AfterEach;
23+
import org.junit.jupiter.api.BeforeEach;
24+
import org.junit.jupiter.api.Test;
2525

2626
import org.springframework.ldap.odm.test.utils.ExecuteRunnable;
2727
import org.springframework.ldap.odm.test.utils.RunnableTests;
@@ -32,12 +32,13 @@
3232
import org.springframework.ldap.odm.typeconversion.impl.converters.ToStringConverter;
3333

3434
import static org.assertj.core.api.Assertions.assertThat;
35+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
3536

3637
public final class ConverterManagerTests {
3738

3839
private ConverterManagerImpl converterManager;
3940

40-
@Before
41+
@BeforeEach
4142
public void setUp() {
4243
this.converterManager = new ConverterManagerImpl();
4344

@@ -64,7 +65,7 @@ public void setUp() {
6465
this.converterManager.addConverter(String.class, "", URI.class, uric);
6566
}
6667

67-
@After
68+
@AfterEach
6869
public void tearDown() {
6970
this.converterManager = null;
7071
}
@@ -141,15 +142,17 @@ public void runTest(ConverterTestData<?> testData) {
141142
}
142143

143144
// No converter for classes
144-
@Test(expected = ConverterException.class)
145-
public void noClassConverter() throws Exception {
146-
this.converterManager.convert(BitSet.class, "", Integer.class);
145+
@Test
146+
public void noClassConverter() {
147+
assertThatExceptionOfType(ConverterException.class)
148+
.isThrownBy(() -> this.converterManager.convert(BitSet.class, "", Integer.class));
147149
}
148150

149151
// Invalid syntax so converter fails
150-
@Test(expected = ConverterException.class)
151-
public void invalidSyntax() throws Exception {
152-
this.converterManager.convert(String.class, "not a uri", URI.class);
152+
@Test
153+
public void invalidSyntax() {
154+
assertThatExceptionOfType(ConverterException.class)
155+
.isThrownBy(() -> this.converterManager.convert(String.class, "not a uri", URI.class));
153156
}
154157

155158
private static final class ConverterTestData<T> {

odm/src/test/java/org/springframework/ldap/odm/test/JDependTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
import java.io.IOException;
2020

2121
import jdepend.framework.JDepend;
22-
import org.junit.Before;
23-
import org.junit.Test;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
2424

2525
import static org.assertj.core.api.Assertions.assertThat;
2626

2727
public class JDependTests {
2828

2929
private JDepend jdepend;
3030

31-
@Before
31+
@BeforeEach
3232
public void setUp() throws IOException {
3333
this.jdepend = new JDepend();
3434
this.jdepend.addDirectory("build/classes/java/main");

odm/src/test/java/org/springframework/ldap/odm/test/LdapTests.java

Lines changed: 45 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
import org.apache.commons.cli.Options;
3636
import org.apache.commons.cli.ParseException;
3737
import org.apache.commons.cli.PosixParser;
38-
import org.junit.After;
39-
import org.junit.AfterClass;
40-
import org.junit.Before;
41-
import org.junit.BeforeClass;
42-
import org.junit.Test;
38+
import org.junit.jupiter.api.AfterAll;
39+
import org.junit.jupiter.api.AfterEach;
40+
import org.junit.jupiter.api.BeforeAll;
41+
import org.junit.jupiter.api.BeforeEach;
42+
import org.junit.jupiter.api.Test;
4343
import org.slf4j.Logger;
4444
import org.slf4j.LoggerFactory;
4545

@@ -68,6 +68,7 @@
6868
import org.springframework.util.CollectionUtils;
6969

7070
import static org.assertj.core.api.Assertions.assertThat;
71+
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
7172

7273
// Tests all OdmManager functions
7374
public final class LdapTests {
@@ -128,7 +129,7 @@ public final class LdapTests {
128129
}
129130
}
130131

131-
@BeforeClass
132+
@BeforeAll
132133
public static void setUpClass() throws Exception {
133134
// Added because the close down of Apache DS on Linux does
134135
// not seem to free up its port.
@@ -138,7 +139,7 @@ public static void setUpClass() throws Exception {
138139
LdapTestUtils.startEmbeddedServer(port, baseName.toString(), "odm-test");
139140
}
140141

141-
@AfterClass
142+
@AfterAll
142143
public static void tearDownClass() throws Exception {
143144
LdapTestUtils.shutdownEmbeddedServer();
144145
}
@@ -192,12 +193,12 @@ public void setUp(String url, String username, String password) throws Exception
192193
this.odmManager = new OdmManagerImpl(this.converterManager, this.contextSource, managedClasses);
193194
}
194195

195-
@Before
196+
@BeforeEach
196197
public void setUp() throws Exception {
197198
setUp("ldap://127.0.0.1:" + port, "", "");
198199
}
199200

200-
@After
201+
@AfterEach
201202
public void tearDown() throws Exception {
202203
LdapTestUtils.clearSubContexts(this.contextSource, baseName);
203204

@@ -437,70 +438,81 @@ public void delete() throws Exception {
437438
}
438439

439440
// Trying to read a non-existant entry should be flagged as an error
440-
@Test(expected = NameNotFoundException.class)
441-
public void readNonExistant() throws Exception {
442-
this.odmManager.read(Person.class, LdapUtils.newLdapName("cn=Hili Harvey,ou=Doctors,o=Whoniverse"));
441+
@Test
442+
public void readNonExistant() {
443+
assertThatExceptionOfType(NameNotFoundException.class).isThrownBy(() -> this.odmManager.read(Person.class,
444+
LdapUtils.newLdapName("cn=Hili Harvey,ou=Doctors,o=Whoniverse")));
443445
}
444446

445447
// Read an entry with classes in addition to those supported by the Entry
446-
@Test(expected = OdmException.class)
447-
public void readNonMatchingObjectclasses() throws Exception {
448-
this.odmManager.read(Person.class, LdapUtils.newLdapName("ou=Doctors,o=Whoniverse"));
448+
@Test
449+
public void readNonMatchingObjectclasses() {
450+
assertThatExceptionOfType(OdmException.class)
451+
.isThrownBy(() -> this.odmManager.read(Person.class, LdapUtils.newLdapName("ou=Doctors,o=Whoniverse")));
449452
}
450453

451454
// Every class to be managed must be annotated @Entry
452-
@Test(expected = MetaDataException.class)
455+
@Test
453456
public void noEntryAnnotation() {
454-
((OdmManagerImpl) this.odmManager).addManagedClass(NoEntry.class);
457+
assertThatExceptionOfType(MetaDataException.class)
458+
.isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(NoEntry.class));
455459
}
456460

457461
// There must be a field with the @Id annotation
458-
@Test(expected = MetaDataException.class)
462+
@Test
459463
public void noId() {
460-
((OdmManagerImpl) this.odmManager).addManagedClass(NoId.class);
464+
assertThatExceptionOfType(MetaDataException.class)
465+
.isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(NoId.class));
461466
}
462467

463468
// Only one field may be annotated @Id
464-
@Test(expected = MetaDataException.class)
469+
@Test
465470
public void twoIds() {
466-
((OdmManagerImpl) this.odmManager).addManagedClass(TwoIds.class);
471+
assertThatExceptionOfType(MetaDataException.class)
472+
.isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(TwoIds.class));
467473
}
468474

469475
// All Entry annotated classes must have a zero argument public constructor
470-
@Test(expected = InvalidEntryException.class)
476+
@Test
471477
public void noConstructor() {
472-
((OdmManagerImpl) this.odmManager).addManagedClass(NoConstructor.class);
478+
assertThatExceptionOfType(InvalidEntryException.class)
479+
.isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(NoConstructor.class));
473480
}
474481

475482
// It is illegal put put both the Id and the Attribute annotation on the same field
476-
@Test(expected = MetaDataException.class)
483+
@Test
477484
public void attributeOnId() {
478-
((OdmManagerImpl) this.odmManager).addManagedClass(AttributeOnId.class);
485+
assertThatExceptionOfType(MetaDataException.class)
486+
.isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(AttributeOnId.class));
479487
}
480488

481489
// The field annotation with @Id must be of type javax.naming.Name
482-
@Test(expected = MetaDataException.class)
490+
@Test
483491
public void idIsNotAName() {
484-
((OdmManagerImpl) this.odmManager).addManagedClass(IdIsNotAName.class);
492+
assertThatExceptionOfType(MetaDataException.class)
493+
.isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(IdIsNotAName.class));
485494
}
486495

487496
// The OdmManager should flag any missing converters when it is instantiated
488-
@Test(expected = InvalidEntryException.class)
497+
@Test
489498
public void missingConverter() {
490-
((OdmManagerImpl) this.odmManager).addManagedClass(MissingConverter.class);
499+
assertThatExceptionOfType(InvalidEntryException.class)
500+
.isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(MissingConverter.class));
491501
}
492502

493503
// The OdmManager should flag if the objectClass attribute is not of the appropriate
494504
// type
495-
@Test(expected = MetaDataException.class)
505+
@Test
496506
public void wrongClassForOc() {
497-
((OdmManagerImpl) this.odmManager).addManagedClass(WrongClassForOc.class);
507+
assertThatExceptionOfType(MetaDataException.class)
508+
.isThrownBy(() -> ((OdmManagerImpl) this.odmManager).addManagedClass(WrongClassForOc.class));
498509
}
499510

500511
// The OdmManager should flag any attempt to use a "unmanaged" class
501-
@Test(expected = MetaDataException.class)
512+
@Test
502513
public void unManagedClass() {
503-
this.odmManager.read(Integer.class, baseName);
514+
assertThatExceptionOfType(MetaDataException.class)
515+
.isThrownBy(() -> this.odmManager.read(Integer.class, baseName));
504516
}
505517

506518
@Test

odm/src/test/java/org/springframework/ldap/odm/test/SchemaToJavaTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030

3131
import javax.naming.ldap.LdapName;
3232

33-
import org.junit.After;
34-
import org.junit.AfterClass;
35-
import org.junit.Before;
36-
import org.junit.BeforeClass;
37-
import org.junit.Test;
33+
import org.junit.jupiter.api.AfterAll;
34+
import org.junit.jupiter.api.AfterEach;
35+
import org.junit.jupiter.api.BeforeAll;
36+
import org.junit.jupiter.api.BeforeEach;
37+
import org.junit.jupiter.api.Test;
3838
import org.slf4j.Logger;
3939
import org.slf4j.LoggerFactory;
4040

@@ -69,7 +69,7 @@ public final class SchemaToJavaTests {
6969

7070
private LdapContextSource contextSource;
7171

72-
@BeforeClass
72+
@BeforeAll
7373
public static void setUpClass() throws Exception {
7474
// Added because the close down of Apache DS on Linux does
7575
// not seem to free up its port.
@@ -79,13 +79,13 @@ public static void setUpClass() throws Exception {
7979
LdapTestUtils.startEmbeddedServer(port, baseName.toString(), "odm-test");
8080
}
8181

82-
@AfterClass
82+
@AfterAll
8383
public static void tearDownClass() throws Exception {
8484
// Stop the in process LDAP server
8585
LdapTestUtils.shutdownEmbeddedServer();
8686
}
8787

88-
@Before
88+
@BeforeEach
8989
public void setUp() throws Exception {
9090
// Create some basic converters and a converter manager
9191
this.converterManager = new ConverterManagerImpl();
@@ -120,7 +120,7 @@ public void setUp() throws Exception {
120120
LdapTestUtils.cleanAndSetup(this.contextSource, baseName, new ClassPathResource("testdata.ldif"));
121121
}
122122

123-
@After
123+
@AfterEach
124124
public void tearDown() throws Exception {
125125
LdapTestUtils.shutdownEmbeddedServer();
126126

odm/src/test/java/org/springframework/ldap/odm/test/SchemaViewerTests.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424

2525
import javax.naming.ldap.LdapName;
2626

27-
import org.junit.After;
28-
import org.junit.AfterClass;
29-
import org.junit.Before;
30-
import org.junit.BeforeClass;
31-
import org.junit.Test;
27+
import org.junit.jupiter.api.AfterAll;
28+
import org.junit.jupiter.api.AfterEach;
29+
import org.junit.jupiter.api.BeforeAll;
30+
import org.junit.jupiter.api.BeforeEach;
31+
import org.junit.jupiter.api.Test;
3232

3333
import org.springframework.ldap.odm.test.utils.ExecuteRunnable;
3434
import org.springframework.ldap.odm.test.utils.GetFreePort;
@@ -50,7 +50,7 @@ public final class SchemaViewerTests {
5050

5151
private static String[] commonFlags;
5252

53-
@BeforeClass
53+
@BeforeAll
5454
public static void setUpClass() throws Exception {
5555
// Added because the close down of Apache DS on Linux does
5656
// not seem to free up its port.
@@ -63,16 +63,16 @@ public static void setUpClass() throws Exception {
6363
LdapTestUtils.startEmbeddedServer(port, baseName.toString(), "odm-test");
6464
}
6565

66-
@AfterClass
66+
@AfterAll
6767
public static void tearDownClass() throws Exception {
6868
LdapTestUtils.shutdownEmbeddedServer();
6969
}
7070

71-
@Before
71+
@BeforeEach
7272
public void setUp() throws Exception {
7373
}
7474

75-
@After
75+
@AfterEach
7676
public void tearDown() throws Exception {
7777
}
7878

0 commit comments

Comments
 (0)