Merge branch 'stable-3.0' into stable-3.1
* stable-3.0:
Upgrade bazlets to latest stable-3.0 to build with 3.0.10 API
Upgrade bazlets to latest stable-2.16 to build with 2.16.21 API
Upgrade bazlets to latest stable-2.15 to build with 2.15.19 API
Upgrade bazlets to latest stable-2.14 to build with 2.14.21 API
Change-Id: Id978019223c7563b40e925ce0229e8a475b50766
diff --git a/.gitignore b/.gitignore
index f3a0d53..a832ec3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@
/.settings
/bazel-*
/eclipse-out
+/.apt_generated/
diff --git a/WORKSPACE b/WORKSPACE
index 7518321..e40364d 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -3,7 +3,7 @@
load("//:bazlets.bzl", "load_bazlets")
load_bazlets(
- commit = "928c928345646ae958b946e9bbdb462f58dd1384",
+ commit = "51c1fd2758fcc1b900a80d4ebb037bc373f85d39",
#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 dc74595..6a3b9a3 100644
--- a/src/main/java/com/ericsson/gerrit/plugins/goimport/GoImportFilter.java
+++ b/src/main/java/com/ericsson/gerrit/plugins/goimport/GoImportFilter.java
@@ -16,11 +16,11 @@
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Strings;
+import com.google.gerrit.entities.BranchNameKey;
+import com.google.gerrit.entities.Project;
+import com.google.gerrit.entities.RefNames;
import com.google.gerrit.httpd.AllRequestFilter;
import com.google.gerrit.httpd.HtmlDomUtil;
-import com.google.gerrit.reviewdb.client.Branch;
-import com.google.gerrit.reviewdb.client.Project;
-import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.AnonymousUser;
import com.google.gerrit.server.config.CanonicalWebUrl;
import com.google.gerrit.server.permissions.PermissionBackend;
@@ -186,14 +186,13 @@
private boolean allowsAnonymousAccess(String projectName) {
AnonymousUser anonymous = anonProvider.get();
- Branch.NameKey heads =
- new Branch.NameKey(new Project.NameKey(projectName), RefNames.REFS_HEADS);
+ BranchNameKey heads = BranchNameKey.create(Project.nameKey(projectName), RefNames.REFS_HEADS);
return permissions.user(anonymous).ref(heads).testOrFalse(RefPermission.READ);
}
private boolean projectExists(String projectName) {
- ProjectState p = projectCache.get(new Project.NameKey(projectName));
+ ProjectState p = projectCache.get(Project.nameKey(projectName));
return p != null;
}
}
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 0939935..4bc2978 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/goimport/GoImportFilterTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/goimport/GoImportFilterTest.java
@@ -17,14 +17,14 @@
import static com.ericsson.gerrit.plugins.goimport.GoImportFilter.CONTENT_PLH;
import static com.ericsson.gerrit.plugins.goimport.GoImportFilter.PAGE_200;
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.Mockito.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
-import com.google.gerrit.reviewdb.client.Project;
+import com.google.gerrit.entities.Project;
import com.google.gerrit.server.AnonymousUser;
import com.google.gerrit.server.permissions.PermissionBackend;
import com.google.gerrit.server.permissions.RefPermission;
@@ -140,7 +140,7 @@
public void testDoFilterWithExistingProject() throws Exception {
when(mockRequest.getServletPath()).thenReturn("/" + PROJECT_NAME);
when(mockRequest.getParameter("go-get")).thenReturn("1");
- when(mockProjectCache.get(new Project.NameKey(PROJECT_NAME))).thenReturn(mockProjectState);
+ when(mockProjectCache.get(Project.nameKey(PROJECT_NAME))).thenReturn(mockProjectState);
when(mockPermsForRef.testOrFalse(RefPermission.READ)).thenReturn(false);
unitUnderTest.doFilter(mockRequest, mockResponse, mockChain);
verify(mockOutputStream, times(1)).write(response200(false, false));
@@ -154,7 +154,7 @@
public void testDoFilterAuthenticatedWithExistingProject() throws Exception {
when(mockRequest.getServletPath()).thenReturn("/a/" + PROJECT_NAME);
when(mockRequest.getParameter("go-get")).thenReturn("1");
- when(mockProjectCache.get(new Project.NameKey(PROJECT_NAME))).thenReturn(mockProjectState);
+ when(mockProjectCache.get(Project.nameKey(PROJECT_NAME))).thenReturn(mockProjectState);
when(mockPermsForRef.testOrFalse(RefPermission.READ)).thenReturn(false);
unitUnderTest.doFilter(mockRequest, mockResponse, mockChain);
verify(mockOutputStream, times(1)).write(response200(false, true));
@@ -168,7 +168,7 @@
public void testDoFilterWithExistingProjectAndPackage() throws Exception {
when(mockRequest.getServletPath()).thenReturn("/" + PROJECT_NAME + "/my/package");
when(mockRequest.getParameter("go-get")).thenReturn("1");
- when(mockProjectCache.get(new Project.NameKey(PROJECT_NAME))).thenReturn(mockProjectState);
+ when(mockProjectCache.get(Project.nameKey(PROJECT_NAME))).thenReturn(mockProjectState);
when(mockPermsForRef.testOrFalse(RefPermission.READ)).thenReturn(false);
unitUnderTest.doFilter(mockRequest, mockResponse, mockChain);
verify(mockOutputStream, times(1)).write(response200(false, false));
@@ -181,7 +181,7 @@
public void testDoFilterWithAnonymousAccessibleProject() throws Exception {
when(mockRequest.getServletPath()).thenReturn("/projectName");
when(mockRequest.getParameter("go-get")).thenReturn("1");
- when(mockProjectCache.get(new Project.NameKey("projectName"))).thenReturn(mockProjectState);
+ when(mockProjectCache.get(Project.nameKey("projectName"))).thenReturn(mockProjectState);
when(mockPermsForRef.testOrFalse(RefPermission.READ)).thenReturn(true);
unitUnderTest.doFilter(mockRequest, mockResponse, mockChain);
verify(mockOutputStream, times(1)).write(response200(true, false));
@@ -210,25 +210,20 @@
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);
- try {
- unitUnderTest.doFilter(mockRequest, mockResponse, mockChain);
- fail("IOException should occur!");
- } catch (IOException e) {
- assertThat(msg).isEqualTo(e.getMessage());
- verify(mockOutputStream, times(1)).write(any(byte[].class));
- }
+ IOException thrown =
+ assertThrows(
+ IOException.class, () -> unitUnderTest.doFilter(mockRequest, mockResponse, mockChain));
+ assertThat(thrown).hasMessageThat().isEqualTo(msg);
+ verify(mockOutputStream, times(1)).write(any(byte[].class));
}
@Test
public void testDoFilterWithServletException() throws Exception {
String msg = "test-serv-error";
doThrow(new ServletException(msg)).when(mockChain).doFilter(null, null);
- try {
- unitUnderTest.doFilter(null, null, mockChain);
- fail("ServletException should occur!");
- } catch (ServletException e) {
- assertThat(msg).isEqualTo(e.getMessage());
- verify(mockChain, times(1)).doFilter(null, null);
- }
+ ServletException thrown =
+ assertThrows(ServletException.class, () -> unitUnderTest.doFilter(null, null, mockChain));
+ assertThat(thrown).hasMessageThat().isEqualTo(msg);
+ verify(mockChain, times(1)).doFilter(null, null);
}
}
diff --git a/src/test/java/com/ericsson/gerrit/plugins/goimport/HttpModuleTest.java b/src/test/java/com/ericsson/gerrit/plugins/goimport/HttpModuleTest.java
index a0a107d..021c154 100644
--- a/src/test/java/com/ericsson/gerrit/plugins/goimport/HttpModuleTest.java
+++ b/src/test/java/com/ericsson/gerrit/plugins/goimport/HttpModuleTest.java
@@ -51,7 +51,7 @@
GoImportFilter filter1 = injector.getInstance(GoImportFilter.class);
assertThat(filter1).isNotNull();
GoImportFilter filter2 = injector.getInstance(GoImportFilter.class);
- assertThat(filter1).isSameAs(filter2);
+ assertThat(filter1).isSameInstanceAs(filter2);
}
public class TestModule extends AbstractModule {