use of com.google.gerrit.server.permissions.PermissionBackend in project gerrit by GerritCodeReview.
the class UiActionsTest method permissionBackendConditionEvaluationDeduplicatesAndBackfills.
@Test
public void permissionBackendConditionEvaluationDeduplicatesAndBackfills() throws Exception {
FakeForProject forProject = new FakeForProject();
// Create three conditions, two of which are identical
PermissionBackendCondition cond1 = (PermissionBackendCondition) forProject.testCond(ProjectPermission.CREATE_CHANGE);
PermissionBackendCondition cond2 = (PermissionBackendCondition) forProject.testCond(ProjectPermission.READ);
PermissionBackendCondition cond3 = (PermissionBackendCondition) forProject.testCond(ProjectPermission.CREATE_CHANGE);
// Set up the Mock to expect a call of bulkEvaluateTest to only contain cond{1,2} since cond3
// needs to be identified as duplicate and not called out explicitly.
PermissionBackend permissionBackendMock = mock(PermissionBackend.class);
UiActions.evaluatePermissionBackendConditions(permissionBackendMock, ImmutableList.of(cond1, cond2, cond3));
// Disallow queries for value to ensure that cond3 (previously left behind) is backfilled with
// the value of cond1 and issues no additional call to PermissionBackend.
forProject.disallowValueQueries();
verify(permissionBackendMock, only()).bulkEvaluateTest(ImmutableSet.of(cond1, cond2));
// Assert the values of all conditions
assertThat(cond1.value()).isFalse();
assertThat(cond2.value()).isTrue();
assertThat(cond3.value()).isFalse();
}
Aggregations