1616
1717package org .springframework .boot .autoconfigure .ldap ;
1818
19- import java .util .Hashtable ;
20-
21- import javax .naming .directory .DirContext ;
22-
2319import org .junit .jupiter .api .Test ;
2420
2521import org .springframework .boot .autoconfigure .AutoConfigurations ;
3632import org .springframework .test .util .ReflectionTestUtils ;
3733
3834import static org .assertj .core .api .Assertions .assertThat ;
35+ import static org .mockito .Mockito .mock ;
3936
4037/**
4138 * Tests for {@link LdapAutoConfiguration}.
@@ -97,14 +94,11 @@ void contextSourceWithExtraCustomization() {
9794 @ Test
9895 void contextSourceWithNoCustomization () {
9996 this .contextRunner .run ((context ) -> {
100- assertThat (context ).doesNotHaveBean (DirContextAuthenticationStrategy .class );
10197 LdapContextSource contextSource = context .getBean (LdapContextSource .class );
10298 assertThat (contextSource .getUserDn ()).isEqualTo ("" );
10399 assertThat (contextSource .getPassword ()).isEqualTo ("" );
104100 assertThat (contextSource .isAnonymousReadOnly ()).isFalse ();
105101 assertThat (contextSource .getBaseLdapPathAsString ()).isEqualTo ("" );
106- assertThat (ReflectionTestUtils .getField (contextSource , "authenticationStrategy" ))
107- .isInstanceOf (SimpleDirContextAuthenticationStrategy .class );
108102 });
109103 }
110104
@@ -129,7 +123,7 @@ void contextSourceWithCustomUniqueDirContextAuthenticationStrategy() {
129123 assertThat (context ).hasSingleBean (DirContextAuthenticationStrategy .class );
130124 LdapContextSource contextSource = context .getBean (LdapContextSource .class );
131125 assertThat (ReflectionTestUtils .getField (contextSource , "authenticationStrategy" ))
132- .isEqualTo (context .getBean (DirContextAuthenticationStrategy . class ));
126+ .isSameAs (context .getBean ("customDirContextAuthenticationStrategy" ));
133127 });
134128 }
135129
@@ -139,15 +133,10 @@ void contextSourceWithCustomNonUniqueDirContextAuthenticationStrategy() {
139133 AnotherCustomDirContextAuthenticationStrategy .class ).run ((context ) -> {
140134 assertThat (context ).hasBean ("customDirContextAuthenticationStrategy" )
141135 .hasBean ("anotherCustomDirContextAuthenticationStrategy" );
142- TestDirContextAuthenticationStrategy customDirContextAuthenticationStrategy = context .getBean (
143- "customDirContextAuthenticationStrategy" , TestDirContextAuthenticationStrategy .class );
144- TestDirContextAuthenticationStrategy anotherCustomDirContextAuthenticationStrategy = context
145- .getBean ("anotherCustomDirContextAuthenticationStrategy" ,
146- TestDirContextAuthenticationStrategy .class );
147136 LdapContextSource contextSource = context .getBean (LdapContextSource .class );
148137 assertThat (ReflectionTestUtils .getField (contextSource , "authenticationStrategy" ))
149- .isNotEqualTo ( customDirContextAuthenticationStrategy )
150- .isNotEqualTo ( anotherCustomDirContextAuthenticationStrategy )
138+ .isNotSameAs ( context . getBean ( " customDirContextAuthenticationStrategy" ) )
139+ .isNotSameAs ( context . getBean ( " anotherCustomDirContextAuthenticationStrategy" ) )
151140 .isInstanceOf (SimpleDirContextAuthenticationStrategy .class );
152141 });
153142 }
@@ -170,7 +159,7 @@ static class CustomDirContextAuthenticationStrategy {
170159
171160 @ Bean
172161 DirContextAuthenticationStrategy customDirContextAuthenticationStrategy () {
173- return new TestDirContextAuthenticationStrategy ( );
162+ return mock ( DirContextAuthenticationStrategy . class );
174163 }
175164
176165 }
@@ -180,21 +169,7 @@ static class AnotherCustomDirContextAuthenticationStrategy {
180169
181170 @ Bean
182171 DirContextAuthenticationStrategy anotherCustomDirContextAuthenticationStrategy () {
183- return new TestDirContextAuthenticationStrategy ();
184- }
185-
186- }
187-
188- static class TestDirContextAuthenticationStrategy implements DirContextAuthenticationStrategy {
189-
190- @ Override
191- public void setupEnvironment (Hashtable <String , Object > env , String userDn , String password ) {
192-
193- }
194-
195- @ Override
196- public DirContext processContextAfterCreation (DirContext ctx , String userDn , String password ) {
197- return ctx ;
172+ return mock (DirContextAuthenticationStrategy .class );
198173 }
199174
200175 }
0 commit comments