BatchUpdateTest: Migrate from try-catch-fail to assertFails

Change-Id: I1db0c85bbbaa52a12fc77d4a000ffec57b35e83d
This commit is contained in:
David Pursehouse
2019-05-22 20:38:58 +09:00
parent a20a890fb7
commit 8dde9c4c98

View File

@@ -17,7 +17,7 @@ package com.google.gerrit.server.update;
import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Preconditions.checkState;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth.assert_; import static com.google.gerrit.testing.GerritJUnit.assertThrows;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.gerrit.common.Nullable; import com.google.gerrit.common.Nullable;
@@ -106,12 +106,11 @@ public class BatchUpdateTest {
ObjectId oldMetaId = getMetaId(id); ObjectId oldMetaId = getMetaId(id);
try (BatchUpdate bu = batchUpdateFactory.create(project, user.get(), TimeUtil.nowTs())) { try (BatchUpdate bu = batchUpdateFactory.create(project, user.get(), TimeUtil.nowTs())) {
bu.addOp(id, new AddMessageOp("Excessive update")); bu.addOp(id, new AddMessageOp("Excessive update"));
try { ResourceConflictException thrown =
bu.execute(); assertThrows(ResourceConflictException.class, () -> bu.execute());
assert_().fail("expected ResourceConflictException"); assertThat(thrown)
} catch (ResourceConflictException e) { .hasMessageThat()
assertThat(e).hasMessageThat().isEqualTo(TooManyUpdatesException.message(id, MAX_UPDATES)); .isEqualTo(TooManyUpdatesException.message(id, MAX_UPDATES));
}
} }
assertThat(getUpdateCount(id)).isEqualTo(MAX_UPDATES); assertThat(getUpdateCount(id)).isEqualTo(MAX_UPDATES);
assertThat(getMetaId(id)).isEqualTo(oldMetaId); assertThat(getMetaId(id)).isEqualTo(oldMetaId);
@@ -125,12 +124,11 @@ public class BatchUpdateTest {
try (BatchUpdate bu = batchUpdateFactory.create(project, user.get(), TimeUtil.nowTs())) { try (BatchUpdate bu = batchUpdateFactory.create(project, user.get(), TimeUtil.nowTs())) {
bu.addOp(id, new AddMessageOp("Update on PS1", PatchSet.id(id, 1))); bu.addOp(id, new AddMessageOp("Update on PS1", PatchSet.id(id, 1)));
bu.addOp(id, new AddMessageOp("Update on PS2", PatchSet.id(id, 2))); bu.addOp(id, new AddMessageOp("Update on PS2", PatchSet.id(id, 2)));
try { ResourceConflictException thrown =
bu.execute(); assertThrows(ResourceConflictException.class, () -> bu.execute());
assert_().fail("expected ResourceConflictException"); assertThat(thrown)
} catch (ResourceConflictException e) { .hasMessageThat()
assertThat(e).hasMessageThat().isEqualTo(TooManyUpdatesException.message(id, MAX_UPDATES)); .isEqualTo(TooManyUpdatesException.message(id, MAX_UPDATES));
}
} }
assertThat(getUpdateCount(id)).isEqualTo(MAX_UPDATES - 1); assertThat(getUpdateCount(id)).isEqualTo(MAX_UPDATES - 1);
assertThat(getMetaId(id)).isEqualTo(oldMetaId); assertThat(getMetaId(id)).isEqualTo(oldMetaId);