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