Catch `URISyntaxException` in TestUriUpdates constructor And retrow as RuntimeException so that it doesn't have to be caught in tests (sometimes with empty catch block that is being flagged as ERROR after migration to newer errorprone). Bug: Issue 303819949 Change-Id: Ia7a9427f0472bb464104ed7cc24b850e08869118
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java index 94646c3..643a781 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java
@@ -26,7 +26,6 @@ import com.googlesource.gerrit.plugins.replication.ReplicationTasksStorage.ReplicateRefUpdate; import com.googlesource.gerrit.plugins.replication.api.ReplicationConfig.FilterType; import java.io.IOException; -import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; @@ -96,12 +95,9 @@ changeReplicationTasksForRemote(tasksStorage.streamWaiting(), changeRef, remote1) .forEach( (update) -> { - try { - UriUpdates uriUpdates = new TestUriUpdates(update); - tasksStorage.start(uriUpdates); - tasksStorage.finish(uriUpdates); - } catch (URISyntaxException e) { - } + UriUpdates uriUpdates = new TestUriUpdates(update); + tasksStorage.start(uriUpdates); + tasksStorage.finish(uriUpdates); }); reloadConfig(); @@ -125,12 +121,9 @@ changeReplicationTasksForRemote(tasksStorage.streamWaiting(), changeRef, remote1) .forEach( (update) -> { - try { - UriUpdates uriUpdates = new TestUriUpdates(update); - tasksStorage.start(uriUpdates); - tasksStorage.finish(uriUpdates); - } catch (URISyntaxException e) { - } + UriUpdates uriUpdates = new TestUriUpdates(update); + tasksStorage.start(uriUpdates); + tasksStorage.finish(uriUpdates); }); setReplicationDestination(remote1, suffix1, ALL_PROJECTS);
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java index cf5168f..1f1c512 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationTasksStorageMPTest.java
@@ -21,7 +21,6 @@ import com.google.common.jimfs.Configuration; import com.google.common.jimfs.Jimfs; import com.googlesource.gerrit.plugins.replication.ReplicationTasksStorage.ReplicateRefUpdate; -import java.net.URISyntaxException; import java.nio.file.FileSystem; import java.nio.file.Path; import java.util.Set; @@ -40,7 +39,7 @@ ReplicateRefUpdate.create(PROJECT, Set.of(REF), URISH, REMOTE); protected static final ReplicateRefUpdate STORED_REF_UPDATE = ReplicateRefUpdate.create(REF_UPDATE, REF_UPDATE.sha1()); - protected static final UriUpdates URI_UPDATES = getUriUpdates(REF_UPDATE); + protected static final UriUpdates URI_UPDATES = new TestUriUpdates(REF_UPDATE); protected ReplicationTasksStorage nodeA; protected ReplicationTasksStorage nodeB; @@ -209,12 +208,4 @@ assertThat(nodeB.start(URI_UPDATES)).isEmpty(); assertThatStream(persistedView.streamRunning()).containsExactly(STORED_REF_UPDATE); } - - public static UriUpdates getUriUpdates(ReplicationTasksStorage.ReplicateRefUpdate refUpdate) { - try { - return new TestUriUpdates(refUpdate); - } catch (URISyntaxException e) { - throw new RuntimeException("Cannot instantiate UriUpdates object", e); - } - } }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/replication/TestUriUpdates.java b/src/test/java/com/googlesource/gerrit/plugins/replication/TestUriUpdates.java index f6eec83..74b2082 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/replication/TestUriUpdates.java +++ b/src/test/java/com/googlesource/gerrit/plugins/replication/TestUriUpdates.java
@@ -27,11 +27,15 @@ private final String remote; private final Set<ImmutableSet<String>> refs; - public TestUriUpdates(ReplicateRefUpdate update) throws URISyntaxException { - project = Project.nameKey(update.project()); - uri = new URIish(update.uri()); - remote = update.remote(); - refs = Set.of(update.refs()); + public TestUriUpdates(ReplicateRefUpdate update) { + try { + project = Project.nameKey(update.project()); + uri = new URIish(update.uri()); + remote = update.remote(); + refs = Set.of(update.refs()); + } catch (URISyntaxException e) { + throw new RuntimeException("TestUriUpdates init failed.", e); + } } @Override