Merge branch 'stable-3.0'

* stable-3.0:
  Switch required bazel version to 0.29.1
  Make build tests name consistent with stable-2.15

Change-Id: I726282af6b146656be906e3909e09a8f70458e87
diff --git a/WORKSPACE b/WORKSPACE
index 86a6ded..5b89d45 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,27 +3,27 @@
 load("//:bazlets.bzl", "load_bazlets")
 
 load_bazlets(
-    commit = "0ca51936ca46049cddd34e971a595d3baafe731b",
+    commit = "7744d119c623494f7c7ec621e20cd66ea5bc04f6",
     #local_path = "/home/<user>/projects/bazlets",
 )
 
 # Snapshot Plugin API
-#load(
-#    "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
-#    "gerrit_api_maven_local",
-#)
-
-# Load snapshot Plugin API
-#gerrit_api_maven_local()
-
-# Release Plugin API
 load(
-    "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
-    "gerrit_api",
+    "@com_googlesource_gerrit_bazlets//:gerrit_api_maven_local.bzl",
+    "gerrit_api_maven_local",
 )
 
+# Load snapshot Plugin API
+gerrit_api_maven_local()
+
+# Release Plugin API
+#load(
+#    "@com_googlesource_gerrit_bazlets//:gerrit_api.bzl",
+#    "gerrit_api",
+#)
+
 # Load release Plugin API
-gerrit_api()
+#gerrit_api()
 
 load("//:external_plugin_deps.bzl", "external_plugin_deps")
 
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/command/AddToQueue.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/command/AddToQueue.java
index d9fe107..49ecb62 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/command/AddToQueue.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/command/AddToQueue.java
@@ -85,7 +85,7 @@
       throw die("Unable to resolve path to " + repository);
     }
     String projectName = extractFrom(repository);
-    Project.NameKey nameKey = new Project.NameKey(projectName);
+    Project.NameKey nameKey = Project.nameKey(projectName);
     if (projectCache.get(nameKey) == null) {
       throw die(String.format("Repository %s not found", repository));
     }
diff --git a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/Evaluator.java b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/Evaluator.java
index 5ae7fac..52cf01e 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/Evaluator.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/Evaluator.java
@@ -109,7 +109,7 @@
   @Override
   public void onGitReferenceUpdated(Event event) {
     String projectName = event.getProjectName();
-    Project.NameKey projectNameKey = new Project.NameKey(projectName);
+    Project.NameKey projectNameKey = Project.nameKey(projectName);
     try (Repository repository = repoManager.openRepository(projectNameKey)) {
       String repositoryPath = repository.getDirectory().getAbsolutePath();
       queueEvaluationIfNecessary(repositoryPath);
diff --git a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/EvaluatorTest.java b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/EvaluatorTest.java
index 7dc403b..905d737 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/EvaluatorTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/evaluator/EvaluatorTest.java
@@ -43,7 +43,7 @@
 public class EvaluatorTest {
   private static final String REPOSITORY_PATH = "/path/someRepo.git";
   private static final String REPOSITORY_PATH_OTHER = "/path/otherRepo.git";
-  private static final Project.NameKey NAME_KEY = new Project.NameKey("testProject");
+  private static final Project.NameKey NAME_KEY = Project.nameKey("testProject");
 
   @Mock private GitReferenceUpdatedListener.Event event;
   @Mock private GitRepositoryManager repoManager;
diff --git a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ConfigUtilTest.java b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ConfigUtilTest.java
index c99201a..1485d72 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ConfigUtilTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ConfigUtilTest.java
@@ -15,6 +15,7 @@
 package com.ericsson.gerrit.plugins.gcconductor.executor;
 
 import static com.google.common.truth.Truth.assertThat;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
 import static java.util.concurrent.TimeUnit.DAYS;
 import static java.util.concurrent.TimeUnit.HOURS;
 import static java.util.concurrent.TimeUnit.MILLISECONDS;
@@ -52,22 +53,24 @@
         .isEqualTo(DEFAULT_VALUE);
   }
 
-  @Test(expected = IllegalArgumentException.class)
+  @Test
   public void testGetTimeThrowsExceptionIfNegativeValue() {
     when(config.getString("", null, "")).thenReturn("-1");
-    assertThat(ConfigUtil.getTimeUnit(config, "", "", DEFAULT_VALUE, DAYS))
-        .isEqualTo(DEFAULT_VALUE);
+    assertThrows(
+        IllegalArgumentException.class,
+        () -> ConfigUtil.getTimeUnit(config, "", "", DEFAULT_VALUE, DAYS));
 
     when(config.getString("", null, "")).thenReturn("");
     assertThat(ConfigUtil.getTimeUnit(config, "", "", DEFAULT_VALUE, DAYS))
         .isEqualTo(DEFAULT_VALUE);
   }
 
-  @Test(expected = IllegalArgumentException.class)
+  @Test
   public void testGetTimeThrowsExceptionIfBadTimeUnit() {
     when(config.getString("", null, "")).thenReturn("1s");
-    assertThat(ConfigUtil.getTimeUnit(config, "", "", DEFAULT_VALUE, DAYS))
-        .isEqualTo(DEFAULT_VALUE);
+    assertThrows(
+        IllegalArgumentException.class,
+        () -> ConfigUtil.getTimeUnit(config, "", "", DEFAULT_VALUE, DAYS));
   }
 
   @Test
@@ -99,9 +102,9 @@
     assertEquals(ms(1, MILLISECONDS), parse(""));
   }
 
-  @Test(expected = IllegalArgumentException.class)
+  @Test
   public void testUnsupportedTimeUnit() {
-    parse("1 min");
+    assertThrows(IllegalArgumentException.class, () -> parse("1 min"));
   }
 
   private static long ms(int cnt, TimeUnit unit) {
diff --git a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ExecutorModuleTest.java b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ExecutorModuleTest.java
index f4d3cef..3e88f2b 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ExecutorModuleTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ExecutorModuleTest.java
@@ -15,7 +15,7 @@
 package com.ericsson.gerrit.plugins.gcconductor.executor;
 
 import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.common.truth.Truth8.assertThat;
 import static org.mockito.Mockito.when;
 
 import com.google.inject.Binder;
@@ -45,9 +45,7 @@
     String host = "hostname";
     when(execCfg.isPickOwnHostOnly()).thenReturn(true);
     Optional<String> wasQueuedFrom = executorModule.wasQueuedFrom(execCfg, host);
-    if (!wasQueuedFrom.isPresent()) {
-      fail("wasQueued from is empty");
-    }
+    assertThat(wasQueuedFrom).isPresent();
     assertThat(wasQueuedFrom.get()).isEqualTo(host);
 
     when(execCfg.isPickOwnHostOnly()).thenReturn(false);
diff --git a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ScheduledEvaluationTaskTest.java b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ScheduledEvaluationTaskTest.java
index c560fbf..302c4c8 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ScheduledEvaluationTaskTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/executor/ScheduledEvaluationTaskTest.java
@@ -14,6 +14,7 @@
 
 package com.ericsson.gerrit.plugins.gcconductor.executor;
 
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.verifyZeroInteractions;
@@ -50,10 +51,12 @@
     periodicEvaluator = new ScheduledEvaluationTask(evaluationTaskFactory, config);
   }
 
-  @Test(expected = ProvisionException.class)
-  public void shouldThrowAnExceptionOnInvalidrepositoryPath() {
+  @Test
+  public void shouldThrowAnExceptionOnInvalidrepositoryPath() throws Exception {
     when(config.getRepositoriesPath()).thenReturn("unexistingPath");
-    periodicEvaluator = new ScheduledEvaluationTask(evaluationTaskFactory, config);
+    assertThrows(
+        ProvisionException.class,
+        () -> periodicEvaluator = new ScheduledEvaluationTask(evaluationTaskFactory, config));
   }
 
   @Test
diff --git a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresModuleTest.java b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresModuleTest.java
index 5df97d0..7721b8c 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresModuleTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresModuleTest.java
@@ -18,6 +18,7 @@
 import static com.ericsson.gerrit.plugins.gcconductor.postgresqueue.TestUtil.invalidConfigMockFor;
 import static com.ericsson.gerrit.plugins.gcconductor.postgresqueue.TestUtil.newContainer;
 import static com.google.common.truth.Truth.assertThat;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
 import static org.mockito.Mockito.doThrow;
 import static org.mockito.Mockito.mock;
 
@@ -73,9 +74,10 @@
     assertThat(dataSource.isClosed()).isFalse();
   }
 
-  @Test(expected = SQLException.class)
-  public void shouldFailIfDatabaseNameIsInvalid() throws SQLException {
-    module.provideGcDatabaseAccess(invalidConfigMockFor(container));
+  @Test
+  public void shouldFailIfDatabaseNameIsInvalid() throws Exception {
+    assertThrows(
+        SQLException.class, () -> module.provideGcDatabaseAccess(invalidConfigMockFor(container)));
   }
 
   @Test
@@ -87,11 +89,11 @@
     assertThat(dataSource.isClosed()).isTrue();
   }
 
-  @Test(expected = RuntimeException.class)
-  public void shouldThrowExceptionIfFailsToCloseDatabaseAccess() throws SQLException {
+  @Test
+  public void shouldThrowExceptionIfFailsToCloseDatabaseAccess() throws Exception {
     BasicDataSource dataSouceMock = mock(BasicDataSource.class);
     doThrow(new SQLException("somme error")).when(dataSouceMock).close();
     DatabaseAccessCleanUp dbCleanUp = new DatabaseAccessCleanUp(dataSouceMock);
-    dbCleanUp.onShutdown();
+    assertThrows(RuntimeException.class, () -> dbCleanUp.onShutdown());
   }
 }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueueTest.java b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueueTest.java
index b767d04..aab695c 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueueTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/gcconductor/postgresqueue/PostgresQueueTest.java
@@ -17,7 +17,7 @@
 import static com.ericsson.gerrit.plugins.gcconductor.postgresqueue.TestUtil.configMockFor;
 import static com.ericsson.gerrit.plugins.gcconductor.postgresqueue.TestUtil.newContainer;
 import static com.google.common.truth.Truth.assertThat;
-import static org.junit.Assert.fail;
+import static com.google.gerrit.testing.GerritJUnit.assertThrows;
 import static org.mockito.ArgumentMatchers.anyString;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
@@ -52,33 +52,33 @@
   }
 
   @Before
-  public void setUp() throws SQLException, GcQueueException {
+  public void setUp() throws Exception {
     dataSource = new PostgresModule(null).provideGcDatabaseAccess(configMockFor(container));
     queue = new PostgresQueue(dataSource);
     emptyQueue();
   }
 
   @After
-  public void tearDown() throws SQLException {
+  public void tearDown() throws Exception {
     if (dataSource != null) {
       dataSource.close();
     }
   }
 
   @Test
-  public void shouldCreateSchemaOnInit() throws GcQueueException {
+  public void shouldCreateSchemaOnInit() throws Exception {
     assertThat(queue.list()).isEmpty();
   }
 
-  @Test(expected = SQLException.class)
+  @Test
   public void shouldThrowExceptionIfFailsToCreateSchemaOnInit() throws Exception {
     BasicDataSource dataSouceMock = mock(BasicDataSource.class);
     when(dataSouceMock.getConnection()).thenThrow(new SQLException("some message"));
-    queue = new PostgresQueue(dataSouceMock);
+    assertThrows(SQLException.class, () -> queue = new PostgresQueue(dataSouceMock));
   }
 
   @Test
-  public void testAddContainsAndRemove() throws GcQueueException {
+  public void testAddContainsAndRemove() throws Exception {
     String repoPath = "/some/path/to/some/repository";
     String hostname = "someHostname";
 
@@ -115,68 +115,68 @@
     assertThat(queue.contains(repoPath)).isFalse();
   }
 
-  @Test(expected = GcQueueException.class)
+  @Test
   public void testAddThatFailsWhenGettingConnection() throws Exception {
     queue = new PostgresQueue(createDataSourceThatFailsWhenGettingConnection());
-    queue.add("repo", "hostname");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testAddThatFailsWhenCreatingStatement() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
-    queue.add("repo", "hostname");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testAddThatFailsWhenExecutingQuery() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
-    queue.add("repo", "hostname");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testContainsThatFailsWhenGettingConnection() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenGettingConnection());
-    queue.contains("repo");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testContainsThatFailsWhenCreatingStatement() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
-    queue.contains("repo");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testContainsThatFailsWhenExecutingQuery() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
-    queue.contains("repo");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testContainsThatFailsWhenIteratingResults() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenIteratingResults());
-    queue.contains("repo");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testRemoveThatFailsWhenGettingConnection() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenGettingConnection());
-    queue.remove("repo");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testRemoveThatFailsWhenCreatingStatement() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
-    queue.remove("repo");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testRemoveThatFailsWhenExecutingQuery() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
-    queue.remove("repo");
+    assertThrows(GcQueueException.class, () -> queue.add("repo", "hostname"));
   }
 
   @Test
-  public void testList() throws GcQueueException {
+  public void testAddThatFailsWhenCreatingStatement() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
+    assertThrows(GcQueueException.class, () -> queue.add("repo", "hostname"));
+  }
+
+  @Test
+  public void testAddThatFailsWhenExecutingQuery() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
+    assertThrows(GcQueueException.class, () -> queue.add("repo", "hostname"));
+  }
+
+  @Test
+  public void testContainsThatFailsWhenGettingConnection() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenGettingConnection());
+    assertThrows(GcQueueException.class, () -> queue.contains("repo"));
+  }
+
+  @Test
+  public void testContainsThatFailsWhenCreatingStatement() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
+    assertThrows(GcQueueException.class, () -> queue.contains("repo"));
+  }
+
+  @Test
+  public void testContainsThatFailsWhenExecutingQuery() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
+    assertThrows(GcQueueException.class, () -> queue.contains("repo"));
+  }
+
+  @Test
+  public void testContainsThatFailsWhenIteratingResults() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenIteratingResults());
+    assertThrows(GcQueueException.class, () -> queue.contains("repo"));
+  }
+
+  @Test
+  public void testRemoveThatFailsWhenGettingConnection() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenGettingConnection());
+    assertThrows(GcQueueException.class, () -> queue.remove("repo"));
+  }
+
+  @Test
+  public void testRemoveThatFailsWhenCreatingStatement() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
+    assertThrows(GcQueueException.class, () -> queue.remove("repo"));
+  }
+
+  @Test
+  public void testRemoveThatFailsWhenExecutingQuery() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
+    assertThrows(GcQueueException.class, () -> queue.remove("repo"));
+  }
+
+  @Test
+  public void testList() throws Exception {
     String repoPath = "/some/path/to/some/repository.git";
     String repoPath2 = "/some/path/to/some/repository2.git";
     String hostname = "hostname";
@@ -208,32 +208,32 @@
     assertThat(timestampDiff).isAtMost(TimeUnit.SECONDS.toMillis(1));
   }
 
-  @Test(expected = GcQueueException.class)
+  @Test
   public void testListThatFailsWhenGettingConnection() throws Exception {
     queue = new PostgresQueue(createDataSourceThatFailsWhenGettingConnection());
-    queue.list();
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testListThatFailsWhenCreatingStatement() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
-    queue.list();
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testListThatFailsWhenExecutingQuery() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
-    queue.list();
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testListThatFailsWhenIteratingResults() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenIteratingResults());
-    queue.list();
+    assertThrows(GcQueueException.class, () -> queue.list());
   }
 
   @Test
-  public void testPick() throws GcQueueException {
+  public void testListThatFailsWhenCreatingStatement() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
+    assertThrows(GcQueueException.class, () -> queue.list());
+  }
+
+  @Test
+  public void testListThatFailsWhenExecutingQuery() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
+    assertThrows(GcQueueException.class, () -> queue.list());
+  }
+
+  @Test
+  public void testListThatFailsWhenIteratingResults() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenIteratingResults());
+    assertThrows(GcQueueException.class, () -> queue.list());
+  }
+
+  @Test
+  public void testPick() throws Exception {
     String repoPath = "/some/path/to/some/repository";
     String hostname = "someHostname";
     String executor = "someExecutor";
@@ -262,7 +262,7 @@
   }
 
   @Test
-  public void testPickRepositoriesInOrder() throws GcQueueException {
+  public void testPickRepositoriesInOrder() throws Exception {
     String repositoryFormat = "my/path%s.git";
     for (int i = 0; i < 100; i++) {
       queue.add(String.format(repositoryFormat, i), "someHostname");
@@ -275,7 +275,7 @@
   }
 
   @Test
-  public void testPickInQueueForLongerThan() throws GcQueueException, InterruptedException {
+  public void testPickInQueueForLongerThan() throws Exception {
     String repoPath = "/some/path/to/some/repository";
     String hostname = "someHostname";
     String executor = "someExecutor";
@@ -293,7 +293,7 @@
   }
 
   @Test
-  public void testPickQueuedFrom() throws GcQueueException {
+  public void testPickQueuedFrom() throws Exception {
     String repoPath = "/some/path/to/some/repository";
     String hostname = "hostname";
     String otherHostname = "otherHostname";
@@ -310,32 +310,32 @@
     assertThat(picked.getExecutor()).isEqualTo(executor);
   }
 
-  @Test(expected = GcQueueException.class)
+  @Test
   public void testPickThatFailsWhenGettingConnection() throws Exception {
     queue = new PostgresQueue(createDataSourceThatFailsWhenGettingConnection());
-    queue.pick("executor", 0, Optional.empty());
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testPickThatFailsWhenCreatingStatement() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
-    queue.pick("executor", 0, Optional.empty());
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testPickThatFailsWhenExecutingQuery() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
-    queue.pick("executor", 0, Optional.empty());
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testPickThatFailsWhenIteratingResults() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenIteratingResults());
-    queue.pick("executor", 0, Optional.empty());
+    assertThrows(GcQueueException.class, () -> queue.pick("executor", 0, Optional.empty()));
   }
 
   @Test
-  public void testUnpick() throws GcQueueException {
+  public void testPickThatFailsWhenCreatingStatement() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
+    assertThrows(GcQueueException.class, () -> queue.pick("executor", 0, Optional.empty()));
+  }
+
+  @Test
+  public void testPickThatFailsWhenExecutingQuery() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
+    assertThrows(GcQueueException.class, () -> queue.pick("executor", 0, Optional.empty()));
+  }
+
+  @Test
+  public void testPickThatFailsWhenIteratingResults() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenIteratingResults());
+    assertThrows(GcQueueException.class, () -> queue.pick("executor", 0, Optional.empty()));
+  }
+
+  @Test
+  public void testUnpick() throws Exception {
     String repoPath = "/some/path/to/some/repository";
     String hostname = "someHostname";
     String executor = "someExecutor";
@@ -354,26 +354,26 @@
     assertThat(picked.getExecutor()).isEqualTo(executor);
   }
 
-  @Test(expected = GcQueueException.class)
+  @Test
   public void testUnpickThatFailsWhenGettingConnection() throws Exception {
     queue = new PostgresQueue(createDataSourceThatFailsWhenGettingConnection());
-    queue.unpick("/some/path/to/some/repository.git");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testUnpickFailsWhenCreatingStatement() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
-    queue.unpick("/some/path/to/some/repository.git");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testUnpickThatFailsWhenExecutingQuery() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
-    queue.unpick("/some/path/to/some/repository.git");
+    assertThrows(GcQueueException.class, () -> queue.unpick("/some/path/to/some/repository.git"));
   }
 
   @Test
-  public void testResetQueuedFrom() throws GcQueueException {
+  public void testUnpickFailsWhenCreatingStatement() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
+    assertThrows(GcQueueException.class, () -> queue.unpick("/some/path/to/some/repository.git"));
+  }
+
+  @Test
+  public void testUnpickThatFailsWhenExecutingQuery() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
+    assertThrows(GcQueueException.class, () -> queue.unpick("/some/path/to/some/repository.git"));
+  }
+
+  @Test
+  public void testResetQueuedFrom() throws Exception {
     String repoPath = "/some/path/to/some/repository";
     String repoPath2 = "/some/path/to/some/repository2";
     String hostname = "hostname";
@@ -389,26 +389,26 @@
     assertThat(queue.list().get(1).getQueuedFrom()).isEqualTo(otherHostname);
   }
 
-  @Test(expected = GcQueueException.class)
+  @Test
   public void testResetQueuedFromThatFailsWhenGettingConnection() throws Exception {
     queue = new PostgresQueue(createDataSourceThatFailsWhenGettingConnection());
-    queue.resetQueuedFrom("someHostname");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testResetQueuedFromFailsWhenCreatingStatement() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
-    queue.resetQueuedFrom("someHostname");
-  }
-
-  @Test(expected = GcQueueException.class)
-  public void testResetQueuedFromThatFailsWhenExecutingQuery() throws Exception {
-    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
-    queue.resetQueuedFrom("someHostname");
+    assertThrows(GcQueueException.class, () -> queue.resetQueuedFrom("someHostname"));
   }
 
   @Test
-  public void testBumpToFirst() throws GcQueueException {
+  public void testResetQueuedFromFailsWhenCreatingStatement() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
+    assertThrows(GcQueueException.class, () -> queue.resetQueuedFrom("someHostname"));
+  }
+
+  @Test
+  public void testResetQueuedFromThatFailsWhenExecutingQuery() throws Exception {
+    queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
+    assertThrows(GcQueueException.class, () -> queue.resetQueuedFrom("someHostname"));
+  }
+
+  @Test
+  public void testBumpToFirst() throws Exception {
     String repoPath = "/some/path/to/some/repository";
     String repoPath2 = "/some/path/to/some/repository2";
     String repoPath3 = "/some/path/to/some/repository3";
@@ -439,25 +439,25 @@
     assertThat(queue.list().get(2).getPath()).isEqualTo(repoPath2);
   }
 
-  @Test(expected = GcQueueException.class)
+  @Test
   public void testBumpToFirstThatFailsWhenGettingConnection() throws Exception {
     queue = new PostgresQueue(createDataSourceThatFailsWhenGettingConnection());
-    queue.bumpToFirst("someHostname");
+    assertThrows(GcQueueException.class, () -> queue.bumpToFirst("someHostname"));
   }
 
-  @Test(expected = GcQueueException.class)
+  @Test
   public void testBumpToFirstFailsWhenCreatingStatement() throws Exception {
     queue = new PostgresQueue(createDataSourceThatFailsWhenCreatingStatement());
-    queue.bumpToFirst("someHostname");
+    assertThrows(GcQueueException.class, () -> queue.bumpToFirst("someHostname"));
   }
 
-  @Test(expected = GcQueueException.class)
+  @Test
   public void testBumpToFirstThatFailsWhenExecutingQuery() throws Exception {
     queue = new PostgresQueue(createDataSourceThatFailsWhenExecutingQuery());
-    queue.bumpToFirst("someHostname");
+    assertThrows(GcQueueException.class, () -> queue.bumpToFirst("someHostname"));
   }
 
-  private BasicDataSource createDataSourceThatFailsWhenGettingConnection() throws SQLException {
+  private BasicDataSource createDataSourceThatFailsWhenGettingConnection() throws Exception {
     BasicDataSource dataSouceMock = mock(BasicDataSource.class);
     Connection connectionMock = mock(Connection.class);
     Statement statementMock = mock(Statement.class);
@@ -468,7 +468,7 @@
     return dataSouceMock;
   }
 
-  private BasicDataSource createDataSourceThatFailsWhenCreatingStatement() throws SQLException {
+  private BasicDataSource createDataSourceThatFailsWhenCreatingStatement() throws Exception {
     BasicDataSource dataSouceMock = mock(BasicDataSource.class);
     Connection connectionMock = mock(Connection.class);
     Statement statementMock = mock(Statement.class);
@@ -479,7 +479,7 @@
     return dataSouceMock;
   }
 
-  private BasicDataSource createDataSourceThatFailsWhenExecutingQuery() throws SQLException {
+  private BasicDataSource createDataSourceThatFailsWhenExecutingQuery() throws Exception {
     BasicDataSource dataSouceMock = mock(BasicDataSource.class);
     Connection connectionMock = mock(Connection.class);
     Statement statementMock = mock(Statement.class);
@@ -492,7 +492,7 @@
     return dataSouceMock;
   }
 
-  private BasicDataSource createDataSourceThatFailsWhenIteratingResults() throws SQLException {
+  private BasicDataSource createDataSourceThatFailsWhenIteratingResults() throws Exception {
     BasicDataSource dataSouceMock = mock(BasicDataSource.class);
     Connection connectionMock = mock(Connection.class);
     Statement statementMock = mock(Statement.class);
@@ -506,17 +506,16 @@
     return dataSouceMock;
   }
 
-  private void emptyQueue() throws GcQueueException {
-    queue.list().stream()
-        .map(RepositoryInfo::getPath)
-        .forEach(
-            repository -> {
-              try {
-                queue.remove(repository);
-              } catch (GcQueueException e) {
-                fail();
-              }
-            });
+  private void emptyQueue() throws Exception {
+    queue.list().stream().map(RepositoryInfo::getPath).forEach(this::doEmptyQueue);
     assertThat(queue.list()).isEmpty();
   }
+
+  private void doEmptyQueue(String repository) {
+    try {
+      queue.remove(repository);
+    } catch (GcQueueException e) {
+      throw new RuntimeException(e);
+    }
+  }
 }