37
37
import static org .junit .jupiter .api .Assertions .assertEquals ;
38
38
import static org .junit .jupiter .api .Assertions .assertFalse ;
39
39
import static org .mockito .ArgumentMatchers .any ;
40
+ import static org .mockito .Mockito .doReturn ;
40
41
import static org .mockito .Mockito .times ;
41
42
import static org .mockito .Mockito .verify ;
42
43
43
- public class LdapFacadeTest {
44
+ class LdapFacadeTest {
44
45
@ Test
45
- public void testSearchControlsConfig () {
46
+ void testSearchControlsConfig () {
46
47
Configuration config = new Configuration ();
47
48
int searchTimeout = 1234 ;
48
49
config .setSearchTimeout (searchTimeout );
@@ -62,13 +63,13 @@ private LdapServer getSpyLdapServer(String name) throws UnknownHostException {
62
63
private LdapServer getSpyLdapServer (String name , boolean working ) throws UnknownHostException {
63
64
LdapServer server = new LdapServer (name );
64
65
LdapServer serverSpy = Mockito .spy (server );
65
- Mockito . when ( serverSpy . getAddresses ( any ())). thenReturn ( new InetAddress []{InetAddress .getLocalHost ()});
66
- Mockito .when (serverSpy .isWorking ()). thenReturn ( working );
66
+ doReturn ( new InetAddress []{InetAddress .getLocalHost ()}). when ( serverSpy ). getAddresses ( any () );
67
+ doReturn ( working ) .when (serverSpy ) .isWorking ();
67
68
return serverSpy ;
68
69
}
69
70
70
71
@ Test
71
- public void testConnectTimeoutInheritance () throws UnknownHostException {
72
+ void testConnectTimeoutInheritance () throws UnknownHostException {
72
73
Configuration config = new Configuration ();
73
74
74
75
LdapServer [] servers = {getSpyLdapServer ("ldap://foo.com" ), getSpyLdapServer ("ldap://bar.com" )};
@@ -87,12 +88,12 @@ public void testConnectTimeoutInheritance() throws UnknownHostException {
87
88
}
88
89
89
90
@ Test
90
- public void testToStringNegative () throws UnknownHostException {
91
+ void testToStringNegative () throws UnknownHostException {
91
92
Configuration config = new Configuration ();
92
93
LdapServer server1 = new LdapServer ("ldap://foo.com" );
93
94
LdapServer serverSpy1 = Mockito .spy (server1 );
94
- Mockito . when ( serverSpy1 . getAddresses ( any ())). thenReturn ( new InetAddress []{InetAddress .getLocalHost ()});
95
- Mockito .when (serverSpy1 .isReachable ()). thenReturn ( false );
95
+ doReturn ( new InetAddress []{InetAddress .getLocalHost ()}). when ( serverSpy1 ). getAddresses ( any () );
96
+ doReturn ( false ) .when (serverSpy1 ) .isReachable ();
96
97
97
98
config .setServers (Collections .singletonList (serverSpy1 ));
98
99
config .setSearchBase ("dc=foo,dc=com" );
@@ -104,11 +105,11 @@ public void testToStringNegative() throws UnknownHostException {
104
105
}
105
106
106
107
@ Test
107
- public void testToStringPositive () throws UnknownHostException {
108
+ void testToStringPositive () {
108
109
Configuration config = new Configuration ();
109
110
LdapServer server1 = new LdapServer ("ldap://foo.com" );
110
111
LdapServer serverSpy1 = Mockito .spy (server1 );
111
- Mockito . doReturn (true ).when (serverSpy1 ).isWorking ();
112
+ doReturn (true ).when (serverSpy1 ).isWorking ();
112
113
113
114
config .setServers (Collections .singletonList (serverSpy1 ));
114
115
config .setSearchBase ("dc=foo,dc=com" );
@@ -120,7 +121,7 @@ public void testToStringPositive() throws UnknownHostException {
120
121
}
121
122
122
123
@ Test
123
- public void testPrepareServersNegative () throws UnknownHostException {
124
+ void testPrepareServersNegative () throws UnknownHostException {
124
125
Configuration config = new Configuration ();
125
126
config .setServers (Arrays .asList (getSpyLdapServer ("ldap://foo.com" , false ),
126
127
getSpyLdapServer ("ldap://bar.com" , true )));
@@ -129,15 +130,15 @@ public void testPrepareServersNegative() throws UnknownHostException {
129
130
}
130
131
131
132
@ Test
132
- public void testGetSearchDescription () {
133
+ void testGetSearchDescription () {
133
134
assertEquals ("DN: foo, filter: bar, attributes: Bilbo,Frodo" ,
134
135
LdapFacade .getSearchDescription ("foo" , "bar" , new String []{"Bilbo" , "Frodo" }));
135
136
assertEquals ("DN: foo, filter: bar" ,
136
137
LdapFacade .getSearchDescription ("foo" , "bar" , null ));
137
138
}
138
139
139
140
@ Test
140
- public void testPrepareServersCloseUnused () throws UnknownHostException {
141
+ void testPrepareServersCloseUnused () throws UnknownHostException {
141
142
Configuration config = new Configuration ();
142
143
143
144
LdapServer server1 = getSpyLdapServer ("ldap://foo.com" );
0 commit comments