3131import org .junit .jupiter .api .BeforeEach ;
3232import org .junit .jupiter .api .Test ;
3333
34- import org .springframework .ldap .core .AttributesMapper ;
3534import org .springframework .ldap .core .LdapTemplate ;
3635import org .springframework .ldap .core .support .LdapContextSource ;
3736import org .springframework .ldap .query .LdapQueryBuilder ;
3837
3938import static org .assertj .core .api .Assertions .assertThat ;
4039import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
4140
42- public class EmbeddedLdapServerTests {
41+ class EmbeddedLdapServerTests {
4342
4443 private int port ;
4544
4645 @ BeforeEach
47- public void setUp () throws IOException {
46+ void setUp () throws IOException {
4847 this .port = getFreePort ();
4948 }
5049
5150 @ Test
52- public void shouldStartAndCloseServer () throws Exception {
51+ void shouldStartAndCloseServer () throws Exception {
5352 assertPortIsFree (this .port );
5453
5554 EmbeddedLdapServer server = EmbeddedLdapServer .newEmbeddedServer ("jayway" , "dc=jayway,dc=se" , this .port );
@@ -60,7 +59,7 @@ public void shouldStartAndCloseServer() throws Exception {
6059 }
6160
6261 @ Test
63- public void shouldStartAndAutoCloseServer () throws Exception {
62+ void shouldStartAndAutoCloseServer () throws Exception {
6463 assertPortIsFree (this .port );
6564
6665 try (EmbeddedLdapServer ignored = EmbeddedLdapServer .newEmbeddedServer ("jayway" , "dc=jayway,dc=se" ,
@@ -71,7 +70,7 @@ public void shouldStartAndAutoCloseServer() throws Exception {
7170 }
7271
7372 @ Test
74- public void shouldStartAndCloseServerViaLdapTestUtils () throws Exception {
73+ void shouldStartAndCloseServerViaLdapTestUtils () throws Exception {
7574 assertPortIsFree (this .port );
7675
7776 LdapTestUtils .startEmbeddedServer (this .port , "dc=jayway,dc=se" , "jayway" );
@@ -82,13 +81,13 @@ public void shouldStartAndCloseServerViaLdapTestUtils() throws Exception {
8281 }
8382
8483 @ Test
85- public void startWhenNewEmbeddedServerThenException () throws Exception {
84+ void startWhenNewEmbeddedServerThenException () throws Exception {
8685 EmbeddedLdapServer server = EmbeddedLdapServer .newEmbeddedServer ("jayway" , "dc=jayway,dc=se" , this .port );
8786 assertThatExceptionOfType (IllegalArgumentException .class ).isThrownBy (server ::start );
8887 }
8988
9089 @ Test
91- public void startWhenUnstartedThenWorks () throws Exception {
90+ void startWhenUnstartedThenWorks () throws Exception {
9291 InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig ("dc=jayway,dc=se" );
9392 config .setListenerConfigs (InMemoryListenerConfig .createLDAPConfig ("LDAP" , this .port ));
9493 InMemoryDirectoryServer ds = new InMemoryDirectoryServer (config );
@@ -99,7 +98,7 @@ public void startWhenUnstartedThenWorks() throws Exception {
9998 }
10099
101100 @ Test
102- public void startWhenAlreadyStartedThenFails () throws Exception {
101+ void startWhenAlreadyStartedThenFails () throws Exception {
103102 InMemoryDirectoryServerConfig config = new InMemoryDirectoryServerConfig ("dc=jayway,dc=se" );
104103 config .setListenerConfigs (InMemoryListenerConfig .createLDAPConfig ("LDAP" , this .port ));
105104 InMemoryDirectoryServer ds = new InMemoryDirectoryServer (config );
@@ -111,13 +110,13 @@ public void startWhenAlreadyStartedThenFails() throws Exception {
111110 }
112111
113112 @ Test
114- public void shouldBuildButNotStartTheServer () {
113+ void shouldBuildButNotStartTheServer () {
115114 EmbeddedLdapServer .withPartitionSuffix ("dc=jayway,dc=se" ).port (this .port ).build ();
116115 assertPortIsFree (this .port );
117116 }
118117
119118 @ Test
120- public void shouldBuildTheServerWithCustomPort () {
119+ void shouldBuildTheServerWithCustomPort () {
121120 EmbeddedLdapServer .Builder serverBuilder = EmbeddedLdapServer .withPartitionSuffix ("dc=jayway,dc=se" )
122121 .port (this .port );
123122
@@ -129,7 +128,7 @@ public void shouldBuildTheServerWithCustomPort() {
129128 }
130129
131130 @ Test
132- public void shouldBuildLdapServerAndApplyCustomConfiguration () throws IOException {
131+ void shouldBuildLdapServerAndApplyCustomConfiguration () throws IOException {
133132 String tempLogFile = Files .createTempFile ("ldap-log-" , ".txt" ).toAbsolutePath ().toString ();
134133
135134 EmbeddedLdapServer .Builder serverBuilder = EmbeddedLdapServer .withPartitionSuffix ("dc=jayway,dc=se" )
@@ -140,18 +139,18 @@ public void shouldBuildLdapServerAndApplyCustomConfiguration() throws IOExceptio
140139 server .start ();
141140
142141 ldapTemplate ("dc=jayway,dc=se" , this .port )
143- .search (LdapQueryBuilder .query ().where ("objectclass" ).is ("person" ), new AttributesMapper <>() {
144- public String mapFromAttributes (Attributes attrs ) throws NamingException {
145- return (String ) attrs .get ("cn" ).get ();
146- }
147- });
142+ .search (LdapQueryBuilder .query ().where ("objectclass" ).is ("person" ), this ::commonNameAttribute );
148143 }
149144
150145 assertThat (Path .of (tempLogFile ))
151146 .as ("Applying the custom configuration should create a log file and populate it with the request" )
152147 .isNotEmptyFile ();
153148 }
154149
150+ private String commonNameAttribute (Attributes attrs ) throws NamingException {
151+ return (String ) attrs .get ("cn" ).get ();
152+ }
153+
155154 static void assertPortIsFree (int port ) {
156155 assertThat (isPortOpen (port )).isFalse ();
157156 }
0 commit comments