Use assertThat from Hamcrest instead of JUnit 4

org.junit.Assert.assertThat() is deprecated as of JUnit 4.13.

See gh-22894
This commit is contained in:
Sam Brannen
2019-05-05 19:14:21 +02:00
parent 47c39304af
commit d616e10dca
103 changed files with 126 additions and 70 deletions

View File

@@ -19,11 +19,11 @@ package org.springframework.http;
import org.hamcrest.Matchers;
import org.junit.Test;
import static org.junit.Assert.*;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* @author Brian Clozel
*/

View File

@@ -35,9 +35,9 @@ import java.util.Locale;
import java.util.TimeZone;
import org.hamcrest.Matchers;
import org.junit.Ignore;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

View File

@@ -19,9 +19,7 @@ package org.springframework.http;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;

View File

@@ -21,6 +21,7 @@ import java.time.Duration;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**

View File

@@ -25,6 +25,7 @@ import java.util.concurrent.TimeUnit;
import org.hamcrest.Matchers;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**

View File

@@ -29,7 +29,7 @@ import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Tests for {@link InterceptingHttpAccessor}.

View File

@@ -34,11 +34,11 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.StringUtils;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertThat;
import static org.springframework.http.MediaType.TEXT_PLAIN;
import static org.springframework.mock.http.server.reactive.test.MockServerHttpRequest.get;

View File

@@ -34,6 +34,7 @@ import org.springframework.http.MediaType;
import org.springframework.http.codec.Pojo;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.springframework.core.io.buffer.DataBufferUtils.release;
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;

View File

@@ -47,11 +47,11 @@ import org.springframework.util.MultiValueMap;
import static org.hamcrest.CoreMatchers.allOf;
import static org.hamcrest.CoreMatchers.endsWith;
import static org.hamcrest.CoreMatchers.startsWith;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.never;
import static org.mockito.BDDMockito.verify;

View File

@@ -37,6 +37,7 @@ import org.springframework.util.FileCopyUtils;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsInstanceOf.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.mockito.BDDMockito.any;
import static org.mockito.BDDMockito.*;

View File

@@ -38,9 +38,9 @@ import org.springframework.http.MediaType;
import org.springframework.http.MockHttpOutputMessage;
import org.springframework.util.StringUtils;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**

View File

@@ -16,9 +16,6 @@
package org.springframework.http.converter.feed;
import static org.junit.Assert.*;
import static org.xmlunit.matchers.CompareMatcher.*;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
@@ -39,6 +36,10 @@ import org.springframework.http.MediaType;
import org.springframework.http.MockHttpInputMessage;
import org.springframework.http.MockHttpOutputMessage;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.xmlunit.matchers.CompareMatcher.*;
/**
* @author Arjen Poutsma
*/

View File

@@ -16,8 +16,6 @@
package org.springframework.http.converter.feed;
import static org.junit.Assert.*;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
@@ -36,6 +34,9 @@ import org.springframework.http.MediaType;
import org.springframework.http.MockHttpInputMessage;
import org.springframework.http.MockHttpOutputMessage;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**
* @author Arjen Poutsma
*/

View File

@@ -43,6 +43,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.lang.Nullable;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**

View File

@@ -42,6 +42,7 @@ import org.springframework.http.MockHttpInputMessage;
import org.springframework.http.MockHttpOutputMessage;
import org.springframework.http.converter.HttpMessageNotReadableException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.xmlunit.diff.ComparisonType.*;
import static org.xmlunit.diff.DifferenceEvaluators.*;

View File

@@ -33,6 +33,7 @@ import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.http.converter.json.MappingJacksonValue;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**

View File

@@ -48,6 +48,7 @@ import org.springframework.http.MockHttpOutputMessage;
import org.springframework.http.converter.HttpMessageNotReadableException;
import org.springframework.util.FileCopyUtils;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
import static org.xmlunit.matchers.CompareMatcher.*;

View File

@@ -33,7 +33,7 @@ import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* @author Stephane Maldini

View File

@@ -33,6 +33,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

View File

@@ -16,9 +16,6 @@
package org.springframework.web.bind.support;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.beans.PropertyEditorSupport;
import java.util.Arrays;
import java.util.HashMap;
@@ -39,6 +36,10 @@ import org.springframework.web.bind.ServletRequestParameterPropertyValues;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.multipart.support.StringMultipartFileEditor;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
* @author Juergen Hoeller
*/

View File

@@ -32,6 +32,7 @@ import org.junit.Before;
import org.springframework.http.MediaType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**

View File

@@ -28,6 +28,7 @@ import org.junit.Test;
import org.springframework.http.HttpStatus;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**

View File

@@ -29,8 +29,6 @@ import java.util.Set;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import com.fasterxml.jackson.annotation.JsonView;
import org.hamcrest.Matchers;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -58,6 +56,7 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import static org.junit.Assert.*;
import static org.junit.Assume.assumeFalse;
import static org.springframework.http.HttpMethod.POST;
/**
@@ -161,8 +160,8 @@ public class RestTemplateIntegrationTests extends AbstractMockWebServerTestCase
@Test
public void patchForObject() throws URISyntaxException {
// JDK client does not support the PATCH method
Assume.assumeThat(this.clientHttpRequestFactory,
Matchers.not(Matchers.instanceOf(SimpleClientHttpRequestFactory.class)));
assumeFalse(this.clientHttpRequestFactory instanceof SimpleClientHttpRequestFactory);
String s = template.patchForObject(baseUrl + "/{method}", helloWorld, String.class, "patch");
assertEquals("Invalid content", helloWorld, s);
}

View File

@@ -16,7 +16,6 @@
package org.springframework.web.context.request.async;
import java.util.function.Consumer;
import javax.servlet.AsyncEvent;
@@ -28,12 +27,12 @@ import org.springframework.mock.web.test.MockAsyncContext;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.mock;

View File

@@ -25,6 +25,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**

View File

@@ -25,7 +25,7 @@ import org.springframework.core.env.StandardEnvironment;
import org.springframework.tests.mock.jndi.SimpleNamingContextBuilder;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
/**
* Unit tests for {@link StandardServletEnvironment}.

View File

@@ -26,6 +26,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.*;

View File

@@ -28,11 +28,11 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.server.ServerWebExchange;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_ALLOW_HEADERS;
import static org.springframework.http.HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN;

View File

@@ -17,7 +17,6 @@
package org.springframework.web.filter;
import java.io.IOException;
import java.net.URI;
import java.util.Enumeration;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;

View File

@@ -31,8 +31,8 @@ import org.springframework.mock.web.test.server.MockServerWebExchange;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilterChain;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
/**
* Tests for {@link HiddenHttpMethodFilter}.

View File

@@ -29,6 +29,7 @@ import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.context.request.ServletWebRequest;
import org.springframework.web.method.ResolvableMethod;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

View File

@@ -30,6 +30,7 @@ import org.springframework.util.MultiValueMap;
import org.springframework.web.multipart.MultipartFile;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.*;
/**

View File

@@ -33,6 +33,7 @@ import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.util.StringUtils;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;

View File

@@ -27,6 +27,7 @@ import java.util.Collections;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.springframework.web.util.UriComponentsBuilder.*;

View File

@@ -34,11 +34,11 @@ import org.springframework.util.AntPathMatcher;
import org.springframework.web.util.pattern.PathPattern.PathRemainingMatchInfo;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;