Merge branch 'stable-2.15'

* stable-2.15:
  Throw specific exceptions
  Add private constructor to utility class
  Add Eclipse compiler settings
  SetupLocalHAReplica: Rename "replica" instance member to avoid hiding
  CacheEvictionHandler#onRemoval: Rename parameter to avoid hiding
  FileBasedWebSessionCacheTest: Open InputStream in try-with-resource
  JGroupsPeerInfoProvider: Refactor to avoid false positive Eclipse warning
  ForwardedIndexingHandler: Add missing default case in switch
  Mark methods as static where possible
  Remove superfluous exceptions
  Delete repeated test
  Remove useless parentheses
  Remove null check for Optional
  Rename methods to comply with naming convention
  Remove empty statements
  Extract repeated strings to constants
  Move private methods to inner classes
  Fix forwarding of updates to the project list cache

Change-Id: Ic3bd6b35aade64dde8498f0293a09d3e4f473fb8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..e14e27f
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,111 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
+org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
+org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
+org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
+org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
+org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
+org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.8
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.APILeak=warning
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDefaultCase=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
+org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
+org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
+org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=warning
+org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=warning
+org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
+org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
+org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
+org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedImport=warning
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.8
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java
index 0cd4701..56f2767 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/Configuration.java
@@ -202,22 +202,6 @@
     }
   }
 
-  private static boolean getBoolean(Config cfg, String section, String name, boolean defaultValue) {
-    try {
-      return cfg.getBoolean(section, name, defaultValue);
-    } catch (IllegalArgumentException e) {
-      log.error("invalid value for {}; using default value {}", name, defaultValue);
-      log.debug("Failed to retrieve boolean value: {}", e.getMessage(), e);
-      return defaultValue;
-    }
-  }
-
-  private static String getString(
-      Config cfg, String section, String subSection, String name, String defaultValue) {
-    String value = cfg.getString(section, subSection, name);
-    return ((value == null) ? defaultValue : value);
-  }
-
   @Nullable
   private static String trimTrailingSlash(@Nullable String in) {
     return in == null ? null : CharMatcher.is('/').trimTrailingFrom(in);
@@ -302,7 +286,13 @@
           protocolStack.isPresent() ? protocolStack.get() : "not configured, using default stack.");
     }
 
-    private Optional<Path> getProtocolStack(Config cfg, SitePaths site) {
+    private static String getString(
+        Config cfg, String section, String subSection, String name, String defaultValue) {
+      String value = cfg.getString(section, subSection, name);
+      return value == null ? defaultValue : value;
+    }
+
+    private static Optional<Path> getProtocolStack(Config cfg, SitePaths site) {
       String location = cfg.getString(JGROUPS_SECTION, null, PROTOCOL_STACK_KEY);
       return location == null ? Optional.empty() : Optional.of(site.etc_dir.resolve(location));
     }
@@ -370,6 +360,17 @@
       synchronize = getBoolean(cfg, section, SYNCHRONIZE_KEY, DEFAULT_SYNCHRONIZE);
     }
 
+    private static boolean getBoolean(
+        Config cfg, String section, String name, boolean defaultValue) {
+      try {
+        return cfg.getBoolean(section, name, defaultValue);
+      } catch (IllegalArgumentException e) {
+        log.error("invalid value for {}; using default value {}", name, defaultValue);
+        log.debug("Failed to retrieve boolean value: {}", e.getMessage(), e);
+        return defaultValue;
+      }
+    }
+
     public boolean synchronize() {
       return synchronize;
     }
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/SetupLocalHAReplica.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/SetupLocalHAReplica.java
index 7756b1e..ddbd994 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/SetupLocalHAReplica.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/SetupLocalHAReplica.java
@@ -39,27 +39,31 @@
 import java.util.ArrayList;
 import java.util.EnumSet;
 import java.util.List;
+import org.eclipse.jgit.errors.ConfigInvalidException;
 import org.eclipse.jgit.storage.file.FileBasedConfig;
 import org.eclipse.jgit.util.FS;
 
 class SetupLocalHAReplica {
-  private final SitePaths master;
+  private static final String DATABASE = "database";
+
+  private final SitePaths masterSitePaths;
   private final FileBasedConfig masterConfig;
   private final Path sharedDir;
 
-  private SitePaths replica;
+  private SitePaths replicaSitePaths;
 
   @Inject
-  SetupLocalHAReplica(SitePaths master, InitFlags flags) {
-    this.master = master;
+  SetupLocalHAReplica(SitePaths masterSitePaths, InitFlags flags) {
+    this.masterSitePaths = masterSitePaths;
     this.masterConfig = flags.cfg;
-    this.sharedDir = master.site_path.resolve(DEFAULT_SHARED_DIRECTORY);
+    this.sharedDir = masterSitePaths.site_path.resolve(DEFAULT_SHARED_DIRECTORY);
   }
 
-  void run(SitePaths replica, FileBasedConfig pluginConfig) throws Exception {
-    this.replica = replica;
+  void run(SitePaths replica, FileBasedConfig pluginConfig)
+      throws IOException, ConfigInvalidException {
+    this.replicaSitePaths = replica;
 
-    FileUtil.mkdirsOrDie(replica.site_path, "cannot create " + replica.site_path);
+    FileUtil.mkdirsOrDie(replicaSitePaths.site_path, "cannot create " + replicaSitePaths.site_path);
 
     configureMainSection(pluginConfig);
     configurePeerInfo(pluginConfig);
@@ -68,18 +72,18 @@
       copyFiles(dir);
     }
 
-    mkdir(replica.logs_dir);
-    mkdir(replica.tmp_dir);
+    mkdir(replicaSitePaths.logs_dir);
+    mkdir(replicaSitePaths.tmp_dir);
     symlink(Paths.get(masterConfig.getString("gerrit", null, "basePath")));
     symlink(sharedDir);
 
     FileBasedConfig replicaConfig =
-        new FileBasedConfig(replica.gerrit_config.toFile(), FS.DETECTED);
+        new FileBasedConfig(replicaSitePaths.gerrit_config.toFile(), FS.DETECTED);
     replicaConfig.load();
 
-    if ("h2".equals(masterConfig.getString("database", null, "type"))) {
-      masterConfig.setBoolean("database", "h2", "autoServer", true);
-      replicaConfig.setBoolean("database", "h2", "autoServer", true);
+    if ("h2".equals(masterConfig.getString(DATABASE, null, "type"))) {
+      masterConfig.setBoolean(DATABASE, "h2", "autoServer", true);
+      replicaConfig.setBoolean(DATABASE, "h2", "autoServer", true);
       symlinkH2ReviewDbDir();
     }
   }
@@ -87,32 +91,32 @@
   private List<Path> listDirsForCopy() throws IOException {
     ImmutableList.Builder<Path> toSkipBuilder = ImmutableList.builder();
     toSkipBuilder.add(
-        master.resolve(masterConfig.getString("gerrit", null, "basePath")),
-        master.db_dir,
-        master.logs_dir,
-        replica.site_path,
-        master.site_path.resolve(sharedDir),
-        master.tmp_dir);
-    if ("h2".equals(masterConfig.getString("database", null, "type"))) {
+        masterSitePaths.resolve(masterConfig.getString("gerrit", null, "basePath")),
+        masterSitePaths.db_dir,
+        masterSitePaths.logs_dir,
+        replicaSitePaths.site_path,
+        masterSitePaths.site_path.resolve(sharedDir),
+        masterSitePaths.tmp_dir);
+    if ("h2".equals(masterConfig.getString(DATABASE, null, "type"))) {
       toSkipBuilder.add(
-          master.resolve(masterConfig.getString("database", null, "database")).getParent());
+          masterSitePaths.resolve(masterConfig.getString(DATABASE, null, DATABASE)).getParent());
     }
     final ImmutableList<Path> toSkip = toSkipBuilder.build();
 
     final ArrayList<Path> dirsForCopy = new ArrayList<>();
     Files.walkFileTree(
-        master.site_path,
+        masterSitePaths.site_path,
         EnumSet.of(FileVisitOption.FOLLOW_LINKS),
         Integer.MAX_VALUE,
         new SimpleFileVisitor<Path>() {
           @Override
           public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
               throws IOException {
-            if (Files.isSameFile(dir, master.site_path)) {
+            if (Files.isSameFile(dir, masterSitePaths.site_path)) {
               return FileVisitResult.CONTINUE;
             }
 
-            Path p = master.site_path.relativize(dir);
+            Path p = masterSitePaths.site_path.relativize(dir);
             if (shouldSkip(p)) {
               return FileVisitResult.SKIP_SUBTREE;
             }
@@ -121,7 +125,7 @@
           }
 
           private boolean shouldSkip(Path p) throws IOException {
-            Path resolved = master.site_path.resolve(p);
+            Path resolved = masterSitePaths.site_path.resolve(p);
             for (Path skip : toSkip) {
               if (skip.toFile().exists() && Files.isSameFile(resolved, skip)) {
                 return true;
@@ -135,8 +139,8 @@
   }
 
   private void copyFiles(Path dir) throws IOException {
-    final Path source = master.site_path.resolve(dir);
-    final Path target = replica.site_path.resolve(dir);
+    final Path source = masterSitePaths.site_path.resolve(dir);
+    final Path target = replicaSitePaths.site_path.resolve(dir);
     Files.createDirectories(target);
     Files.walkFileTree(
         source,
@@ -162,13 +166,13 @@
   private void symlink(Path path) throws IOException {
     if (!path.isAbsolute()) {
       Files.createSymbolicLink(
-          replica.site_path.resolve(path),
-          master.site_path.resolve(path).toAbsolutePath().normalize());
+          replicaSitePaths.site_path.resolve(path),
+          masterSitePaths.site_path.resolve(path).toAbsolutePath().normalize());
     }
   }
 
   private void symlinkH2ReviewDbDir() throws IOException {
-    symlink(Paths.get(masterConfig.getString("database", null, "database")).getParent());
+    symlink(Paths.get(masterConfig.getString(DATABASE, null, DATABASE)).getParent());
   }
 
   private void configureMainSection(FileBasedConfig pluginConfig) throws IOException {
@@ -176,11 +180,11 @@
         MAIN_SECTION,
         null,
         SHARED_DIRECTORY_KEY,
-        master.site_path.relativize(sharedDir).toString());
+        masterSitePaths.site_path.relativize(sharedDir).toString());
     pluginConfig.save();
   }
 
-  private void configurePeerInfo(FileBasedConfig pluginConfig) throws IOException {
+  private static void configurePeerInfo(FileBasedConfig pluginConfig) throws IOException {
     pluginConfig.setString(PEER_INFO_SECTION, null, STRATEGY_KEY, "jgroups");
     pluginConfig.setString(
         PEER_INFO_SECTION, JGROUPS_SUBSECTION, CLUSTER_NAME_KEY, DEFAULT_CLUSTER_NAME);
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionHandler.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionHandler.java
index c100d05..324a70c 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionHandler.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/CacheEvictionHandler.java
@@ -41,10 +41,9 @@
   }
 
   @Override
-  public void onRemoval(
-      String pluginName, String cacheName, RemovalNotification<K, V> notification) {
-    if (!Context.isForwardedEvent() && !notification.wasEvicted() && matcher.matches(cacheName)) {
-      executor.execute(new CacheEvictionTask(cacheName, notification.getKey()));
+  public void onRemoval(String plugin, String cache, RemovalNotification<K, V> notification) {
+    if (!Context.isForwardedEvent() && !notification.wasEvicted() && matcher.matches(cache)) {
+      executor.execute(new CacheEvictionTask(cache, notification.getKey()));
     }
   }
 
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/ProjectListUpdateHandler.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/ProjectListUpdateHandler.java
index 5514538..7205137 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/ProjectListUpdateHandler.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/cache/ProjectListUpdateHandler.java
@@ -79,7 +79,7 @@
     public String toString() {
       return String.format(
           "[%s] Update project list in target instance: %s '%s'",
-          pluginName, (delete ? "remove" : "add"), projectName);
+          pluginName, delete ? "remove" : "add", projectName);
     }
   }
 }
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandler.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandler.java
index c65813b..fdbc71e 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandler.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexChangeHandler.java
@@ -74,12 +74,12 @@
     log.debug("Change {} successfully deleted from index", id);
   }
 
-  private Change.Id parseChangeId(String id) {
+  private static Change.Id parseChangeId(String id) {
     Change.Id changeId = new Change.Id(Integer.parseInt(Splitter.on("~").splitToList(id).get(1)));
     return changeId;
   }
 
-  private boolean isCausedByNoSuchChangeException(Throwable throwable) {
+  private static boolean isCausedByNoSuchChangeException(Throwable throwable) {
     while (throwable != null) {
       if (throwable instanceof NoSuchChangeException) {
         return true;
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexingHandler.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexingHandler.java
index db1aa8f..f24c38f 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexingHandler.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedIndexingHandler.java
@@ -70,6 +70,9 @@
           case DELETE:
             doDelete(id);
             break;
+          default:
+            log.error("unexpected operation: {}", operation);
+            break;
         }
       } finally {
         idLock.unlock();
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServlet.java
index 849e60f..5ebd728 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/EventRestApiServlet.java
@@ -68,7 +68,7 @@
     }
   }
 
-  private Event getEventFromRequest(HttpServletRequest req) throws IOException {
+  private static Event getEventFromRequest(HttpServletRequest req) throws IOException {
     String jsonEvent = CharStreams.toString(req.getReader());
     Gson gson =
         new GsonBuilder()
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpClientProvider.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpClientProvider.java
index bd3077f..e6dcfdc 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpClientProvider.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpClientProvider.java
@@ -90,11 +90,11 @@
     return connManager;
   }
 
-  private SSLConnectionSocketFactory buildSslSocketFactory() {
+  private static SSLConnectionSocketFactory buildSslSocketFactory() {
     return new SSLConnectionSocketFactory(buildSslContext(), NoopHostnameVerifier.INSTANCE);
   }
 
-  private SSLContext buildSslContext() {
+  private static SSLContext buildSslContext() {
     try {
       TrustManager[] trustAllCerts = new TrustManager[] {new DummyX509TrustManager()};
       SSLContext context = SSLContext.getInstance("TLS");
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandler.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandler.java
index 12356b0..e22a763 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandler.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandler.java
@@ -52,11 +52,11 @@
     return new HttpResult(isSuccessful(response), parseResponse(response));
   }
 
-  private boolean isSuccessful(HttpResponse response) {
+  private static boolean isSuccessful(HttpResponse response) {
     return response.getStatusLine().getStatusCode() == SC_NO_CONTENT;
   }
 
-  private String parseResponse(HttpResponse response) {
+  private static String parseResponse(HttpResponse response) {
     HttpEntity entity = response.getEntity();
     String asString = "";
     if (entity != null) {
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListApiServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListApiServlet.java
index 28e6a37..39138e3 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListApiServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListApiServlet.java
@@ -18,6 +18,7 @@
 import static javax.servlet.http.HttpServletResponse.SC_NO_CONTENT;
 
 import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedProjectListUpdateHandler;
+import com.google.gerrit.extensions.restapi.Url;
 import com.google.inject.Inject;
 import com.google.inject.Singleton;
 import java.io.IOException;
@@ -47,10 +48,10 @@
 
   private void process(HttpServletRequest req, HttpServletResponse rsp, boolean delete) {
     setHeaders(rsp);
-    String path = req.getPathInfo();
-    String projectName = path.substring(path.lastIndexOf('/') + 1);
+    String requestURI = req.getRequestURI();
+    String projectName = requestURI.substring(requestURI.lastIndexOf('/') + 1);
     try {
-      forwardedProjectListUpdateHandler.update(projectName, delete);
+      forwardedProjectListUpdateHandler.update(Url.decode(projectName), delete);
       rsp.setStatus(SC_NO_CONTENT);
     } catch (IOException e) {
       log.error("Unable to update project list", e);
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
index 53ca073..c5c2049 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarder.java
@@ -143,7 +143,8 @@
   }
 
   private String buildProjectListEndpoint(String projectName) {
-    return Joiner.on("/").join(pluginRelativePath, "cache", Constants.PROJECT_LIST, projectName);
+    return Joiner.on("/")
+        .join(pluginRelativePath, "cache", Constants.PROJECT_LIST, Url.encode(projectName));
   }
 
   private abstract class Request {
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/health/HealthServlet.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/health/HealthServlet.java
index 0d01aba..6d98d83 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/health/HealthServlet.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/health/HealthServlet.java
@@ -95,7 +95,7 @@
     rsp.setStatus(SC_NO_CONTENT);
   }
 
-  private void sendError(HttpServletResponse rsp, int statusCode) {
+  private static void sendError(HttpServletResponse rsp, int statusCode) {
     try {
       rsp.sendError(statusCode);
     } catch (IOException e) {
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/JGroupsPeerInfoProvider.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/JGroupsPeerInfoProvider.java
index 3bc370a..eb41273 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/JGroupsPeerInfoProvider.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/JGroupsPeerInfoProvider.java
@@ -150,13 +150,15 @@
   private JChannel getChannel() throws Exception {
     Optional<Path> protocolStack = jgroupsConfig.protocolStack();
     try {
-      return protocolStack.isPresent()
-          ? new JChannel(protocolStack.get().toString())
-          : new JChannel();
+      if (protocolStack.isPresent()) {
+        return new JChannel(protocolStack.get().toString());
+      } else {
+        return new JChannel();
+      }
     } catch (Exception e) {
       log.error(
           "Unable to create a channel with protocol stack: {}",
-          protocolStack == null ? "default" : protocolStack,
+          protocolStack.isPresent() ? protocolStack : "default",
           e);
       throw e;
     }
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/MyUrlProvider.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/MyUrlProvider.java
index 2e0c14d..adf7d2e 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/MyUrlProvider.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/MyUrlProvider.java
@@ -59,7 +59,7 @@
     return myUrl;
   }
 
-  private String getMyUrlFromListenUrl(Config srvConfig) throws MyUrlProviderException {
+  private static String getMyUrlFromListenUrl(Config srvConfig) throws MyUrlProviderException {
     String[] listenUrls = srvConfig.getStringList(HTTPD_SECTION, null, LISTEN_URL_KEY);
     if (listenUrls.length != 1) {
       throw new MyUrlProviderException(
diff --git a/src/main/java/com/ericsson/gerrit/plugins/highavailability/websession/file/FileBasedWebsessionCache.java b/src/main/java/com/ericsson/gerrit/plugins/highavailability/websession/file/FileBasedWebsessionCache.java
index 120c615..b4c99b5 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/highavailability/websession/file/FileBasedWebsessionCache.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/highavailability/websession/file/FileBasedWebsessionCache.java
@@ -53,6 +53,10 @@
   static class TimeMachine {
     private static Clock clock = Clock.systemDefaultZone();
 
+    private TimeMachine() {
+      throw new IllegalAccessError("Utility class. Not meant to be instantiated.");
+    }
+
     static Instant now() {
       return Instant.now(getClock());
     }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/ConfigurationTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/ConfigurationTest.java
index 01d1b40..1c5f046 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/ConfigurationTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/ConfigurationTest.java
@@ -76,6 +76,8 @@
 
 @RunWith(MockitoJUnitRunner.class)
 public class ConfigurationTest {
+  private static final String INVALID_BOOLEAN = "invalidBoolean";
+  private static final String INVALID_INT = "invalidInt";
   private static final String PLUGIN_NAME = "high-availability";
   private static final String PASS = "fakePass";
   private static final String USER = "fakeUser";
@@ -211,7 +213,7 @@
     globalPluginConfig.setInt(HTTP_SECTION, null, CONNECTION_TIMEOUT_KEY, TIMEOUT);
     assertThat(getConfiguration().http().connectionTimeout()).isEqualTo(TIMEOUT);
 
-    globalPluginConfig.setString(HTTP_SECTION, null, CONNECTION_TIMEOUT_KEY, "invalidInt");
+    globalPluginConfig.setString(HTTP_SECTION, null, CONNECTION_TIMEOUT_KEY, INVALID_INT);
     assertThat(getConfiguration().http().connectionTimeout()).isEqualTo(DEFAULT_TIMEOUT_MS);
   }
 
@@ -222,7 +224,7 @@
     globalPluginConfig.setInt(HTTP_SECTION, null, SOCKET_TIMEOUT_KEY, TIMEOUT);
     assertThat(getConfiguration().http().socketTimeout()).isEqualTo(TIMEOUT);
 
-    globalPluginConfig.setString(HTTP_SECTION, null, SOCKET_TIMEOUT_KEY, "invalidInt");
+    globalPluginConfig.setString(HTTP_SECTION, null, SOCKET_TIMEOUT_KEY, INVALID_INT);
     assertThat(getConfiguration().http().socketTimeout()).isEqualTo(DEFAULT_TIMEOUT_MS);
   }
 
@@ -233,7 +235,7 @@
     globalPluginConfig.setInt(HTTP_SECTION, null, MAX_TRIES_KEY, MAX_TRIES);
     assertThat(getConfiguration().http().maxTries()).isEqualTo(MAX_TRIES);
 
-    globalPluginConfig.setString(HTTP_SECTION, null, MAX_TRIES_KEY, "invalidInt");
+    globalPluginConfig.setString(HTTP_SECTION, null, MAX_TRIES_KEY, INVALID_INT);
     assertThat(getConfiguration().http().maxTries()).isEqualTo(DEFAULT_MAX_TRIES);
   }
 
@@ -244,7 +246,7 @@
     globalPluginConfig.setInt(HTTP_SECTION, null, RETRY_INTERVAL_KEY, RETRY_INTERVAL);
     assertThat(getConfiguration().http().retryInterval()).isEqualTo(RETRY_INTERVAL);
 
-    globalPluginConfig.setString(HTTP_SECTION, null, RETRY_INTERVAL_KEY, "invalidInt");
+    globalPluginConfig.setString(HTTP_SECTION, null, RETRY_INTERVAL_KEY, INVALID_INT);
     assertThat(getConfiguration().http().retryInterval()).isEqualTo(DEFAULT_RETRY_INTERVAL);
   }
 
@@ -255,7 +257,7 @@
     globalPluginConfig.setInt(INDEX_SECTION, null, THREAD_POOL_SIZE_KEY, THREAD_POOL_SIZE);
     assertThat(getConfiguration().index().threadPoolSize()).isEqualTo(THREAD_POOL_SIZE);
 
-    globalPluginConfig.setString(INDEX_SECTION, null, THREAD_POOL_SIZE_KEY, "invalidInt");
+    globalPluginConfig.setString(INDEX_SECTION, null, THREAD_POOL_SIZE_KEY, INVALID_INT);
     assertThat(getConfiguration().index().threadPoolSize()).isEqualTo(DEFAULT_THREAD_POOL_SIZE);
   }
 
@@ -269,7 +271,7 @@
     globalPluginConfig.setBoolean(INDEX_SECTION, null, SYNCHRONIZE_KEY, true);
     assertThat(getConfiguration().index().synchronize()).isTrue();
 
-    globalPluginConfig.setString(INDEX_SECTION, null, SYNCHRONIZE_KEY, "invalidBoolean");
+    globalPluginConfig.setString(INDEX_SECTION, null, SYNCHRONIZE_KEY, INVALID_BOOLEAN);
     assertThat(getConfiguration().index().synchronize()).isTrue();
   }
 
@@ -280,7 +282,7 @@
     globalPluginConfig.setInt(CACHE_SECTION, null, THREAD_POOL_SIZE_KEY, THREAD_POOL_SIZE);
     assertThat(getConfiguration().cache().threadPoolSize()).isEqualTo(THREAD_POOL_SIZE);
 
-    globalPluginConfig.setString(CACHE_SECTION, null, THREAD_POOL_SIZE_KEY, "invalidInt");
+    globalPluginConfig.setString(CACHE_SECTION, null, THREAD_POOL_SIZE_KEY, INVALID_INT);
     assertThat(getConfiguration().cache().threadPoolSize()).isEqualTo(DEFAULT_THREAD_POOL_SIZE);
   }
 
@@ -294,7 +296,7 @@
     globalPluginConfig.setBoolean(CACHE_SECTION, null, SYNCHRONIZE_KEY, true);
     assertThat(getConfiguration().cache().synchronize()).isTrue();
 
-    globalPluginConfig.setString(CACHE_SECTION, null, SYNCHRONIZE_KEY, "invalidBoolean");
+    globalPluginConfig.setString(CACHE_SECTION, null, SYNCHRONIZE_KEY, INVALID_BOOLEAN);
     assertThat(getConfiguration().cache().synchronize()).isTrue();
   }
 
@@ -308,7 +310,7 @@
     globalPluginConfig.setBoolean(EVENT_SECTION, null, SYNCHRONIZE_KEY, true);
     assertThat(getConfiguration().event().synchronize()).isTrue();
 
-    globalPluginConfig.setString(EVENT_SECTION, null, SYNCHRONIZE_KEY, "invalidBoolean");
+    globalPluginConfig.setString(EVENT_SECTION, null, SYNCHRONIZE_KEY, INVALID_BOOLEAN);
     assertThat(getConfiguration().event().synchronize()).isTrue();
   }
 
@@ -352,7 +354,7 @@
     globalPluginConfig.setBoolean(WEBSESSION_SECTION, null, SYNCHRONIZE_KEY, true);
     assertThat(getConfiguration().websession().synchronize()).isTrue();
 
-    globalPluginConfig.setString(WEBSESSION_SECTION, null, SYNCHRONIZE_KEY, "invalidBoolean");
+    globalPluginConfig.setString(WEBSESSION_SECTION, null, SYNCHRONIZE_KEY, INVALID_BOOLEAN);
     assertThat(getConfiguration().websession().synchronize()).isTrue();
   }
 
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/ProjectListIT.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/ProjectListIT.java
index 4f056bf..0e509d0 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/ProjectListIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/cache/ProjectListIT.java
@@ -30,6 +30,7 @@
 import com.google.gerrit.acceptance.NoHttpd;
 import com.google.gerrit.acceptance.TestPlugin;
 import com.google.gerrit.acceptance.UseLocalDisk;
+import com.google.gerrit.extensions.restapi.Url;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import org.apache.http.HttpStatus;
@@ -59,9 +60,9 @@
   @GlobalPluginConfig(pluginName = "high-availability", name = "peerInfo.static.url", value = URL)
   @GlobalPluginConfig(pluginName = "high-availability", name = "http.retryInterval", value = "100")
   public void addToProjectListAreForwarded() throws Exception {
-    String createdProject = "someProject";
+    String createdProjectEncoded = Url.encode("org-a/some-project");
     String expectedRequest =
-        "/plugins/high-availability/cache/" + Constants.PROJECT_LIST + "/" + createdProject;
+        "/plugins/high-availability/cache/" + Constants.PROJECT_LIST + "/" + createdProjectEncoded;
     CountDownLatch expectedRequestLatch = new CountDownLatch(1);
     wireMockRule.addMockServiceRequestListener(
         (request, response) -> {
@@ -70,7 +71,7 @@
           }
         });
 
-    adminRestSession.put("/projects/" + createdProject).assertCreated();
+    adminRestSession.put("/projects/" + createdProjectEncoded).assertCreated();
     assertThat(expectedRequestLatch.await(5, TimeUnit.SECONDS)).isTrue();
     verify(postRequestedFor(urlEqualTo(expectedRequest)));
   }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandlerTest.java
index 2e263dd..3ee8581 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandlerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/ForwardedProjectListUpdateHandlerTest.java
@@ -34,6 +34,7 @@
 public class ForwardedProjectListUpdateHandlerTest {
 
   private static final String PROJECT_NAME = "someProject";
+  private static final String SOME_MESSAGE = "someMessage";
   private static final Project.NameKey PROJECT_KEY = new Project.NameKey(PROJECT_NAME);
   @Rule public ExpectedException exception = ExpectedException.none();
   @Mock private ProjectCache projectCacheMock;
@@ -48,13 +49,13 @@
   public void testSuccessfulAdd() throws Exception {
     handler.update(PROJECT_NAME, false);
     verify(projectCacheMock).onCreateProject(PROJECT_KEY);
-  };
+  }
 
   @Test
   public void testSuccessfulRemove() throws Exception {
     handler.update(PROJECT_NAME, true);
     verify(projectCacheMock).remove(PROJECT_KEY);
-  };
+  }
 
   @Test
   public void shouldSetAndUnsetForwardedContextOnAdd() throws Exception {
@@ -102,7 +103,7 @@
             (Answer<Void>)
                 invocation -> {
                   assertThat(Context.isForwardedEvent()).isTrue();
-                  throw new RuntimeException("someMessage");
+                  throw new RuntimeException(SOME_MESSAGE);
                 })
         .when(projectCacheMock)
         .onCreateProject(PROJECT_KEY);
@@ -112,7 +113,7 @@
       handler.update(PROJECT_NAME, false);
       fail("should have thrown a RuntimeException");
     } catch (RuntimeException e) {
-      assertThat(e.getMessage()).isEqualTo("someMessage");
+      assertThat(e.getMessage()).isEqualTo(SOME_MESSAGE);
     }
     assertThat(Context.isForwardedEvent()).isFalse();
 
@@ -125,7 +126,7 @@
             (Answer<Void>)
                 invocation -> {
                   assertThat(Context.isForwardedEvent()).isTrue();
-                  throw new RuntimeException("someMessage");
+                  throw new RuntimeException(SOME_MESSAGE);
                 })
         .when(projectCacheMock)
         .remove(PROJECT_KEY);
@@ -133,10 +134,9 @@
     assertThat(Context.isForwardedEvent()).isFalse();
     try {
       handler.update(PROJECT_NAME, true);
-      ;
       fail("should have thrown a RuntimeException");
     } catch (RuntimeException e) {
-      assertThat(e.getMessage()).isEqualTo("someMessage");
+      assertThat(e.getMessage()).isEqualTo(SOME_MESSAGE);
     }
     assertThat(Context.isForwardedEvent()).isFalse();
 
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/CacheRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/CacheRestApiServletTest.java
index cf15787..503e5d4 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/CacheRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/CacheRestApiServletTest.java
@@ -109,15 +109,6 @@
     verify(responseMock).sendError(SC_BAD_REQUEST, e.getMessage());
   }
 
-  @Test
-  public void errorWhileSendingErrorMessage() throws Exception {
-    when(requestMock.getPathInfo()).thenReturn("/someCache");
-    String errorMessage = "someError";
-    doThrow(new IOException(errorMessage)).when(requestMock).getReader();
-    servlet.doPost(requestMock, responseMock);
-    verify(responseMock).sendError(SC_BAD_REQUEST, errorMessage);
-  }
-
   private void verifyResponseIsOK() throws Exception {
     servlet.doPost(requestMock, responseMock);
     verify(responseMock).setStatus(SC_NO_CONTENT);
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParserTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParserTest.java
index 53f50a4..a5ff912 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParserTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/GsonParserTest.java
@@ -25,35 +25,35 @@
   private static final Object EMPTY_JSON = "{}";
 
   @Test
-  public void AccountIDParse() {
+  public void accountIDParse() {
     Account.Id accountId = new Account.Id(1);
     String json = GsonParser.toJson(Constants.ACCOUNTS, accountId);
     assertThat(accountId).isEqualTo(GsonParser.fromJson(Constants.ACCOUNTS, json));
   }
 
   @Test
-  public void AccountGroupIDParse() {
+  public void accountGroupIDParse() {
     AccountGroup.Id accountGroupId = new AccountGroup.Id(1);
     String json = GsonParser.toJson(Constants.GROUPS, accountGroupId);
     assertThat(accountGroupId).isEqualTo(GsonParser.fromJson(Constants.GROUPS, json));
   }
 
   @Test
-  public void AccountGroupUUIDParse() {
+  public void accountGroupUUIDParse() {
     AccountGroup.UUID accountGroupUuid = new AccountGroup.UUID("abc123");
     String json = GsonParser.toJson(Constants.GROUPS_BYINCLUDE, accountGroupUuid);
     assertThat(accountGroupUuid).isEqualTo(GsonParser.fromJson(Constants.GROUPS_BYINCLUDE, json));
   }
 
   @Test
-  public void StringParse() {
+  public void stringParse() {
     String key = "key";
     String json = GsonParser.toJson(Constants.PROJECTS, key);
     assertThat(key).isEqualTo(GsonParser.fromJson(Constants.PROJECTS, json));
   }
 
   @Test
-  public void NoKeyParse() {
+  public void noKeyParse() {
     Object object = new Object();
     String json = GsonParser.toJson(Constants.PROJECT_LIST, object);
     assertThat(json).isEqualTo(EMPTY_JSON);
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandlerTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandlerTest.java
index 69b8152..515e778 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandlerTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/HttpResponseHandlerTest.java
@@ -55,7 +55,8 @@
     assertThat(result.getMessage()).contains(ERROR_ENTITY);
   }
 
-  private HttpResponse setupMocks(int httpCode, String entity) throws UnsupportedEncodingException {
+  private static HttpResponse setupMocks(int httpCode, String entity)
+      throws UnsupportedEncodingException {
     StatusLine status = mock(StatusLine.class);
     when(status.getStatusCode()).thenReturn(httpCode);
     HttpResponse response = mock(HttpResponse.class);
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServletTest.java
index fbfbfcf..2046092 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexAccountRestApiServletTest.java
@@ -37,6 +37,7 @@
 @RunWith(MockitoJUnitRunner.class)
 public class IndexAccountRestApiServletTest {
   private static final int ACCOUNT_NUMBER = 1;
+  private static final String IO_ERROR = "io-error";
 
   @Mock private ForwardedIndexAccountHandler handlerMock;
   @Mock private HttpServletRequest requestMock;
@@ -68,16 +69,16 @@
 
   @Test
   public void indexerThrowsIOExceptionTryingToIndexAccount() throws Exception {
-    doThrow(new IOException("io-error")).when(handlerMock).index(id, Operation.INDEX);
+    doThrow(new IOException(IO_ERROR)).when(handlerMock).index(id, Operation.INDEX);
     servlet.doPost(requestMock, responseMock);
-    verify(responseMock).sendError(SC_CONFLICT, "io-error");
+    verify(responseMock).sendError(SC_CONFLICT, IO_ERROR);
   }
 
   @Test
   public void sendErrorThrowsIOException() throws Exception {
-    doThrow(new IOException("io-error")).when(handlerMock).index(id, Operation.INDEX);
-    doThrow(new IOException("someError")).when(responseMock).sendError(SC_CONFLICT, "io-error");
+    doThrow(new IOException(IO_ERROR)).when(handlerMock).index(id, Operation.INDEX);
+    doThrow(new IOException("someError")).when(responseMock).sendError(SC_CONFLICT, IO_ERROR);
     servlet.doPost(requestMock, responseMock);
-    verify(responseMock).sendError(SC_CONFLICT, "io-error");
+    verify(responseMock).sendError(SC_CONFLICT, IO_ERROR);
   }
 }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServletTest.java
index 7e8e2c0..0d72960 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexChangeRestApiServletTest.java
@@ -40,6 +40,7 @@
   private static final String PROJECT_NAME = "test/project";
   private static final String PROJECT_NAME_URL_ENC = "test%2Fproject";
   private static final String CHANGE_ID = PROJECT_NAME + "~" + CHANGE_NUMBER;
+  private static final String IO_ERROR = "io-error";
 
   @Mock private ForwardedIndexChangeHandler handlerMock;
   @Mock private HttpServletRequest requestMock;
@@ -70,9 +71,9 @@
 
   @Test
   public void indexerThrowsIOExceptionTryingToIndexChange() throws Exception {
-    doThrow(new IOException("io-error")).when(handlerMock).index(CHANGE_ID, Operation.INDEX);
+    doThrow(new IOException(IO_ERROR)).when(handlerMock).index(CHANGE_ID, Operation.INDEX);
     servlet.doPost(requestMock, responseMock);
-    verify(responseMock).sendError(SC_CONFLICT, "io-error");
+    verify(responseMock).sendError(SC_CONFLICT, IO_ERROR);
   }
 
   @Test
@@ -84,9 +85,9 @@
 
   @Test
   public void sendErrorThrowsIOException() throws Exception {
-    doThrow(new IOException("io-error")).when(handlerMock).index(CHANGE_ID, Operation.INDEX);
-    doThrow(new IOException("someError")).when(responseMock).sendError(SC_CONFLICT, "io-error");
+    doThrow(new IOException(IO_ERROR)).when(handlerMock).index(CHANGE_ID, Operation.INDEX);
+    doThrow(new IOException("someError")).when(responseMock).sendError(SC_CONFLICT, IO_ERROR);
     servlet.doPost(requestMock, responseMock);
-    verify(responseMock).sendError(SC_CONFLICT, "io-error");
+    verify(responseMock).sendError(SC_CONFLICT, IO_ERROR);
   }
 }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServletTest.java
index 278b157..d138f60 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/IndexGroupRestApiServletTest.java
@@ -36,6 +36,7 @@
 
 @RunWith(MockitoJUnitRunner.class)
 public class IndexGroupRestApiServletTest {
+  private static final String IO_ERROR = "io-error";
   private static final String UUID = "we235jdf92nfj2351";
 
   @Mock private ForwardedIndexGroupHandler handlerMock;
@@ -67,16 +68,16 @@
 
   @Test
   public void indexerThrowsIOExceptionTryingToIndexGroup() throws Exception {
-    doThrow(new IOException("io-error")).when(handlerMock).index(uuid, Operation.INDEX);
+    doThrow(new IOException(IO_ERROR)).when(handlerMock).index(uuid, Operation.INDEX);
     servlet.doPost(requestMock, responseMock);
-    verify(responseMock).sendError(SC_CONFLICT, "io-error");
+    verify(responseMock).sendError(SC_CONFLICT, IO_ERROR);
   }
 
   @Test
   public void sendErrorThrowsIOException() throws Exception {
-    doThrow(new IOException("io-error")).when(handlerMock).index(uuid, Operation.INDEX);
-    doThrow(new IOException("someError")).when(responseMock).sendError(SC_CONFLICT, "io-error");
+    doThrow(new IOException(IO_ERROR)).when(handlerMock).index(uuid, Operation.INDEX);
+    doThrow(new IOException("someError")).when(responseMock).sendError(SC_CONFLICT, IO_ERROR);
     servlet.doPost(requestMock, responseMock);
-    verify(responseMock).sendError(SC_CONFLICT, "io-error");
+    verify(responseMock).sendError(SC_CONFLICT, IO_ERROR);
   }
 }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletIT.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletIT.java
index 65e2d5d..f16bade 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletIT.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletIT.java
@@ -20,6 +20,7 @@
 import com.google.gerrit.acceptance.NoHttpd;
 import com.google.gerrit.acceptance.TestPlugin;
 import com.google.gerrit.acceptance.UseLocalDisk;
+import com.google.gerrit.extensions.restapi.Url;
 import com.google.gerrit.reviewdb.client.Project;
 import org.junit.Test;
 
@@ -30,24 +31,26 @@
   httpModule = "com.ericsson.gerrit.plugins.highavailability.HttpModule"
 )
 public class ProjectListRestApiServletIT extends LightweightPluginDaemonTest {
+  private static final Project.NameKey SOME_PROJECT = new Project.NameKey("org-a/some-project");
+
   @Test
   @UseLocalDisk
   public void addProject() throws Exception {
-    Project.NameKey newProject = new Project.NameKey("someNewProject");
-    assertThat(projectCache.all()).doesNotContain(newProject);
+
+    assertThat(projectCache.all()).doesNotContain(SOME_PROJECT);
     adminRestSession
-        .post("/plugins/high-availability/cache/project_list/" + newProject.get())
+        .post("/plugins/high-availability/cache/project_list/" + Url.encode(SOME_PROJECT.get()))
         .assertNoContent();
-    assertThat(projectCache.all()).contains(newProject);
+    assertThat(projectCache.all()).contains(SOME_PROJECT);
   }
 
   @Test
   @UseLocalDisk
   public void removeProject() throws Exception {
-    assertThat(projectCache.all()).contains(project);
+    addProject();
     adminRestSession
-        .delete("/plugins/high-availability/cache/project_list/" + project.get())
+        .delete("/plugins/high-availability/cache/project_list/" + Url.encode(SOME_PROJECT.get()))
         .assertNoContent();
-    assertThat(projectCache.all()).doesNotContain(project);
+    assertThat(projectCache.all()).doesNotContain(SOME_PROJECT);
   }
 }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletTest.java
index fa0a3ed..38ab488 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/ProjectListRestApiServletTest.java
@@ -20,6 +20,7 @@
 import static org.mockito.Mockito.when;
 
 import com.ericsson.gerrit.plugins.highavailability.forwarder.ForwardedProjectListUpdateHandler;
+import com.google.gerrit.extensions.restapi.Url;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 import org.junit.Before;
@@ -30,7 +31,7 @@
 
 @RunWith(MockitoJUnitRunner.class)
 public class ProjectListRestApiServletTest {
-  private static final String PROJECT_NAME = "someProject";
+  private static final String PROJECT_NAME = "org-a/some-project";
 
   @Mock private ForwardedProjectListUpdateHandler handlerMock;
   @Mock private HttpServletRequest requestMock;
@@ -41,7 +42,10 @@
   @Before
   public void setUpMocks() {
     servlet = new ProjectListApiServlet(handlerMock);
-    when(requestMock.getPathInfo()).thenReturn("/cache/project_list/" + PROJECT_NAME);
+    when(requestMock.getRequestURI())
+        .thenReturn(
+            "http://hostname/plugins/high-availability/cache/project_list/"
+                + Url.encode(PROJECT_NAME));
   }
 
   @Test
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
index d1805d3..f2e03ad 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/forwarder/rest/RestForwarderTest.java
@@ -37,6 +37,11 @@
 public class RestForwarderTest {
   private static final String PLUGIN_NAME = "high-availability";
   private static final String EMPTY_MSG = "";
+  private static final String ERROR = "Error";
+  private static final String PLUGINS = "/plugins";
+  private static final String PROJECT_TO_ADD = "projectToAdd";
+  private static final String PROJECT_TO_DELETE = "projectToDelete";
+  private static final String SUCCESS = "Success";
   private static final boolean SUCCESSFUL = true;
   private static final boolean FAILED = false;
 
@@ -46,20 +51,18 @@
   private static final String PROJECT_NAME_URL_END = "test%2Fproject";
   private static final String INDEX_CHANGE_ENDPOINT =
       Joiner.on("/")
-          .join(
-              "/plugins", PLUGIN_NAME, "index/change", PROJECT_NAME_URL_END + "~" + CHANGE_NUMBER);
+          .join(PLUGINS, PLUGIN_NAME, "index/change", PROJECT_NAME_URL_END + "~" + CHANGE_NUMBER);
   private static final String DELETE_CHANGE_ENDPOINT =
       Joiner.on("/").join("/plugins", PLUGIN_NAME, "index/change", "~" + CHANGE_NUMBER);
   private static final int ACCOUNT_NUMBER = 2;
   private static final String INDEX_ACCOUNT_ENDPOINT =
-      Joiner.on("/").join("/plugins", PLUGIN_NAME, "index/account", ACCOUNT_NUMBER);
+      Joiner.on("/").join(PLUGINS, PLUGIN_NAME, "index/account", ACCOUNT_NUMBER);
   private static final String UUID = "we235jdf92nfj2351";
   private static final String INDEX_GROUP_ENDPOINT =
-      Joiner.on("/").join("/plugins", PLUGIN_NAME, "index/group", UUID);
+      Joiner.on("/").join(PLUGINS, PLUGIN_NAME, "index/group", UUID);
 
   // Event
-  private static final String EVENT_ENDPOINT =
-      Joiner.on("/").join("/plugins", PLUGIN_NAME, "event");
+  private static final String EVENT_ENDPOINT = Joiner.on("/").join(PLUGINS, PLUGIN_NAME, "event");
   private static Event event = new Event("test-event") {};
   private static String eventJson = new GsonBuilder().create().toJson(event);
 
@@ -175,7 +178,7 @@
 
   @Test
   public void testEvictProjectOK() throws Exception {
-    String key = "projectName";
+    String key = PROJECT_NAME;
     String keyJson = new GsonBuilder().create().toJson(key);
     when(httpSessionMock.post(buildCacheEndpoint(Constants.PROJECTS), keyJson))
         .thenReturn(new HttpResult(SUCCESSFUL, EMPTY_MSG));
@@ -220,7 +223,7 @@
 
   @Test
   public void testEvictCacheFailed() throws Exception {
-    String key = "projectName";
+    String key = PROJECT_NAME;
     String keyJson = new GsonBuilder().create().toJson(key);
     when(httpSessionMock.post(buildCacheEndpoint(Constants.PROJECTS), keyJson))
         .thenReturn(new HttpResult(FAILED, EMPTY_MSG));
@@ -229,7 +232,7 @@
 
   @Test
   public void testEvictCacheThrowsException() throws Exception {
-    String key = "projectName";
+    String key = PROJECT_NAME;
     String keyJson = new GsonBuilder().create().toJson(key);
     doThrow(new IOException())
         .when(httpSessionMock)
@@ -237,13 +240,13 @@
     assertThat(forwarder.evict(Constants.PROJECTS, key)).isFalse();
   }
 
-  private String buildCacheEndpoint(String name) {
-    return Joiner.on("/").join("/plugins", PLUGIN_NAME, "cache", name);
+  private static String buildCacheEndpoint(String name) {
+    return Joiner.on("/").join(PLUGINS, PLUGIN_NAME, "cache", name);
   }
 
   @Test
   public void testAddToProjectListOK() throws Exception {
-    String projectName = "projectToAdd";
+    String projectName = PROJECT_TO_ADD;
     when(httpSessionMock.post(buildProjectListCacheEndpoint(projectName)))
         .thenReturn(new HttpResult(SUCCESSFUL, EMPTY_MSG));
     assertThat(forwarder.addToProjectList(projectName)).isTrue();
@@ -251,7 +254,7 @@
 
   @Test
   public void testAddToProjectListFailed() throws Exception {
-    String projectName = "projectToAdd";
+    String projectName = PROJECT_TO_ADD;
     when(httpSessionMock.post(buildProjectListCacheEndpoint(projectName)))
         .thenReturn(new HttpResult(FAILED, EMPTY_MSG));
     assertThat(forwarder.addToProjectList(projectName)).isFalse();
@@ -259,7 +262,7 @@
 
   @Test
   public void testAddToProjectListThrowsException() throws Exception {
-    String projectName = "projectToAdd";
+    String projectName = PROJECT_TO_ADD;
     doThrow(new IOException())
         .when(httpSessionMock)
         .post((buildProjectListCacheEndpoint(projectName)));
@@ -268,7 +271,7 @@
 
   @Test
   public void testRemoveFromProjectListOK() throws Exception {
-    String projectName = "projectToDelete";
+    String projectName = PROJECT_TO_DELETE;
     when(httpSessionMock.delete(buildProjectListCacheEndpoint(projectName)))
         .thenReturn(new HttpResult(SUCCESSFUL, EMPTY_MSG));
     assertThat(forwarder.removeFromProjectList(projectName)).isTrue();
@@ -276,7 +279,7 @@
 
   @Test
   public void testRemoveToProjectListFailed() throws Exception {
-    String projectName = "projectToDelete";
+    String projectName = PROJECT_TO_DELETE;
     when(httpSessionMock.delete(buildProjectListCacheEndpoint(projectName)))
         .thenReturn(new HttpResult(FAILED, EMPTY_MSG));
     assertThat(forwarder.removeFromProjectList(projectName)).isFalse();
@@ -284,23 +287,23 @@
 
   @Test
   public void testRemoveToProjectListThrowsException() throws Exception {
-    String projectName = "projectToDelete";
+    String projectName = PROJECT_TO_DELETE;
     doThrow(new IOException())
         .when(httpSessionMock)
         .delete((buildProjectListCacheEndpoint(projectName)));
     assertThat(forwarder.removeFromProjectList(projectName)).isFalse();
   }
 
-  private String buildProjectListCacheEndpoint(String projectName) {
+  private static String buildProjectListCacheEndpoint(String projectName) {
     return Joiner.on("/").join(buildCacheEndpoint(Constants.PROJECT_LIST), projectName);
   }
 
   @Test
   public void testRetryOnErrorThenSuccess() throws IOException {
     when(httpSessionMock.post(anyString(), anyString()))
-        .thenReturn(new HttpResult(false, "Error"))
-        .thenReturn(new HttpResult(false, "Error"))
-        .thenReturn(new HttpResult(true, "Success"));
+        .thenReturn(new HttpResult(false, ERROR))
+        .thenReturn(new HttpResult(false, ERROR))
+        .thenReturn(new HttpResult(true, SUCCESS));
 
     assertThat(forwarder.evict(Constants.PROJECT_LIST, new Object())).isTrue();
   }
@@ -310,7 +313,7 @@
     when(httpSessionMock.post(anyString(), anyString()))
         .thenThrow(new IOException())
         .thenThrow(new IOException())
-        .thenReturn(new HttpResult(true, "Success"));
+        .thenReturn(new HttpResult(true, SUCCESS));
 
     assertThat(forwarder.evict(Constants.PROJECT_LIST, new Object())).isTrue();
   }
@@ -319,7 +322,7 @@
   public void testNoRetryAfterNonRecoverableException() throws IOException {
     when(httpSessionMock.post(anyString(), anyString()))
         .thenThrow(new SSLException("Non Recoverable"))
-        .thenReturn(new HttpResult(true, "Success"));
+        .thenReturn(new HttpResult(true, SUCCESS));
 
     assertThat(forwarder.evict(Constants.PROJECT_LIST, new Object())).isFalse();
   }
@@ -327,9 +330,9 @@
   @Test
   public void testFailureAfterMaxTries() throws IOException {
     when(httpSessionMock.post(anyString(), anyString()))
-        .thenReturn(new HttpResult(false, "Error"))
-        .thenReturn(new HttpResult(false, "Error"))
-        .thenReturn(new HttpResult(false, "Error"));
+        .thenReturn(new HttpResult(false, ERROR))
+        .thenReturn(new HttpResult(false, ERROR))
+        .thenReturn(new HttpResult(false, ERROR));
 
     assertThat(forwarder.evict(Constants.PROJECT_LIST, new Object())).isFalse();
   }
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/MyUrlProviderTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/MyUrlProviderTest.java
index 2a2c853..f3e8b7d 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/MyUrlProviderTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/peers/jgroups/MyUrlProviderTest.java
@@ -34,6 +34,10 @@
 @RunWith(MockitoJUnitRunner.class)
 public class MyUrlProviderTest {
 
+  private static final String HTTPD = "httpd";
+  private static final String HTTPS = "https://";
+  private static final String LISTEN_URL = "listenUrl";
+
   @Rule public ExpectedException exception = ExpectedException.none();
 
   @Mock(answer = RETURNS_DEEP_STUBS)
@@ -42,7 +46,7 @@
   private Config gerritServerConfig;
 
   @Before
-  public void setUp() throws Exception {
+  public void setUp() {
     gerritServerConfig = new Config();
   }
 
@@ -54,14 +58,14 @@
   public void testGetJGroupsMyUrlFromListenUrl() throws Exception {
     String hostName = getLocalHost().getHostName();
 
-    gerritServerConfig.setString("httpd", null, "listenUrl", "https://foo:8080");
-    assertThat(getMyUrlProvider().get()).isEqualTo("https://" + hostName + ":8080");
+    gerritServerConfig.setString(HTTPD, null, LISTEN_URL, "https://foo:8080");
+    assertThat(getMyUrlProvider().get()).isEqualTo(HTTPS + hostName + ":8080");
 
-    gerritServerConfig.setString("httpd", null, "listenUrl", "https://foo");
-    assertThat(getMyUrlProvider().get()).isEqualTo("https://" + hostName);
+    gerritServerConfig.setString(HTTPD, null, LISTEN_URL, "https://foo");
+    assertThat(getMyUrlProvider().get()).isEqualTo(HTTPS + hostName);
 
-    gerritServerConfig.setString("httpd", null, "listenUrl", "https://foo/");
-    assertThat(getMyUrlProvider().get()).isEqualTo("https://" + hostName);
+    gerritServerConfig.setString(HTTPD, null, LISTEN_URL, "https://foo/");
+    assertThat(getMyUrlProvider().get()).isEqualTo(HTTPS + hostName);
   }
 
   @Test
@@ -73,7 +77,7 @@
 
   @Test
   public void testGetJGroupsMyUrlFromListenUrlWhenMultipleListenUrlsSpecified() throws Exception {
-    gerritServerConfig.setStringList("httpd", null, "listenUrl", Lists.newArrayList("a", "b"));
+    gerritServerConfig.setStringList(HTTPD, null, LISTEN_URL, Lists.newArrayList("a", "b"));
     exception.expect(ProvisionException.class);
     exception.expectMessage("exactly 1 value configured; found 2");
     getMyUrlProvider();
@@ -81,7 +85,7 @@
 
   @Test
   public void testGetJGroupsMyUrlFromListenUrlWhenReverseProxyConfigured() throws Exception {
-    gerritServerConfig.setString("httpd", null, "listenUrl", "proxy-https://foo");
+    gerritServerConfig.setString(HTTPD, null, LISTEN_URL, "proxy-https://foo");
     exception.expect(ProvisionException.class);
     exception.expectMessage("when configured as reverse-proxy");
     getMyUrlProvider();
@@ -89,7 +93,7 @@
 
   @Test
   public void testGetJGroupsMyUrlFromListenUrlWhenWildcardConfigured() throws Exception {
-    gerritServerConfig.setString("httpd", null, "listenUrl", "https://*");
+    gerritServerConfig.setString(HTTPD, null, LISTEN_URL, "https://*");
     exception.expect(ProvisionException.class);
     exception.expectMessage("when configured with wildcard");
     getMyUrlProvider();
diff --git a/src/test/java/com/ericsson/gerrit/plugins/highavailability/websession/file/FileBasedWebSessionCacheTest.java b/src/test/java/com/ericsson/gerrit/plugins/highavailability/websession/file/FileBasedWebSessionCacheTest.java
index 314099e..d4a012e 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/highavailability/websession/file/FileBasedWebSessionCacheTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/highavailability/websession/file/FileBasedWebSessionCacheTest.java
@@ -43,6 +43,7 @@
   private static final String EXISTING_KEY = "aSceprtBc02YaMY573T5jfW64ZudJfPbDq";
   private static final String EMPTY_KEY = "aOc2prqlZRpSO3LpauGO5efCLs1L9r9KkG";
   private static final String INVALID_KEY = "aOFdpHriBM6dN055M13PjDdTZagl5r5aSG";
+  private static final String NEW_KEY = "abcde12345";
 
   @Rule public TemporaryFolder tempFolder = new TemporaryFolder();
 
@@ -214,29 +215,26 @@
   public void putTest() throws Exception {
     loadKeyToCacheDir(EXISTING_KEY);
     Val val = cache.getIfPresent(EXISTING_KEY);
-    String newKey = "abcde12345";
-    cache.put(newKey, val);
-    assertThat(cache.getIfPresent(newKey)).isNotNull();
+    cache.put(NEW_KEY, val);
+    assertThat(cache.getIfPresent(NEW_KEY)).isNotNull();
   }
 
   @Test
   public void putAllTest() throws Exception {
     loadKeyToCacheDir(EXISTING_KEY);
     Val val = cache.getIfPresent(EXISTING_KEY);
-    String newKey = "abcde12345";
-    Map<String, Val> sessions = ImmutableMap.of(newKey, val);
+    Map<String, Val> sessions = ImmutableMap.of(NEW_KEY, val);
     cache.putAll(sessions);
-    assertThat(cache.asMap()).containsKey(newKey);
+    assertThat(cache.asMap()).containsKey(NEW_KEY);
   }
 
   @Test
   public void putWithErrorsTest() throws Exception {
     loadKeyToCacheDir(EXISTING_KEY);
     Val val = cache.getIfPresent(EXISTING_KEY);
-    String newKey = "abcde12345";
     tempFolder.delete();
-    cache.put(newKey, val);
-    assertThat(cache.getIfPresent(newKey)).isNull();
+    cache.put(NEW_KEY, val);
+    assertThat(cache.getIfPresent(NEW_KEY)).isNull();
   }
 
   @Test
@@ -260,7 +258,7 @@
     return keys;
   }
 
-  private boolean isDirEmpty(final Path dir) throws IOException {
+  private static boolean isDirEmpty(final Path dir) throws IOException {
     try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir)) {
       return !dirStream.iterator().hasNext();
     }
@@ -270,10 +268,11 @@
     if (key.equals(EMPTY_KEY)) {
       return Files.createFile(websessionDir.resolve(EMPTY_KEY));
     }
-    InputStream in = loadFile(key);
-    Path target = websessionDir.resolve(key);
-    Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING);
-    return target;
+    try (InputStream in = loadFile(key)) {
+      Path target = websessionDir.resolve(key);
+      Files.copy(in, target, StandardCopyOption.REPLACE_EXISTING);
+      return target;
+    }
   }
 
   private InputStream loadFile(String file) {