3535import org .apache .commons .cli .Options ;
3636import org .apache .commons .cli .ParseException ;
3737import 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 ;
4343import org .slf4j .Logger ;
4444import org .slf4j .LoggerFactory ;
4545
6868import org .springframework .util .CollectionUtils ;
6969
7070import static org .assertj .core .api .Assertions .assertThat ;
71+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
7172
7273// Tests all OdmManager functions
7374public 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
0 commit comments