RefUpdateUtilTest: Migrate from try-catch-fail to assertThrows

Change-Id: I59a4e86e200d5fddf264918d07eba50caed167ae
This commit is contained in:
David Pursehouse 2019-05-22 19:13:08 +09:00
parent 53e8618bdd
commit b8ae81642b

View File

@ -16,7 +16,7 @@ package com.google.gerrit.git;
import static com.google.common.base.Preconditions.checkState;
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 java.io.IOException;
@ -80,23 +80,18 @@ public class RefUpdateUtilTest {
@SafeVarargs
private static void assertIoException(Consumer<ReceiveCommand>... resultSetters) {
try {
RefUpdateUtil.checkResults(newBatchRefUpdate(resultSetters));
assert_().fail("expected IOException");
} catch (IOException e) {
assertThat(e).isNotInstanceOf(LockFailureException.class);
}
IOException thrown =
assertThrows(
IOException.class, () -> RefUpdateUtil.checkResults(newBatchRefUpdate(resultSetters)));
assertThat(thrown).isNotInstanceOf(LockFailureException.class);
}
@SafeVarargs
private static void assertLockFailureException(Consumer<ReceiveCommand>... resultSetters)
throws Exception {
try {
RefUpdateUtil.checkResults(newBatchRefUpdate(resultSetters));
assert_().fail("expected LockFailureException");
} catch (LockFailureException e) {
// Expected.
}
assertThrows(
LockFailureException.class,
() -> RefUpdateUtil.checkResults(newBatchRefUpdate(resultSetters)));
}
@SafeVarargs