Migrate Hamcrest assertions to AssertJ

Migrate all existing `assertThat(..., Matcher)` assertions to AssertJ
and add checkstyle rules to ensure they don't return.

See gh-23022
This commit is contained in:
Phillip Webb
2019-05-23 15:48:03 -07:00
parent 2294625cf0
commit 95a9d46a87
322 changed files with 4358 additions and 4814 deletions

View File

@@ -47,10 +47,6 @@ import org.springframework.web.servlet.SimpleWebApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -131,8 +127,8 @@ public class ContextLoaderTests {
listener.contextInitialized(new ServletContextEvent(sc));
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
TestBean testBean = wac.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("testName"));
assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
assertThat(testBean.getName()).isEqualTo("testName");
assertThat(wac.getServletContext().getAttribute("initialized")).isNotNull();
}
@Test
@@ -146,8 +142,8 @@ public class ContextLoaderTests {
listener.contextInitialized(new ServletContextEvent(sc));
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
TestBean testBean = wac.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("testName"));
assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
assertThat(testBean.getName()).isEqualTo("testName");
assertThat(wac.getServletContext().getAttribute("initialized")).isNotNull();
}
@Test
@@ -161,8 +157,8 @@ public class ContextLoaderTests {
listener.contextInitialized(new ServletContextEvent(sc));
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
TestBean testBean = wac.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("testName"));
assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
assertThat(testBean.getName()).isEqualTo("testName");
assertThat(wac.getServletContext().getAttribute("initialized")).isNotNull();
}
@Test
@@ -175,8 +171,8 @@ public class ContextLoaderTests {
listener.contextInitialized(new ServletContextEvent(sc));
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
TestBean testBean = wac.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("testName"));
assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
assertThat(testBean.getName()).isEqualTo("testName");
assertThat(wac.getServletContext().getAttribute("initialized")).isNotNull();
}
@Test
@@ -190,8 +186,8 @@ public class ContextLoaderTests {
listener.contextInitialized(new ServletContextEvent(sc));
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
TestBean testBean = wac.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("testName"));
assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
assertThat(testBean.getName()).isEqualTo("testName");
assertThat(wac.getServletContext().getAttribute("initialized")).isNotNull();
}
@Test
@@ -205,8 +201,8 @@ public class ContextLoaderTests {
listener.contextInitialized(new ServletContextEvent(sc));
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
TestBean testBean = wac.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("testName"));
assertThat(wac.getServletContext().getAttribute("initialized"), notNullValue());
assertThat(testBean.getName()).isEqualTo("testName");
assertThat(wac.getServletContext().getAttribute("initialized")).isNotNull();
}
@Test
@@ -381,7 +377,7 @@ public class ContextLoaderTests {
// test that ApplicationContextInitializers can access ServletContext properties
// via the environment (SPR-8991)
String value = applicationContext.getEnvironment().getRequiredProperty("someProperty");
assertThat(value, is("someValue"));
assertThat(value).isEqualTo("someValue");
}
}

View File

@@ -38,8 +38,6 @@ import org.springframework.web.context.support.XmlWebApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -91,10 +89,10 @@ public class XmlWebApplicationContextTests extends AbstractApplicationContextTes
@Test
@SuppressWarnings("deprecation")
public void environmentMerge() {
assertThat(this.root.getEnvironment().acceptsProfiles("rootProfile1"), is(true));
assertThat(this.root.getEnvironment().acceptsProfiles("wacProfile1"), is(false));
assertThat(this.applicationContext.getEnvironment().acceptsProfiles("rootProfile1"), is(true));
assertThat(this.applicationContext.getEnvironment().acceptsProfiles("wacProfile1"), is(true));
assertThat(this.root.getEnvironment().acceptsProfiles("rootProfile1")).isTrue();
assertThat(this.root.getEnvironment().acceptsProfiles("wacProfile1")).isFalse();
assertThat(this.applicationContext.getEnvironment().acceptsProfiles("rootProfile1")).isTrue();
assertThat(this.applicationContext.getEnvironment().acceptsProfiles("wacProfile1")).isTrue();
}
/**

View File

@@ -58,13 +58,9 @@ import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.util.WebUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -779,10 +775,10 @@ public class DispatcherServletTests {
public void environmentOperations() {
DispatcherServlet servlet = new DispatcherServlet();
ConfigurableEnvironment defaultEnv = servlet.getEnvironment();
assertThat(defaultEnv, notNullValue());
assertThat(defaultEnv).isNotNull();
ConfigurableEnvironment env1 = new StandardServletEnvironment();
servlet.setEnvironment(env1); // should succeed
assertThat(servlet.getEnvironment(), sameInstance(env1));
assertThat(servlet.getEnvironment()).isSameAs(env1);
assertThatIllegalArgumentException().as("non-configurable Environment").isThrownBy(() ->
servlet.setEnvironment(new DummyEnvironment()));
class CustomServletEnvironment extends StandardServletEnvironment { }
@@ -793,7 +789,7 @@ public class DispatcherServletTests {
return new CustomServletEnvironment();
}
};
assertThat(custom.getEnvironment(), instanceOf(CustomServletEnvironment.class));
assertThat(custom.getEnvironment()).isInstanceOf(CustomServletEnvironment.class);
}
@Test
@@ -804,7 +800,7 @@ public class DispatcherServletTests {
servlet.setDispatchOptionsRequest(false);
servlet.service(request, response);
verify(response, never()).getHeader(anyString()); // SPR-10341
assertThat(response.getHeader("Allow"), equalTo("GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH"));
assertThat(response.getHeader("Allow")).isEqualTo("GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH");
}
@Test

View File

@@ -18,7 +18,6 @@ package org.springframework.web.servlet.config;
import java.util.List;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
@@ -50,7 +49,7 @@ import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyAdvice;
import org.springframework.web.servlet.mvc.method.annotation.ServletWebArgumentResolverAdapter;
import org.springframework.web.util.UrlPathHelper;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -90,11 +89,10 @@ public class AnnotationDrivenBeanDefinitionParserTests {
assertTrue(hm.useSuffixPatternMatch());
assertFalse(hm.useTrailingSlashMatch());
assertTrue(hm.useRegisteredSuffixPatternMatch());
assertThat(hm.getUrlPathHelper(), Matchers.instanceOf(TestPathHelper.class));
assertThat(hm.getPathMatcher(), Matchers.instanceOf(TestPathMatcher.class));
assertThat(hm.getUrlPathHelper()).isInstanceOf(TestPathHelper.class);
assertThat(hm.getPathMatcher()).isInstanceOf(TestPathMatcher.class);
List<String> fileExtensions = hm.getContentNegotiationManager().getAllFileExtensions();
assertThat(fileExtensions, Matchers.contains("xml"));
assertThat(fileExtensions, Matchers.hasSize(1));
assertThat(fileExtensions).containsExactly("xml");
}
@Test

View File

@@ -39,7 +39,6 @@ import com.fasterxml.jackson.databind.MapperFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import org.apache.tiles.definition.UnresolvingLocaleDefinitionsFactory;
import org.hamcrest.Matchers;
import org.joda.time.LocalDate;
import org.junit.Before;
import org.junit.Test;
@@ -141,10 +140,8 @@ import org.springframework.web.servlet.view.tiles3.TilesConfigurer;
import org.springframework.web.servlet.view.tiles3.TilesViewResolver;
import org.springframework.web.util.UrlPathHelper;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -379,8 +376,8 @@ public class MvcNamespaceTests {
List<Class<?>> interceptors = beans.values().stream()
.map(mappedInterceptor -> mappedInterceptor.getInterceptor().getClass())
.collect(Collectors.toList());
assertThat(interceptors, containsInAnyOrder(ConversionServiceExposingInterceptor.class,
ResourceUrlProviderExposingInterceptor.class));
assertThat(interceptors).contains(ConversionServiceExposingInterceptor.class,
ResourceUrlProviderExposingInterceptor.class);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/resources/foo.css");
@@ -427,21 +424,21 @@ public class MvcNamespaceTests {
assertNotNull(handler.getUrlPathHelper());
List<ResourceResolver> resolvers = handler.getResourceResolvers();
assertThat(resolvers, Matchers.hasSize(4));
assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
assertThat(resolvers.get(1), Matchers.instanceOf(VersionResourceResolver.class));
assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));
assertThat(resolvers).hasSize(4);
assertThat(resolvers.get(0)).isInstanceOf(CachingResourceResolver.class);
assertThat(resolvers.get(1)).isInstanceOf(VersionResourceResolver.class);
assertThat(resolvers.get(2)).isInstanceOf(WebJarsResourceResolver.class);
assertThat(resolvers.get(3)).isInstanceOf(PathResourceResolver.class);
CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
assertThat(cachingResolver.getCache()).isInstanceOf(ConcurrentMapCache.class);
assertEquals("test-resource-cache", cachingResolver.getCache().getName());
VersionResourceResolver versionResolver = (VersionResourceResolver) resolvers.get(1);
assertThat(versionResolver.getStrategyMap().get("/**/*.js"),
Matchers.instanceOf(FixedVersionStrategy.class));
assertThat(versionResolver.getStrategyMap().get("/**"),
Matchers.instanceOf(ContentVersionStrategy.class));
assertThat(versionResolver.getStrategyMap().get("/**/*.js"))
.isInstanceOf(FixedVersionStrategy.class);
assertThat(versionResolver.getStrategyMap().get("/**"))
.isInstanceOf(ContentVersionStrategy.class);
PathResourceResolver pathResolver = (PathResourceResolver) resolvers.get(3);
Map<Resource, Charset> locationCharsets = pathResolver.getLocationCharsets();
@@ -449,13 +446,13 @@ public class MvcNamespaceTests {
assertEquals(StandardCharsets.ISO_8859_1, locationCharsets.values().iterator().next());
List<ResourceTransformer> transformers = handler.getResourceTransformers();
assertThat(transformers, Matchers.hasSize(3));
assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
assertThat(transformers.get(1), Matchers.instanceOf(CssLinkResourceTransformer.class));
assertThat(transformers.get(2), Matchers.instanceOf(AppCacheManifestTransformer.class));
assertThat(transformers).hasSize(3);
assertThat(transformers.get(0)).isInstanceOf(CachingResourceTransformer.class);
assertThat(transformers.get(1)).isInstanceOf(CssLinkResourceTransformer.class);
assertThat(transformers.get(2)).isInstanceOf(AppCacheManifestTransformer.class);
CachingResourceTransformer cachingTransformer = (CachingResourceTransformer) transformers.get(0);
assertThat(cachingTransformer.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
assertThat(cachingTransformer.getCache()).isInstanceOf(ConcurrentMapCache.class);
assertEquals("test-resource-cache", cachingTransformer.getCache().getName());
}
@@ -470,26 +467,26 @@ public class MvcNamespaceTests {
ResourceHttpRequestHandler.class);
assertNotNull(handler);
assertThat(handler.getCacheControl().getHeaderValue(),
Matchers.equalTo(CacheControl.maxAge(1, TimeUnit.HOURS)
.sMaxAge(30, TimeUnit.MINUTES).cachePublic().getHeaderValue()));
assertThat(handler.getCacheControl().getHeaderValue())
.isEqualTo(CacheControl.maxAge(1, TimeUnit.HOURS)
.sMaxAge(30, TimeUnit.MINUTES).cachePublic().getHeaderValue());
List<ResourceResolver> resolvers = handler.getResourceResolvers();
assertThat(resolvers, Matchers.hasSize(3));
assertThat(resolvers.get(0), Matchers.instanceOf(VersionResourceResolver.class));
assertThat(resolvers.get(1), Matchers.instanceOf(EncodedResourceResolver.class));
assertThat(resolvers.get(2), Matchers.instanceOf(PathResourceResolver.class));
assertThat(resolvers).hasSize(3);
assertThat(resolvers.get(0)).isInstanceOf(VersionResourceResolver.class);
assertThat(resolvers.get(1)).isInstanceOf(EncodedResourceResolver.class);
assertThat(resolvers.get(2)).isInstanceOf(PathResourceResolver.class);
VersionResourceResolver versionResolver = (VersionResourceResolver) resolvers.get(0);
assertThat(versionResolver.getStrategyMap().get("/**/*.js"),
Matchers.instanceOf(FixedVersionStrategy.class));
assertThat(versionResolver.getStrategyMap().get("/**"),
Matchers.instanceOf(ContentVersionStrategy.class));
assertThat(versionResolver.getStrategyMap().get("/**/*.js"))
.isInstanceOf(FixedVersionStrategy.class);
assertThat(versionResolver.getStrategyMap().get("/**"))
.isInstanceOf(ContentVersionStrategy.class);
List<ResourceTransformer> transformers = handler.getResourceTransformers();
assertThat(transformers, Matchers.hasSize(2));
assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
assertThat(transformers.get(1), Matchers.instanceOf(AppCacheManifestTransformer.class));
assertThat(transformers).hasSize(2);
assertThat(transformers.get(0)).isInstanceOf(CachingResourceTransformer.class);
assertThat(transformers.get(1)).isInstanceOf(AppCacheManifestTransformer.class);
}
@Test
@@ -702,7 +699,7 @@ public class MvcNamespaceTests {
ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old");
assertNotNull(redirectViewController);
assertThat(redirectViewController.getView(), Matchers.instanceOf(RedirectView.class));
assertThat(redirectViewController.getView()).isInstanceOf(RedirectView.class);
ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad");
assertNotNull(statusViewController);
@@ -775,7 +772,7 @@ public class MvcNamespaceTests {
assertEquals(TilesViewResolver.class, resolvers.get(2).getClass());
resolver = resolvers.get(3);
assertThat(resolver, instanceOf(FreeMarkerViewResolver.class));
assertThat(resolver).isInstanceOf(FreeMarkerViewResolver.class);
accessor = new DirectFieldAccessor(resolver);
assertEquals("freemarker-", accessor.getPropertyValue("prefix"));
assertEquals(".freemarker", accessor.getPropertyValue("suffix"));
@@ -783,14 +780,14 @@ public class MvcNamespaceTests {
assertEquals(1024, accessor.getPropertyValue("cacheLimit"));
resolver = resolvers.get(4);
assertThat(resolver, instanceOf(GroovyMarkupViewResolver.class));
assertThat(resolver).isInstanceOf(GroovyMarkupViewResolver.class);
accessor = new DirectFieldAccessor(resolver);
assertEquals("", accessor.getPropertyValue("prefix"));
assertEquals(".tpl", accessor.getPropertyValue("suffix"));
assertEquals(1024, accessor.getPropertyValue("cacheLimit"));
resolver = resolvers.get(5);
assertThat(resolver, instanceOf(ScriptTemplateViewResolver.class));
assertThat(resolver).isInstanceOf(ScriptTemplateViewResolver.class);
accessor = new DirectFieldAccessor(resolver);
assertEquals("", accessor.getPropertyValue("prefix"));
assertEquals("", accessor.getPropertyValue("suffix"));

View File

@@ -21,7 +21,6 @@ import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -49,7 +48,7 @@ import org.springframework.web.servlet.resource.VersionResourceResolver;
import org.springframework.web.servlet.resource.WebJarsResourceResolver;
import org.springframework.web.util.UrlPathHelper;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -111,12 +110,11 @@ public class ResourceHandlerRegistryTests {
@Test
public void cacheControl() {
assertThat(getHandler("/resources/**").getCacheControl(),
Matchers.nullValue());
assertThat(getHandler("/resources/**").getCacheControl()).isNull();
this.registration.setCacheControl(CacheControl.noCache().cachePrivate());
assertThat(getHandler("/resources/**").getCacheControl().getHeaderValue(),
Matchers.equalTo(CacheControl.noCache().cachePrivate().getHeaderValue()));
assertThat(getHandler("/resources/**").getCacheControl().getHeaderValue())
.isEqualTo(CacheControl.noCache().cachePrivate().getHeaderValue());
}
@Test
@@ -141,18 +139,18 @@ public class ResourceHandlerRegistryTests {
ResourceHttpRequestHandler handler = getHandler("/resources/**");
List<ResourceResolver> resolvers = handler.getResourceResolvers();
assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
assertThat(resolvers).hasSize(4);
assertThat(resolvers.get(0)).isInstanceOf(CachingResourceResolver.class);
CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
assertThat(resolvers.get(1), Matchers.equalTo(mockResolver));
assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));
assertThat(cachingResolver.getCache()).isInstanceOf(ConcurrentMapCache.class);
assertThat(resolvers.get(1)).isEqualTo(mockResolver);
assertThat(resolvers.get(2)).isInstanceOf(WebJarsResourceResolver.class);
assertThat(resolvers.get(3)).isInstanceOf(PathResourceResolver.class);
List<ResourceTransformer> transformers = handler.getResourceTransformers();
assertThat(transformers, Matchers.hasSize(2));
assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
assertThat(transformers.get(1), Matchers.equalTo(mockTransformer));
assertThat(transformers).hasSize(2);
assertThat(transformers.get(0)).isInstanceOf(CachingResourceTransformer.class);
assertThat(transformers.get(1)).isEqualTo(mockTransformer);
}
@Test
@@ -161,12 +159,12 @@ public class ResourceHandlerRegistryTests {
ResourceHttpRequestHandler handler = getHandler("/resources/**");
List<ResourceResolver> resolvers = handler.getResourceResolvers();
assertThat(resolvers, Matchers.hasSize(2));
assertThat(resolvers.get(0), Matchers.instanceOf(WebJarsResourceResolver.class));
assertThat(resolvers.get(1), Matchers.instanceOf(PathResourceResolver.class));
assertThat(resolvers).hasSize(2);
assertThat(resolvers.get(0)).isInstanceOf(WebJarsResourceResolver.class);
assertThat(resolvers.get(1)).isInstanceOf(PathResourceResolver.class);
List<ResourceTransformer> transformers = handler.getResourceTransformers();
assertThat(transformers, Matchers.hasSize(0));
assertThat(transformers).isEmpty();
}
@Test
@@ -180,17 +178,17 @@ public class ResourceHandlerRegistryTests {
ResourceHttpRequestHandler handler = getHandler("/resources/**");
List<ResourceResolver> resolvers = handler.getResourceResolvers();
assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
assertThat(resolvers.get(1), Matchers.sameInstance(versionResolver));
assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));
assertThat(resolvers).hasSize(4);
assertThat(resolvers.get(0)).isInstanceOf(CachingResourceResolver.class);
assertThat(resolvers.get(1)).isSameAs(versionResolver);
assertThat(resolvers.get(2)).isInstanceOf(WebJarsResourceResolver.class);
assertThat(resolvers.get(3)).isInstanceOf(PathResourceResolver.class);
List<ResourceTransformer> transformers = handler.getResourceTransformers();
assertThat(transformers, Matchers.hasSize(3));
assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
assertThat(transformers.get(1), Matchers.instanceOf(CssLinkResourceTransformer.class));
assertThat(transformers.get(2), Matchers.instanceOf(AppCacheManifestTransformer.class));
assertThat(transformers).hasSize(3);
assertThat(transformers.get(0)).isInstanceOf(CachingResourceTransformer.class);
assertThat(transformers.get(1)).isInstanceOf(CssLinkResourceTransformer.class);
assertThat(transformers.get(2)).isInstanceOf(AppCacheManifestTransformer.class);
}
@Test
@@ -215,17 +213,17 @@ public class ResourceHandlerRegistryTests {
ResourceHttpRequestHandler handler = getHandler("/resources/**");
List<ResourceResolver> resolvers = handler.getResourceResolvers();
assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
assertThat(resolvers.get(0), Matchers.sameInstance(cachingResolver));
assertThat(resolvers.get(1), Matchers.sameInstance(versionResolver));
assertThat(resolvers.get(2), Matchers.sameInstance(webjarsResolver));
assertThat(resolvers.get(3), Matchers.sameInstance(pathResourceResolver));
assertThat(resolvers).hasSize(4);
assertThat(resolvers.get(0)).isSameAs(cachingResolver);
assertThat(resolvers.get(1)).isSameAs(versionResolver);
assertThat(resolvers.get(2)).isSameAs(webjarsResolver);
assertThat(resolvers.get(3)).isSameAs(pathResourceResolver);
List<ResourceTransformer> transformers = handler.getResourceTransformers();
assertThat(transformers, Matchers.hasSize(3));
assertThat(transformers.get(0), Matchers.sameInstance(cachingTransformer));
assertThat(transformers.get(1), Matchers.sameInstance(appCacheTransformer));
assertThat(transformers.get(2), Matchers.sameInstance(cssLinkTransformer));
assertThat(transformers).hasSize(3);
assertThat(transformers.get(0)).isSameAs(cachingTransformer);
assertThat(transformers.get(1)).isSameAs(appCacheTransformer);
assertThat(transformers.get(2)).isSameAs(cssLinkTransformer);
}
@Test

View File

@@ -21,7 +21,6 @@ import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -34,7 +33,8 @@ import org.springframework.web.servlet.HandlerExecutionChain;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.support.WebContentGenerator;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for
@@ -66,8 +66,8 @@ public class HandlerMappingTests {
this.handlerMapping.setInterceptors(mappedInterceptor1, i2, mappedInterceptor3, i4);
this.handlerMapping.setApplicationContext(this.context);
HandlerExecutionChain chain = this.handlerMapping.getHandlerExecutionChain(new SimpleHandler(), this.request);
assertThat(chain.getInterceptors(), Matchers.arrayContaining(
mappedInterceptor1.getInterceptor(), i2, mappedInterceptor3.getInterceptor(), i4));
assertThat(chain.getInterceptors()).contains(
mappedInterceptor1.getInterceptor(), i2, mappedInterceptor3.getInterceptor(), i4);
}
class TestHandlerMapping extends AbstractHandlerMapping {

View File

@@ -18,15 +18,15 @@ package org.springframework.web.servlet.mvc;
import java.util.Properties;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
/**
* @author Rick Evans
@@ -47,7 +47,7 @@ public class WebContentInterceptorTests {
interceptor.preHandle(request, response, null);
Iterable<String> cacheControlHeaders = response.getHeaders("Cache-Control");
assertThat(cacheControlHeaders, Matchers.hasItem("max-age=10"));
assertThat(cacheControlHeaders).contains("max-age=10");
}
@Test
@@ -64,14 +64,14 @@ public class WebContentInterceptorTests {
interceptor.preHandle(request, response, null);
Iterable<String> cacheControlHeaders = response.getHeaders("Cache-Control");
assertThat(cacheControlHeaders, Matchers.emptyIterable());
assertThat(cacheControlHeaders).isEmpty();
// request.setRequestURI("http://localhost:7070/example/bingo.html");
request.setRequestURI("example/bingo.html");
interceptor.preHandle(request, response, null);
cacheControlHeaders = response.getHeaders("Cache-Control");
assertThat(cacheControlHeaders, Matchers.hasItem("max-age=10"));
assertThat(cacheControlHeaders).contains("max-age=10");
}
@Test
@@ -82,7 +82,7 @@ public class WebContentInterceptorTests {
interceptor.preHandle(request, response, null);
Iterable<String> cacheControlHeaders = response.getHeaders("Cache-Control");
assertThat(cacheControlHeaders, Matchers.contains("no-store"));
assertThat(cacheControlHeaders).contains("no-store");
}
@Test
@@ -93,9 +93,9 @@ public class WebContentInterceptorTests {
interceptor.preHandle(request, response, null);
Iterable<String> expiresHeaders = response.getHeaders("Expires");
assertThat(expiresHeaders, Matchers.emptyIterable());
assertThat(expiresHeaders).isEmpty();
Iterable<String> cacheControlHeaders = response.getHeaders("Cache-Control");
assertThat(cacheControlHeaders, Matchers.emptyIterable());
assertThat(cacheControlHeaders).isEmpty();
}
// SPR-13252, SPR-14053
@@ -108,8 +108,8 @@ public class WebContentInterceptorTests {
interceptor.preHandle(request, response, null);
assertThat(response.getHeader("Pragma"), is(""));
assertThat(response.getHeader("Expires"), is(""));
assertThat(response.getHeader("Pragma")).isEqualTo("");
assertThat(response.getHeader("Expires")).isEqualTo("");
}
// SPR-13252, SPR-14053
@@ -124,8 +124,8 @@ public class WebContentInterceptorTests {
interceptor.preHandle(request, response, null);
assertThat(response.getHeader("Pragma"), is(""));
assertThat(response.getHeader("Expires"), is(""));
assertThat(response.getHeader("Pragma")).isEqualTo("");
assertThat(response.getHeader("Expires")).isEqualTo("");
}
@SuppressWarnings("deprecation")
@@ -144,11 +144,11 @@ public class WebContentInterceptorTests {
interceptor.preHandle(request, response, null);
Iterable<String> expiresHeaders = response.getHeaders("Expires");
assertThat(expiresHeaders, Matchers.iterableWithSize(1));
assertThat(expiresHeaders).hasSize(1);
Iterable<String> cacheControlHeaders = response.getHeaders("Cache-Control");
assertThat(cacheControlHeaders, Matchers.contains("no-cache", "no-store"));
assertThat(cacheControlHeaders).containsExactly("no-cache", "no-store");
Iterable<String> pragmaHeaders = response.getHeaders("Pragma");
assertThat(pragmaHeaders, Matchers.contains("no-cache"));
assertThat(pragmaHeaders).containsExactly("no-cache");
// request.setRequestURI("https://example.org/page.cache.html");
request = new MockHttpServletRequest("GET", "foo/page.cache.html");
@@ -156,9 +156,9 @@ public class WebContentInterceptorTests {
interceptor.preHandle(request, response, null);
expiresHeaders = response.getHeaders("Expires");
assertThat(expiresHeaders, Matchers.iterableWithSize(1));
assertThat(expiresHeaders).hasSize(1);
cacheControlHeaders = response.getHeaders("Cache-Control");
assertThat(cacheControlHeaders, Matchers.contains("max-age=10, must-revalidate"));
assertThat(cacheControlHeaders).containsExactly("max-age=10, must-revalidate");
}
@Test

View File

@@ -29,7 +29,6 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -58,8 +57,8 @@ import org.springframework.web.method.support.ModelAndViewContainer;
import static java.time.Instant.ofEpochMilli;
import static java.time.format.DateTimeFormatter.RFC_1123_DATE_TIME;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -576,7 +575,7 @@ public class HttpEntityMethodProcessorMockTests {
then(resourceMessageConverter).should(times(1)).write(
any(InputStreamResource.class), eq(APPLICATION_OCTET_STREAM), any(HttpOutputMessage.class));
assertEquals(200, servletResponse.getStatus());
assertThat(servletResponse.getHeader(HttpHeaders.ACCEPT_RANGES), Matchers.isEmptyOrNullString());
assertThat(servletResponse.getHeader(HttpHeaders.ACCEPT_RANGES)).isNull();
}
@Test //SPR-16921

View File

@@ -26,7 +26,6 @@ import java.util.List;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import org.hamcrest.Matchers;
import org.joda.time.DateTime;
import org.joda.time.format.ISODateTimeFormat;
import org.junit.After;
@@ -62,13 +61,8 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertEquals;
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromController;
import static org.springframework.web.servlet.mvc.method.annotation.MvcUriComponentsBuilder.fromMappingName;
@@ -104,32 +98,32 @@ public class MvcUriComponentsBuilderTests {
@Test
public void fromControllerPlain() {
UriComponents uriComponents = fromController(PersonControllerImpl.class).build();
assertThat(uriComponents.toUriString(), Matchers.endsWith("/people"));
assertThat(uriComponents.toUriString()).endsWith("/people");
}
@Test
public void fromControllerUriTemplate() {
UriComponents uriComponents = fromController(PersonsAddressesController.class).buildAndExpand(15);
assertThat(uriComponents.toUriString(), endsWith("/people/15/addresses"));
assertThat(uriComponents.toUriString()).endsWith("/people/15/addresses");
}
@Test
public void fromControllerSubResource() {
UriComponents uriComponents = fromController(PersonControllerImpl.class).pathSegment("something").build();
assertThat(uriComponents.toUriString(), endsWith("/people/something"));
assertThat(uriComponents.toUriString()).endsWith("/people/something");
}
@Test
public void fromControllerTwoTypeLevelMappings() {
UriComponents uriComponents = fromController(InvalidController.class).build();
assertThat(uriComponents.toUriString(), is("http://localhost/persons"));
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/persons");
}
@Test
public void fromControllerNotMapped() {
UriComponents uriComponents = fromController(UnmappedController.class).build();
assertThat(uriComponents.toUriString(), is("http://localhost/"));
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/");
}
@Test
@@ -158,7 +152,7 @@ public class MvcUriComponentsBuilderTests {
adaptRequestFromForwardedHeaders();
UriComponents uriComponents = fromController(PersonControllerImpl.class).build();
assertThat(uriComponents.toUriString(), startsWith("https://somethingDifferent"));
assertThat(uriComponents.toUriString()).startsWith("https://somethingDifferent");
}
@Test
@@ -168,7 +162,7 @@ public class MvcUriComponentsBuilderTests {
adaptRequestFromForwardedHeaders();
UriComponents uriComponents = fromController(PersonControllerImpl.class).build();
assertThat(uriComponents.toUriString(), startsWith("https://foobar:8088"));
assertThat(uriComponents.toUriString()).startsWith("https://foobar:8088");
}
@Test
@@ -178,7 +172,7 @@ public class MvcUriComponentsBuilderTests {
adaptRequestFromForwardedHeaders();
UriComponents uriComponents = fromController(PersonControllerImpl.class).build();
assertThat(uriComponents.toUriString(), startsWith("https://barfoo:8888"));
assertThat(uriComponents.toUriString()).startsWith("https://barfoo:8888");
}
// SPR-16668
@@ -194,7 +188,7 @@ public class MvcUriComponentsBuilderTests {
UriComponents uriComponents = fromMethodName(ControllerWithMethods.class,
"methodWithPathVariable", "1").build();
assertThat(uriComponents.toUriString(), is("http://localhost/something/1/foo"));
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/something/1/foo");
}
@Test
@@ -203,7 +197,7 @@ public class MvcUriComponentsBuilderTests {
UriComponents uriComponents = fromMethodName(
PersonsAddressesController.class, "getAddressesForCountry", "DE").buildAndExpand("1");
assertThat(uriComponents.toUriString(), is("http://localhost/myapp/people/1/addresses/DE"));
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/myapp/people/1/addresses/DE");
}
@Test
@@ -212,7 +206,7 @@ public class MvcUriComponentsBuilderTests {
UriComponents uriComponents = fromMethodName(
ControllerWithMethods.class, "methodWithTwoPathVariables", 1, now).build();
assertThat(uriComponents.getPath(), is("/something/1/foo/" + ISODateTimeFormat.date().print(now)));
assertThat(uriComponents.getPath()).isEqualTo("/something/1/foo/" + ISODateTimeFormat.date().print(now));
}
@Test
@@ -220,31 +214,31 @@ public class MvcUriComponentsBuilderTests {
UriComponents uriComponents = fromMethodName(
ControllerWithMethods.class, "methodForNextPage", "1", 10, 5).build();
assertThat(uriComponents.getPath(), is("/something/1/foo"));
assertThat(uriComponents.getPath()).isEqualTo("/something/1/foo");
MultiValueMap<String, String> queryParams = uriComponents.getQueryParams();
assertThat(queryParams.get("limit"), contains("5"));
assertThat(queryParams.get("offset"), contains("10"));
assertThat(queryParams.get("limit")).contains("5");
assertThat(queryParams.get("offset")).contains("10");
}
@Test // SPR-12977
public void fromMethodNameWithBridgedMethod() {
UriComponents uriComponents = fromMethodName(PersonCrudController.class, "get", (long) 42).build();
assertThat(uriComponents.toUriString(), is("http://localhost/42"));
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/42");
}
@Test // SPR-11391
public void fromMethodNameTypeLevelPathVariableWithoutArgumentValue() {
UriComponents uriComponents = fromMethodName(UserContactController.class, "showCreate", 123).build();
assertThat(uriComponents.getPath(), is("/user/123/contacts/create"));
assertThat(uriComponents.getPath()).isEqualTo("/user/123/contacts/create");
}
@Test
public void fromMethodNameNotMapped() {
UriComponents uriComponents = fromMethodName(UnmappedController.class, "unmappedMethod").build();
assertThat(uriComponents.toUriString(), is("http://localhost/"));
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/");
}
@Test
@@ -273,7 +267,7 @@ public class MvcUriComponentsBuilderTests {
UriComponents uriComponents = fromMethodName(ControllerWithMethods.class,
"methodWithOptionalParam", new Object[] {null}).build();
assertThat(uriComponents.toUriString(), is("http://localhost/something/optional-param"));
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/something/optional-param");
}
@Test // gh-22656
@@ -281,31 +275,31 @@ public class MvcUriComponentsBuilderTests {
UriComponents uriComponents = fromMethodName(ControllerWithMethods.class,
"methodWithOptionalNamedParam", Optional.of("foo")).build();
assertThat(uriComponents.toUriString(),
is("http://localhost/something/optional-param-with-name?search=foo"));
assertThat(uriComponents.toUriString())
.isEqualTo("http://localhost/something/optional-param-with-name?search=foo");
}
@Test
public void fromMethodNameWithMetaAnnotation() {
UriComponents uriComponents = fromMethodName(MetaAnnotationController.class, "handleInput").build();
assertThat(uriComponents.toUriString(), is("http://localhost/input"));
assertThat(uriComponents.toUriString()).isEqualTo("http://localhost/input");
}
@Test
public void fromMethodCallPlain() {
UriComponents uriComponents = fromMethodCall(on(ControllerWithMethods.class).myMethod(null)).build();
assertThat(uriComponents.toUriString(), startsWith("http://localhost"));
assertThat(uriComponents.toUriString(), endsWith("/something/else"));
assertThat(uriComponents.toUriString()).startsWith("http://localhost");
assertThat(uriComponents.toUriString()).endsWith("/something/else");
}
@Test
public void fromMethodCallOnSubclass() {
UriComponents uriComponents = fromMethodCall(on(ExtendedController.class).myMethod(null)).build();
assertThat(uriComponents.toUriString(), startsWith("http://localhost"));
assertThat(uriComponents.toUriString(), endsWith("/extended/else"));
assertThat(uriComponents.toUriString()).startsWith("http://localhost");
assertThat(uriComponents.toUriString()).endsWith("/extended/else");
}
@Test
@@ -313,7 +307,7 @@ public class MvcUriComponentsBuilderTests {
UriComponents uriComponents = fromMethodCall(
on(PersonsAddressesController.class).getAddressesForCountry("DE")).buildAndExpand(15);
assertThat(uriComponents.toUriString(), endsWith("/people/15/addresses/DE"));
assertThat(uriComponents.toUriString()).endsWith("/people/15/addresses/DE");
}
@Test
@@ -321,8 +315,8 @@ public class MvcUriComponentsBuilderTests {
UriComponents uriComponents = fromMethodCall(
on(ControllerWithMethods.class).methodWithPathVariable("1")).build();
assertThat(uriComponents.toUriString(), startsWith("http://localhost"));
assertThat(uriComponents.toUriString(), endsWith("/something/1/foo"));
assertThat(uriComponents.toUriString()).startsWith("http://localhost");
assertThat(uriComponents.toUriString()).endsWith("/something/1/foo");
}
@Test
@@ -330,11 +324,11 @@ public class MvcUriComponentsBuilderTests {
UriComponents uriComponents = fromMethodCall(
on(ControllerWithMethods.class).methodForNextPage("1", 10, 5)).build();
assertThat(uriComponents.getPath(), is("/something/1/foo"));
assertThat(uriComponents.getPath()).isEqualTo("/something/1/foo");
MultiValueMap<String, String> queryParams = uriComponents.getQueryParams();
assertThat(queryParams.get("limit"), contains("5"));
assertThat(queryParams.get("offset"), contains("10"));
assertThat(queryParams.get("limit")).contains("5");
assertThat(queryParams.get("offset")).contains("10");
}
@Test
@@ -342,11 +336,11 @@ public class MvcUriComponentsBuilderTests {
UriComponents uriComponents = fromMethodCall(
on(ControllerWithMethods.class).methodWithMultiValueRequestParams("1", Arrays.asList(3, 7), 5)).build();
assertThat(uriComponents.getPath(), is("/something/1/foo"));
assertThat(uriComponents.getPath()).isEqualTo("/something/1/foo");
MultiValueMap<String, String> queryParams = uriComponents.getQueryParams();
assertThat(queryParams.get("limit"), contains("5"));
assertThat(queryParams.get("items"), containsInAnyOrder("3", "7"));
assertThat(queryParams.get("limit")).contains("5");
assertThat(queryParams.get("items")).containsExactly("3", "7");
}
@Test

View File

@@ -34,7 +34,6 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -85,7 +84,7 @@ import org.springframework.web.servlet.HandlerMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.util.UriComponentsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -373,7 +372,7 @@ public class RequestMappingHandlerAdapterIntegrationTests {
assertNull(mav);
assertEquals(HttpStatus.OK.value(), response.getStatus());
assertEquals("Handled requestBody=[Hello Server]", new String(response.getContentAsByteArray(), "UTF-8"));
assertThat(response.getHeaderValues("Cache-Control"), Matchers.contains("max-age=3600"));
assertThat(response.getHeaderValues("Cache-Control")).containsExactly("max-age=3600");
}
@Test

View File

@@ -29,8 +29,7 @@ import org.springframework.core.io.Resource;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.util.FileCopyUtils;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
/**
@@ -104,18 +103,17 @@ public class AppCacheManifestTransformerTests {
byte[] bytes = FileCopyUtils.copyToByteArray(actual.getInputStream());
String content = new String(bytes, "UTF-8");
assertThat("should rewrite resource links", content,
containsString("/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css"));
assertThat("should rewrite resource links", content,
containsString("/static/bar-11e16cf79faee7ac698c805cf28248d2.css"));
assertThat("should rewrite resource links", content,
containsString("/static/js/bar-bd508c62235b832d960298ca6c0b7645.js"));
assertThat(content).as("rewrite resource links")
.contains("/static/foo-e36d2e05253c6c7085a91522ce43a0b4.css")
.contains("/static/bar-11e16cf79faee7ac698c805cf28248d2.css")
.contains("/static/js/bar-bd508c62235b832d960298ca6c0b7645.js");
assertThat("should not rewrite external resources", content, containsString("//example.org/style.css"));
assertThat("should not rewrite external resources", content, containsString("http://example.org/image.png"));
assertThat(content).as("not rewrite external resources")
.contains("//example.org/style.css")
.contains("http://example.org/image.png");
assertThat("should generate fingerprint", content,
containsString("# Hash: 4bf0338bcbeb0a5b3a4ec9ed8864107d"));
assertThat(content).as("generate fingerprint")
.contains("# Hash: 4bf0338bcbeb0a5b3a4ec9ed8864107d");
}
private Resource getResource(String filePath) {

View File

@@ -23,7 +23,6 @@ import java.util.Collections;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
@@ -42,9 +41,9 @@ import org.springframework.web.accept.ContentNegotiationManager;
import org.springframework.web.accept.ContentNegotiationManagerFactoryBean;
import org.springframework.web.servlet.HandlerMapping;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -187,7 +186,7 @@ public class ResourceHttpRequestHandlerTests {
this.handler.handleRequest(this.request, this.response);
assertEquals("no-cache", this.response.getHeader("Pragma"));
assertThat(this.response.getHeaderValues("Cache-Control"), Matchers.iterableWithSize(1));
assertThat(this.response.getHeaderValues("Cache-Control")).hasSize(1);
assertEquals("no-cache", this.response.getHeader("Cache-Control"));
assertTrue(this.response.getDateHeader("Expires") <= System.currentTimeMillis());
assertTrue(this.response.containsHeader("Last-Modified"));

View File

@@ -21,7 +21,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
@@ -34,7 +33,7 @@ import org.springframework.mock.web.test.MockServletContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
@@ -148,7 +147,7 @@ public class ResourceUrlProviderTests {
context.refresh();
ResourceUrlProvider urlProviderBean = context.getBean(ResourceUrlProvider.class);
assertThat(urlProviderBean.getHandlerMap(), Matchers.hasKey("/resources/**"));
assertThat(urlProviderBean.getHandlerMap()).containsKey("/resources/**");
assertFalse(urlProviderBean.isAutodetect());
}

View File

@@ -21,8 +21,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
@@ -30,9 +28,7 @@ import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.mock.web.test.MockHttpServletRequest;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.BDDMockito.given;
@@ -158,7 +154,7 @@ public class VersionResourceResolverTests {
Resource actual = this.resolver.resolveResourceInternal(request, versionFile, this.locations, this.chain);
assertEquals(expected.getFilename(), actual.getFilename());
verify(this.versionStrategy, times(1)).getResourceVersion(expected);
assertThat(actual, instanceOf(HttpResource.class));
assertThat(actual).isInstanceOf(HttpResource.class);
assertEquals("\"" + version + "\"", ((HttpResource)actual).getResponseHeaders().getETag());
}
@@ -183,19 +179,18 @@ public class VersionResourceResolverTests {
this.resolver.addFixedVersionStrategy("fixedversion", "/js/**", "/css/**", "/fixedversion/css/**");
Matcher<VersionStrategy> matcher = Matchers.instanceOf(FixedVersionStrategy.class);
assertThat(this.resolver.getStrategyMap().size(), is(4));
assertThat(this.resolver.getStrategyForPath("js/something.js"), matcher);
assertThat(this.resolver.getStrategyForPath("fixedversion/js/something.js"), matcher);
assertThat(this.resolver.getStrategyForPath("css/something.css"), matcher);
assertThat(this.resolver.getStrategyForPath("fixedversion/css/something.css"), matcher);
assertThat(this.resolver.getStrategyMap()).hasSize(4);
assertThat(this.resolver.getStrategyForPath("js/something.js")).isInstanceOf(FixedVersionStrategy.class);
assertThat(this.resolver.getStrategyForPath("fixedversion/js/something.js")).isInstanceOf(FixedVersionStrategy.class);
assertThat(this.resolver.getStrategyForPath("css/something.css")).isInstanceOf(FixedVersionStrategy.class);
assertThat(this.resolver.getStrategyForPath("fixedversion/css/something.css")).isInstanceOf(FixedVersionStrategy.class);
}
@Test // SPR-15372
public void resolveUrlPathNoVersionStrategy() throws Exception {
given(this.chain.resolveUrlPath("/foo.css", this.locations)).willReturn("/foo.css");
String resolved = this.resolver.resolveUrlPathInternal("/foo.css", this.locations, this.chain);
assertThat(resolved, is("/foo.css"));
assertThat(resolved).isEqualTo("/foo.css");
}

View File

@@ -30,8 +30,7 @@ import org.junit.Test;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockPageContext;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -55,7 +54,7 @@ public class UrlTagTests extends AbstractTagTests {
@Test
public void paramSupport() {
assertThat(tag, instanceOf(ParamAware.class));
assertThat(tag).isInstanceOf(ParamAware.class);
}
@Test

View File

@@ -32,9 +32,8 @@ import org.springframework.web.context.support.ServletContextResource;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.servlet.View;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
@@ -88,7 +87,7 @@ public class ResourceBundleViewResolverTests {
@Test
public void debugViewEnglish() throws Exception {
View v = rb.resolveViewName("debugView", Locale.ENGLISH);
assertThat(v, instanceOf(InternalResourceView.class));
assertThat(v).isInstanceOf(InternalResourceView.class);
InternalResourceView jv = (InternalResourceView) v;
assertEquals("debugView must have correct URL", "jsp/debug/debug.jsp", jv.getUrl());
@@ -103,7 +102,7 @@ public class ResourceBundleViewResolverTests {
@Test
public void debugViewFrench() throws Exception {
View v = rb.resolveViewName("debugView", Locale.FRENCH);
assertThat(v, instanceOf(InternalResourceView.class));
assertThat(v).isInstanceOf(InternalResourceView.class);
InternalResourceView jv = (InternalResourceView) v;
assertEquals("French debugView must have correct URL", "jsp/debug/deboug.jsp", jv.getUrl());
assertEquals("Correct overridden (XML) content type", "text/xml;charset=ISO-8859-1", jv.getContentType());
@@ -119,7 +118,7 @@ public class ResourceBundleViewResolverTests {
rb.setApplicationContext(wac);
View v = rb.resolveViewName("debugView", Locale.FRENCH);
assertThat(v, instanceOf(InternalResourceView.class));
assertThat(v).isInstanceOf(InternalResourceView.class);
InternalResourceView jv = (InternalResourceView) v;
assertEquals("French debugView must have correct URL", "jsp/debug/deboug.jsp", jv.getUrl());
assertEquals("Correct overridden (XML) content type", "text/xml;charset=ISO-8859-1", jv.getContentType());

View File

@@ -27,12 +27,12 @@ import com.rometools.rome.feed.atom.Content;
import com.rometools.rome.feed.atom.Entry;
import com.rometools.rome.feed.atom.Feed;
import org.junit.Test;
import org.xmlunit.matchers.CompareMatcher;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.tests.XmlContent;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
/**
@@ -56,12 +56,9 @@ public class AtomFeedViewTests {
String expected = "<feed xmlns=\"http://www.w3.org/2005/Atom\">" + "<title>Test Feed</title>" +
"<entry><title>2</title><summary>This is entry 2</summary></entry>" +
"<entry><title>1</title><summary>This is entry 1</summary></entry>" + "</feed>";
assertThat(response.getContentAsString(), isSimilarTo(expected));
assertThat(XmlContent.of(response.getContentAsString())).isSimilarToIgnoringWhitespace(expected);
}
private static CompareMatcher isSimilarTo(String content) {
return CompareMatcher.isSimilarTo(content).ignoreWhitespace();
}
private static class MyAtomFeedView extends AbstractAtomFeedView {

View File

@@ -30,10 +30,10 @@ import org.junit.Test;
import org.springframework.mock.web.test.MockHttpServletRequest;
import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.tests.XmlContent;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.xmlunit.matchers.CompareMatcher.isSimilarTo;
/**
* @author Arjen Poutsma
@@ -61,7 +61,7 @@ public class RssFeedViewTests {
"<item><title>2</title><description>This is entry 2</description></item>" +
"<item><title>1</title><description>This is entry 1</description></item>" +
"</channel></rss>";
assertThat(response.getContentAsString(), isSimilarTo(expected).ignoreWhitespace());
assertThat(XmlContent.of(response.getContentAsString())).isSimilarToIgnoringWhitespace(expected);
}

View File

@@ -34,9 +34,8 @@ import org.springframework.ui.freemarker.FreeMarkerConfigurationFactoryBean;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;
import org.springframework.ui.freemarker.SpringTemplateLoader;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIOException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -88,7 +87,7 @@ public class FreeMarkerConfigurerTests {
}
});
fcfb.afterPropertiesSet();
assertThat(fcfb.getObject(), instanceOf(Configuration.class));
assertThat(fcfb.getObject()).isInstanceOf(Configuration.class);
Configuration fc = fcfb.getObject();
Template ft = fc.getTemplate("test");
assertEquals("test", FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap()));

View File

@@ -18,21 +18,19 @@ package org.springframework.web.servlet.view.groovy;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Arrays;
import java.util.Locale;
import groovy.text.TemplateEngine;
import groovy.text.markup.MarkupTemplateEngine;
import groovy.text.markup.TemplateConfiguration;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.StaticApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIOException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -112,19 +110,19 @@ public class GroovyMarkupConfigurerTests {
ClassLoader classLoader = this.configurer.createTemplateClassLoader();
assertNotNull(classLoader);
URLClassLoader urlClassLoader = (URLClassLoader) classLoader;
assertThat(Arrays.asList(urlClassLoader.getURLs()), Matchers.hasSize(1));
assertThat(Arrays.asList(urlClassLoader.getURLs()).get(0).toString(),
Matchers.endsWith("org/springframework/web/servlet/view/groovy/"));
assertThat(urlClassLoader.getURLs()).hasSize(1);
assertThat(urlClassLoader.getURLs()[0].toString())
.endsWith("org/springframework/web/servlet/view/groovy/");
this.configurer.setResourceLoaderPath(RESOURCE_LOADER_PATH + ",classpath:org/springframework/web/servlet/view/");
classLoader = this.configurer.createTemplateClassLoader();
assertNotNull(classLoader);
urlClassLoader = (URLClassLoader) classLoader;
assertThat(Arrays.asList(urlClassLoader.getURLs()), Matchers.hasSize(2));
assertThat(Arrays.asList(urlClassLoader.getURLs()).get(0).toString(),
Matchers.endsWith("org/springframework/web/servlet/view/groovy/"));
assertThat(Arrays.asList(urlClassLoader.getURLs()).get(1).toString(),
Matchers.endsWith("org/springframework/web/servlet/view/"));
assertThat(urlClassLoader.getURLs()).hasSize(2);
assertThat(urlClassLoader.getURLs()[0].toString())
.endsWith("org/springframework/web/servlet/view/groovy/");
assertThat(urlClassLoader.getURLs()[1].toString())
.endsWith("org/springframework/web/servlet/view/");
}
private class TestTemplateEngine extends MarkupTemplateEngine {
@@ -145,7 +143,7 @@ public class GroovyMarkupConfigurerTests {
LocaleContextHolder.setLocale(Locale.GERMANY);
URL url = this.configurer.resolveTemplate(getClass().getClassLoader(), TEMPLATE_PREFIX + "i18n.tpl");
assertNotNull(url);
assertThat(url.getPath(), Matchers.containsString("i18n_de_DE.tpl"));
assertThat(url.getPath()).contains("i18n_de_DE.tpl");
}
@Test
@@ -153,7 +151,7 @@ public class GroovyMarkupConfigurerTests {
LocaleContextHolder.setLocale(Locale.FRANCE);
URL url = this.configurer.resolveTemplate(getClass().getClassLoader(), TEMPLATE_PREFIX + "i18n.tpl");
assertNotNull(url);
assertThat(url.getPath(), Matchers.containsString("i18n_fr.tpl"));
assertThat(url.getPath()).contains("i18n_fr.tpl");
}
@Test
@@ -161,7 +159,7 @@ public class GroovyMarkupConfigurerTests {
LocaleContextHolder.setLocale(Locale.US);
URL url = this.configurer.resolveTemplate(getClass().getClassLoader(), TEMPLATE_PREFIX + "i18n.tpl");
assertNotNull(url);
assertThat(url.getPath(), Matchers.containsString("i18n.tpl"));
assertThat(url.getPath()).contains("i18n.tpl");
}
@Test

View File

@@ -26,7 +26,6 @@ import groovy.text.Template;
import groovy.text.TemplateEngine;
import groovy.text.markup.MarkupTemplateEngine;
import groovy.text.markup.TemplateConfiguration;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
@@ -41,8 +40,8 @@ import org.springframework.mock.web.test.MockHttpServletResponse;
import org.springframework.mock.web.test.MockServletContext;
import org.springframework.web.context.WebApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -135,7 +134,7 @@ public class GroovyMarkupViewTests {
Map<String, Object> model = new HashMap<>();
model.put("name", "Spring");
MockHttpServletResponse response = renderViewWithModel("test.tpl", model, Locale.US);
assertThat(response.getContentAsString(), Matchers.containsString("<h1>Hello Spring</h1>"));
assertThat(response.getContentAsString()).contains("<h1>Hello Spring</h1>");
}
@Test

View File

@@ -52,9 +52,7 @@ import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.servlet.View;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -322,8 +320,8 @@ public class MappingJackson2JsonViewTests {
String content = response.getContentAsString();
assertTrue(content.length() > 0);
assertEquals(content.length(), response.getContentLength());
assertThat(content, containsString("\"property1\":\"value\""));
assertThat(content, not(containsString("\"property2\":\"value\"")));
assertThat(content).contains("\"property1\":\"value\"");
assertThat(content).doesNotContain("\"property2\":\"value\"");
assertFalse(content.contains(FilterProvider.class.getName()));
}