This is an automated email from the ASF dual-hosted git repository.

sunnianjun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 1139d40f57e Refactor PrivilegeProviderFixture (#29619)
1139d40f57e is described below

commit 1139d40f57e6aa023a1f0fbada571c50292d94eb
Author: Liang Zhang <[email protected]>
AuthorDate: Mon Jan 1 18:31:52 2024 +0800

    Refactor PrivilegeProviderFixture (#29619)
---
 .../authority/fixture/PrivilegeProviderFixture.java           | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git 
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/PrivilegeProviderFixture.java
 
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/PrivilegeProviderFixture.java
index 65c2799b49e..e41e8251355 100644
--- 
a/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/PrivilegeProviderFixture.java
+++ 
b/kernel/authority/core/src/test/java/org/apache/shardingsphere/authority/fixture/PrivilegeProviderFixture.java
@@ -21,14 +21,14 @@ import 
org.apache.shardingsphere.authority.model.ShardingSpherePrivileges;
 import org.apache.shardingsphere.authority.spi.PrivilegeProvider;
 import org.apache.shardingsphere.infra.metadata.user.Grantee;
 import org.apache.shardingsphere.infra.metadata.user.ShardingSphereUser;
+import org.mockito.Answers;
 
 import java.util.Collection;
 import java.util.Map;
 import java.util.stream.Collectors;
 
-import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+import static org.mockito.Mockito.withSettings;
 
 public final class PrivilegeProviderFixture implements PrivilegeProvider {
     
@@ -38,10 +38,9 @@ public final class PrivilegeProviderFixture implements 
PrivilegeProvider {
         return 
users.stream().collect(Collectors.toMap(ShardingSphereUser::getGrantee, each -> 
privileges));
     }
     
-    private static ShardingSpherePrivileges mockPrivileges() {
-        ShardingSpherePrivileges result = mock(ShardingSpherePrivileges.class);
-        when(result.hasPrivileges(any())).thenReturn(true);
-        return result;
+    private ShardingSpherePrivileges mockPrivileges() {
+        return mock(ShardingSpherePrivileges.class,
+                withSettings().defaultAnswer(invocation -> Boolean.TYPE == 
invocation.getMethod().getReturnType() ? true : 
Answers.RETURNS_DEFAULTS.answer(invocation)));
     }
     
     @Override

Reply via email to