LabelNormalizer: record what happens to each approval
Unchanged, updated, and deleted approvals may need to be handled separately by the underlying storage layer, e.g. in Submit. Record this information in the result of LabelNormalizer.normalize(). For callers that don't care whether approvals were updated or not, provide a convenience method to concatenate them. Change-Id: Ifea7db3f7333d3ddb5e4d647a1d7e8eeb8cbff11
This commit is contained in:
@@ -38,6 +38,7 @@ import com.google.gerrit.server.IdentifiedUser;
|
||||
import com.google.gerrit.server.account.AccountManager;
|
||||
import com.google.gerrit.server.account.AuthRequest;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.git.LabelNormalizer.Result;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.schema.SchemaCreator;
|
||||
import com.google.gerrit.server.util.TimeUtil;
|
||||
@@ -52,6 +53,8 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/** Unit tests for {@link LabelNormalizer}. */
|
||||
public class LabelNormalizerTest {
|
||||
@Inject private AccountManager accountManager;
|
||||
@@ -136,8 +139,11 @@ public class LabelNormalizerTest {
|
||||
|
||||
PatchSetApproval cr = psa(userId, "Code-Review", 2);
|
||||
PatchSetApproval v = psa(userId, "Verified", 1);
|
||||
assertEquals(ImmutableList.of(copy(cr, 1), v),
|
||||
norm.normalize(change, ImmutableList.of(cr, v)));
|
||||
assertEquals(new Result(
|
||||
list(v),
|
||||
list(copy(cr, 1)),
|
||||
list()),
|
||||
norm.normalize(change, list(cr, v)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,16 +155,22 @@ public class LabelNormalizerTest {
|
||||
|
||||
PatchSetApproval cr = psa(userId, "Code-Review", 5);
|
||||
PatchSetApproval v = psa(userId, "Verified", 5);
|
||||
assertEquals(ImmutableList.of(copy(cr, 2), copy(v, 1)),
|
||||
norm.normalize(change, ImmutableList.of(cr, v)));
|
||||
assertEquals(new Result(
|
||||
list(),
|
||||
list(copy(cr, 2), copy(v, 1)),
|
||||
list()),
|
||||
norm.normalize(change, list(cr, v)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyPermissionRangeOmitsResult() throws Exception {
|
||||
PatchSetApproval cr = psa(userId, "Code-Review", 1);
|
||||
PatchSetApproval v = psa(userId, "Verified", 1);
|
||||
assertEquals(ImmutableList.of(),
|
||||
norm.normalize(change, ImmutableList.of(cr, v)));
|
||||
assertEquals(new Result(
|
||||
list(),
|
||||
list(),
|
||||
list(cr, v)),
|
||||
norm.normalize(change, list(cr, v)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -169,8 +181,11 @@ public class LabelNormalizerTest {
|
||||
|
||||
PatchSetApproval cr = psa(userId, "Code-Review", 0);
|
||||
PatchSetApproval v = psa(userId, "Verified", 0);
|
||||
assertEquals(ImmutableList.of(cr),
|
||||
norm.normalize(change, ImmutableList.of(cr, v)));
|
||||
assertEquals(new Result(
|
||||
list(cr),
|
||||
list(),
|
||||
list(v)),
|
||||
norm.normalize(change, list(cr, v)));
|
||||
}
|
||||
|
||||
private ProjectConfig loadAllProjects() throws Exception {
|
||||
@@ -204,4 +219,8 @@ public class LabelNormalizerTest {
|
||||
result.setValue((short) newValue);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<PatchSetApproval> list(PatchSetApproval... psas) {
|
||||
return ImmutableList.<PatchSetApproval> copyOf(psas);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user