IndexServletTest: Migrate from easymock to mockito
Bug: Issue 5057
Change-Id: I0454741bf7f44220a4db452ef2a87174a7e36443
diff --git a/javatests/com/google/gerrit/httpd/BUILD b/javatests/com/google/gerrit/httpd/BUILD
index 6849d66..2254c4e 100644
--- a/javatests/com/google/gerrit/httpd/BUILD
+++ b/javatests/com/google/gerrit/httpd/BUILD
@@ -19,11 +19,11 @@
"//lib:junit",
"//lib:servlet-api-3_1-without-neverlink",
"//lib:soy",
- "//lib/easymock",
"//lib/guice",
"//lib/guice:guice-servlet",
"//lib/jgit/org.eclipse.jgit:jgit",
"//lib/jgit/org.eclipse.jgit.junit:junit",
+ "//lib/mockito",
"//lib/truth",
"//lib/truth:truth-java8-extension",
],
diff --git a/javatests/com/google/gerrit/httpd/raw/IndexServletTest.java b/javatests/com/google/gerrit/httpd/raw/IndexServletTest.java
index 99835dd..77ab58b 100644
--- a/javatests/com/google/gerrit/httpd/raw/IndexServletTest.java
+++ b/javatests/com/google/gerrit/httpd/raw/IndexServletTest.java
@@ -15,10 +15,8 @@
package com.google.gerrit.httpd.raw;
import static com.google.common.truth.Truth.assertThat;
-import static org.easymock.EasyMock.createMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.easymock.EasyMock.verify;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableList;
import com.google.gerrit.extensions.api.GerritApi;
@@ -35,22 +33,22 @@
@Test
public void renderTemplate() throws Exception {
- Accounts accountsApi = createMock(Accounts.class);
- expect(accountsApi.self()).andThrow(new AuthException("user needs to be authenticated"));
+ Accounts accountsApi = mock(Accounts.class);
+ when(accountsApi.self()).thenThrow(new AuthException("user needs to be authenticated"));
- Server serverApi = createMock(Server.class);
- expect(serverApi.getVersion()).andReturn("123");
- expect(serverApi.topMenus()).andReturn(ImmutableList.of());
+ Server serverApi = mock(Server.class);
+ when(serverApi.getVersion()).thenReturn("123");
+ when(serverApi.topMenus()).thenReturn(ImmutableList.of());
ServerInfo serverInfo = new ServerInfo();
serverInfo.defaultTheme = "my-default-theme";
- expect(serverApi.getInfo()).andReturn(serverInfo);
+ when(serverApi.getInfo()).thenReturn(serverInfo);
- Config configApi = createMock(Config.class);
- expect(configApi.server()).andReturn(serverApi);
+ Config configApi = mock(Config.class);
+ when(configApi.server()).thenReturn(serverApi);
- GerritApi gerritApi = createMock(GerritApi.class);
- expect(gerritApi.accounts()).andReturn(accountsApi);
- expect(gerritApi.config()).andReturn(configApi);
+ GerritApi gerritApi = mock(GerritApi.class);
+ when(gerritApi.accounts()).thenReturn(accountsApi);
+ when(gerritApi.config()).thenReturn(configApi);
String testCanonicalUrl = "foo-url";
String testCdnPath = "bar-cdn";
@@ -60,18 +58,8 @@
FakeHttpServletResponse response = new FakeHttpServletResponse();
- replay(gerritApi);
- replay(configApi);
- replay(serverApi);
- replay(accountsApi);
-
servlet.doGet(new FakeHttpServletRequest(), response);
- verify(gerritApi);
- verify(configApi);
- verify(serverApi);
- verify(accountsApi);
-
String output = response.getActualBodyString();
assertThat(output).contains("<!DOCTYPE html>");
assertThat(output).contains("window.CANONICAL_PATH = '" + testCanonicalUrl);