<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
- <version>1.10.19</version>
+ <version>2.13.0</version>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
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;
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;
new DefaultHttpDownloader.BaseHttpDownloader(system, settings.asConfig(), null);
- verify(system).setDefaultAuthenticator(argThat(new TypeSafeMatcher<Authenticator>() {
- @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");
}));
}
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;
verify(mock).call(argThat(new RequestMatcher(path)));
}
- private static class RequestMatcher extends BaseMatcher<WsRequest> {
+ private static class RequestMatcher implements ArgumentMatcher<WsRequest> {
private String path;
public RequestMatcher(String path) {
}
@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);
}
}
}
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;
}
private void expectWritten(List<ScannerReport.ContextProperty> expected) {
- verify(writer).writeContextProperties(argThat(new TypeSafeMatcher<Iterable<ScannerReport.ContextProperty>>() {
- @Override
- protected boolean matchesSafely(Iterable<ScannerReport.ContextProperty> props) {
- List<ScannerReport.ContextProperty> copy = Lists.newArrayList(props);
- copy.removeAll(expected);
- return copy.isEmpty();
- }
-
- @Override
- public void describeTo(Description description) {
- }
+ verify(writer).writeContextProperties(argThat(props -> {
+ List<ScannerReport.ContextProperty> copy = Lists.newArrayList(props);
+ copy.removeAll(expected);
+ return copy.isEmpty();
}));
}
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;
when(connector.call(any(LocalConnector.LocalRequest.class))).thenReturn(response);
}
- private void verifyRequested(final String expectedMethod, final String expectedPath,
- final String expectedMediaType,
- final Map<String, String> expectedParams) {
- verify(connector).call(argThat(new TypeSafeMatcher<LocalConnector.LocalRequest>() {
+ private void verifyRequested(String expectedMethod, String expectedPath,
+ String expectedMediaType, Map<String, String> expectedParams) {
+ verify(connector).call(argThat(new ArgumentMatcher<LocalConnector.LocalRequest>() {
@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<String, String> expectedParam : expectedParams.entrySet()) {
}
return ok;
}
-
- @Override
- public void describeTo(Description description) {
- }
}));
}