From a94a1252b9212e483944ef2547a066e16a079161 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 22 May 2019 19:18:13 +0900 Subject: [PATCH] ProtosTest: Migrate from try-catch-fail to assertThrows Change-Id: If25fad9f907a2747a64cb116da41117848904c85 --- .../com/google/gerrit/proto/ProtosTest.java | 56 +++++++------------ 1 file changed, 19 insertions(+), 37 deletions(-) diff --git a/javatests/com/google/gerrit/proto/ProtosTest.java b/javatests/com/google/gerrit/proto/ProtosTest.java index edaca548d0..550bcc5777 100644 --- a/javatests/com/google/gerrit/proto/ProtosTest.java +++ b/javatests/com/google/gerrit/proto/ProtosTest.java @@ -14,8 +14,8 @@ package com.google.gerrit.proto; -import static com.google.common.truth.Truth.assert_; import static com.google.common.truth.extensions.proto.ProtoTruth.assertThat; +import static com.google.gerrit.testing.GerritJUnit.assertThrows; import com.google.gerrit.server.cache.proto.Cache.ChangeNotesKeyProto; import com.google.gerrit.server.cache.proto.Cache.ChangeNotesStateProto; @@ -33,23 +33,17 @@ public class ProtosTest { .setId(ByteString.copyFromUtf8("foo")) .build(); byte[] bytes = Protos.toByteArray(proto); - try { - Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes); - assert_().fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // Expected. - } + assertThrows( + IllegalArgumentException.class, + () -> Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes)); } @Test public void parseUncheckedByteArrayInvalidData() { byte[] bytes = new byte[] {0x00}; - try { - Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes); - assert_().fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // Expected. - } + assertThrows( + IllegalArgumentException.class, + () -> Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes)); } @Test @@ -73,23 +67,17 @@ public class ProtosTest { .setId(ByteString.copyFromUtf8("foo")) .build(); byte[] bytes = Protos.toByteArray(proto); - try { - Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes, 0, bytes.length); - assert_().fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // Expected. - } + assertThrows( + IllegalArgumentException.class, + () -> Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes, 0, bytes.length)); } @Test public void parseUncheckedSegmentOfByteArrayInvalidData() { byte[] bytes = new byte[] {0x00}; - try { - Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes, 0, bytes.length); - assert_().fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // Expected. - } + assertThrows( + IllegalArgumentException.class, + () -> Protos.parseUnchecked(ChangeNotesStateProto.parser(), bytes, 0, bytes.length)); } @Test @@ -122,23 +110,17 @@ public class ProtosTest { .setId(ByteString.copyFromUtf8("foo")) .build(); ByteString byteString = Protos.toByteString(proto); - try { - Protos.parseUnchecked(ChangeNotesStateProto.parser(), byteString); - assert_().fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // Expected. - } + assertThrows( + IllegalArgumentException.class, + () -> Protos.parseUnchecked(ChangeNotesStateProto.parser(), byteString)); } @Test public void parseUncheckedByteStringInvalidData() { ByteString byteString = ByteString.copyFrom(new byte[] {0x00}); - try { - Protos.parseUnchecked(ChangeNotesStateProto.parser(), byteString); - assert_().fail("expected IllegalArgumentException"); - } catch (IllegalArgumentException e) { - // Expected. - } + assertThrows( + IllegalArgumentException.class, + () -> Protos.parseUnchecked(ChangeNotesStateProto.parser(), byteString)); } @Test