Skip to content

Commit

Permalink
Refactor PrivilegeProviderFixture (#29619)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Jan 1, 2024
1 parent 33de11f commit 1139d40
Showing 1 changed file with 5 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
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 {

Expand All @@ -38,10 +38,9 @@ public Map<Grantee, ShardingSpherePrivileges> build(final Collection<ShardingSph
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
Expand Down

0 comments on commit 1139d40

Please sign in to comment.