Skip to content

Commit bd65108

Browse files
ahornaceVladimir Kotal
authored andcommitted
Do not execute methods on spy in LdapFacadeTest
1 parent 86a8861 commit bd65108

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

plugins/src/test/java/opengrok/auth/plugin/ldap/LdapFacadeTest.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737
import static org.junit.jupiter.api.Assertions.assertEquals;
3838
import static org.junit.jupiter.api.Assertions.assertFalse;
3939
import static org.mockito.ArgumentMatchers.any;
40+
import static org.mockito.Mockito.doReturn;
4041
import static org.mockito.Mockito.times;
4142
import static org.mockito.Mockito.verify;
4243

43-
public class LdapFacadeTest {
44+
class LdapFacadeTest {
4445
@Test
45-
public void testSearchControlsConfig() {
46+
void testSearchControlsConfig() {
4647
Configuration config = new Configuration();
4748
int searchTimeout = 1234;
4849
config.setSearchTimeout(searchTimeout);
@@ -62,13 +63,13 @@ private LdapServer getSpyLdapServer(String name) throws UnknownHostException {
6263
private LdapServer getSpyLdapServer(String name, boolean working) throws UnknownHostException {
6364
LdapServer server = new LdapServer(name);
6465
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();
6768
return serverSpy;
6869
}
6970

7071
@Test
71-
public void testConnectTimeoutInheritance() throws UnknownHostException {
72+
void testConnectTimeoutInheritance() throws UnknownHostException {
7273
Configuration config = new Configuration();
7374

7475
LdapServer[] servers = {getSpyLdapServer("ldap://foo.com"), getSpyLdapServer("ldap://bar.com")};
@@ -87,12 +88,12 @@ public void testConnectTimeoutInheritance() throws UnknownHostException {
8788
}
8889

8990
@Test
90-
public void testToStringNegative() throws UnknownHostException {
91+
void testToStringNegative() throws UnknownHostException {
9192
Configuration config = new Configuration();
9293
LdapServer server1 = new LdapServer("ldap://foo.com");
9394
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();
9697

9798
config.setServers(Collections.singletonList(serverSpy1));
9899
config.setSearchBase("dc=foo,dc=com");
@@ -104,11 +105,11 @@ public void testToStringNegative() throws UnknownHostException {
104105
}
105106

106107
@Test
107-
public void testToStringPositive() throws UnknownHostException {
108+
void testToStringPositive() {
108109
Configuration config = new Configuration();
109110
LdapServer server1 = new LdapServer("ldap://foo.com");
110111
LdapServer serverSpy1 = Mockito.spy(server1);
111-
Mockito.doReturn(true).when(serverSpy1).isWorking();
112+
doReturn(true).when(serverSpy1).isWorking();
112113

113114
config.setServers(Collections.singletonList(serverSpy1));
114115
config.setSearchBase("dc=foo,dc=com");
@@ -120,7 +121,7 @@ public void testToStringPositive() throws UnknownHostException {
120121
}
121122

122123
@Test
123-
public void testPrepareServersNegative() throws UnknownHostException {
124+
void testPrepareServersNegative() throws UnknownHostException {
124125
Configuration config = new Configuration();
125126
config.setServers(Arrays.asList(getSpyLdapServer("ldap://foo.com", false),
126127
getSpyLdapServer("ldap://bar.com", true)));
@@ -129,15 +130,15 @@ public void testPrepareServersNegative() throws UnknownHostException {
129130
}
130131

131132
@Test
132-
public void testGetSearchDescription() {
133+
void testGetSearchDescription() {
133134
assertEquals("DN: foo, filter: bar, attributes: Bilbo,Frodo",
134135
LdapFacade.getSearchDescription("foo", "bar", new String[]{"Bilbo", "Frodo"}));
135136
assertEquals("DN: foo, filter: bar",
136137
LdapFacade.getSearchDescription("foo", "bar", null));
137138
}
138139

139140
@Test
140-
public void testPrepareServersCloseUnused() throws UnknownHostException {
141+
void testPrepareServersCloseUnused() throws UnknownHostException {
141142
Configuration config = new Configuration();
142143

143144
LdapServer server1 = getSpyLdapServer("ldap://foo.com");

0 commit comments

Comments
 (0)