Merge branch 'stable-3.1' into stable-3.2
* stable-3.1:
Upgrade bazlets to latest stable-3.1 to build with 3.1.12 API
Upgrade bazlets to latest stable-3.0 to build with 3.0.15 API
Upgrade bazlets to latest stable-2.16 to build with 2.16.26 API
Upgrade bazlets to latest stable-3.1 to build with 3.1.11 API
Upgrade bazlets to latest stable-2.16 to build with 2.16.23 API
Change-Id: Id7f088bca203f4d935d184ad8b288ec5518097b7
diff --git a/WORKSPACE b/WORKSPACE
index aa95c9b..c78f78c 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "87fd5f0d0a89d01df13deaf2d21a4bdb3bc03cfd",
+ commit = "0f81174e3d1b892a1342ebc75bb4bbb158ae0efe",
#local_path = "/home/<user>/projects/bazlets",
)
diff --git a/src/main/java/com/ericsson/gerrit/plugins/goimport/GoImportFilter.java b/src/main/java/com/ericsson/gerrit/plugins/goimport/GoImportFilter.java
index 6a3b9a3..f59c9c1 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/goimport/GoImportFilter.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/goimport/GoImportFilter.java
@@ -37,6 +37,7 @@
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.nio.file.Paths;
+import java.util.Optional;
import java.util.regex.Pattern;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
@@ -192,7 +193,7 @@
}
private boolean projectExists(String projectName) {
- ProjectState p = projectCache.get(Project.nameKey(projectName));
- return p != null;
+ Optional<ProjectState> p = projectCache.get(Project.nameKey(projectName));
+ return p.isPresent();
}
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/goimport/GoImportFilterTest.java b/src/test/java/com/ericsson/gerrit/plugins/goimport/GoImportFilterTest.java
index 4bc2978..89d1ee5 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/goimport/GoImportFilterTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/goimport/GoImportFilterTest.java
@@ -33,6 +33,7 @@
import com.google.inject.Provider;
import java.io.IOException;
import java.net.URISyntaxException;
+import java.util.Optional;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
@@ -90,7 +91,6 @@
unitUnderTest = new GoImportFilter(mockAnonProvider, mockPerms, mockProjectCache, PROD_URL);
assertThat(unitUnderTest).isNotNull();
when(mockResponse.getOutputStream()).thenReturn(mockOutputStream);
-
when(mockAnonProvider.get()).thenReturn(mockAnon);
when(mockPerms.user(mockAnon)).thenReturn(mockPermsWithUser);
when(mockPermsWithUser.ref(any())).thenReturn(mockPermsForRef);
@@ -140,7 +140,8 @@
public void testDoFilterWithExistingProject() throws Exception {
when(mockRequest.getServletPath()).thenReturn("/" + PROJECT_NAME);
when(mockRequest.getParameter("go-get")).thenReturn("1");
- when(mockProjectCache.get(Project.nameKey(PROJECT_NAME))).thenReturn(mockProjectState);
+ when(mockProjectCache.get(Project.nameKey(PROJECT_NAME)))
+ .thenReturn(Optional.of(mockProjectState));
when(mockPermsForRef.testOrFalse(RefPermission.READ)).thenReturn(false);
unitUnderTest.doFilter(mockRequest, mockResponse, mockChain);
verify(mockOutputStream, times(1)).write(response200(false, false));
@@ -154,7 +155,8 @@
public void testDoFilterAuthenticatedWithExistingProject() throws Exception {
when(mockRequest.getServletPath()).thenReturn("/a/" + PROJECT_NAME);
when(mockRequest.getParameter("go-get")).thenReturn("1");
- when(mockProjectCache.get(Project.nameKey(PROJECT_NAME))).thenReturn(mockProjectState);
+ when(mockProjectCache.get(Project.nameKey(PROJECT_NAME)))
+ .thenReturn(Optional.of(mockProjectState));
when(mockPermsForRef.testOrFalse(RefPermission.READ)).thenReturn(false);
unitUnderTest.doFilter(mockRequest, mockResponse, mockChain);
verify(mockOutputStream, times(1)).write(response200(false, true));
@@ -168,7 +170,8 @@
public void testDoFilterWithExistingProjectAndPackage() throws Exception {
when(mockRequest.getServletPath()).thenReturn("/" + PROJECT_NAME + "/my/package");
when(mockRequest.getParameter("go-get")).thenReturn("1");
- when(mockProjectCache.get(Project.nameKey(PROJECT_NAME))).thenReturn(mockProjectState);
+ when(mockProjectCache.get(Project.nameKey(PROJECT_NAME)))
+ .thenReturn(Optional.of(mockProjectState));
when(mockPermsForRef.testOrFalse(RefPermission.READ)).thenReturn(false);
unitUnderTest.doFilter(mockRequest, mockResponse, mockChain);
verify(mockOutputStream, times(1)).write(response200(false, false));
@@ -181,7 +184,8 @@
public void testDoFilterWithAnonymousAccessibleProject() throws Exception {
when(mockRequest.getServletPath()).thenReturn("/projectName");
when(mockRequest.getParameter("go-get")).thenReturn("1");
- when(mockProjectCache.get(Project.nameKey("projectName"))).thenReturn(mockProjectState);
+ when(mockProjectCache.get(Project.nameKey(PROJECT_NAME)))
+ .thenReturn(Optional.of(mockProjectState));
when(mockPermsForRef.testOrFalse(RefPermission.READ)).thenReturn(true);
unitUnderTest.doFilter(mockRequest, mockResponse, mockChain);
verify(mockOutputStream, times(1)).write(response200(true, false));
@@ -195,7 +199,7 @@
public void testDoFilterWithNonExistingProject() throws Exception {
when(mockRequest.getServletPath()).thenReturn("/" + PROJECT_NAME);
when(mockRequest.getParameter("go-get")).thenReturn("1");
- when(mockProjectCache.get(any(Project.NameKey.class))).thenReturn(null);
+ when(mockProjectCache.get(any(Project.NameKey.class))).thenReturn(Optional.empty());
unitUnderTest.doFilter(mockRequest, mockResponse, mockChain);
verify(mockOutputStream, times(1)).write(any(byte[].class));
verify(mockChain, times(0)).doFilter(mockRequest, mockResponse);
@@ -209,7 +213,8 @@
when(mockRequest.getServletPath()).thenReturn("/" + PROJECT_NAME);
when(mockRequest.getParameter("go-get")).thenReturn("1");
doThrow(new IOException(msg)).when(mockOutputStream).write(any(byte[].class));
- when(mockProjectCache.get(any(Project.NameKey.class))).thenReturn(mockProjectState);
+ when(mockProjectCache.get(any(Project.NameKey.class)))
+ .thenReturn(Optional.of(mockProjectState));
IOException thrown =
assertThrows(
IOException.class, () -> unitUnderTest.doFilter(mockRequest, mockResponse, mockChain));