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

@@ -36,10 +36,9 @@ import org.springframework.tests.aop.interceptor.NopInterceptor;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
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.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
@@ -294,7 +293,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
as.addAdvice(new NopInterceptor());
cglib = new CglibAopProxy(as);
assertThat(cglib.getProxy(), instanceOf(ITestBean.class));
assertThat(cglib.getProxy()).isInstanceOf(ITestBean.class);
}
@Test

View File

@@ -22,8 +22,8 @@ import org.springframework.aop.interceptor.DebugInterceptor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration test for Objenesis proxy creation.
@@ -41,8 +41,8 @@ public class ObjenesisProxyTests {
bean.method();
DebugInterceptor interceptor = context.getBean(DebugInterceptor.class);
assertThat(interceptor.getCount(), is(1L));
assertThat(bean.getDependency().getValue(), is(1));
assertThat(interceptor.getCount()).isEqualTo(1L);
assertThat(bean.getDependency().getValue()).isEqualTo(1);
}
}

View File

@@ -63,9 +63,6 @@ import org.springframework.util.SerializationTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIOException;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -347,8 +344,8 @@ public class ProxyFactoryBeanTests {
*/
@Test
public void testCanAddAndRemoveAspectInterfacesOnPrototype() {
assertThat("Shouldn't implement TimeStamped before manipulation",
factory.getBean("test2"), not(instanceOf(TimeStamped.class)));
assertThat(factory.getBean("test2")).as("Shouldn't implement TimeStamped before manipulation")
.isNotInstanceOf(TimeStamped.class);
ProxyFactoryBean config = (ProxyFactoryBean) factory.getBean("&test2");
long time = 666L;
@@ -369,8 +366,8 @@ public class ProxyFactoryBeanTests {
// Check no change on existing object reference
assertTrue(ts.getTimeStamp() == time);
assertThat("Should no longer implement TimeStamped",
factory.getBean("test2"), not(instanceOf(TimeStamped.class)));
assertThat(factory.getBean("test2")).as("Should no longer implement TimeStamped")
.isNotInstanceOf(TimeStamped.class);
// Now check non-effect of removing interceptor that isn't there
config.removeAdvice(new DebugInterceptor());

View File

@@ -69,8 +69,6 @@ import org.springframework.util.StopWatch;
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.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -626,7 +624,7 @@ public class XmlBeanFactoryTests {
public void testFactoryReferenceWithDoublePrefix() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(FACTORY_CIRCLE_CONTEXT);
assertThat(xbf.getBean("&&singletonFactory"), instanceOf(DummyFactory.class));
assertThat(xbf.getBean("&&singletonFactory")).isInstanceOf(DummyFactory.class);
}
@Test

View File

@@ -24,8 +24,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -207,7 +206,7 @@ public abstract class AbstractCacheTests<T extends Cache> {
latch.await();
assertEquals(10, results.size());
results.forEach(r -> assertThat(r, is(1))); // Only one method got invoked
results.forEach(r -> assertThat(r).isEqualTo(1)); // Only one method got invoked
}
protected String createRandomKey() {

View File

@@ -33,10 +33,8 @@ import org.springframework.cache.interceptor.CacheOperation;
import org.springframework.cache.interceptor.CacheableOperation;
import org.springframework.core.annotation.AliasFor;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
@@ -104,14 +102,14 @@ public class AnnotationCacheOperationSourceTests {
Iterator<CacheOperation> it = ops.iterator();
CacheOperation cacheOperation = it.next();
assertThat(cacheOperation, instanceOf(CacheableOperation.class));
assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("directly declared")));
assertThat(cacheOperation.getKey(), equalTo(""));
assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("directly declared"));
assertThat(cacheOperation.getKey()).isEqualTo("");
cacheOperation = it.next();
assertThat(cacheOperation, instanceOf(CacheableOperation.class));
assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache")));
assertThat(cacheOperation.getKey(), equalTo("composedKey"));
assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("composedCache"));
assertThat(cacheOperation.getKey()).isEqualTo("composedKey");
}
@Test
@@ -120,24 +118,24 @@ public class AnnotationCacheOperationSourceTests {
Iterator<CacheOperation> it = ops.iterator();
CacheOperation cacheOperation = it.next();
assertThat(cacheOperation, instanceOf(CacheableOperation.class));
assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("directly declared")));
assertThat(cacheOperation.getKey(), equalTo(""));
assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("directly declared"));
assertThat(cacheOperation.getKey()).isEqualTo("");
cacheOperation = it.next();
assertThat(cacheOperation, instanceOf(CacheableOperation.class));
assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCache")));
assertThat(cacheOperation.getKey(), equalTo("composedKey"));
assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("composedCache"));
assertThat(cacheOperation.getKey()).isEqualTo("composedKey");
cacheOperation = it.next();
assertThat(cacheOperation, instanceOf(CacheableOperation.class));
assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("foo")));
assertThat(cacheOperation.getKey(), equalTo(""));
assertThat(cacheOperation).isInstanceOf(CacheableOperation.class);
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("foo"));
assertThat(cacheOperation.getKey()).isEqualTo("");
cacheOperation = it.next();
assertThat(cacheOperation, instanceOf(CacheEvictOperation.class));
assertThat(cacheOperation.getCacheNames(), equalTo(Collections.singleton("composedCacheEvict")));
assertThat(cacheOperation.getKey(), equalTo("composedEvictionKey"));
assertThat(cacheOperation).isInstanceOf(CacheEvictOperation.class);
assertThat(cacheOperation.getCacheNames()).isEqualTo(Collections.singleton("composedCacheEvict"));
assertThat(cacheOperation.getKey()).isEqualTo("composedEvictionKey");
}
@Test

View File

@@ -29,11 +29,9 @@ import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.context.ConfigurableApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIOException;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
@@ -276,8 +274,8 @@ public abstract class AbstractCacheAnnotationTests {
cache.clear();
service.unless(10);
service.unless(11);
assertThat(cache.get(10).get(), equalTo(10L));
assertThat(cache.get(11), nullValue());
assertThat(cache.get(10).get()).isEqualTo(10L);
assertThat(cache.get(11)).isNull();
}
public void testKeyExpression(CacheableService<?> service) throws Exception {

View File

@@ -38,10 +38,6 @@ import org.springframework.util.ReflectionUtils;
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.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -105,21 +101,21 @@ public class ExpressionEvaluatorTests {
public void withReturnValue() {
EvaluationContext context = createEvaluationContext("theResult");
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value, equalTo("theResult"));
assertThat(value).isEqualTo("theResult");
}
@Test
public void withNullReturn() {
EvaluationContext context = createEvaluationContext(null);
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value, nullValue());
assertThat(value).isNull();
}
@Test
public void withoutReturnValue() {
EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.NO_RESULT);
Object value = new SpelExpressionParser().parseExpression("#result").getValue(context);
assertThat(value, nullValue());
assertThat(value).isNull();
}
@Test
@@ -139,7 +135,7 @@ public class ExpressionEvaluatorTests {
EvaluationContext context = createEvaluationContext(CacheOperationExpressionEvaluator.NO_RESULT, applicationContext);
Object value = new SpelExpressionParser().parseExpression("@myBean.class.getName()").getValue(context);
assertThat(value, is(String.class.getName()));
assertThat(value).isEqualTo(String.class.getName());
}
private EvaluationContext createEvaluationContext(Object result) {

View File

@@ -18,10 +18,11 @@ package org.springframework.cache.interceptor;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link SimpleKeyGenerator} and {@link SimpleKey}.
@@ -39,10 +40,10 @@ public class SimpleKeyGeneratorTests {
Object k1 = generateKey(new Object[] {});
Object k2 = generateKey(new Object[] {});
Object k3 = generateKey(new Object[] { "different" });
assertThat(k1.hashCode(), equalTo(k2.hashCode()));
assertThat(k1.hashCode(), not(equalTo(k3.hashCode())));
assertThat(k1, equalTo(k2));
assertThat(k1, not(equalTo(k3)));
assertThat(k1.hashCode()).isEqualTo(k2.hashCode());
assertThat(k1.hashCode()).isNotEqualTo(k3.hashCode());
assertThat(k1).isEqualTo(k2);
assertThat(k1).isNotEqualTo(k3);
}
@Test
@@ -50,11 +51,11 @@ public class SimpleKeyGeneratorTests {
Object k1 = generateKey(new Object[] { "a" });
Object k2 = generateKey(new Object[] { "a" });
Object k3 = generateKey(new Object[] { "different" });
assertThat(k1.hashCode(), equalTo(k2.hashCode()));
assertThat(k1.hashCode(), not(equalTo(k3.hashCode())));
assertThat(k1, equalTo(k2));
assertThat(k1, not(equalTo(k3)));
assertThat(k1, equalTo("a"));
assertThat(k1.hashCode()).isEqualTo(k2.hashCode());
assertThat(k1.hashCode()).isNotEqualTo(k3.hashCode());
assertThat(k1).isEqualTo(k2);
assertThat(k1).isNotEqualTo(k3);
assertThat(k1).isEqualTo("a");
}
@Test
@@ -62,10 +63,10 @@ public class SimpleKeyGeneratorTests {
Object k1 = generateKey(new Object[] { "a", 1, "b" });
Object k2 = generateKey(new Object[] { "a", 1, "b" });
Object k3 = generateKey(new Object[] { "b", 1, "a" });
assertThat(k1.hashCode(), equalTo(k2.hashCode()));
assertThat(k1.hashCode(), not(equalTo(k3.hashCode())));
assertThat(k1, equalTo(k2));
assertThat(k1, not(equalTo(k3)));
assertThat(k1.hashCode()).isEqualTo(k2.hashCode());
assertThat(k1.hashCode()).isNotEqualTo(k3.hashCode());
assertThat(k1).isEqualTo(k2);
assertThat(k1).isNotEqualTo(k3);
}
@Test
@@ -73,11 +74,11 @@ public class SimpleKeyGeneratorTests {
Object k1 = generateKey(new Object[] { null });
Object k2 = generateKey(new Object[] { null });
Object k3 = generateKey(new Object[] { "different" });
assertThat(k1.hashCode(), equalTo(k2.hashCode()));
assertThat(k1.hashCode(), not(equalTo(k3.hashCode())));
assertThat(k1, equalTo(k2));
assertThat(k1, not(equalTo(k3)));
assertThat(k1, instanceOf(SimpleKey.class));
assertThat(k1.hashCode()).isEqualTo(k2.hashCode());
assertThat(k1.hashCode()).isNotEqualTo(k3.hashCode());
assertThat(k1).isEqualTo(k2);
assertThat(k1).isNotEqualTo(k3);
assertThat(k1).isInstanceOf(SimpleKey.class);
}
@Test
@@ -85,10 +86,10 @@ public class SimpleKeyGeneratorTests {
Object k1 = generateKey(new Object[] { "a", null, "b", null });
Object k2 = generateKey(new Object[] { "a", null, "b", null });
Object k3 = generateKey(new Object[] { "a", null, "b" });
assertThat(k1.hashCode(), equalTo(k2.hashCode()));
assertThat(k1.hashCode(), not(equalTo(k3.hashCode())));
assertThat(k1, equalTo(k2));
assertThat(k1, not(equalTo(k3)));
assertThat(k1.hashCode()).isEqualTo(k2.hashCode());
assertThat(k1.hashCode()).isNotEqualTo(k3.hashCode());
assertThat(k1).isEqualTo(k2);
assertThat(k1).isNotEqualTo(k3);
}
@Test
@@ -96,10 +97,10 @@ public class SimpleKeyGeneratorTests {
Object k1 = generateKey(new Object[] { new String[]{"a", "b"} });
Object k2 = generateKey(new Object[] { new String[]{"a", "b"} });
Object k3 = generateKey(new Object[] { new String[]{"b", "a"} });
assertThat(k1.hashCode(), equalTo(k2.hashCode()));
assertThat(k1.hashCode(), not(equalTo(k3.hashCode())));
assertThat(k1, equalTo(k2));
assertThat(k1, not(equalTo(k3)));
assertThat(k1.hashCode()).isEqualTo(k2.hashCode());
assertThat(k1.hashCode()).isNotEqualTo(k3.hashCode());
assertThat(k1).isEqualTo(k2);
assertThat(k1).isNotEqualTo(k3);
}
@Test
@@ -107,10 +108,10 @@ public class SimpleKeyGeneratorTests {
Object k1 = generateKey(new Object[] { new String[]{"a", "b"}, "c" });
Object k2 = generateKey(new Object[] { new String[]{"a", "b"}, "c" });
Object k3 = generateKey(new Object[] { new String[]{"b", "a"}, "c" });
assertThat(k1.hashCode(), equalTo(k2.hashCode()));
assertThat(k1.hashCode(), not(equalTo(k3.hashCode())));
assertThat(k1, equalTo(k2));
assertThat(k1, not(equalTo(k3)));
assertThat(k1.hashCode()).isEqualTo(k2.hashCode());
assertThat(k1.hashCode()).isNotEqualTo(k3.hashCode());
assertThat(k1).isEqualTo(k2);
assertThat(k1).isNotEqualTo(k3);
}

View File

@@ -34,11 +34,8 @@ import org.springframework.core.ResolvableType;
import org.springframework.util.ObjectUtils;
import static java.lang.String.format;
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.allOf;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -97,7 +94,7 @@ public class AnnotationConfigApplicationContextTests {
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
TestBean testBean = context.getBean(TestBean.class);
assertNotNull(testBean);
assertThat(testBean.name, equalTo("foo"));
assertThat(testBean.name).isEqualTo("foo");
}
@Test
@@ -114,19 +111,11 @@ public class AnnotationConfigApplicationContextTests {
@Test
public void getBeanByTypeAmbiguityRaisesException() {
ApplicationContext context = new AnnotationConfigApplicationContext(TwoTestBeanConfig.class);
try {
context.getBean(TestBean.class);
}
catch (NoSuchBeanDefinitionException ex) {
assertThat(ex.getMessage(),
allOf(
containsString("No qualifying bean of type '" + TestBean.class.getName() + "'"),
containsString("tb1"),
containsString("tb2")
)
);
}
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
context.getBean(TestBean.class))
.withMessageContaining("No qualifying bean of type '" + TestBean.class.getName() + "'")
.withMessageContaining("tb1")
.withMessageContaining("tb2");
}
/**
@@ -158,7 +147,7 @@ public class AnnotationConfigApplicationContextTests {
@Test
public void autowiringIsEnabledByDefault() {
ApplicationContext context = new AnnotationConfigApplicationContext(AutowiredConfig.class);
assertThat(context.getBean(TestBean.class).name, equalTo("foo"));
assertThat(context.getBean(TestBean.class).name).isEqualTo("foo");
}
@Test

View File

@@ -25,9 +25,10 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.AnnotatedBeanDefinition;
import org.springframework.beans.factory.config.BeanDefinition;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Phillip Webb
@@ -39,10 +40,10 @@ public class BeanMethodMetadataTests {
public void providesBeanMethodBeanDefinition() throws Exception {
AnnotationConfigApplicationContext context= new AnnotationConfigApplicationContext(Conf.class);
BeanDefinition beanDefinition = context.getBeanDefinition("myBean");
assertThat("should provide AnnotatedBeanDefinition", beanDefinition, instanceOf(AnnotatedBeanDefinition.class));
assertThat(beanDefinition).as("should provide AnnotatedBeanDefinition").isInstanceOf(AnnotatedBeanDefinition.class);
Map<String, Object> annotationAttributes =
((AnnotatedBeanDefinition) beanDefinition).getFactoryMethodMetadata().getAnnotationAttributes(MyAnnotation.class.getName());
assertThat(annotationAttributes.get("value"), equalTo("test"));
assertThat(annotationAttributes.get("value")).isEqualTo("test");
context.close();
}

View File

@@ -25,8 +25,7 @@ import org.springframework.aop.interceptor.SimpleTraceInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.support.RootBeanDefinition;
import static org.hamcrest.CoreMatchers.equalTo;
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.assertTrue;
@@ -98,7 +97,7 @@ public class BeanMethodPolymorphismTests {
ctx.register(ConfigWithOverloading.class);
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertThat(ctx.getBean(String.class), equalTo("regular"));
assertThat(ctx.getBean(String.class)).isEqualTo("regular");
}
@Test
@@ -108,7 +107,7 @@ public class BeanMethodPolymorphismTests {
ctx.getDefaultListableBeanFactory().registerSingleton("anInt", 5);
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertThat(ctx.getBean(String.class), equalTo("overloaded5"));
assertThat(ctx.getBean(String.class)).isEqualTo("overloaded5");
}
@Test
@@ -118,7 +117,7 @@ public class BeanMethodPolymorphismTests {
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getBean(String.class), equalTo("regular"));
assertThat(ctx.getBean(String.class)).isEqualTo("regular");
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
}
@@ -130,7 +129,7 @@ public class BeanMethodPolymorphismTests {
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getBean(String.class), equalTo("overloaded5"));
assertThat(ctx.getBean(String.class)).isEqualTo("overloaded5");
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
}
@@ -141,7 +140,7 @@ public class BeanMethodPolymorphismTests {
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getBean(String.class), equalTo("overloaded5"));
assertThat(ctx.getBean(String.class)).isEqualTo("overloaded5");
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
}
@@ -153,7 +152,7 @@ public class BeanMethodPolymorphismTests {
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getBean(String.class), equalTo("overloaded5"));
assertThat(ctx.getBean(String.class)).isEqualTo("overloaded5");
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
}
@@ -165,7 +164,7 @@ public class BeanMethodPolymorphismTests {
@Test
public void beanMethodShadowing() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ShadowConfig.class);
assertThat(ctx.getBean(String.class), equalTo("shadow"));
assertThat(ctx.getBean(String.class)).isEqualTo("shadow");
}
@Test

View File

@@ -55,9 +55,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
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.assertTrue;
@@ -368,7 +366,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
public void testWithNullEnvironment() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(false));
assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class)).isFalse();
}
@Test
@@ -378,7 +376,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
env.setActiveProfiles("other");
provider.setEnvironment(env);
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(false));
assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class)).isFalse();
}
@Test
@@ -388,7 +386,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
env.setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
provider.setEnvironment(env);
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_PROFILE_PACKAGE);
assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class), is(true));
assertThat(containsBeanClass(candidates, ProfileAnnotatedComponent.class)).isTrue();
}
@Test
@@ -396,7 +394,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ProfileAnnotatedComponent.class);
ctx.refresh();
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME), is(false));
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isFalse();
}
@Test
@@ -405,7 +403,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
ctx.getEnvironment().setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
ctx.register(ProfileAnnotatedComponent.class);
ctx.refresh();
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME), is(true));
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isTrue();
}
@Test
@@ -414,7 +412,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
ctx.getEnvironment().setActiveProfiles(DevComponent.PROFILE_NAME);
ctx.register(ProfileMetaAnnotatedComponent.class);
ctx.refresh();
assertThat(ctx.containsBean(ProfileMetaAnnotatedComponent.BEAN_NAME), is(true));
assertThat(ctx.containsBean(ProfileMetaAnnotatedComponent.BEAN_NAME)).isTrue();
}
@Test
@@ -423,7 +421,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
ctx.getEnvironment().setActiveProfiles("other");
ctx.register(ProfileAnnotatedComponent.class);
ctx.refresh();
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME), is(false));
assertThat(ctx.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isFalse();
}
@Test
@@ -432,7 +430,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
ctx.getEnvironment().setActiveProfiles("other");
ctx.register(ProfileMetaAnnotatedComponent.class);
ctx.refresh();
assertThat(ctx.containsBean(ProfileMetaAnnotatedComponent.BEAN_NAME), is(false));
assertThat(ctx.containsBean(ProfileMetaAnnotatedComponent.BEAN_NAME)).isFalse();
}
@Test
@@ -442,7 +440,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
// no active profiles are set
ctx.register(DefaultProfileAnnotatedComponent.class);
ctx.refresh();
assertThat(ctx.containsBean(DefaultProfileAnnotatedComponent.BEAN_NAME), is(true));
assertThat(ctx.containsBean(DefaultProfileAnnotatedComponent.BEAN_NAME)).isTrue();
}
@Test
@@ -455,7 +453,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
// no active profiles are set
ctx.register(beanClass);
ctx.refresh();
assertThat(ctx.containsBean(beanName), is(true));
assertThat(ctx.containsBean(beanName)).isTrue();
}
{
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -463,7 +461,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
ctx.getEnvironment().setActiveProfiles("dev");
ctx.register(beanClass);
ctx.refresh();
assertThat(ctx.containsBean(beanName), is(true));
assertThat(ctx.containsBean(beanName)).isTrue();
}
{
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -471,7 +469,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
ctx.getEnvironment().setActiveProfiles("other");
ctx.register(beanClass);
ctx.refresh();
assertThat(ctx.containsBean(beanName), is(false));
assertThat(ctx.containsBean(beanName)).isFalse();
}
}
@@ -485,7 +483,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
// no active profiles are set
ctx.register(beanClass);
ctx.refresh();
assertThat(ctx.containsBean(beanName), is(true));
assertThat(ctx.containsBean(beanName)).isTrue();
}
{
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -493,7 +491,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
ctx.getEnvironment().setActiveProfiles("dev");
ctx.register(beanClass);
ctx.refresh();
assertThat(ctx.containsBean(beanName), is(true));
assertThat(ctx.containsBean(beanName)).isTrue();
}
{
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
@@ -501,7 +499,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
ctx.getEnvironment().setActiveProfiles("other");
ctx.register(beanClass);
ctx.refresh();
assertThat(ctx.containsBean(beanName), is(false));
assertThat(ctx.containsBean(beanName)).isFalse();
}
}
@@ -517,7 +515,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
private void assertBeanDefinitionType(Set<BeanDefinition> candidates,
Class<? extends BeanDefinition> expectedType) {
candidates.forEach(c ->
assertThat(c, is(instanceOf(expectedType)))
assertThat(c).isInstanceOf(expectedType)
);
}

View File

@@ -61,12 +61,7 @@ import org.springframework.core.type.filter.TypeFilter;
import org.springframework.tests.context.SimpleMapScope;
import org.springframework.util.SerializationTestUtils;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -88,8 +83,8 @@ public class ComponentScanAnnotationIntegrationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan(example.scannable._package.class.getPackage().getName());
ctx.refresh();
assertThat("control scan for example.scannable package failed to register FooServiceImpl bean",
ctx.containsBean("fooServiceImpl"), is(true));
assertThat(ctx.containsBean("fooServiceImpl")).as(
"control scan for example.scannable package failed to register FooServiceImpl bean").isTrue();
}
@Test
@@ -99,10 +94,11 @@ public class ComponentScanAnnotationIntegrationTests {
ctx.refresh();
ctx.getBean(ComponentScanAnnotatedConfig.class);
ctx.getBean(TestBean.class);
assertThat("config class bean not found", ctx.containsBeanDefinition("componentScanAnnotatedConfig"), is(true));
assertThat("@ComponentScan annotated @Configuration class registered directly against " +
"AnnotationConfigApplicationContext did not trigger component scanning as expected",
ctx.containsBean("fooServiceImpl"), is(true));
assertThat(ctx.containsBeanDefinition("componentScanAnnotatedConfig")).as("config class bean not found")
.isTrue();
assertThat(ctx.containsBean("fooServiceImpl")).as("@ComponentScan annotated @Configuration class registered directly against " +
"AnnotationConfigApplicationContext did not trigger component scanning as expected")
.isTrue();
}
@Test
@@ -112,10 +108,11 @@ public class ComponentScanAnnotationIntegrationTests {
ctx.refresh();
ctx.getBean(ComponentScanAnnotatedConfig_WithValueAttribute.class);
ctx.getBean(TestBean.class);
assertThat("config class bean not found", ctx.containsBeanDefinition("componentScanAnnotatedConfig_WithValueAttribute"), is(true));
assertThat("@ComponentScan annotated @Configuration class registered directly against " +
"AnnotationConfigApplicationContext did not trigger component scanning as expected",
ctx.containsBean("fooServiceImpl"), is(true));
assertThat(ctx.containsBeanDefinition("componentScanAnnotatedConfig_WithValueAttribute")).as("config class bean not found")
.isTrue();
assertThat(ctx.containsBean("fooServiceImpl")).as("@ComponentScan annotated @Configuration class registered directly against " +
"AnnotationConfigApplicationContext did not trigger component scanning as expected")
.isTrue();
}
@Test
@@ -124,11 +121,13 @@ public class ComponentScanAnnotationIntegrationTests {
ctx.register(ComponentScanAnnotatedConfigWithImplicitBasePackage.class);
ctx.refresh();
ctx.getBean(ComponentScanAnnotatedConfigWithImplicitBasePackage.class);
assertThat("config class bean not found", ctx.containsBeanDefinition("componentScanAnnotatedConfigWithImplicitBasePackage"), is(true));
assertThat("@ComponentScan annotated @Configuration class registered directly against " +
"AnnotationConfigApplicationContext did not trigger component scanning as expected",
ctx.containsBean("scannedComponent"), is(true));
assertThat("@Bean method overrides scanned class", ctx.getBean(ConfigurableComponent.class).isFlag(), is(true));
assertThat(ctx.containsBeanDefinition("componentScanAnnotatedConfigWithImplicitBasePackage")).as("config class bean not found")
.isTrue();
assertThat(ctx.containsBean("scannedComponent")).as("@ComponentScan annotated @Configuration class registered directly against " +
"AnnotationConfigApplicationContext did not trigger component scanning as expected")
.isTrue();
assertThat(ctx.getBean(ConfigurableComponent.class).isFlag()).as("@Bean method overrides scanned class")
.isTrue();
}
@Test
@@ -140,11 +139,11 @@ public class ComponentScanAnnotationIntegrationTests {
ctx.getBean(SimpleComponent.class);
ctx.getBean(ClassWithNestedComponents.NestedComponent.class);
ctx.getBean(ClassWithNestedComponents.OtherNestedComponent.class);
assertThat("config class bean not found",
ctx.containsBeanDefinition("componentScanAnnotationIntegrationTests.ComposedAnnotationConfig"), is(true));
assertThat("@ComponentScan annotated @Configuration class registered directly against " +
"AnnotationConfigApplicationContext did not trigger component scanning as expected",
ctx.containsBean("simpleComponent"), is(true));
assertThat(ctx.containsBeanDefinition("componentScanAnnotationIntegrationTests.ComposedAnnotationConfig")).as("config class bean not found")
.isTrue();
assertThat(ctx.containsBean("simpleComponent")).as("@ComponentScan annotated @Configuration class registered directly against " +
"AnnotationConfigApplicationContext did not trigger component scanning as expected")
.isTrue();
}
@Test
@@ -158,10 +157,11 @@ public class ComponentScanAnnotationIntegrationTests {
ctx.refresh();
ctx.getBean(ComponentScanAnnotatedConfig.class);
ctx.getBean(TestBean.class);
assertThat("config class bean not found", ctx.containsBeanDefinition("componentScanAnnotatedConfig"), is(true));
assertThat("@ComponentScan annotated @Configuration class registered " +
"as bean definition did not trigger component scanning as expected",
ctx.containsBean("fooServiceImpl"), is(true));
assertThat(ctx.containsBeanDefinition("componentScanAnnotatedConfig")).as("config class bean not found")
.isTrue();
assertThat(ctx.containsBean("fooServiceImpl")).as("@ComponentScan annotated @Configuration class registered as bean " +
"definition did not trigger component scanning as expected")
.isTrue();
}
@Test
@@ -169,8 +169,8 @@ public class ComponentScanAnnotationIntegrationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ComponentScanWithBeanNameGenerator.class);
ctx.refresh();
assertThat(ctx.containsBean("custom_fooServiceImpl"), is(true));
assertThat(ctx.containsBean("fooServiceImpl"), is(false));
assertThat(ctx.containsBean("custom_fooServiceImpl")).isTrue();
assertThat(ctx.containsBean("fooServiceImpl")).isFalse();
}
@Test
@@ -178,15 +178,15 @@ public class ComponentScanAnnotationIntegrationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithScopeResolver.class);
// custom scope annotation makes the bean prototype scoped. subsequent calls
// to getBean should return distinct instances.
assertThat(ctx.getBean(CustomScopeAnnotationBean.class), not(sameInstance(ctx.getBean(CustomScopeAnnotationBean.class))));
assertThat(ctx.containsBean("scannedComponent"), is(false));
assertThat(ctx.getBean(CustomScopeAnnotationBean.class)).isNotSameAs(ctx.getBean(CustomScopeAnnotationBean.class));
assertThat(ctx.containsBean("scannedComponent")).isFalse();
}
@Test
public void multiComponentScan() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(MultiComponentScan.class);
assertThat(ctx.getBean(CustomScopeAnnotationBean.class), not(sameInstance(ctx.getBean(CustomScopeAnnotationBean.class))));
assertThat(ctx.containsBean("scannedComponent"), is(true));
assertThat(ctx.getBean(CustomScopeAnnotationBean.class)).isNotSameAs(ctx.getBean(CustomScopeAnnotationBean.class));
assertThat(ctx.containsBean("scannedComponent")).isTrue();
}
@Test
@@ -194,7 +194,7 @@ public class ComponentScanAnnotationIntegrationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithCustomTypeFilter.class);
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("componentScanParserTests.KustomAnnotationAutowiredBean"));
KustomAnnotationAutowiredBean testBean = ctx.getBean("componentScanParserTests.KustomAnnotationAutowiredBean", KustomAnnotationAutowiredBean.class);
assertThat(testBean.getDependency(), notNullValue());
assertThat(testBean.getDependency()).isNotNull();
}
@Test
@@ -212,12 +212,12 @@ public class ComponentScanAnnotationIntegrationTests {
// should cast to the interface
FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
// should be dynamic proxy
assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
assertThat(AopUtils.isJdkDynamicProxy(bean)).isTrue();
// test serializability
assertThat(bean.foo(1), equalTo("bar"));
assertThat(bean.foo(1)).isEqualTo("bar");
FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
assertThat(deserialized, notNullValue());
assertThat(deserialized.foo(1), equalTo("bar"));
assertThat(deserialized).isNotNull();
assertThat(deserialized.foo(1)).isEqualTo("bar");
}
@Test
@@ -229,7 +229,7 @@ public class ComponentScanAnnotationIntegrationTests {
// should cast to the interface
FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
// should be dynamic proxy
assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
assertThat(AopUtils.isJdkDynamicProxy(bean)).isTrue();
}
@Test
@@ -241,7 +241,7 @@ public class ComponentScanAnnotationIntegrationTests {
// should cast to the interface
FooService bean = (FooService) ctx.getBean("scopedProxyTestBean");
// should be dynamic proxy
assertThat(AopUtils.isJdkDynamicProxy(bean), is(true));
assertThat(AopUtils.isJdkDynamicProxy(bean)).isTrue();
}
@Test
@@ -267,7 +267,7 @@ public class ComponentScanAnnotationIntegrationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ComponentScanWithBasePackagesAndValueAlias.class);
ctx.refresh();
assertThat(ctx.containsBean("fooServiceImpl"), is(true));
assertThat(ctx.containsBean("fooServiceImpl")).isTrue();
}

View File

@@ -23,8 +23,8 @@ import org.springframework.context.annotation.componentscan.level1.Level1Config;
import org.springframework.context.annotation.componentscan.level2.Level2Config;
import org.springframework.context.annotation.componentscan.level3.Level3Component;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests ensuring that configuration classes marked with @ComponentScan
@@ -47,8 +47,8 @@ public class ComponentScanAnnotationRecursionTests {
ctx.getBean(Level3Component.class);
// assert that enhancement is working
assertThat(ctx.getBean("level1Bean"), sameInstance(ctx.getBean("level1Bean")));
assertThat(ctx.getBean("level2Bean"), sameInstance(ctx.getBean("level2Bean")));
assertThat(ctx.getBean("level1Bean")).isSameAs(ctx.getBean("level1Bean"));
assertThat(ctx.getBean("level2Bean")).isSameAs(ctx.getBean("level2Bean"));
}
public void evenCircularScansAreSupported() {

View File

@@ -33,8 +33,7 @@ import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
import static org.hamcrest.CoreMatchers.is;
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;
@@ -127,7 +126,7 @@ public class ComponentScanParserTests {
GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load(xmlLocation);
context.refresh();
assertThat(context.containsBean(ProfileAnnotatedComponent.BEAN_NAME), is(false));
assertThat(context.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isFalse();
context.close();
}
{ // should include the profile-annotated bean with active profiles set
@@ -135,7 +134,7 @@ public class ComponentScanParserTests {
context.getEnvironment().setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
context.load(xmlLocation);
context.refresh();
assertThat(context.containsBean(ProfileAnnotatedComponent.BEAN_NAME), is(true));
assertThat(context.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isTrue();
context.close();
}
{ // ensure the same works for AbstractRefreshableApplicationContext impls too
@@ -143,7 +142,7 @@ public class ComponentScanParserTests {
false);
context.getEnvironment().setActiveProfiles(ProfileAnnotatedComponent.PROFILE_NAME);
context.refresh();
assertThat(context.containsBean(ProfileAnnotatedComponent.BEAN_NAME), is(true));
assertThat(context.containsBean(ProfileAnnotatedComponent.BEAN_NAME)).isTrue();
context.close();
}
}

View File

@@ -24,11 +24,8 @@ import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests semantics of declaring {@link BeanFactoryPostProcessor}-returning @Bean
@@ -47,7 +44,7 @@ public class ConfigurationClassAndBFPPTests {
ctx.refresh();
// instance method BFPP interferes with lifecycle -> autowiring fails!
// WARN-level logging should have been issued about returning BFPP from non-static @Bean method
assertThat(ctx.getBean(AutowiredConfigWithBFPPAsInstanceMethod.class).autowiredTestBean, nullValue());
assertThat(ctx.getBean(AutowiredConfigWithBFPPAsInstanceMethod.class).autowiredTestBean).isNull();
}
@Test
@@ -56,7 +53,7 @@ public class ConfigurationClassAndBFPPTests {
ctx.register(TestBeanConfig.class, AutowiredConfigWithBFPPAsStaticMethod.class);
ctx.refresh();
// static method BFPP does not interfere with lifecycle -> autowiring succeeds
assertThat(ctx.getBean(AutowiredConfigWithBFPPAsStaticMethod.class).autowiredTestBean, notNullValue());
assertThat(ctx.getBean(AutowiredConfigWithBFPPAsStaticMethod.class).autowiredTestBean).isNotNull();
}
@@ -106,7 +103,7 @@ public class ConfigurationClassAndBFPPTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithStaticBeanMethod.class);
ctx.refresh();
assertThat(ConfigWithStaticBeanMethod.testBean(), not(sameInstance(ConfigWithStaticBeanMethod.testBean())));
assertThat(ConfigWithStaticBeanMethod.testBean()).isNotSameAs(ConfigWithStaticBeanMethod.testBean());
}

View File

@@ -23,8 +23,8 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests cornering the issue reported in SPR-8080. If the product of a @Bean method
@@ -56,7 +56,7 @@ public class ConfigurationClassPostConstructAndAutowiringTests {
assertions(ctx);
Config2 config2 = ctx.getBean(Config2.class);
assertThat(config2.testBean, is(ctx.getBean(TestBean.class)));
assertThat(config2.testBean).isEqualTo(ctx.getBean(TestBean.class));
}
/**
@@ -75,8 +75,8 @@ public class ConfigurationClassPostConstructAndAutowiringTests {
private void assertions(AnnotationConfigApplicationContext ctx) {
Config1 config1 = ctx.getBean(Config1.class);
TestBean testBean = ctx.getBean(TestBean.class);
assertThat(config1.beanMethodCallCount, is(1));
assertThat(testBean.getAge(), is(2));
assertThat(config1.beanMethodCallCount).isEqualTo(1);
assertThat(testBean.getAge()).isEqualTo(2);
}

View File

@@ -31,8 +31,7 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.stereotype.Component;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
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.assertTrue;
@@ -248,7 +247,7 @@ public class ConfigurationClassWithConditionTests {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
AnnotationAttributes attributes = AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(MetaConditional.class.getName()));
assertThat(attributes.getString("value"), equalTo("test"));
assertThat(attributes.getString("value")).isEqualTo("test");
return true;
}
}

View File

@@ -24,8 +24,8 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Chris Beams
@@ -48,27 +48,27 @@ public class DestroyMethodInferenceTests {
WithInheritedCloseMethod c8 = ctx.getBean("c8", WithInheritedCloseMethod.class);
WithDisposableBean c9 = ctx.getBean("c9", WithDisposableBean.class);
assertThat(c0.closed, is(false));
assertThat(c1.closed, is(false));
assertThat(c2.closed, is(false));
assertThat(c3.closed, is(false));
assertThat(c4.closed, is(false));
assertThat(c5.closed, is(false));
assertThat(c6.closed, is(false));
assertThat(c7.closed, is(false));
assertThat(c8.closed, is(false));
assertThat(c9.closed, is(false));
assertThat(c0.closed).as("c0").isFalse();
assertThat(c1.closed).as("c1").isFalse();
assertThat(c2.closed).as("c2").isFalse();
assertThat(c3.closed).as("c3").isFalse();
assertThat(c4.closed).as("c4").isFalse();
assertThat(c5.closed).as("c5").isFalse();
assertThat(c6.closed).as("c6").isFalse();
assertThat(c7.closed).as("c7").isFalse();
assertThat(c8.closed).as("c8").isFalse();
assertThat(c9.closed).as("c9").isFalse();
ctx.close();
assertThat("c0", c0.closed, is(true));
assertThat("c1", c1.closed, is(true));
assertThat("c2", c2.closed, is(true));
assertThat("c3", c3.closed, is(true));
assertThat("c4", c4.closed, is(true));
assertThat("c5", c5.closed, is(true));
assertThat("c6", c6.closed, is(false));
assertThat("c7", c7.closed, is(true));
assertThat("c8", c8.closed, is(false));
assertThat("c9", c9.closed, is(true));
assertThat(c0.closed).as("c0").isTrue();
assertThat(c1.closed).as("c1").isTrue();
assertThat(c2.closed).as("c2").isTrue();
assertThat(c3.closed).as("c3").isTrue();
assertThat(c4.closed).as("c4").isTrue();
assertThat(c5.closed).as("c5").isTrue();
assertThat(c6.closed).as("c6").isFalse();
assertThat(c7.closed).as("c7").isTrue();
assertThat(c8.closed).as("c8").isFalse();
assertThat(c9.closed).as("c9").isTrue();
}
@Test
@@ -81,16 +81,16 @@ public class DestroyMethodInferenceTests {
WithNoCloseMethod x4 = ctx.getBean("x4", WithNoCloseMethod.class);
WithInheritedCloseMethod x8 = ctx.getBean("x8", WithInheritedCloseMethod.class);
assertThat(x1.closed, is(false));
assertThat(x2.closed, is(false));
assertThat(x3.closed, is(false));
assertThat(x4.closed, is(false));
assertThat(x1.closed).isFalse();
assertThat(x2.closed).isFalse();
assertThat(x3.closed).isFalse();
assertThat(x4.closed).isFalse();
ctx.close();
assertThat(x1.closed, is(false));
assertThat(x2.closed, is(true));
assertThat(x3.closed, is(true));
assertThat(x4.closed, is(false));
assertThat(x8.closed, is(false));
assertThat(x1.closed).isFalse();
assertThat(x2.closed).isTrue();
assertThat(x3.closed).isTrue();
assertThat(x4.closed).isFalse();
assertThat(x8.closed).isFalse();
}

View File

@@ -32,8 +32,7 @@ import org.springframework.aop.support.AopUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import static org.hamcrest.CoreMatchers.is;
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.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -49,7 +48,7 @@ public class EnableAspectJAutoProxyTests {
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithJdkProxy.class);
aspectIsApplied(ctx);
assertThat(AopUtils.isJdkDynamicProxy(ctx.getBean(FooService.class)), is(true));
assertThat(AopUtils.isJdkDynamicProxy(ctx.getBean(FooService.class))).isTrue();
}
@Test
@@ -57,7 +56,7 @@ public class EnableAspectJAutoProxyTests {
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithCglibProxy.class);
aspectIsApplied(ctx);
assertThat(AopUtils.isCglibProxy(ctx.getBean(FooService.class)), is(true));
assertThat(AopUtils.isCglibProxy(ctx.getBean(FooService.class))).isTrue();
}
@Test
@@ -65,7 +64,7 @@ public class EnableAspectJAutoProxyTests {
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithExposedProxy.class);
aspectIsApplied(ctx);
assertThat(AopUtils.isJdkDynamicProxy(ctx.getBean(FooService.class)), is(true));
assertThat(AopUtils.isJdkDynamicProxy(ctx.getBean(FooService.class))).isTrue();
}
private void aspectIsApplied(ApplicationContext ctx) {

View File

@@ -36,9 +36,7 @@ import org.springframework.core.type.StandardAnnotationMetadata;
import org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor;
import org.springframework.util.Assert;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
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.assertNotNull;
@@ -61,11 +59,11 @@ public class ImportAwareTests {
ImportedConfig importAwareConfig = ctx.getBean(ImportedConfig.class);
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
assertThat("import metadata was not injected", importMetadata, notNullValue());
assertThat(importMetadata.getClassName(), is(ImportingConfig.class.getName()));
assertThat(importMetadata).isNotNull();
assertThat(importMetadata.getClassName()).isEqualTo(ImportingConfig.class.getName());
AnnotationAttributes importAttribs = AnnotationConfigUtils.attributesFor(importMetadata, Import.class);
Class<?>[] importedClasses = importAttribs.getClassArray("value");
assertThat(importedClasses[0].getName(), is(ImportedConfig.class.getName()));
assertThat(importedClasses[0].getName()).isEqualTo(ImportedConfig.class.getName());
}
@Test
@@ -77,11 +75,11 @@ public class ImportAwareTests {
ImportedConfig importAwareConfig = ctx.getBean(ImportedConfig.class);
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
assertThat("import metadata was not injected", importMetadata, notNullValue());
assertThat(importMetadata.getClassName(), is(IndirectlyImportingConfig.class.getName()));
assertThat(importMetadata).isNotNull();
assertThat(importMetadata.getClassName()).isEqualTo(IndirectlyImportingConfig.class.getName());
AnnotationAttributes enableAttribs = AnnotationConfigUtils.attributesFor(importMetadata, EnableImportedConfig.class);
String foo = enableAttribs.getString("foo");
assertThat(foo, is("xyz"));
assertThat(foo).isEqualTo("xyz");
}
@Test
@@ -93,11 +91,11 @@ public class ImportAwareTests {
ImportedConfigLite importAwareConfig = ctx.getBean(ImportedConfigLite.class);
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
assertThat("import metadata was not injected", importMetadata, notNullValue());
assertThat(importMetadata.getClassName(), is(ImportingConfigLite.class.getName()));
assertThat(importMetadata).isNotNull();
assertThat(importMetadata.getClassName()).isEqualTo(ImportingConfigLite.class.getName());
AnnotationAttributes importAttribs = AnnotationConfigUtils.attributesFor(importMetadata, Import.class);
Class<?>[] importedClasses = importAttribs.getClassArray("value");
assertThat(importedClasses[0].getName(), is(ImportedConfigLite.class.getName()));
assertThat(importedClasses[0].getName()).isEqualTo(ImportedConfigLite.class.getName());
}
@Test

View File

@@ -35,9 +35,8 @@ import org.springframework.core.env.Environment;
import org.springframework.core.io.ResourceLoader;
import org.springframework.core.type.AnnotationMetadata;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link ImportBeanDefinitionRegistrar}.
@@ -52,10 +51,10 @@ public class ImportBeanDefinitionRegistrarTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
context.getBean(MessageSource.class);
assertThat(SampleRegistrar.beanFactory, is(context.getBeanFactory()));
assertThat(SampleRegistrar.classLoader, is(context.getBeanFactory().getBeanClassLoader()));
assertThat(SampleRegistrar.resourceLoader, is(notNullValue()));
assertThat(SampleRegistrar.environment, is(context.getEnvironment()));
assertThat(SampleRegistrar.beanFactory).isEqualTo(context.getBeanFactory());
assertThat(SampleRegistrar.classLoader).isEqualTo(context.getBeanFactory().getBeanClassLoader());
assertThat(SampleRegistrar.resourceLoader).isNotNull();
assertThat(SampleRegistrar.environment).isEqualTo(context.getEnvironment());
}

View File

@@ -31,8 +31,6 @@ import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import org.hamcrest.Matcher;
import org.hamcrest.collection.IsIterableContainingInOrder;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InOrder;
@@ -53,11 +51,7 @@ import org.springframework.lang.Nullable;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.inOrder;
@@ -100,20 +94,20 @@ public class ImportSelectorTests {
@Test
public void invokeAwareMethodsInImportSelector() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AwareConfig.class);
assertThat(SampleImportSelector.beanFactory, is(context.getBeanFactory()));
assertThat(SampleImportSelector.classLoader, is(context.getBeanFactory().getBeanClassLoader()));
assertThat(SampleImportSelector.resourceLoader, is(notNullValue()));
assertThat(SampleImportSelector.environment, is(context.getEnvironment()));
assertThat(SampleImportSelector.beanFactory).isEqualTo(context.getBeanFactory());
assertThat(SampleImportSelector.classLoader).isEqualTo(context.getBeanFactory().getBeanClassLoader());
assertThat(SampleImportSelector.resourceLoader).isNotNull();
assertThat(SampleImportSelector.environment).isEqualTo(context.getEnvironment());
}
@Test
public void correctMetaDataOnIndirectImports() {
new AnnotationConfigApplicationContext(IndirectConfig.class);
Matcher<String> isFromIndirect = equalTo(IndirectImport.class.getName());
assertThat(importFrom.get(ImportSelector1.class), isFromIndirect);
assertThat(importFrom.get(ImportSelector2.class), isFromIndirect);
assertThat(importFrom.get(DeferredImportSelector1.class), isFromIndirect);
assertThat(importFrom.get(DeferredImportSelector2.class), isFromIndirect);
String indirectImport = IndirectImport.class.getName();
assertThat(importFrom.get(ImportSelector1.class)).isEqualTo(indirectImport);
assertThat(importFrom.get(ImportSelector2.class)).isEqualTo(indirectImport);
assertThat(importFrom.get(DeferredImportSelector1.class)).isEqualTo(indirectImport);
assertThat(importFrom.get(DeferredImportSelector2.class)).isEqualTo(indirectImport);
}
@Test
@@ -127,9 +121,9 @@ public class ImportSelectorTests {
ordered.verify(beanFactory).registerBeanDefinition(eq("b"), any());
ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any());
assertThat(TestImportGroup.instancesCount.get(), equalTo(1));
assertThat(TestImportGroup.imports.size(), equalTo(1));
assertThat(TestImportGroup.imports.values().iterator().next().size(), equalTo(2));
assertThat(TestImportGroup.instancesCount.get()).isEqualTo(1);
assertThat(TestImportGroup.imports.size()).isEqualTo(1);
assertThat(TestImportGroup.imports.values().iterator().next().size()).isEqualTo(2);
}
@Test
@@ -142,11 +136,11 @@ public class ImportSelectorTests {
InOrder ordered = inOrder(beanFactory);
ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any());
assertThat(TestImportGroup.instancesCount.get(), equalTo(1));
assertThat(TestImportGroup.imports.size(), equalTo(2));
assertThat(TestImportGroup.instancesCount.get()).isEqualTo(1);
assertThat(TestImportGroup.imports.size()).isEqualTo(2);
Iterator<AnnotationMetadata> iterator = TestImportGroup.imports.keySet().iterator();
assertThat(iterator.next().getClassName(), equalTo(GroupedConfig2.class.getName()));
assertThat(iterator.next().getClassName(), equalTo(GroupedConfig1.class.getName()));
assertThat(iterator.next().getClassName()).isEqualTo(GroupedConfig2.class.getName());
assertThat(iterator.next().getClassName()).isEqualTo(GroupedConfig1.class.getName());
}
@Test
@@ -159,15 +153,14 @@ public class ImportSelectorTests {
ordered.verify(beanFactory).registerBeanDefinition(eq("a"), any());
ordered.verify(beanFactory).registerBeanDefinition(eq("e"), any());
ordered.verify(beanFactory).registerBeanDefinition(eq("c"), any());
assertThat(TestImportGroup.instancesCount.get(), equalTo(2));
assertThat(TestImportGroup.imports.size(), equalTo(2));
assertThat(TestImportGroup.allImports(), hasEntry(
is(ParentConfiguration1.class.getName()),
IsIterableContainingInOrder.contains(DeferredImportSelector1.class.getName(),
ChildConfiguration1.class.getName())));
assertThat(TestImportGroup.allImports(), hasEntry(
is(ChildConfiguration1.class.getName()),
IsIterableContainingInOrder.contains(DeferredImportedSelector3.class.getName())));
assertThat(TestImportGroup.instancesCount.get()).isEqualTo(2);
assertThat(TestImportGroup.imports.size()).isEqualTo(2);
assertThat(TestImportGroup.allImports())
.containsOnlyKeys(ParentConfiguration1.class.getName(), ChildConfiguration1.class.getName());
assertThat(TestImportGroup.allImports().get(ParentConfiguration1.class.getName()))
.containsExactly(DeferredImportSelector1.class.getName(), ChildConfiguration1.class.getName());
assertThat(TestImportGroup.allImports().get(ChildConfiguration1.class.getName()))
.containsExactly(DeferredImportedSelector3.class.getName());
}
@Test
@@ -179,24 +172,23 @@ public class ImportSelectorTests {
InOrder ordered = inOrder(beanFactory);
ordered.verify(beanFactory).registerBeanDefinition(eq("b"), any());
ordered.verify(beanFactory).registerBeanDefinition(eq("d"), any());
assertThat(TestImportGroup.instancesCount.get(), equalTo(2));
assertThat(TestImportGroup.allImports().size(), equalTo(2));
assertThat(TestImportGroup.allImports(), hasEntry(
is(ParentConfiguration2.class.getName()),
IsIterableContainingInOrder.contains(DeferredImportSelector2.class.getName(),
ChildConfiguration2.class.getName())));
assertThat(TestImportGroup.allImports(), hasEntry(
is(ChildConfiguration2.class.getName()),
IsIterableContainingInOrder.contains(DeferredImportSelector2.class.getName())));
assertThat(TestImportGroup.instancesCount.get()).isEqualTo(2);
assertThat(TestImportGroup.allImports().size()).isEqualTo(2);
assertThat(TestImportGroup.allImports())
.containsOnlyKeys(ParentConfiguration2.class.getName(), ChildConfiguration2.class.getName());
assertThat(TestImportGroup.allImports().get(ParentConfiguration2.class.getName()))
.containsExactly(DeferredImportSelector2.class.getName(), ChildConfiguration2.class.getName());
assertThat(TestImportGroup.allImports().get(ChildConfiguration2.class.getName()))
.containsExactly(DeferredImportSelector2.class.getName());
}
@Test
public void invokeAwareMethodsInImportGroup() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(GroupedConfig1.class);
assertThat(TestImportGroup.beanFactory, is(context.getBeanFactory()));
assertThat(TestImportGroup.classLoader, is(context.getBeanFactory().getBeanClassLoader()));
assertThat(TestImportGroup.resourceLoader, is(notNullValue()));
assertThat(TestImportGroup.environment, is(context.getEnvironment()));
assertThat(TestImportGroup.beanFactory).isEqualTo(context.getBeanFactory());
assertThat(TestImportGroup.classLoader).isEqualTo(context.getBeanFactory().getBeanClassLoader());
assertThat(TestImportGroup.resourceLoader).isNotNull();
assertThat(TestImportGroup.environment).isEqualTo(context.getEnvironment());
}

View File

@@ -21,8 +21,7 @@ import org.junit.Test;
import org.springframework.stereotype.Component;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
@@ -52,7 +51,7 @@ public class NestedConfigurationClassTests {
ctx.getBean("l2Bean");
// ensure that override order is correct
assertThat(ctx.getBean("overrideBean", TestBean.class).getName(), is("override-l1"));
assertThat(ctx.getBean("overrideBean", TestBean.class).getName()).isEqualTo("override-l1");
}
@Test
@@ -74,7 +73,7 @@ public class NestedConfigurationClassTests {
ctx.getBean("l2Bean");
// ensure that override order is correct
assertThat(ctx.getBean("overrideBean", TestBean.class).getName(), is("override-l0"));
assertThat(ctx.getBean("overrideBean", TestBean.class).getName()).isEqualTo("override-l0");
}
@Test
@@ -96,7 +95,7 @@ public class NestedConfigurationClassTests {
ctx.getBean("l2Bean");
// ensure that override order is correct
assertThat(ctx.getBean("overrideBean", TestBean.class).getName(), is("override-l0"));
assertThat(ctx.getBean("overrideBean", TestBean.class).getName()).isEqualTo("override-l0");
}
@Test
@@ -118,7 +117,7 @@ public class NestedConfigurationClassTests {
// ensure that override order is correct and that it is a singleton
TestBean ob = ctx.getBean("overrideBean", TestBean.class);
assertThat(ob.getName(), is("override-s1"));
assertThat(ob.getName()).isEqualTo("override-s1");
assertTrue(ob == ctx.getBean("overrideBean", TestBean.class));
TestBean pb1 = ctx.getBean("prototypeBean", TestBean.class);
@@ -146,7 +145,7 @@ public class NestedConfigurationClassTests {
// ensure that override order is correct and that it is a singleton
TestBean ob = ctx.getBean("overrideBean", TestBean.class);
assertThat(ob.getName(), is("override-s1"));
assertThat(ob.getName()).isEqualTo("override-s1");
assertTrue(ob == ctx.getBean("overrideBean", TestBean.class));
TestBean pb1 = ctx.getBean("prototypeBean", TestBean.class);
@@ -174,7 +173,7 @@ public class NestedConfigurationClassTests {
// ensure that override order is correct and that it is a singleton
TestBean ob = ctx.getBean("overrideBean", TestBean.class);
assertThat(ob.getName(), is("override-s1"));
assertThat(ob.getName()).isEqualTo("override-s1");
assertTrue(ob == ctx.getBean("overrideBean", TestBean.class));
TestBean pb1 = ctx.getBean("prototypeBean", TestBean.class);

View File

@@ -23,8 +23,8 @@ import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests changes introduced for SPR-8874, allowing beans of primitive types to be looked
@@ -47,34 +47,34 @@ public class PrimitiveBeanLookupAndAutowiringTests {
public void primitiveLookupByName() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
boolean b = ctx.getBean("b", boolean.class);
assertThat(b, equalTo(true));
assertThat(b).isEqualTo(true);
int i = ctx.getBean("i", int.class);
assertThat(i, equalTo(42));
assertThat(i).isEqualTo(42);
}
@Test
public void primitiveLookupByType() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
boolean b = ctx.getBean(boolean.class);
assertThat(b, equalTo(true));
assertThat(b).isEqualTo(true);
int i = ctx.getBean(int.class);
assertThat(i, equalTo(42));
assertThat(i).isEqualTo(42);
}
@Test
public void primitiveAutowiredInjection() {
ApplicationContext ctx =
new AnnotationConfigApplicationContext(Config.class, AutowiredComponent.class);
assertThat(ctx.getBean(AutowiredComponent.class).b, equalTo(true));
assertThat(ctx.getBean(AutowiredComponent.class).i, equalTo(42));
assertThat(ctx.getBean(AutowiredComponent.class).b).isEqualTo(true);
assertThat(ctx.getBean(AutowiredComponent.class).i).isEqualTo(42);
}
@Test
public void primitiveResourceInjection() {
ApplicationContext ctx =
new AnnotationConfigApplicationContext(Config.class, ResourceComponent.class);
assertThat(ctx.getBean(ResourceComponent.class).b, equalTo(true));
assertThat(ctx.getBean(ResourceComponent.class).i, equalTo(42));
assertThat(ctx.getBean(ResourceComponent.class).b).isEqualTo(true);
assertThat(ctx.getBean(ResourceComponent.class).i).isEqualTo(42);
}

View File

@@ -38,10 +38,8 @@ import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.core.io.support.PropertySourceFactory;
import org.springframework.tests.sample.beans.TestBean;
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.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;
/**
@@ -61,7 +59,7 @@ public class PropertySourceAnnotationTests {
ctx.refresh();
assertTrue("property source p1 was not added",
ctx.getEnvironment().getPropertySources().contains("p1"));
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
// assert that the property source was added last to the set of sources
String name;
@@ -72,7 +70,7 @@ public class PropertySourceAnnotationTests {
}
while (iterator.hasNext());
assertThat(name, is("p1"));
assertThat(name).isEqualTo("p1");
}
@Test
@@ -82,7 +80,7 @@ public class PropertySourceAnnotationTests {
ctx.refresh();
assertTrue("property source p1 was not added",
ctx.getEnvironment().getPropertySources().contains("class path resource [org/springframework/context/annotation/p1.properties]"));
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
}
@Test
@@ -105,7 +103,7 @@ public class PropertySourceAnnotationTests {
ctx.register(ConfigWithImplicitName.class, P2Config.class);
ctx.refresh();
// p2 should 'win' as it was registered last
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p2TestBean"));
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p2TestBean");
}
{
@@ -113,7 +111,7 @@ public class PropertySourceAnnotationTests {
ctx.register(P2Config.class, ConfigWithImplicitName.class);
ctx.refresh();
// p1 should 'win' as it was registered last
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
}
}
@@ -122,7 +120,7 @@ public class PropertySourceAnnotationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithImplicitName.class, WithCustomFactory.class);
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("P2TESTBEAN"));
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("P2TESTBEAN");
}
@Test
@@ -130,7 +128,7 @@ public class PropertySourceAnnotationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithImplicitName.class, WithCustomFactoryAsMeta.class);
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("P2TESTBEAN"));
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("P2TESTBEAN");
}
@Test
@@ -150,7 +148,7 @@ public class PropertySourceAnnotationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithUnresolvablePlaceholderAndDefault.class);
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
}
@Test
@@ -159,7 +157,7 @@ public class PropertySourceAnnotationTests {
ctx.register(ConfigWithResolvablePlaceholder.class);
System.setProperty("path.to.properties", "org/springframework/context/annotation");
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
System.clearProperty("path.to.properties");
}
@@ -169,7 +167,7 @@ public class PropertySourceAnnotationTests {
ctx.register(ConfigWithResolvablePlaceholderAndFactoryBean.class);
System.setProperty("path.to.properties", "org/springframework/context/annotation");
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("p1TestBean"));
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
System.clearProperty("path.to.properties");
}
@@ -188,37 +186,37 @@ public class PropertySourceAnnotationTests {
@Test
public void withNameAndMultipleResourceLocations() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNameAndMultipleResourceLocations.class);
assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p1")).isTrue();
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
// p2 should 'win' as it was registered last
assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
}
@Test
public void withMultipleResourceLocations() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithMultipleResourceLocations.class);
assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p1")).isTrue();
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
// p2 should 'win' as it was registered last
assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
}
@Test
public void withPropertySources() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithPropertySources.class);
assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p1")).isTrue();
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
// p2 should 'win' as it was registered last
assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
}
@Test
public void withNamedPropertySources() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNamedPropertySources.class);
assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p1")).isTrue();
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
// p2 should 'win' as it was registered last
assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
}
@Test
@@ -231,16 +229,16 @@ public class PropertySourceAnnotationTests {
@Test
public void withIgnoredPropertySource() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithIgnoredPropertySource.class);
assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p1")).isTrue();
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
}
@Test
public void withSameSourceImportedInDifferentOrder() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithSameSourceImportedInDifferentOrder.class);
assertThat(ctx.getEnvironment().containsProperty("from.p1"), is(true));
assertThat(ctx.getEnvironment().containsProperty("from.p2"), is(true));
assertThat(ctx.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
assertThat(ctx.getEnvironment().containsProperty("from.p1")).isTrue();
assertThat(ctx.getEnvironment().containsProperty("from.p2")).isTrue();
assertThat(ctx.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
}
@Test
@@ -248,15 +246,15 @@ public class PropertySourceAnnotationTests {
// SPR-10820: p2 should 'win' as it was registered last
AnnotationConfigApplicationContext ctxWithName = new AnnotationConfigApplicationContext(ConfigWithNameAndMultipleResourceLocations.class);
AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext(ConfigWithMultipleResourceLocations.class);
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
assertThat(ctxWithName.getEnvironment().getProperty("testbean.name"), equalTo("p2TestBean"));
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
assertThat(ctxWithName.getEnvironment().getProperty("testbean.name")).isEqualTo("p2TestBean");
}
@Test
public void orderingWithAndWithoutNameAndFourResourceLocations() {
// SPR-12198: p4 should 'win' as it was registered last
AnnotationConfigApplicationContext ctxWithoutName = new AnnotationConfigApplicationContext(ConfigWithFourResourceLocations.class);
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name"), equalTo("p4TestBean"));
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name")).isEqualTo("p4TestBean");
}
@Test
@@ -267,7 +265,7 @@ public class PropertySourceAnnotationTests {
ctxWithoutName.getEnvironment().getPropertySources().addLast(mySource);
ctxWithoutName.register(ConfigWithFourResourceLocations.class);
ctxWithoutName.refresh();
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name"), equalTo("myTestBean"));
assertThat(ctxWithoutName.getEnvironment().getProperty("testbean.name")).isEqualTo("myTestBean");
}

View File

@@ -22,8 +22,7 @@ import org.junit.Test;
import org.springframework.util.ReflectionUtils;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
/**
@@ -46,7 +45,7 @@ public class ReflectionUtilsIntegrationTests {
m1MethodCount++;
}
}
assertThat(m1MethodCount, is(1));
assertThat(m1MethodCount).isEqualTo(1);
for (Method method : methods) {
if (method.getName().contains("m1")) {
assertEquals(method.getReturnType(), Integer.class);

View File

@@ -22,8 +22,8 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.role.ComponentWithRole;
import org.springframework.context.annotation.role.ComponentWithoutRole;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests the use of the @Role and @Description annotation on @Bean methods and @Component classes.
@@ -39,12 +39,10 @@ public class RoleAndDescriptionAnnotationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class);
ctx.refresh();
assertThat("Expected bean to have ROLE_APPLICATION",
ctx.getBeanDefinition("foo").getRole(), is(BeanDefinition.ROLE_APPLICATION));
assertThat(ctx.getBeanDefinition("foo").getDescription(), is((Object) null));
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
ctx.getBeanDefinition("bar").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
assertThat(ctx.getBeanDefinition("bar").getDescription(), is("A Bean method with a role"));
assertThat(ctx.getBeanDefinition("foo").getRole()).isEqualTo(BeanDefinition.ROLE_APPLICATION);
assertThat(ctx.getBeanDefinition("foo").getDescription()).isNull();
assertThat(ctx.getBeanDefinition("bar").getRole()).isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
assertThat(ctx.getBeanDefinition("bar").getDescription()).isEqualTo("A Bean method with a role");
}
@Test
@@ -52,12 +50,10 @@ public class RoleAndDescriptionAnnotationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ComponentWithoutRole.class, ComponentWithRole.class);
ctx.refresh();
assertThat("Expected bean to have ROLE_APPLICATION",
ctx.getBeanDefinition("componentWithoutRole").getRole(), is(BeanDefinition.ROLE_APPLICATION));
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription(), is((Object) null));
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
ctx.getBeanDefinition("componentWithRole").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription(), is("A Component with a role"));
assertThat(ctx.getBeanDefinition("componentWithoutRole").getRole()).isEqualTo(BeanDefinition.ROLE_APPLICATION);
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription()).isNull();
assertThat(ctx.getBeanDefinition("componentWithRole").getRole()).isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription()).isEqualTo("A Component with a role");
}
@@ -66,12 +62,10 @@ public class RoleAndDescriptionAnnotationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan("org.springframework.context.annotation.role");
ctx.refresh();
assertThat("Expected bean to have ROLE_APPLICATION",
ctx.getBeanDefinition("componentWithoutRole").getRole(), is(BeanDefinition.ROLE_APPLICATION));
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription(), is((Object) null));
assertThat("Expected bean to have ROLE_INFRASTRUCTURE",
ctx.getBeanDefinition("componentWithRole").getRole(), is(BeanDefinition.ROLE_INFRASTRUCTURE));
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription(), is("A Component with a role"));
assertThat(ctx.getBeanDefinition("componentWithoutRole").getRole()).isEqualTo(BeanDefinition.ROLE_APPLICATION);
assertThat(ctx.getBeanDefinition("componentWithoutRole").getDescription()).isNull();
assertThat(ctx.getBeanDefinition("componentWithRole").getRole()).isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
assertThat(ctx.getBeanDefinition("componentWithRole").getDescription()).isEqualTo("A Component with a role");
}

View File

@@ -21,9 +21,8 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
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.core.Is.is;
/**
* @author Stephane Nicoll
@@ -43,14 +42,14 @@ public class Spr12278Tests {
public void componentSingleConstructor() {
this.context = new AnnotationConfigApplicationContext(BaseConfiguration.class,
SingleConstructorComponent.class);
assertThat(this.context.getBean(SingleConstructorComponent.class).autowiredName, is("foo"));
assertThat(this.context.getBean(SingleConstructorComponent.class).autowiredName).isEqualTo("foo");
}
@Test
public void componentTwoConstructorsNoHint() {
this.context = new AnnotationConfigApplicationContext(BaseConfiguration.class,
TwoConstructorsComponent.class);
assertThat(this.context.getBean(TwoConstructorsComponent.class).name, is("fallback"));
assertThat(this.context.getBean(TwoConstructorsComponent.class).name).isEqualTo("fallback");
}
@Test

View File

@@ -22,9 +22,8 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests to verify that FactoryBean semantics are the same in Configuration
@@ -49,16 +48,16 @@ public class Spr6602Tests {
Bar bar1 = ctx.getBean(Bar.class);
Bar bar2 = ctx.getBean(Bar.class);
assertThat(bar1, is(bar2));
assertThat(bar1, is(foo.bar));
assertThat(bar1).isEqualTo(bar2);
assertThat(bar1).isEqualTo(foo.bar);
BarFactory barFactory1 = ctx.getBean(BarFactory.class);
BarFactory barFactory2 = ctx.getBean(BarFactory.class);
assertThat(barFactory1, is(barFactory2));
assertThat(barFactory1).isEqualTo(barFactory2);
Bar bar3 = barFactory1.getObject();
Bar bar4 = barFactory1.getObject();
assertThat(bar3, is(not(bar4)));
assertThat(bar3).isNotEqualTo(bar4);
}

View File

@@ -27,10 +27,8 @@ import org.springframework.beans.factory.config.InstantiationAwareBeanPostProces
import org.springframework.beans.factory.support.AbstractBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for SPR-8954, in which a custom {@link InstantiationAwareBeanPostProcessor}
@@ -53,19 +51,19 @@ public class Spr8954Tests {
bf.getBeanFactory().addBeanPostProcessor(new PredictingBPP());
bf.refresh();
assertThat(bf.getBean("foo"), instanceOf(Foo.class));
assertThat(bf.getBean("&foo"), instanceOf(FooFactoryBean.class));
assertThat(bf.getBean("foo")).isInstanceOf(Foo.class);
assertThat(bf.getBean("&foo")).isInstanceOf(FooFactoryBean.class);
assertThat(bf.isTypeMatch("&foo", FactoryBean.class), is(true));
assertThat(bf.isTypeMatch("&foo", FactoryBean.class)).isTrue();
@SuppressWarnings("rawtypes")
Map<String, FactoryBean> fbBeans = bf.getBeansOfType(FactoryBean.class);
assertThat(1, equalTo(fbBeans.size()));
assertThat("&foo", equalTo(fbBeans.keySet().iterator().next()));
assertThat(1).isEqualTo(fbBeans.size());
assertThat("&foo").isEqualTo(fbBeans.keySet().iterator().next());
Map<String, AnInterface> aiBeans = bf.getBeansOfType(AnInterface.class);
assertThat(1, equalTo(aiBeans.size()));
assertThat("&foo", equalTo(aiBeans.keySet().iterator().next()));
assertThat(1).isEqualTo(aiBeans.size());
assertThat("&foo").isEqualTo(aiBeans.keySet().iterator().next());
}
@Test
@@ -75,16 +73,16 @@ public class Spr8954Tests {
bf.getBeanFactory().addBeanPostProcessor(new PredictingBPP());
bf.refresh();
assertThat(bf.isTypeMatch("&foo", FactoryBean.class), is(true));
assertThat(bf.isTypeMatch("&foo", FactoryBean.class)).isTrue();
@SuppressWarnings("rawtypes")
Map<String, FactoryBean> fbBeans = bf.getBeansOfType(FactoryBean.class);
assertThat(1, equalTo(fbBeans.size()));
assertThat("&foo", equalTo(fbBeans.keySet().iterator().next()));
assertThat(1).isEqualTo(fbBeans.size());
assertThat("&foo").isEqualTo(fbBeans.keySet().iterator().next());
Map<String, AnInterface> aiBeans = bf.getBeansOfType(AnInterface.class);
assertThat(1, equalTo(aiBeans.size()));
assertThat("&foo", equalTo(aiBeans.keySet().iterator().next()));
assertThat(1).isEqualTo(aiBeans.size());
assertThat("&foo").isEqualTo(aiBeans.keySet().iterator().next());
}

View File

@@ -44,8 +44,7 @@ import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.Colour;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -65,8 +64,8 @@ public class AutowiredConfigurationTests {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
AutowiredConfigurationTests.class.getSimpleName() + ".xml", AutowiredConfigurationTests.class);
assertThat(context.getBean("colour", Colour.class), equalTo(Colour.RED));
assertThat(context.getBean("testBean", TestBean.class).getName(), equalTo(Colour.RED.toString()));
assertThat(context.getBean("colour", Colour.class)).isEqualTo(Colour.RED);
assertThat(context.getBean("testBean", TestBean.class).getName()).isEqualTo(Colour.RED.toString());
}
@Test
@@ -74,8 +73,8 @@ public class AutowiredConfigurationTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
AutowiredMethodConfig.class, ColorConfig.class);
assertThat(context.getBean(Colour.class), equalTo(Colour.RED));
assertThat(context.getBean(TestBean.class).getName(), equalTo("RED-RED"));
assertThat(context.getBean(Colour.class)).isEqualTo(Colour.RED);
assertThat(context.getBean(TestBean.class).getName()).isEqualTo("RED-RED");
}
@Test
@@ -83,8 +82,8 @@ public class AutowiredConfigurationTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
OptionalAutowiredMethodConfig.class, ColorConfig.class);
assertThat(context.getBean(Colour.class), equalTo(Colour.RED));
assertThat(context.getBean(TestBean.class).getName(), equalTo("RED-RED"));
assertThat(context.getBean(Colour.class)).isEqualTo(Colour.RED);
assertThat(context.getBean(TestBean.class).getName()).isEqualTo("RED-RED");
}
@Test
@@ -93,7 +92,7 @@ public class AutowiredConfigurationTests {
OptionalAutowiredMethodConfig.class);
assertTrue(context.getBeansOfType(Colour.class).isEmpty());
assertThat(context.getBean(TestBean.class).getName(), equalTo(""));
assertThat(context.getBean(TestBean.class).getName()).isEqualTo("");
}
@Test
@@ -186,10 +185,10 @@ public class AutowiredConfigurationTests {
System.setProperty("myProp", "foo");
testBean = context.getBean("testBean", TestBean.class);
assertThat(testBean.getName(), equalTo("foo"));
assertThat(testBean.getName()).isEqualTo("foo");
testBean = context.getBean("testBean2", TestBean.class);
assertThat(testBean.getName(), equalTo("foo"));
assertThat(testBean.getName()).isEqualTo("foo");
System.clearProperty("myProp");
@@ -206,8 +205,8 @@ public class AutowiredConfigurationTests {
"AutowiredConfigurationTests-custom.xml", AutowiredConfigurationTests.class);
TestBean testBean = context.getBean("testBean", TestBean.class);
assertThat(testBean.getName(), equalTo("localhost"));
assertThat(testBean.getAge(), equalTo(contentLength()));
assertThat(testBean.getName()).isEqualTo("localhost");
assertThat(testBean.getAge()).isEqualTo(contentLength());
}
@Test
@@ -218,8 +217,8 @@ public class AutowiredConfigurationTests {
context.refresh();
TestBean testBean = context.getBean("testBean", TestBean.class);
assertThat(testBean.getName(), equalTo("localhost"));
assertThat(testBean.getAge(), equalTo(contentLength()));
assertThat(testBean.getName()).isEqualTo("localhost");
assertThat(testBean.getAge()).isEqualTo(contentLength());
}
private int contentLength() throws IOException {

View File

@@ -35,8 +35,7 @@ import org.springframework.stereotype.Component;
import org.springframework.tests.sample.beans.NestedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -56,8 +55,8 @@ public class BeanMethodQualificationTests {
new AnnotationConfigApplicationContext(StandardConfig.class, StandardPojo.class);
assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
StandardPojo pojo = ctx.getBean(StandardPojo.class);
assertThat(pojo.testBean.getName(), equalTo("interesting"));
assertThat(pojo.testBean2.getName(), equalTo("boring"));
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
assertThat(pojo.testBean2.getName()).isEqualTo("boring");
}
@Test
@@ -66,8 +65,8 @@ public class BeanMethodQualificationTests {
new AnnotationConfigApplicationContext(ScopedConfig.class, StandardPojo.class);
assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
StandardPojo pojo = ctx.getBean(StandardPojo.class);
assertThat(pojo.testBean.getName(), equalTo("interesting"));
assertThat(pojo.testBean2.getName(), equalTo("boring"));
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
assertThat(pojo.testBean2.getName()).isEqualTo("boring");
}
@Test
@@ -76,8 +75,8 @@ public class BeanMethodQualificationTests {
new AnnotationConfigApplicationContext(ScopedProxyConfig.class, StandardPojo.class);
assertTrue(ctx.getBeanFactory().containsSingleton("testBean1")); // a shared scoped proxy
StandardPojo pojo = ctx.getBean(StandardPojo.class);
assertThat(pojo.testBean.getName(), equalTo("interesting"));
assertThat(pojo.testBean2.getName(), equalTo("boring"));
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
assertThat(pojo.testBean2.getName()).isEqualTo("boring");
}
@Test
@@ -89,10 +88,10 @@ public class BeanMethodQualificationTests {
assertTrue(BeanFactoryAnnotationUtils.isQualifierMatch(value -> value.equals("boring"),
"testBean2", ctx.getDefaultListableBeanFactory()));
CustomPojo pojo = ctx.getBean(CustomPojo.class);
assertThat(pojo.testBean.getName(), equalTo("interesting"));
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
TestBean testBean2 = BeanFactoryAnnotationUtils.qualifiedBeanOfType(
ctx.getDefaultListableBeanFactory(), TestBean.class, "boring");
assertThat(testBean2.getName(), equalTo("boring"));
assertThat(testBean2.getName()).isEqualTo("boring");
}
@Test
@@ -106,7 +105,7 @@ public class BeanMethodQualificationTests {
assertTrue(BeanFactoryAnnotationUtils.isQualifierMatch(value -> value.equals("boring"),
"testBean2", ctx.getDefaultListableBeanFactory()));
CustomPojo pojo = ctx.getBean(CustomPojo.class);
assertThat(pojo.testBean.getName(), equalTo("interesting"));
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
}
@Test
@@ -120,7 +119,7 @@ public class BeanMethodQualificationTests {
assertFalse(ctx.getBeanFactory().containsSingleton("testBean1"));
assertFalse(ctx.getBeanFactory().containsSingleton("testBean2"));
CustomPojo pojo = ctx.getBean(CustomPojo.class);
assertThat(pojo.testBean.getName(), equalTo("interesting"));
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
}
@Test
@@ -129,7 +128,7 @@ public class BeanMethodQualificationTests {
new AnnotationConfigApplicationContext(CustomConfigWithAttributeOverride.class, CustomPojo.class);
assertFalse(ctx.getBeanFactory().containsSingleton("testBeanX"));
CustomPojo pojo = ctx.getBean(CustomPojo.class);
assertThat(pojo.testBean.getName(), equalTo("interesting"));
assertThat(pojo.testBean.getName()).isEqualTo("interesting");
}
@Test

View File

@@ -27,8 +27,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests ensuring that configuration class bean names as expressed via @Configuration
@@ -45,10 +45,10 @@ public class ConfigurationBeanNameTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(A.class);
ctx.refresh();
assertThat(ctx.containsBean("outer"), is(true));
assertThat(ctx.containsBean("imported"), is(true));
assertThat(ctx.containsBean("nested"), is(true));
assertThat(ctx.containsBean("nestedBean"), is(true));
assertThat(ctx.containsBean("outer")).isTrue();
assertThat(ctx.containsBean("imported")).isTrue();
assertThat(ctx.containsBean("nested")).isTrue();
assertThat(ctx.containsBean("nestedBean")).isTrue();
}
@Test
@@ -56,10 +56,10 @@ public class ConfigurationBeanNameTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(A.B.class);
ctx.refresh();
assertThat(ctx.containsBean("outer"), is(false));
assertThat(ctx.containsBean("imported"), is(false));
assertThat(ctx.containsBean("nested"), is(true));
assertThat(ctx.containsBean("nestedBean"), is(true));
assertThat(ctx.containsBean("outer")).isFalse();
assertThat(ctx.containsBean("imported")).isFalse();
assertThat(ctx.containsBean("nested")).isTrue();
assertThat(ctx.containsBean("nestedBean")).isTrue();
}
@Test
@@ -74,10 +74,10 @@ public class ConfigurationBeanNameTests {
});
ctx.register(A.class);
ctx.refresh();
assertThat(ctx.containsBean("custom-outer"), is(true));
assertThat(ctx.containsBean("custom-imported"), is(true));
assertThat(ctx.containsBean("custom-nested"), is(true));
assertThat(ctx.containsBean("nestedBean"), is(true));
assertThat(ctx.containsBean("custom-outer")).isTrue();
assertThat(ctx.containsBean("custom-imported")).isTrue();
assertThat(ctx.containsBean("custom-nested")).isTrue();
assertThat(ctx.containsBean("nestedBean")).isTrue();
}
@Configuration("outer")

View File

@@ -35,8 +35,8 @@ import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* System tests covering use of AspectJ {@link Aspect}s in conjunction with {@link Configuration} classes.
@@ -73,9 +73,9 @@ public class ConfigurationClassAspectIntegrationTests {
ctx.refresh();
TestBean testBean = ctx.getBean("testBean", TestBean.class);
assertThat(testBean.getName(), equalTo("name"));
assertThat(testBean.getName()).isEqualTo("name");
testBean.absquatulate();
assertThat(testBean.getName(), equalTo("advisedName"));
assertThat(testBean.getName()).isEqualTo("advisedName");
}
@Test

View File

@@ -26,9 +26,8 @@ import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* A configuration class that registers a non-static placeholder configurer {@code @Bean}
@@ -71,7 +70,7 @@ public class ConfigurationClassWithPlaceholderConfigurerBeanTests {
TestBean testBean = ctx.getBean(TestBean.class);
// Proof that the @Value field did not get set:
assertThat(testBean.getName(), nullValue());
assertThat(testBean.getName()).isNull();
}
@Test
@@ -84,7 +83,7 @@ public class ConfigurationClassWithPlaceholderConfigurerBeanTests {
System.clearProperty("test.name");
TestBean testBean = ctx.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("foo"));
assertThat(testBean.getName()).isEqualTo("foo");
}
@Test
@@ -98,7 +97,7 @@ public class ConfigurationClassWithPlaceholderConfigurerBeanTests {
System.clearProperty("test.name");
TestBean testBean = ctx.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("foo"));
assertThat(testBean.getName()).isEqualTo("foo");
}
@Test
@@ -110,7 +109,7 @@ public class ConfigurationClassWithPlaceholderConfigurerBeanTests {
ctx.refresh();
TestBean testBean = ctx.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("bar"));
assertThat(testBean.getName()).isEqualTo("bar");
}
@Test
@@ -122,7 +121,7 @@ public class ConfigurationClassWithPlaceholderConfigurerBeanTests {
ctx.refresh();
TestBean testBean = ctx.getBean(TestBean.class);
assertThat(testBean.getName(), equalTo("bar"));
assertThat(testBean.getName()).isEqualTo("bar");
}

View File

@@ -26,9 +26,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Ensures that @Configuration is supported properly as a meta-annotation.
@@ -42,10 +41,10 @@ public class ConfigurationMetaAnnotationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(Config.class);
ctx.refresh();
assertThat(ctx.containsBean("customName"), is(true));
assertThat(ctx.containsBean("customName")).isTrue();
TestBean a = ctx.getBean("a", TestBean.class);
TestBean b = ctx.getBean("b", TestBean.class);
assertThat(b, sameInstance(a.getSpouse()));
assertThat(b).isSameAs(a.getSpouse());
}

View File

@@ -29,8 +29,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests that @Import may be used both as a locally declared and meta-declared
@@ -48,8 +48,8 @@ public class ImportAnnotationDetectionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(MultiMetaImportConfig.class);
ctx.refresh();
assertThat(ctx.containsBean("testBean1"), is(true));
assertThat(ctx.containsBean("testBean2"), is(true));
assertThat(ctx.containsBean("testBean1")).isTrue();
assertThat(ctx.containsBean("testBean2")).isTrue();
}
@Test
@@ -57,9 +57,9 @@ public class ImportAnnotationDetectionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(MultiMetaImportConfigWithLocalImport.class);
ctx.refresh();
assertThat(ctx.containsBean("testBean1"), is(true));
assertThat(ctx.containsBean("testBean2"), is(true));
assertThat(ctx.containsBean("testBean3"), is(true));
assertThat(ctx.containsBean("testBean1")).isTrue();
assertThat(ctx.containsBean("testBean2")).isTrue();
assertThat(ctx.containsBean("testBean3")).isTrue();
}
@Test
@@ -67,9 +67,9 @@ public class ImportAnnotationDetectionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(MultiMetaImportConfigWithLocalImportWithBeanOverride.class);
ctx.refresh();
assertThat(ctx.containsBean("testBean1"), is(true));
assertThat(ctx.containsBean("testBean2"), is(true));
assertThat(ctx.getBean("testBean2", TestBean.class).getName(), is("2a"));
assertThat(ctx.containsBean("testBean1")).isTrue();
assertThat(ctx.containsBean("testBean2")).isTrue();
assertThat(ctx.getBean("testBean2", TestBean.class).getName()).isEqualTo("2a");
}
@Test
@@ -77,9 +77,9 @@ public class ImportAnnotationDetectionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImportFromBean.class);
ctx.refresh();
assertThat(ctx.containsBean("importAnnotationDetectionTests.ImportFromBean"), is(true));
assertThat(ctx.containsBean("testBean1"), is(true));
assertThat(ctx.getBean("testBean1", TestBean.class).getName(), is("1"));
assertThat(ctx.containsBean("importAnnotationDetectionTests.ImportFromBean")).isTrue();
assertThat(ctx.containsBean("testBean1")).isTrue();
assertThat(ctx.getBean("testBean1", TestBean.class).getName()).isEqualTo("1");
}
@Configuration

View File

@@ -34,8 +34,7 @@ import org.springframework.core.env.MapPropertySource;
import org.springframework.core.env.PropertySource;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.equalTo;
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.assertTrue;
@@ -107,7 +106,7 @@ public class ImportResourceTests {
public void importXmlWithAutowiredConfig() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ImportXmlAutowiredConfig.class);
String name = ctx.getBean("xmlBeanName", String.class);
assertThat(name, equalTo("xml.declared"));
assertThat(name).isEqualTo("xml.declared");
ctx.close();
}

View File

@@ -29,9 +29,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/**
@@ -54,7 +52,7 @@ public class ImportTests {
private void assertBeanDefinitionCount(int expectedCount, Class<?>... classes) {
DefaultListableBeanFactory beanFactory = processConfigurationClasses(classes);
assertThat(beanFactory.getBeanDefinitionCount(), equalTo(expectedCount));
assertThat(beanFactory.getBeanDefinitionCount()).isEqualTo(expectedCount);
beanFactory.preInstantiateSingletons();
for (Class<?> clazz : classes) {
beanFactory.getBean(clazz);
@@ -70,7 +68,7 @@ public class ImportTests {
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(ConfigurationWithImportAnnotation.class.getName()));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
assertThat(beanFactory.getBeanDefinitionCount(), equalTo(configClasses + beansInClasses));
assertThat(beanFactory.getBeanDefinitionCount()).isEqualTo(configClasses + beansInClasses);
}
@Test
@@ -178,8 +176,8 @@ public class ImportTests {
WithMultipleArgumentsThatWillCauseDuplication.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
assertThat(beanFactory.getBeanDefinitionCount(), equalTo(4));
assertThat(beanFactory.getBean("foo", ITestBean.class).getName(), equalTo("foo2"));
assertThat(beanFactory.getBeanDefinitionCount()).isEqualTo(4);
assertThat(beanFactory.getBean("foo", ITestBean.class).getName()).isEqualTo("foo2");
}
@Configuration
@@ -341,8 +339,8 @@ public class ImportTests {
ctx.register(B.class);
ctx.refresh();
System.out.println(ctx.getBeanFactory());
assertThat(ctx.getBeanNamesForType(B.class)[0], is("config-b"));
assertThat(ctx.getBeanNamesForType(A.class)[0], is("config-a"));
assertThat(ctx.getBeanNamesForType(B.class)[0]).isEqualTo("config-b");
assertThat(ctx.getBeanNamesForType(A.class)[0]).isEqualTo("config-a");
}
@Configuration("config-a")

View File

@@ -27,8 +27,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.ClassUtils;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -73,8 +72,9 @@ public class ImportedConfigurationClassEnhancementTests {
Config config = ctx.getBean(Config.class);
TestBean testBean1 = config.autowiredConfig.testBean();
TestBean testBean2 = config.autowiredConfig.testBean();
assertThat("got two distinct instances of testBean when singleton scoping was expected",
testBean1, sameInstance(testBean2));
assertThat(testBean1)
.as("got two distinct instances of testBean when singleton scoping was expected")
.isSameAs(testBean2);
}

View File

@@ -22,9 +22,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Reproduces SPR-8756, which has been marked as "won't fix" for reasons
@@ -42,7 +41,7 @@ public class PackagePrivateBeanMethodInheritanceTests {
Foo foo1 = ctx.getBean("foo1", Foo.class);
Foo foo2 = ctx.getBean("foo2", Foo.class);
ctx.getBean("packagePrivateBar", Bar.class); // <-- i.e. @Bean was registered
assertThat(foo1.bar, not(is(foo2.bar))); // <-- i.e. @Bean *not* enhanced
assertThat(foo1.bar).isNotEqualTo(foo2.bar); // <-- i.e. @Bean *not* enhanced
}
@Test
@@ -52,8 +51,8 @@ public class PackagePrivateBeanMethodInheritanceTests {
ctx.refresh();
Foo foo1 = ctx.getBean("foo1", Foo.class);
Foo foo2 = ctx.getBean("foo2", Foo.class);
ctx.getBean("protectedBar", Bar.class); // <-- i.e. @Bean was registered
assertThat(foo1.bar, is(foo2.bar)); // <-- i.e. @Bean *was* enhanced
ctx.getBean("protectedBar", Bar.class); // <-- i.e. @Bean was registered
assertThat(foo1.bar).isEqualTo(foo2.bar); // <-- i.e. @Bean *was* enhanced
}
public static class Foo {

View File

@@ -25,9 +25,10 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.sameInstance;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Phillip Webb
@@ -48,19 +49,19 @@ public class Spr10744Tests {
Foo bean1 = context.getBean("foo", Foo.class);
Foo bean2 = context.getBean("foo", Foo.class);
assertThat(bean1, sameInstance(bean2));
assertThat(bean1).isSameAs(bean2);
// Should not have invoked constructor for the proxy instance
assertThat(createCount, equalTo(0));
assertThat(scopeCount, equalTo(0));
assertThat(createCount).isEqualTo(0);
assertThat(scopeCount).isEqualTo(0);
// Proxy mode should create new scoped object on each method call
bean1.getMessage();
assertThat(createCount, equalTo(1));
assertThat(scopeCount, equalTo(1));
assertThat(createCount).isEqualTo(1);
assertThat(scopeCount).isEqualTo(1);
bean1.getMessage();
assertThat(createCount, equalTo(2));
assertThat(scopeCount, equalTo(2));
assertThat(createCount).isEqualTo(2);
assertThat(scopeCount).isEqualTo(2);
context.close();
}

View File

@@ -28,8 +28,7 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.ClassUtils;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
public class Spr7167Tests {
@@ -38,9 +37,9 @@ public class Spr7167Tests {
public void test() {
ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(MyConfig.class);
assertThat("someDependency was not post processed",
ctx.getBeanFactory().getBeanDefinition("someDependency").getDescription(),
equalTo("post processed by MyPostProcessor"));
assertThat(ctx.getBeanFactory().getBeanDefinition("someDependency").getDescription())
.as("someDependency was not post processed")
.isEqualTo("post processed by MyPostProcessor");
MyConfig config = ctx.getBean(MyConfig.class);
assertTrue("Config class was not enhanced", ClassUtils.isCglibProxy(config));

View File

@@ -29,9 +29,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.configuration.spr9031.scanpackage.Spr9031Component;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests cornering bug SPR-9031.
@@ -50,7 +49,7 @@ public class Spr9031Tests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(HighLevelConfig.class);
ctx.refresh();
assertThat(ctx.getBean(LowLevelConfig.class).scanned, not(nullValue()));
assertThat(ctx.getBean(LowLevelConfig.class).scanned).isNotNull();
}
/**
@@ -62,7 +61,7 @@ public class Spr9031Tests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(LowLevelConfig.class);
ctx.refresh();
assertThat(ctx.getBean(LowLevelConfig.class).scanned, not(nullValue()));
assertThat(ctx.getBean(LowLevelConfig.class).scanned).isNotNull();
}
@Configuration

View File

@@ -25,8 +25,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.spr10546.scanpackage.AEnclosingConfig;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Winch
@@ -64,7 +64,7 @@ public class Spr10546Tests {
context = ctx;
ctx.scan(AEnclosingConfig.class.getPackage().getName());
ctx.refresh();
assertThat(context.getBean("myBean",String.class), equalTo("myBean"));
assertThat(context.getBean("myBean",String.class)).isEqualTo("myBean");
}
@Test
@@ -143,7 +143,7 @@ public class Spr10546Tests {
private void assertLoadsMyBean(Class<?>... annotatedClasses) {
context = new AnnotationConfigApplicationContext(annotatedClasses);
assertThat(context.getBean("myBean",String.class), equalTo("myBean"));
assertThat(context.getBean("myBean",String.class)).isEqualTo("myBean");
}
}

View File

@@ -24,8 +24,8 @@ import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Component;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests cornering the regression reported in SPR-8761.
@@ -43,7 +43,7 @@ public class Spr8761Tests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.scan(getClass().getPackage().getName());
ctx.refresh();
assertThat(ctx.containsBean("withNestedAnnotation"), is(true));
assertThat(ctx.containsBean("withNestedAnnotation")).isTrue();
}
}

View File

@@ -64,10 +64,9 @@ import org.springframework.util.Assert;
import org.springframework.validation.annotation.Validated;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
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.hamcrest.Matchers.contains;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
@@ -548,7 +547,7 @@ public class AnnotationDrivenEventListenerTests {
assertTrue(listener.order.isEmpty());
this.context.publishEvent("whatever");
assertThat(listener.order, contains("first", "second", "third"));
assertThat(listener.order).contains("first", "second", "third");
}
@Test @Ignore // SPR-15122
@@ -556,7 +555,7 @@ public class AnnotationDrivenEventListenerTests {
load(EventOnPostConstruct.class, OrderedTestListener.class);
OrderedTestListener listener = this.context.getBean(OrderedTestListener.class);
assertThat(listener.order, contains("first", "second", "third"));
assertThat(listener.order).contains("first", "second", "third");
}

View File

@@ -24,8 +24,7 @@ import org.springframework.context.support.GenericApplicationContext;
import org.springframework.mock.env.MockPropertySource;
import org.springframework.tests.sample.beans.TestBean;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;
/**
@@ -49,7 +48,7 @@ public class EnvironmentAccessorIntegrationTests {
ctx.getEnvironment().getPropertySources().addFirst(new MockPropertySource().withProperty("my.name", "myBean"));
ctx.refresh();
assertThat(ctx.getBean(TestBean.class).getName(), equalTo("myBean"));
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("myBean");
ctx.close();
}

View File

@@ -23,12 +23,13 @@ import org.junit.Test;
import org.springframework.core.io.ClassPathResource;
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.containsInAnyOrder;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
/**
* Tests for {@link CandidateComponentsIndexLoader}.
@@ -40,7 +41,7 @@ public class CandidateComponentsIndexLoaderTests {
@Test
public void validateIndexIsDisabledByDefault() {
CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex(null);
assertThat("No spring.components should be available at the default location", index, is(nullValue()));
assertThat(index).as("No spring.components should be available at the default location").isNull();
}
@Test
@@ -49,9 +50,9 @@ public class CandidateComponentsIndexLoaderTests {
CandidateComponentsTestClassLoader.index(getClass().getClassLoader(),
new ClassPathResource("spring.components", getClass())));
Set<String> components = index.getCandidateTypes("org.springframework", "foo");
assertThat(components, containsInAnyOrder(
assertThat(components).contains(
"org.springframework.context.index.Sample1",
"org.springframework.context.index.Sample2"));
"org.springframework.context.index.Sample2");
}
@Test
@@ -60,8 +61,8 @@ public class CandidateComponentsIndexLoaderTests {
CandidateComponentsTestClassLoader.index(getClass().getClassLoader(),
new ClassPathResource("spring.components", getClass())));
Set<String> components = index.getCandidateTypes("org.springframework", "biz");
assertThat(components, containsInAnyOrder(
"org.springframework.context.index.Sample3"));
assertThat(components).contains(
"org.springframework.context.index.Sample3");
}
@Test
@@ -70,7 +71,7 @@ public class CandidateComponentsIndexLoaderTests {
CandidateComponentsTestClassLoader.index(getClass().getClassLoader(),
new ClassPathResource("spring.components", getClass())));
Set<String> components = index.getCandidateTypes("org.springframework", "none");
assertThat(components, hasSize(0));
assertThat(components).isEmpty();
}
@Test
@@ -79,14 +80,14 @@ public class CandidateComponentsIndexLoaderTests {
CandidateComponentsTestClassLoader.index(getClass().getClassLoader(),
new ClassPathResource("spring.components", getClass())));
Set<String> components = index.getCandidateTypes("com.example", "foo");
assertThat(components, hasSize(0));
assertThat(components).isEmpty();
}
@Test
public void loadIndexNoSpringComponentsResource() {
CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex(
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader()));
assertThat(index, is(nullValue()));
assertThat(index).isNull();
}
@Test
@@ -94,7 +95,7 @@ public class CandidateComponentsIndexLoaderTests {
CandidateComponentsIndex index = CandidateComponentsIndexLoader.loadIndex(
CandidateComponentsTestClassLoader.index(getClass().getClassLoader(),
new ClassPathResource("empty-spring.components", getClass())));
assertThat(index, is(nullValue()));
assertThat(index).isNull();
}
@Test

View File

@@ -23,10 +23,11 @@ import java.util.Set;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.hasSize;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link CandidateComponentsIndex}.
@@ -40,8 +41,8 @@ public class CandidateComponentsIndexTests {
CandidateComponentsIndex index = new CandidateComponentsIndex(
Collections.singletonList(createSampleProperties()));
Set<String> actual = index.getCandidateTypes("com.example.service", "service");
assertThat(actual, containsInAnyOrder("com.example.service.One",
"com.example.service.sub.Two", "com.example.service.Three"));
assertThat(actual).contains("com.example.service.One",
"com.example.service.sub.Two", "com.example.service.Three");
}
@Test
@@ -49,7 +50,7 @@ public class CandidateComponentsIndexTests {
CandidateComponentsIndex index = new CandidateComponentsIndex(
Collections.singletonList(createSampleProperties()));
Set<String> actual = index.getCandidateTypes("com.example.service.sub", "service");
assertThat(actual, containsInAnyOrder("com.example.service.sub.Two"));
assertThat(actual).contains("com.example.service.sub.Two");
}
@Test
@@ -57,7 +58,7 @@ public class CandidateComponentsIndexTests {
CandidateComponentsIndex index = new CandidateComponentsIndex(
Collections.singletonList(createSampleProperties()));
Set<String> actual = index.getCandidateTypes("com.example.service.none", "service");
assertThat(actual, hasSize(0));
assertThat(actual).isEmpty();
}
@Test
@@ -65,7 +66,7 @@ public class CandidateComponentsIndexTests {
CandidateComponentsIndex index = new CandidateComponentsIndex(
Collections.singletonList(createSampleProperties()));
Set<String> actual = index.getCandidateTypes("com.example.service", "entity");
assertThat(actual, hasSize(0));
assertThat(actual).isEmpty();
}
@Test
@@ -73,10 +74,10 @@ public class CandidateComponentsIndexTests {
CandidateComponentsIndex index = new CandidateComponentsIndex(Arrays.asList(
createProperties("com.example.Foo", "service"),
createProperties("com.example.Foo", "entity")));
assertThat(index.getCandidateTypes("com.example", "service"),
contains("com.example.Foo"));
assertThat(index.getCandidateTypes("com.example", "entity"),
contains("com.example.Foo"));
assertThat(index.getCandidateTypes("com.example", "service"))
.contains("com.example.Foo");
assertThat(index.getCandidateTypes("com.example", "entity"))
.contains("com.example.Foo");
}
private static Properties createProperties(String key, String stereotypes) {

View File

@@ -34,9 +34,8 @@ import org.springframework.core.io.FileSystemResource;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.ResourceTestBean;
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.instanceOf;
import static org.junit.Assert.assertTrue;
/**
@@ -142,8 +141,8 @@ public class ConversionServiceFactoryBeanTests {
public ComplexConstructorArgument(Map<String, Class<?>> map) {
assertTrue(!map.isEmpty());
assertThat(map.keySet().iterator().next(), instanceOf(String.class));
assertThat(map.values().iterator().next(), instanceOf(Class.class));
assertThat(map.keySet().iterator().next()).isInstanceOf(String.class);
assertThat(map.values().iterator().next()).isInstanceOf(Class.class);
}
}

View File

@@ -24,9 +24,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.Environment;
import static org.hamcrest.CoreMatchers.anyOf;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests covering the integration of the {@link Environment} into
@@ -47,10 +46,7 @@ public class EnvironmentIntegrationTests {
child.refresh();
ConfigurableEnvironment env = child.getBean(ConfigurableEnvironment.class);
assertThat("unknown env", env, anyOf(
sameInstance(parent.getEnvironment()),
sameInstance(child.getEnvironment())));
assertThat("expected child ctx env", env, sameInstance(child.getEnvironment()));
assertThat(env).isSameAs(child.getEnvironment());
child.close();
parent.close();

View File

@@ -32,8 +32,8 @@ import org.springframework.core.env.StandardEnvironmentTests;
import org.springframework.stereotype.Component;
import static java.lang.String.format;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests integration between Environment and SecurityManagers. See SPR-9970.
@@ -78,7 +78,7 @@ public class EnvironmentSecurityManagerIntegrationTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(bf);
reader.register(C1.class);
assertThat(bf.containsBean("c1"), is(true));
assertThat(bf.containsBean("c1")).isTrue();
}
@Test
@@ -108,7 +108,7 @@ public class EnvironmentSecurityManagerIntegrationTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(bf);
reader.register(C1.class);
assertThat(bf.containsBean("c1"), is(false));
assertThat(bf.containsBean("c1")).isFalse();
}

View File

@@ -21,8 +21,8 @@ import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.util.ClassUtils;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link GenericXmlApplicationContext}.
@@ -43,7 +43,7 @@ public class GenericXmlApplicationContextTests {
@Test
public void classRelativeResourceLoading_ctor() {
ApplicationContext ctx = new GenericXmlApplicationContext(RELATIVE_CLASS, RESOURCE_NAME);
assertThat(ctx.containsBean(TEST_BEAN_NAME), is(true));
assertThat(ctx.containsBean(TEST_BEAN_NAME)).isTrue();
}
@Test
@@ -51,13 +51,13 @@ public class GenericXmlApplicationContextTests {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load(RELATIVE_CLASS, RESOURCE_NAME);
ctx.refresh();
assertThat(ctx.containsBean(TEST_BEAN_NAME), is(true));
assertThat(ctx.containsBean(TEST_BEAN_NAME)).isTrue();
}
@Test
public void fullyQualifiedResourceLoading_ctor() {
ApplicationContext ctx = new GenericXmlApplicationContext(FQ_RESOURCE_PATH);
assertThat(ctx.containsBean(TEST_BEAN_NAME), is(true));
assertThat(ctx.containsBean(TEST_BEAN_NAME)).isTrue();
}
@Test
@@ -65,6 +65,6 @@ public class GenericXmlApplicationContextTests {
GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
ctx.load(FQ_RESOURCE_PATH);
ctx.refresh();
assertThat(ctx.containsBean(TEST_BEAN_NAME), is(true));
assertThat(ctx.containsBean(TEST_BEAN_NAME)).isTrue();
}
}

View File

@@ -33,13 +33,9 @@ import org.springframework.mock.env.MockEnvironment;
import org.springframework.mock.env.MockPropertySource;
import org.springframework.tests.sample.beans.TestBean;
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.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
@@ -66,8 +62,8 @@ public class PropertySourcesPlaceholderConfigurerTests {
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setEnvironment(env);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("myValue"));
assertThat(ppc.getAppliedPropertySources(), not(nullValue()));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("myValue");
assertThat(ppc.getAppliedPropertySources()).isNotNull();
}
@Test
@@ -82,7 +78,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
Resource resource = new ClassPathResource("PropertySourcesPlaceholderConfigurerTests.properties", this.getClass());
ppc.setLocation(resource);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("foo"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("foo");
}
@Test
@@ -109,7 +105,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setPropertySources(propertySources);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("foo"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("foo");
assertEquals(ppc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next());
}
@@ -129,7 +125,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
ppc.setEnvironment(new MockEnvironment().withProperty("my.name", "env"));
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("${my.name}"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("${my.name}");
assertEquals(ppc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next());
}
@@ -152,7 +148,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
}});
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("${my.name}"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("${my.name}");
}
@Test
@@ -180,7 +176,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("${my.name}"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("${my.name}");
}
@Test
@@ -215,7 +211,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
}});
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("${bogus}"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("${bogus}");
}
@Test
@@ -240,7 +236,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
ppc.setEnvironment(env);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("bar"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("bar");
}
@SuppressWarnings("serial")
@@ -260,10 +256,10 @@ public class PropertySourcesPlaceholderConfigurerTests {
ppc.setEnvironment(new MockEnvironment().withProperty("foo", "enclosing"));
ppc.postProcessBeanFactory(bf);
if (override) {
assertThat(bf.getBean(TestBean.class).getName(), equalTo("local"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("local");
}
else {
assertThat(bf.getBean(TestBean.class).getName(), equalTo("enclosing"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("enclosing");
}
}
@@ -287,8 +283,8 @@ public class PropertySourcesPlaceholderConfigurerTests {
System.clearProperty("key1");
System.clearProperty("key2");
assertThat(bf.getBean(TestBean.class).getName(), is("systemKey1Value"));
assertThat(bf.getBean(TestBean.class).getSex(), is("${key2}"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("systemKey1Value");
assertThat(bf.getBean(TestBean.class).getSex()).isEqualTo("${key2}");
}
@Test
@@ -301,7 +297,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
.getBeanDefinition());
ppc.setEnvironment(new MockEnvironment().withProperty("my.name", "customNull"));
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), nullValue());
assertThat(bf.getBean(TestBean.class).getName()).isNull();
}
@Test
@@ -313,7 +309,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
.getBeanDefinition());
ppc.setEnvironment(new MockEnvironment().withProperty("my.name", " myValue "));
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo(" myValue "));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo(" myValue ");
}
@Test
@@ -326,7 +322,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
.getBeanDefinition());
ppc.setEnvironment(new MockEnvironment().withProperty("my.name", " myValue "));
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo("myValue"));
assertThat(bf.getBean(TestBean.class).getName()).isEqualTo("myValue");
}
@Test
@@ -351,7 +347,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
.addPropertyValue("jedi", "${jedi:false}")
.getBeanDefinition());
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).isJedi(), equalTo(true));
assertThat(bf.getBean(TestBean.class).isJedi()).isEqualTo(true);
}
@Test
@@ -370,7 +366,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
ppc.setEnvironment(env);
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(OptionalTestBean.class).getName(), equalTo(Optional.of("myValue")));
assertThat(bf.getBean(OptionalTestBean.class).getName()).isEqualTo(Optional.of("myValue"));
}
@Test
@@ -390,7 +386,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
ppc.setIgnoreUnresolvablePlaceholders(true);
ppc.setNullValue("");
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(OptionalTestBean.class).getName(), equalTo(Optional.empty()));
assertThat(bf.getBean(OptionalTestBean.class).getName()).isEqualTo(Optional.empty());
}

View File

@@ -28,8 +28,7 @@ import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.context.ConfigurableApplicationContext;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.rootBeanDefinition;
/**
@@ -79,17 +78,17 @@ public class SerializableBeanFactoryMemoryLeakTests {
}
private void assertFactoryCountThroughoutLifecycle(ConfigurableApplicationContext ctx) throws Exception {
assertThat(serializableFactoryCount(), equalTo(0));
assertThat(serializableFactoryCount()).isEqualTo(0);
try {
ctx.refresh();
assertThat(serializableFactoryCount(), equalTo(1));
assertThat(serializableFactoryCount()).isEqualTo(1);
ctx.close();
}
catch (BeanCreationException ex) {
// ignore - this is expected on refresh() for failure case tests
}
finally {
assertThat(serializableFactoryCount(), equalTo(0));
assertThat(serializableFactoryCount()).isEqualTo(0);
}
}

View File

@@ -30,10 +30,11 @@ import org.junit.Test;
import org.springframework.format.annotation.DateTimeFormat.ISO;
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.equalTo;
import static org.hamcrest.Matchers.is;
/**
* Tests for {@link DateFormatter}.
@@ -51,8 +52,8 @@ public class DateFormatterTests {
DateFormatter formatter = new DateFormatter();
formatter.setTimeZone(UTC);
Date date = getDate(2009, Calendar.JUNE, 1);
assertThat(formatter.print(date, Locale.US), is("Jun 1, 2009"));
assertThat(formatter.parse("Jun 1, 2009", Locale.US), is(date));
assertThat(formatter.print(date, Locale.US)).isEqualTo("Jun 1, 2009");
assertThat(formatter.parse("Jun 1, 2009", Locale.US)).isEqualTo(date);
}
@Test
@@ -60,8 +61,8 @@ public class DateFormatterTests {
DateFormatter formatter = new DateFormatter("yyyy-MM-dd");
formatter.setTimeZone(UTC);
Date date = getDate(2009, Calendar.JUNE, 1);
assertThat(formatter.print(date, Locale.US), is("2009-06-01"));
assertThat(formatter.parse("2009-06-01", Locale.US), is(date));
assertThat(formatter.print(date, Locale.US)).isEqualTo("2009-06-01");
assertThat(formatter.parse("2009-06-01", Locale.US)).isEqualTo(date);
}
@Test
@@ -70,8 +71,8 @@ public class DateFormatterTests {
formatter.setTimeZone(UTC);
formatter.setStyle(DateFormat.SHORT);
Date date = getDate(2009, Calendar.JUNE, 1);
assertThat(formatter.print(date, Locale.US), is("6/1/09"));
assertThat(formatter.parse("6/1/09", Locale.US), is(date));
assertThat(formatter.print(date, Locale.US)).isEqualTo("6/1/09");
assertThat(formatter.parse("6/1/09", Locale.US)).isEqualTo(date);
}
@Test
@@ -80,8 +81,8 @@ public class DateFormatterTests {
formatter.setTimeZone(UTC);
formatter.setStyle(DateFormat.MEDIUM);
Date date = getDate(2009, Calendar.JUNE, 1);
assertThat(formatter.print(date, Locale.US), is("Jun 1, 2009"));
assertThat(formatter.parse("Jun 1, 2009", Locale.US), is(date));
assertThat(formatter.print(date, Locale.US)).isEqualTo("Jun 1, 2009");
assertThat(formatter.parse("Jun 1, 2009", Locale.US)).isEqualTo(date);
}
@Test
@@ -90,8 +91,8 @@ public class DateFormatterTests {
formatter.setTimeZone(UTC);
formatter.setStyle(DateFormat.LONG);
Date date = getDate(2009, Calendar.JUNE, 1);
assertThat(formatter.print(date, Locale.US), is("June 1, 2009"));
assertThat(formatter.parse("June 1, 2009", Locale.US), is(date));
assertThat(formatter.print(date, Locale.US)).isEqualTo("June 1, 2009");
assertThat(formatter.parse("June 1, 2009", Locale.US)).isEqualTo(date);
}
@Test
@@ -100,8 +101,8 @@ public class DateFormatterTests {
formatter.setTimeZone(UTC);
formatter.setStyle(DateFormat.FULL);
Date date = getDate(2009, Calendar.JUNE, 1);
assertThat(formatter.print(date, Locale.US), is("Monday, June 1, 2009"));
assertThat(formatter.parse("Monday, June 1, 2009", Locale.US), is(date));
assertThat(formatter.print(date, Locale.US)).isEqualTo("Monday, June 1, 2009");
assertThat(formatter.parse("Monday, June 1, 2009", Locale.US)).isEqualTo(date);
}
@Test
@@ -110,9 +111,9 @@ public class DateFormatterTests {
formatter.setTimeZone(UTC);
formatter.setIso(ISO.DATE);
Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);
assertThat(formatter.print(date, Locale.US), is("2009-06-01"));
assertThat(formatter.parse("2009-6-01", Locale.US),
is(getDate(2009, Calendar.JUNE, 1)));
assertThat(formatter.print(date, Locale.US)).isEqualTo("2009-06-01");
assertThat(formatter.parse("2009-6-01", Locale.US))
.isEqualTo(getDate(2009, Calendar.JUNE, 1));
}
@Test
@@ -121,9 +122,9 @@ public class DateFormatterTests {
formatter.setTimeZone(UTC);
formatter.setIso(ISO.TIME);
Date date = getDate(2009, Calendar.JANUARY, 1, 14, 23, 5, 3);
assertThat(formatter.print(date, Locale.US), is("14:23:05.003Z"));
assertThat(formatter.parse("14:23:05.003Z", Locale.US),
is(getDate(1970, Calendar.JANUARY, 1, 14, 23, 5, 3)));
assertThat(formatter.print(date, Locale.US)).isEqualTo("14:23:05.003Z");
assertThat(formatter.parse("14:23:05.003Z", Locale.US))
.isEqualTo(getDate(1970, Calendar.JANUARY, 1, 14, 23, 5, 3));
}
@Test
@@ -132,8 +133,8 @@ public class DateFormatterTests {
formatter.setTimeZone(UTC);
formatter.setIso(ISO.DATE_TIME);
Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);
assertThat(formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003Z"));
assertThat(formatter.parse("2009-06-01T14:23:05.003Z", Locale.US), is(date));
assertThat(formatter.print(date, Locale.US)).isEqualTo("2009-06-01T14:23:05.003Z");
assertThat(formatter.parse("2009-06-01T14:23:05.003Z", Locale.US)).isEqualTo(date);
}
@Test
@@ -162,10 +163,12 @@ public class DateFormatterTests {
formatter.setStylePattern(style);
DateTimeFormatter jodaFormatter = DateTimeFormat.forStyle(style).withLocale(locale).withZone(DateTimeZone.UTC);
String jodaPrinted = jodaFormatter.print(date.getTime());
assertThat("Unable to print style pattern " + style,
formatter.print(date, locale), is(equalTo(jodaPrinted)));
assertThat("Unable to parse style pattern " + style,
formatter.parse(jodaPrinted, locale), is(equalTo(date)));
assertThat(formatter.print(date, locale))
.as("Unable to print style pattern " + style)
.isEqualTo(jodaPrinted);
assertThat(formatter.parse(jodaPrinted, locale))
.as("Unable to parse style pattern " + style)
.isEqualTo(date);
}
@Test
@@ -187,16 +190,16 @@ public class DateFormatterTests {
formatter.setPattern("yyyy");
Date date = getDate(2009, Calendar.JUNE, 1, 14, 23, 5, 3);
assertThat("uses pattern",formatter.print(date, Locale.US), is("2009"));
assertThat(formatter.print(date, Locale.US)).as("uses pattern").isEqualTo("2009");
formatter.setPattern("");
assertThat("uses ISO", formatter.print(date, Locale.US), is("2009-06-01T14:23:05.003Z"));
assertThat(formatter.print(date, Locale.US)).as("uses ISO").isEqualTo("2009-06-01T14:23:05.003Z");
formatter.setIso(ISO.NONE);
assertThat("uses style pattern", formatter.print(date, Locale.US), is("June 1, 2009"));
assertThat(formatter.print(date, Locale.US)).as("uses style pattern").isEqualTo("June 1, 2009");
formatter.setStylePattern("");
assertThat("uses style", formatter.print(date, Locale.US), is("6/1/09"));
assertThat(formatter.print(date, Locale.US)).as("uses style").isEqualTo("6/1/09");
}

View File

@@ -36,8 +36,7 @@ import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.validation.DataBinder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -218,7 +217,7 @@ public class DateFormattingTests {
public void stringToDateWithoutGlobalFormat() {
String string = "Sat, 12 Aug 1995 13:30:00 GM";
Date date = this.conversionService.convert(string, Date.class);
assertThat(date, equalTo(new Date(string)));
assertThat(date).isEqualTo(new Date(string));
}
@Test // SPR-10105

View File

@@ -20,10 +20,11 @@ import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.sameInstance;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Phillip Webb
@@ -36,28 +37,28 @@ public class DateTimeFormatterFactoryBeanTests {
@Test
public void isSingleton() {
assertThat(factory.isSingleton(), is(true));
assertThat(factory.isSingleton()).isTrue();
}
@Test
@SuppressWarnings("rawtypes")
public void getObjectType() {
assertThat(factory.getObjectType(), is(equalTo((Class) DateTimeFormatter.class)));
assertThat(factory.getObjectType()).isEqualTo(DateTimeFormatter.class);
}
@Test
public void getObject() {
factory.afterPropertiesSet();
assertThat(factory.getObject(), is(equalTo(DateTimeFormat.mediumDateTime())));
assertThat(factory.getObject()).isEqualTo(DateTimeFormat.mediumDateTime());
}
@Test
public void getObjectIsAlwaysSingleton() {
factory.afterPropertiesSet();
DateTimeFormatter formatter = factory.getObject();
assertThat(formatter, is(equalTo(DateTimeFormat.mediumDateTime())));
assertThat(formatter).isEqualTo(DateTimeFormat.mediumDateTime());
factory.setStyle("LL");
assertThat(factory.getObject(), is(sameInstance(formatter)));
assertThat(factory.getObject()).isSameAs(formatter);
}
}

View File

@@ -27,11 +27,7 @@ import org.junit.Test;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/**
@@ -55,27 +51,27 @@ public class DateTimeFormatterFactoryTests {
@Test
public void createDateTimeFormatter() {
assertThat(factory.createDateTimeFormatter(), is(equalTo(DateTimeFormat.mediumDateTime())));
assertThat(factory.createDateTimeFormatter()).isEqualTo(DateTimeFormat.mediumDateTime());
}
@Test
public void createDateTimeFormatterWithPattern() {
factory = new DateTimeFormatterFactory("yyyyMMddHHmmss");
DateTimeFormatter formatter = factory.createDateTimeFormatter();
assertThat(formatter.print(dateTime), is("20091021121000"));
assertThat(formatter.print(dateTime)).isEqualTo("20091021121000");
}
@Test
public void createDateTimeFormatterWithNullFallback() {
DateTimeFormatter formatter = factory.createDateTimeFormatter(null);
assertThat(formatter, is(nullValue()));
assertThat(formatter).isNull();
}
@Test
public void createDateTimeFormatterWithFallback() {
DateTimeFormatter fallback = DateTimeFormat.forStyle("LL");
DateTimeFormatter formatter = factory.createDateTimeFormatter(fallback);
assertThat(formatter, is(sameInstance(fallback)));
assertThat(formatter).isSameAs(fallback);
}
@Test
@@ -86,10 +82,10 @@ public class DateTimeFormatterFactoryTests {
assertTrue(value.endsWith("12:10 PM"));
factory.setIso(ISO.DATE);
assertThat(applyLocale(factory.createDateTimeFormatter()).print(dateTime), is("2009-10-21"));
assertThat(applyLocale(factory.createDateTimeFormatter()).print(dateTime)).isEqualTo("2009-10-21");
factory.setPattern("yyyyMMddHHmmss");
assertThat(factory.createDateTimeFormatter().print(dateTime), is("20091021121000"));
assertThat(factory.createDateTimeFormatter().print(dateTime)).isEqualTo("20091021121000");
}
@Test
@@ -99,7 +95,7 @@ public class DateTimeFormatterFactoryTests {
DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(TEST_TIMEZONE);
DateTime dateTime = new DateTime(2009, 10, 21, 12, 10, 00, 00, dateTimeZone);
String offset = (TEST_TIMEZONE.equals(NEW_YORK) ? "-0400" : "+0200");
assertThat(factory.createDateTimeFormatter().print(dateTime), is("20091021121000 " + offset));
assertThat(factory.createDateTimeFormatter().print(dateTime)).isEqualTo("20091021121000 " + offset);
}
private DateTimeFormatter applyLocale(DateTimeFormatter dateTimeFormatter) {

View File

@@ -46,8 +46,7 @@ import org.springframework.format.annotation.DateTimeFormat.ISO;
import org.springframework.format.support.FormattingConversionService;
import org.springframework.validation.DataBinder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -453,7 +452,7 @@ public class JodaTimeFormattingTests {
public void stringToDateWithoutGlobalFormat() {
String string = "Sat, 12 Aug 1995 13:30:00 GM";
Date date = this.conversionService.convert(string, Date.class);
assertThat(date, equalTo(new Date(string)));
assertThat(date).isEqualTo(new Date(string));
}
@Test // SPR-10105

View File

@@ -21,10 +21,11 @@ import java.time.format.FormatStyle;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.sameInstance;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Phillip Webb
@@ -37,27 +38,27 @@ public class DateTimeFormatterFactoryBeanTests {
@Test
public void isSingleton() {
assertThat(factory.isSingleton(), is(true));
assertThat(factory.isSingleton()).isTrue();
}
@Test
public void getObjectType() {
assertThat(factory.getObjectType(), is(equalTo(DateTimeFormatter.class)));
assertThat(factory.getObjectType()).isEqualTo(DateTimeFormatter.class);
}
@Test
public void getObject() {
factory.afterPropertiesSet();
assertThat(factory.getObject().toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
assertThat(factory.getObject().toString()).isEqualTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString());
}
@Test
public void getObjectIsAlwaysSingleton() {
factory.afterPropertiesSet();
DateTimeFormatter formatter = factory.getObject();
assertThat(formatter.toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
assertThat(formatter.toString()).isEqualTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString());
factory.setStylePattern("LL");
assertThat(factory.getObject(), is(sameInstance(formatter)));
assertThat(factory.getObject()).isSameAs(formatter);
}
}

View File

@@ -28,11 +28,7 @@ import org.junit.Test;
import org.springframework.format.annotation.DateTimeFormat.ISO;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/**
@@ -56,27 +52,27 @@ public class DateTimeFormatterFactoryTests {
@Test
public void createDateTimeFormatter() {
assertThat(factory.createDateTimeFormatter().toString(), is(equalTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString())));
assertThat(factory.createDateTimeFormatter().toString()).isEqualTo(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).toString());
}
@Test
public void createDateTimeFormatterWithPattern() {
factory = new DateTimeFormatterFactory("yyyyMMddHHmmss");
DateTimeFormatter formatter = factory.createDateTimeFormatter();
assertThat(formatter.format(dateTime), is("20091021121000"));
assertThat(formatter.format(dateTime)).isEqualTo("20091021121000");
}
@Test
public void createDateTimeFormatterWithNullFallback() {
DateTimeFormatter formatter = factory.createDateTimeFormatter(null);
assertThat(formatter, is(nullValue()));
assertThat(formatter).isNull();
}
@Test
public void createDateTimeFormatterWithFallback() {
DateTimeFormatter fallback = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.LONG);
DateTimeFormatter formatter = factory.createDateTimeFormatter(fallback);
assertThat(formatter, is(sameInstance(fallback)));
assertThat(formatter).isSameAs(fallback);
}
@Test
@@ -87,10 +83,10 @@ public class DateTimeFormatterFactoryTests {
assertTrue(value.endsWith("12:10 PM"));
factory.setIso(ISO.DATE);
assertThat(applyLocale(factory.createDateTimeFormatter()).format(dateTime), is("2009-10-21"));
assertThat(applyLocale(factory.createDateTimeFormatter()).format(dateTime)).isEqualTo("2009-10-21");
factory.setPattern("yyyyMMddHHmmss");
assertThat(factory.createDateTimeFormatter().format(dateTime), is("20091021121000"));
assertThat(factory.createDateTimeFormatter().format(dateTime)).isEqualTo("20091021121000");
}
@Test
@@ -100,7 +96,7 @@ public class DateTimeFormatterFactoryTests {
ZoneId dateTimeZone = TEST_TIMEZONE.toZoneId();
ZonedDateTime dateTime = ZonedDateTime.of(2009, 10, 21, 12, 10, 00, 00, dateTimeZone);
String offset = (TEST_TIMEZONE.equals(NEW_YORK) ? "-0400" : "+0200");
assertThat(factory.createDateTimeFormatter().format(dateTime), is("20091021121000 " + offset));
assertThat(factory.createDateTimeFormatter().format(dateTime)).isEqualTo("20091021121000 " + offset);
}
private DateTimeFormatter applyLocale(DateTimeFormatter dateTimeFormatter) {

View File

@@ -21,8 +21,9 @@ import javax.naming.spi.NamingManager;
import org.junit.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link JndiLocatorDelegate}.
@@ -40,7 +41,7 @@ public class JndiLocatorDelegateTests {
builderField.set(null, null);
try {
assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable(), equalTo(false));
assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()).isEqualTo(false);
}
finally {
builderField.set(null, oldBuilder);

View File

@@ -23,9 +23,7 @@ import org.junit.Test;
import org.springframework.tests.mock.jndi.SimpleNamingContext;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
/**
@@ -40,7 +38,7 @@ public class JndiPropertySourceTests {
@Test
public void nonExistentProperty() {
JndiPropertySource ps = new JndiPropertySource("jndiProperties");
assertThat(ps.getProperty("bogus"), nullValue());
assertThat(ps.getProperty("bogus")).isNull();
}
@Test
@@ -59,7 +57,7 @@ public class JndiPropertySourceTests {
jndiLocator.setJndiTemplate(jndiTemplate);
JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator);
assertThat(ps.getProperty("p1"), equalTo("v1"));
assertThat(ps.getProperty("p1")).isEqualTo("v1");
}
@Test
@@ -78,7 +76,7 @@ public class JndiPropertySourceTests {
jndiLocator.setJndiTemplate(jndiTemplate);
JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator);
assertThat(ps.getProperty("p1"), equalTo("v1"));
assertThat(ps.getProperty("p1")).isEqualTo("v1");
}
@Test
@@ -92,7 +90,7 @@ public class JndiPropertySourceTests {
jndiLocator.setResourceRef(true);
JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator);
assertThat(ps.getProperty("propertyKey:defaultValue"), nullValue());
assertThat(ps.getProperty("propertyKey:defaultValue")).isNull();
}
@Test
@@ -107,7 +105,7 @@ public class JndiPropertySourceTests {
jndiLocator.setResourceRef(false);
JndiPropertySource ps = new JndiPropertySource("jndiProperties", jndiLocator);
assertThat(ps.getProperty("my:key"), equalTo("my:value"));
assertThat(ps.getProperty("my:key")).isEqualTo("my:value");
}
}

View File

@@ -21,8 +21,8 @@ import java.lang.annotation.RetentionPolicy;
import org.junit.Test;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link AnnotationAsyncExecutionInterceptor}.
@@ -38,23 +38,23 @@ public class AnnotationAsyncExecutionInterceptorTests {
AnnotationAsyncExecutionInterceptor i = new AnnotationAsyncExecutionInterceptor(null);
{ // method level
class C { @Async("qMethod") void m() { } }
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qMethod"));
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m"))).isEqualTo("qMethod");
}
{ // class level
@Async("qClass") class C { void m() { } }
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qClass"));
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m"))).isEqualTo("qClass");
}
{ // method and class level -> method value overrides
@Async("qClass") class C { @Async("qMethod") void m() { } }
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qMethod"));
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m"))).isEqualTo("qMethod");
}
{ // method and class level -> method value, even if empty, overrides
@Async("qClass") class C { @Async void m() { } }
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is(""));
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m"))).isEqualTo("");
}
{ // meta annotation with qualifier
@MyAsync class C { void m() { } }
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m")), is("qMeta"));
assertThat(i.getExecutorQualifier(C.class.getDeclaredMethod("m"))).isEqualTo("qMeta");
}
}

View File

@@ -54,12 +54,8 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;
import org.springframework.util.ReflectionUtils;
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.anyOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@@ -79,7 +75,7 @@ public class EnableAsyncTests {
ctx.refresh();
AsyncBean asyncBean = ctx.getBean(AsyncBean.class);
assertThat(AopUtils.isAopProxy(asyncBean), is(true));
assertThat(AopUtils.isAopProxy(asyncBean)).isTrue();
asyncBean.work();
ctx.close();
}
@@ -92,7 +88,7 @@ public class EnableAsyncTests {
AsyncBeanUser asyncBeanUser = ctx.getBean(AsyncBeanUser.class);
AsyncBean asyncBean = asyncBeanUser.getAsyncBean();
assertThat(AopUtils.isAopProxy(asyncBean), is(true));
assertThat(AopUtils.isAopProxy(asyncBean)).isTrue();
asyncBean.work();
ctx.close();
}
@@ -125,13 +121,13 @@ public class EnableAsyncTests {
AsyncBeanWithExecutorQualifiedByName asyncBean = ctx.getBean(AsyncBeanWithExecutorQualifiedByName.class);
Future<Thread> workerThread0 = asyncBean.work0();
assertThat(workerThread0.get().getName(), not(anyOf(startsWith("e1-"), startsWith("otherExecutor-"))));
assertThat(workerThread0.get().getName()).doesNotStartWith("e1-").doesNotStartWith("otherExecutor-");
Future<Thread> workerThread = asyncBean.work();
assertThat(workerThread.get().getName(), startsWith("e1-"));
assertThat(workerThread.get().getName()).startsWith("e1-");
Future<Thread> workerThread2 = asyncBean.work2();
assertThat(workerThread2.get().getName(), startsWith("otherExecutor-"));
assertThat(workerThread2.get().getName()).startsWith("otherExecutor-");
Future<Thread> workerThread3 = asyncBean.work3();
assertThat(workerThread3.get().getName(), startsWith("otherExecutor-"));
assertThat(workerThread3.get().getName()).startsWith("otherExecutor-");
ctx.close();
}
@@ -143,7 +139,7 @@ public class EnableAsyncTests {
ctx.refresh();
AsyncAnnotationBeanPostProcessor bpp = ctx.getBean(AsyncAnnotationBeanPostProcessor.class);
assertThat(bpp.getOrder(), is(Ordered.LOWEST_PRECEDENCE));
assertThat(bpp.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE);
ctx.close();
}
@@ -155,7 +151,7 @@ public class EnableAsyncTests {
ctx.refresh();
AsyncAnnotationBeanPostProcessor bpp = ctx.getBean(AsyncAnnotationBeanPostProcessor.class);
assertThat(bpp.getOrder(), is(Ordered.HIGHEST_PRECEDENCE));
assertThat(bpp.getOrder()).isEqualTo(Ordered.HIGHEST_PRECEDENCE);
ctx.close();
}
@@ -206,7 +202,7 @@ public class EnableAsyncTests {
.atMost(500, TimeUnit.MILLISECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> asyncBean.getThreadOfExecution() != null);
assertThat(asyncBean.getThreadOfExecution().getName(), startsWith("Custom-"));
assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-");
ctx.close();
}
@@ -224,7 +220,7 @@ public class EnableAsyncTests {
.atMost(500, TimeUnit.MILLISECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> asyncBean.getThreadOfExecution() != null);
assertThat(asyncBean.getThreadOfExecution().getName(), startsWith("Custom-"));
assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-");
ctx.close();
}
@@ -263,7 +259,7 @@ public class EnableAsyncTests {
.atMost(500, TimeUnit.MILLISECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> asyncBean.getThreadOfExecution() != null);
assertThat(asyncBean.getThreadOfExecution().getName(), startsWith("Post-"));
assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Post-");
ctx.close();
}
@@ -300,7 +296,7 @@ public class EnableAsyncTests {
.atMost(500, TimeUnit.MILLISECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> asyncBean.getThreadOfExecution() != null);
assertThat(asyncBean.getThreadOfExecution().getName(), startsWith("Custom-"));
assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-");
ctx.close();
}
@@ -316,7 +312,7 @@ public class EnableAsyncTests {
.atMost(500, TimeUnit.MILLISECONDS)
.pollInterval(10, TimeUnit.MILLISECONDS)
.until(() -> asyncBean.getThreadOfExecution() != null);
assertThat(asyncBean.getThreadOfExecution().getName(), startsWith("Custom-"));
assertThat(asyncBean.getThreadOfExecution().getName()).startsWith("Custom-");
ctx.close();
}

View File

@@ -35,12 +35,7 @@ import org.springframework.scheduling.config.TaskManagementConfigUtils;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
import static org.hamcrest.Matchers.lessThanOrEqualTo;
import static org.hamcrest.Matchers.startsWith;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -72,7 +67,7 @@ public class EnableSchedulingTests {
assertEquals(2, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size());
Thread.sleep(100);
assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10));
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThanOrEqualTo(10);
}
@Test
@@ -83,7 +78,7 @@ public class EnableSchedulingTests {
assertEquals(2, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size());
Thread.sleep(100);
assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10));
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThanOrEqualTo(10);
}
@Test
@@ -94,8 +89,8 @@ public class EnableSchedulingTests {
assertEquals(1, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size());
Thread.sleep(100);
assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10));
assertThat(ctx.getBean(ExplicitSchedulerConfig.class).threadName, startsWith("explicitScheduler-"));
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThanOrEqualTo(10);
assertThat(ctx.getBean(ExplicitSchedulerConfig.class).threadName).startsWith("explicitScheduler-");
assertTrue(Arrays.asList(ctx.getDefaultListableBeanFactory().getDependentBeans("myTaskScheduler")).contains(
TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME));
}
@@ -114,8 +109,8 @@ public class EnableSchedulingTests {
assertEquals(1, ctx.getBean(ScheduledTaskHolder.class).getScheduledTasks().size());
Thread.sleep(100);
assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThanOrEqualTo(10));
assertThat(ctx.getBean(ExplicitScheduledTaskRegistrarConfig.class).threadName, startsWith("explicitScheduler1"));
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThanOrEqualTo(10);
assertThat(ctx.getBean(ExplicitScheduledTaskRegistrarConfig.class).threadName).startsWith("explicitScheduler1");
}
@Test
@@ -137,7 +132,7 @@ public class EnableSchedulingTests {
SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedByScheduledTaskRegistrar.class);
Thread.sleep(100);
assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread, startsWith("explicitScheduler2-"));
assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread).startsWith("explicitScheduler2-");
}
@Test
@@ -148,7 +143,7 @@ public class EnableSchedulingTests {
SchedulingEnabled_withAmbiguousTaskSchedulers_andSingleTask_disambiguatedBySchedulerNameAttribute.class);
Thread.sleep(100);
assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread, startsWith("explicitScheduler2-"));
assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread).startsWith("explicitScheduler2-");
}
@Test
@@ -158,7 +153,7 @@ public class EnableSchedulingTests {
ctx = new AnnotationConfigApplicationContext(SchedulingEnabled_withTaskAddedVia_configureTasks.class);
Thread.sleep(100);
assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread, startsWith("taskScheduler-"));
assertThat(ctx.getBean(ThreadAwareWorker.class).executedByThread).startsWith("taskScheduler-");
}
@Test
@@ -168,7 +163,7 @@ public class EnableSchedulingTests {
ctx = new AnnotationConfigApplicationContext(TriggerTaskConfig.class);
Thread.sleep(100);
assertThat(ctx.getBean(AtomicInteger.class).get(), greaterThan(1));
assertThat(ctx.getBean(AtomicInteger.class).get()).isGreaterThan(1);
}
@Test
@@ -182,7 +177,7 @@ public class EnableSchedulingTests {
// The @Scheduled method should have been called at least once but
// not more times than the delay allows.
assertThat(counter.get(), both(greaterThan(0)).and(lessThanOrEqualTo(10)));
assertThat(counter.get()).isBetween(1, 10);
}

View File

@@ -30,8 +30,7 @@ import org.springframework.scheduling.Trigger;
import org.springframework.scheduling.TriggerContext;
import org.springframework.scheduling.support.ScheduledMethodRunnable;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
/**
@@ -110,7 +109,7 @@ public class ScheduledTasksBeanDefinitionParserTests {
List<TriggerTask> tasks = (List<TriggerTask>) new DirectFieldAccessor(
this.registrar).getPropertyValue("triggerTasks");
assertEquals(1, tasks.size());
assertThat(tasks.get(0).getTrigger(), instanceOf(TestTrigger.class));
assertThat(tasks.get(0).getTrigger()).isInstanceOf(TestTrigger.class);
}

View File

@@ -21,9 +21,10 @@ import org.junit.Test;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.validation.DefaultMessageCodesResolver.Format;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link DefaultMessageCodesResolver}.
@@ -37,27 +38,27 @@ public class DefaultMessageCodesResolverTests {
@Test
public void shouldResolveMessageCode() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName");
assertThat(codes, is(equalTo(new String[] {
assertThat(codes).containsExactly(
"errorCode.objectName",
"errorCode" })));
"errorCode");
}
@Test
public void shouldResolveFieldMessageCode() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field",
TestBean.class);
assertThat(codes, is(equalTo(new String[] {
assertThat(codes).containsExactly(
"errorCode.objectName.field",
"errorCode.field",
"errorCode.org.springframework.tests.sample.beans.TestBean",
"errorCode" })));
"errorCode");
}
@Test
public void shouldResolveIndexedFieldMessageCode() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "a.b[3].c[5].d",
TestBean.class);
assertThat(codes, is(equalTo(new String[] {
assertThat(codes).containsExactly(
"errorCode.objectName.a.b[3].c[5].d",
"errorCode.objectName.a.b[3].c.d",
"errorCode.objectName.a.b.c.d",
@@ -66,16 +67,16 @@ public class DefaultMessageCodesResolverTests {
"errorCode.a.b.c.d",
"errorCode.d",
"errorCode.org.springframework.tests.sample.beans.TestBean",
"errorCode" })));
"errorCode");
}
@Test
public void shouldResolveMessageCodeWithPrefix() throws Exception {
resolver.setPrefix("prefix.");
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName");
assertThat(codes, is(equalTo(new String[] {
assertThat(codes).containsExactly(
"prefix.errorCode.objectName",
"prefix.errorCode" })));
"prefix.errorCode");
}
@Test
@@ -83,11 +84,11 @@ public class DefaultMessageCodesResolverTests {
resolver.setPrefix("prefix.");
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field",
TestBean.class);
assertThat(codes, is(equalTo(new String[] {
assertThat(codes).containsExactly(
"prefix.errorCode.objectName.field",
"prefix.errorCode.field",
"prefix.errorCode.org.springframework.tests.sample.beans.TestBean",
"prefix.errorCode" })));
"prefix.errorCode");
}
@Test
@@ -95,41 +96,41 @@ public class DefaultMessageCodesResolverTests {
resolver.setPrefix(null);
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field",
TestBean.class);
assertThat(codes, is(equalTo(new String[] {
assertThat(codes).containsExactly(
"errorCode.objectName.field",
"errorCode.field",
"errorCode.org.springframework.tests.sample.beans.TestBean",
"errorCode" })));
"errorCode");
}
@Test
public void shouldSupportMalformedIndexField() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field[",
TestBean.class);
assertThat(codes, is(equalTo(new String[] {
assertThat(codes).containsExactly(
"errorCode.objectName.field[",
"errorCode.field[",
"errorCode.org.springframework.tests.sample.beans.TestBean",
"errorCode" })));
"errorCode");
}
@Test
public void shouldSupportNullFieldType() throws Exception {
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field",
null);
assertThat(codes, is(equalTo(new String[] {
assertThat(codes).containsExactly(
"errorCode.objectName.field",
"errorCode.field",
"errorCode" })));
"errorCode");
}
@Test
public void shouldSupportPostfixFormat() throws Exception {
resolver.setMessageCodeFormatter(Format.POSTFIX_ERROR_CODE);
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName");
assertThat(codes, is(equalTo(new String[] {
assertThat(codes).containsExactly(
"objectName.errorCode",
"errorCode" })));
"errorCode");
}
@Test
@@ -137,11 +138,11 @@ public class DefaultMessageCodesResolverTests {
resolver.setMessageCodeFormatter(Format.POSTFIX_ERROR_CODE);
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName", "field",
TestBean.class);
assertThat(codes, is(equalTo(new String[] {
assertThat(codes).containsExactly(
"objectName.field.errorCode",
"field.errorCode",
"org.springframework.tests.sample.beans.TestBean.errorCode",
"errorCode" })));
"errorCode");
}
@Test
@@ -154,9 +155,9 @@ public class DefaultMessageCodesResolverTests {
}
});
String[] codes = resolver.resolveMessageCodes("errorCode", "objectName");
assertThat(codes, is(equalTo(new String[] {
assertThat(codes).containsExactly(
"CUSTOM-errorCode.objectName",
"CUSTOM-errorCode" })));
"CUSTOM-errorCode");
}
}

View File

@@ -54,9 +54,7 @@ import org.springframework.validation.FieldError;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.StringContains.containsString;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
@@ -98,13 +96,13 @@ public class SpringValidatorAdapterTests {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(testBean, "testBean");
validatorAdapter.validate(testBean, errors);
assertThat(errors.getFieldErrorCount("password"), is(1));
assertThat(errors.getFieldValue("password"), is("pass"));
assertThat(errors.getFieldErrorCount("password")).isEqualTo(1);
assertThat(errors.getFieldValue("password")).isEqualTo("pass");
FieldError error = errors.getFieldError("password");
assertNotNull(error);
assertThat(messageSource.getMessage(error, Locale.ENGLISH), is("Size of Password is must be between 8 and 128"));
assertThat(messageSource.getMessage(error, Locale.ENGLISH)).isEqualTo("Size of Password is must be between 8 and 128");
assertTrue(error.contains(ConstraintViolation.class));
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString(), is("password"));
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("password");
}
@Test // SPR-13406
@@ -116,13 +114,13 @@ public class SpringValidatorAdapterTests {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(testBean, "testBean");
validatorAdapter.validate(testBean, errors);
assertThat(errors.getFieldErrorCount("password"), is(1));
assertThat(errors.getFieldValue("password"), is("password"));
assertThat(errors.getFieldErrorCount("password")).isEqualTo(1);
assertThat(errors.getFieldValue("password")).isEqualTo("password");
FieldError error = errors.getFieldError("password");
assertNotNull(error);
assertThat(messageSource.getMessage(error, Locale.ENGLISH), is("Password must be same value as Password(Confirm)"));
assertThat(messageSource.getMessage(error, Locale.ENGLISH)).isEqualTo("Password must be same value as Password(Confirm)");
assertTrue(error.contains(ConstraintViolation.class));
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString(), is("password"));
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("password");
}
@Test // SPR-13406
@@ -134,19 +132,19 @@ public class SpringValidatorAdapterTests {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(testBean, "testBean");
validatorAdapter.validate(testBean, errors);
assertThat(errors.getFieldErrorCount("email"), is(1));
assertThat(errors.getFieldValue("email"), is("test@example.com"));
assertThat(errors.getFieldErrorCount("confirmEmail"), is(1));
assertThat(errors.getFieldErrorCount("email")).isEqualTo(1);
assertThat(errors.getFieldValue("email")).isEqualTo("test@example.com");
assertThat(errors.getFieldErrorCount("confirmEmail")).isEqualTo(1);
FieldError error1 = errors.getFieldError("email");
FieldError error2 = errors.getFieldError("confirmEmail");
assertNotNull(error1);
assertNotNull(error2);
assertThat(messageSource.getMessage(error1, Locale.ENGLISH), is("email must be same value as confirmEmail"));
assertThat(messageSource.getMessage(error2, Locale.ENGLISH), is("Email required"));
assertThat(messageSource.getMessage(error1, Locale.ENGLISH)).isEqualTo("email must be same value as confirmEmail");
assertThat(messageSource.getMessage(error2, Locale.ENGLISH)).isEqualTo("Email required");
assertTrue(error1.contains(ConstraintViolation.class));
assertThat(error1.unwrap(ConstraintViolation.class).getPropertyPath().toString(), is("email"));
assertThat(error1.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("email");
assertTrue(error2.contains(ConstraintViolation.class));
assertThat(error2.unwrap(ConstraintViolation.class).getPropertyPath().toString(), is("confirmEmail"));
assertThat(error2.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("confirmEmail");
}
@Test // SPR-15123
@@ -160,19 +158,19 @@ public class SpringValidatorAdapterTests {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(testBean, "testBean");
validatorAdapter.validate(testBean, errors);
assertThat(errors.getFieldErrorCount("email"), is(1));
assertThat(errors.getFieldValue("email"), is("test@example.com"));
assertThat(errors.getFieldErrorCount("confirmEmail"), is(1));
assertThat(errors.getFieldErrorCount("email")).isEqualTo(1);
assertThat(errors.getFieldValue("email")).isEqualTo("test@example.com");
assertThat(errors.getFieldErrorCount("confirmEmail")).isEqualTo(1);
FieldError error1 = errors.getFieldError("email");
FieldError error2 = errors.getFieldError("confirmEmail");
assertNotNull(error1);
assertNotNull(error2);
assertThat(messageSource.getMessage(error1, Locale.ENGLISH), is("email must be same value as confirmEmail"));
assertThat(messageSource.getMessage(error2, Locale.ENGLISH), is("Email required"));
assertThat(messageSource.getMessage(error1, Locale.ENGLISH)).isEqualTo("email must be same value as confirmEmail");
assertThat(messageSource.getMessage(error2, Locale.ENGLISH)).isEqualTo("Email required");
assertTrue(error1.contains(ConstraintViolation.class));
assertThat(error1.unwrap(ConstraintViolation.class).getPropertyPath().toString(), is("email"));
assertThat(error1.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("email");
assertTrue(error2.contains(ConstraintViolation.class));
assertThat(error2.unwrap(ConstraintViolation.class).getPropertyPath().toString(), is("confirmEmail"));
assertThat(error2.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("confirmEmail");
}
@Test
@@ -184,13 +182,13 @@ public class SpringValidatorAdapterTests {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(testBean, "testBean");
validatorAdapter.validate(testBean, errors);
assertThat(errors.getFieldErrorCount("email"), is(1));
assertThat(errors.getFieldValue("email"), is("X"));
assertThat(errors.getFieldErrorCount("email")).isEqualTo(1);
assertThat(errors.getFieldValue("email")).isEqualTo("X");
FieldError error = errors.getFieldError("email");
assertNotNull(error);
assertThat(messageSource.getMessage(error, Locale.ENGLISH), containsString("[\\w.'-]{1,}@[\\w.'-]{1,}"));
assertThat(messageSource.getMessage(error, Locale.ENGLISH)).contains("[\\w.'-]{1,}@[\\w.'-]{1,}");
assertTrue(error.contains(ConstraintViolation.class));
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString(), is("email"));
assertThat(error.unwrap(ConstraintViolation.class).getPropertyPath().toString()).isEqualTo("email");
}
@Test // SPR-16177

View File

@@ -52,8 +52,6 @@ import org.springframework.validation.FieldError;
import org.springframework.validation.ObjectError;
import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -136,8 +134,9 @@ public class ValidatorFactoryTests {
BeanPropertyBindingResult errors = new BeanPropertyBindingResult(person, "person");
validator.validate(person, errors);
assertEquals(1, errors.getErrorCount());
assertThat("Field/Value type mismatch", errors.getFieldError("address").getRejectedValue(),
instanceOf(ValidAddress.class));
assertThat(errors.getFieldError("address").getRejectedValue())
.as("Field/Value type mismatch")
.isInstanceOf(ValidAddress.class);
}
@Test