From: Simon Brandhof Date: Wed, 10 Jan 2018 19:42:03 +0000 (+0100) Subject: Upgrade Mockito from 1.10.19 to 2.13.0 X-Git-Tag: 7.0-RC1~18 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4a5be9fbaba0b9729e909eec935852c56f6e71e2;p=sonarqube.git Upgrade Mockito from 1.10.19 to 2.13.0 --- diff --git a/pom.xml b/pom.xml index 2bd72de3ae4..b9b7d4fda99 100644 --- a/pom.xml +++ b/pom.xml @@ -975,7 +975,7 @@ org.mockito mockito-core - 1.10.19 + 2.13.0 org.hamcrest diff --git a/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java b/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java index edf673b6e24..ecb23275f2e 100644 --- a/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java +++ b/sonar-core/src/test/java/org/sonar/core/util/DefaultHttpDownloaderTest.java @@ -22,7 +22,6 @@ package org.sonar.core.util; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.net.Authenticator; import java.net.InetSocketAddress; import java.net.NoRouteToHostException; import java.net.PasswordAuthentication; @@ -39,7 +38,6 @@ import java.util.Properties; import java.util.zip.GZIPOutputStream; import org.hamcrest.BaseMatcher; import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Rule; @@ -295,18 +293,11 @@ public class DefaultHttpDownloaderTest { new DefaultHttpDownloader.BaseHttpDownloader(system, settings.asConfig(), null); - verify(system).setDefaultAuthenticator(argThat(new TypeSafeMatcher() { - @Override - protected boolean matchesSafely(Authenticator authenticator) { - DefaultHttpDownloader.ProxyAuthenticator a = (DefaultHttpDownloader.ProxyAuthenticator) authenticator; - PasswordAuthentication authentication = a.getPasswordAuthentication(); - return authentication.getUserName().equals("the_login") && - new String(authentication.getPassword()).equals("the_passwd"); - } - - @Override - public void describeTo(Description description) { - } + verify(system).setDefaultAuthenticator(argThat(authenticator -> { + DefaultHttpDownloader.ProxyAuthenticator a = (DefaultHttpDownloader.ProxyAuthenticator) authenticator; + PasswordAuthentication authentication = a.getPasswordAuthentication(); + return authentication.getUserName().equals("the_login") && + new String(authentication.getPassword()).equals("the_passwd"); })); } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/WsTestUtil.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/WsTestUtil.java index 161d44b6fe5..1cda6fd4e15 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/WsTestUtil.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/WsTestUtil.java @@ -21,9 +21,9 @@ package org.sonar.scanner; import java.io.InputStream; import java.io.Reader; +import javax.annotation.Nullable; import org.apache.commons.lang.StringUtils; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; +import org.mockito.ArgumentMatcher; import org.sonar.scanner.bootstrap.ScannerWsClient; import org.sonarqube.ws.client.WsRequest; import org.sonarqube.ws.client.WsResponse; @@ -71,7 +71,7 @@ public class WsTestUtil { verify(mock).call(argThat(new RequestMatcher(path))); } - private static class RequestMatcher extends BaseMatcher { + private static class RequestMatcher implements ArgumentMatcher { private String path; public RequestMatcher(String path) { @@ -79,17 +79,11 @@ public class WsTestUtil { } @Override - public boolean matches(Object item) { + public boolean matches(@Nullable WsRequest item) { if (item == null) { return false; } - WsRequest request = (WsRequest) item; - return StringUtils.equals(request.getPath(), path); - } - - @Override - public void describeTo(Description description) { - description.appendText("request path (\"" + path + "\")"); + return StringUtils.equals(item.getPath(), path); } } } diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ContextPropertiesPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ContextPropertiesPublisherTest.java index 190db162aa0..04bdf6cf150 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ContextPropertiesPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ContextPropertiesPublisherTest.java @@ -24,8 +24,6 @@ import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -91,17 +89,10 @@ public class ContextPropertiesPublisherTest { } private void expectWritten(List expected) { - verify(writer).writeContextProperties(argThat(new TypeSafeMatcher>() { - @Override - protected boolean matchesSafely(Iterable props) { - List copy = Lists.newArrayList(props); - copy.removeAll(expected); - return copy.isEmpty(); - } - - @Override - public void describeTo(Description description) { - } + verify(writer).writeContextProperties(argThat(props -> { + List copy = Lists.newArrayList(props); + copy.removeAll(expected); + return copy.isEmpty(); })); } diff --git a/sonar-ws/src/test/java/org/sonarqube/ws/client/LocalWsConnectorTest.java b/sonar-ws/src/test/java/org/sonarqube/ws/client/LocalWsConnectorTest.java index c4983eaf09f..79b6c6e4583 100644 --- a/sonar-ws/src/test/java/org/sonarqube/ws/client/LocalWsConnectorTest.java +++ b/sonar-ws/src/test/java/org/sonarqube/ws/client/LocalWsConnectorTest.java @@ -25,9 +25,8 @@ import java.util.Collections; import java.util.List; import java.util.Map; import org.apache.commons.io.IOUtils; -import org.hamcrest.Description; -import org.hamcrest.TypeSafeMatcher; import org.junit.Test; +import org.mockito.ArgumentMatcher; import org.sonar.api.server.ws.LocalConnector; import org.sonarqube.ws.MediaTypes; @@ -87,12 +86,11 @@ public class LocalWsConnectorTest { when(connector.call(any(LocalConnector.LocalRequest.class))).thenReturn(response); } - private void verifyRequested(final String expectedMethod, final String expectedPath, - final String expectedMediaType, - final Map expectedParams) { - verify(connector).call(argThat(new TypeSafeMatcher() { + private void verifyRequested(String expectedMethod, String expectedPath, + String expectedMediaType, Map expectedParams) { + verify(connector).call(argThat(new ArgumentMatcher() { @Override - protected boolean matchesSafely(LocalConnector.LocalRequest localRequest) { + public boolean matches(LocalConnector.LocalRequest localRequest) { boolean ok = localRequest.getMethod().equals(expectedMethod) && localRequest.getPath().equals(expectedPath); ok &= localRequest.getMediaType().equals(expectedMediaType); for (Map.Entry expectedParam : expectedParams.entrySet()) { @@ -102,10 +100,6 @@ public class LocalWsConnectorTest { } return ok; } - - @Override - public void describeTo(Description description) { - } })); }