Skip to content

Commit c8cd6fe

Browse files
test: changed test approach for mockito v3 - refactor v1
1 parent c0901b6 commit c8cd6fe

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

fe/fe-core/src/test/java/org/apache/doris/mysql/privilege/PlainAuthWithEmptyPasswordAndLdapTest.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,8 @@ public class PlainAuthWithEmptyPasswordAndLdapTest extends TestWithFeService {
3737
private LdapManager ldapManager = Mockito.mock(LdapManager.class);
3838
private MockedStatic<Env> mockedEnv;
3939

40-
private void setLdapUserExist(boolean res) {
41-
Mockito.when(ldapManager.doesUserExist(Mockito.anyString())).thenReturn(res);
42-
}
43-
44-
private void setCheckPassword(boolean res) {
45-
Mockito.when(ldapManager.checkUserPasswd(
46-
Mockito.anyString(), Mockito.anyString(),
47-
Mockito.anyString(), Mockito.any())).thenReturn(res);
48-
}
49-
5040
@Test
5141
public void testPlainPasswordAuthWithAllowEmptyPassDefault() throws Exception {
52-
setLdapUserExist(true);
53-
setCheckPassword(true);
54-
5542
//running test with non-specified value - ldap_allow_empty_pass should be true
5643
//non empty pass - success
5744
Assertions.assertTrue(LdapConfig.ldap_allow_empty_pass);
@@ -64,9 +51,6 @@ public void testPlainPasswordAuthWithAllowEmptyPassDefault() throws Exception {
6451

6552
@Test
6653
public void testPlainPasswordAuthWithAllowEmptyPassTrue() throws Exception {
67-
setLdapUserExist(true);
68-
setCheckPassword(true);
69-
7054
//running test with specified value - ldap_allow_empty_pass is be true
7155
LdapConfig.ldap_allow_empty_pass = true;
7256

@@ -80,9 +64,6 @@ public void testPlainPasswordAuthWithAllowEmptyPassTrue() throws Exception {
8064

8165
@Test
8266
public void testPlainPasswordAuthWithAllowEmptyPassFalse() throws Exception {
83-
setLdapUserExist(true);
84-
setCheckPassword(true);
85-
8667
//running test with specified value - ldap_allow_empty_pass is false
8768
LdapConfig.ldap_allow_empty_pass = false;
8869

@@ -107,19 +88,18 @@ public void tearDown() {
10788
@BeforeEach
10889
public void setUp() {
10990
LdapConfig.ldap_allow_empty_pass = true; // restoring default value for other tests
110-
}
111-
112-
@Override
113-
protected void runBeforeAll() throws Exception {
114-
System.out.println("5.0 [" + LdapConfig.ldap_allow_empty_pass + "]");
115-
LdapConfig.ldap_allow_empty_pass = true; //restoring default value for other tests
116-
11791
Auth realAuth = Env.getCurrentEnv().getAuth();
11892

11993
mockedEnv = Mockito.mockStatic(Env.class);
12094
Env mockedEnvInstance = Mockito.mock(Env.class);
12195

12296
Auth authSpy = Mockito.spy(realAuth);
97+
98+
Mockito.when(ldapManager.doesUserExist(Mockito.anyString())).thenReturn(true);
99+
Mockito.when(ldapManager.checkUserPasswd(
100+
Mockito.anyString(), Mockito.anyString(),
101+
Mockito.anyString(), Mockito.any())).thenReturn(true);
102+
123103
Mockito.when(authSpy.getLdapManager()).thenReturn(ldapManager);
124104

125105
Mockito.when(mockedEnvInstance.getAuth()).thenReturn(authSpy);

0 commit comments

Comments
 (0)