Migrate JUnit 4 assertions to AssertJ

Migrate all existing JUnit 4 `assert...` based assertions to AssertJ
and add a checkstyle rule to ensure they don't return.

See gh-23022
This commit is contained in:
Phillip Webb
2019-05-23 15:51:39 -07:00
parent 95a9d46a87
commit 9d74da006c
1636 changed files with 37861 additions and 40390 deletions

View File

@@ -26,7 +26,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -53,7 +53,7 @@ public class AfterAdviceBindingTests {
AdviceBindingTestAspect afterAdviceAspect = (AdviceBindingTestAspect) ctx.getBean("testAspect");
testBeanProxy = (ITestBean) ctx.getBean("testBean");
assertTrue(AopUtils.isAopProxy(testBeanProxy));
assertThat(AopUtils.isAopProxy(testBeanProxy)).isTrue();
// we need the real target too, not just the proxy...
testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();

View File

@@ -26,7 +26,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyZeroInteractions;
@@ -61,7 +61,7 @@ public class AfterReturningAdviceBindingTests {
afterAdviceAspect.setCollaborator(mockCollaborator);
testBeanProxy = (ITestBean) ctx.getBean("testBean");
assertTrue(AopUtils.isAopProxy(testBeanProxy));
assertThat(AopUtils.isAopProxy(testBeanProxy)).isTrue();
// we need the real target too, not just the proxy...
this.testBeanTarget = (TestBean) ((Advised)testBeanProxy).getTargetSource().getTarget();

View File

@@ -28,7 +28,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -55,7 +55,7 @@ public class AroundAdviceBindingTests {
AroundAdviceBindingTestAspect aroundAdviceAspect = ((AroundAdviceBindingTestAspect) ctx.getBean("testAspect"));
ITestBean injectedTestBean = (ITestBean) ctx.getBean("testBean");
assertTrue(AopUtils.isAopProxy(injectedTestBean));
assertThat(AopUtils.isAopProxy(injectedTestBean)).isTrue();
this.testBeanProxy = injectedTestBean;
// we need the real target too, not just the proxy...

View File

@@ -20,7 +20,7 @@ import org.junit.Test;
import org.springframework.aop.support.AopUtils;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
@@ -31,9 +31,9 @@ public class AroundAdviceCircularTests extends AroundAdviceBindingTests {
@Test
public void testBothBeansAreProxies() {
Object tb = ctx.getBean("testBean");
assertTrue(AopUtils.isAopProxy(tb));
assertThat(AopUtils.isAopProxy(tb)).isTrue();
Object tb2 = ctx.getBean("testBean2");
assertTrue(AopUtils.isAopProxy(tb2));
assertThat(AopUtils.isAopProxy(tb2)).isTrue();
}
}

View File

@@ -24,7 +24,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Harrop
@@ -49,11 +49,11 @@ public class AspectJExpressionPointcutAdvisorTests {
@Test
public void testPointcutting() {
assertEquals("Count should be 0", 0, interceptor.getCount());
assertThat(interceptor.getCount()).as("Count should be 0").isEqualTo(0);
testBean.getSpouses();
assertEquals("Count should be 1", 1, interceptor.getCount());
assertThat(interceptor.getCount()).as("Count should be 1").isEqualTo(1);
testBean.getSpouse();
assertEquals("Count should be 1", 1, interceptor.getCount());
assertThat(interceptor.getCount()).as("Count should be 1").isEqualTo(1);
}
}

View File

@@ -26,9 +26,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for correct application of the bean() PCD for @AspectJ-based aspects.
@@ -59,20 +57,22 @@ public class BeanNamePointcutAtAspectTests {
@Test
public void testMatchingBeanName() {
assertTrue("Expected a proxy", testBean1 instanceof Advised);
boolean condition = testBean1 instanceof Advised;
assertThat(condition).as("Expected a proxy").isTrue();
// Call two methods to test for SPR-3953-like condition
testBean1.setAge(20);
testBean1.setName("");
assertEquals(2, counterAspect.count);
assertThat(counterAspect.count).isEqualTo(2);
}
@Test
public void testNonMatchingBeanName() {
assertFalse("Didn't expect a proxy", testBean3 instanceof Advised);
boolean condition = testBean3 instanceof Advised;
assertThat(condition).as("Didn't expect a proxy").isFalse();
testBean3.setAge(20);
assertEquals(0, counterAspect.count);
assertThat(counterAspect.count).isEqualTo(0);
}
@Test
@@ -87,9 +87,10 @@ public class BeanNamePointcutAtAspectTests {
ITestBean proxyTestBean = factory.getProxy();
assertTrue("Expected a proxy", proxyTestBean instanceof Advised);
boolean condition = proxyTestBean instanceof Advised;
assertThat(condition).as("Expected a proxy").isTrue();
proxyTestBean.setAge(20);
assertEquals("Programmatically created proxy shouldn't match bean()", 0, myCounterAspect.count);
assertThat(myCounterAspect.count).as("Programmatically created proxy shouldn't match bean()").isEqualTo(0);
}
}

View File

@@ -29,9 +29,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.ITestBean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for correct application of the bean() PCD for XML-based AspectJ aspects.
@@ -77,53 +75,62 @@ public class BeanNamePointcutTests {
@Test
public void testMatchingBeanName() {
assertTrue("Matching bean must be advised (proxied)", this.testBean1 instanceof Advised);
boolean condition = this.testBean1 instanceof Advised;
assertThat(condition).as("Matching bean must be advised (proxied)").isTrue();
// Call two methods to test for SPR-3953-like condition
this.testBean1.setAge(20);
this.testBean1.setName("");
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount());
assertThat(this.counterAspect.getCount()).as("Advice not executed: must have been").isEqualTo(2);
}
@Test
public void testNonMatchingBeanName() {
assertFalse("Non-matching bean must *not* be advised (proxied)", this.testBean2 instanceof Advised);
boolean condition = this.testBean2 instanceof Advised;
assertThat(condition).as("Non-matching bean must *not* be advised (proxied)").isFalse();
this.testBean2.setAge(20);
assertEquals("Advice must *not* have been executed", 0, this.counterAspect.getCount());
assertThat(this.counterAspect.getCount()).as("Advice must *not* have been executed").isEqualTo(0);
}
@Test
public void testNonMatchingNestedBeanName() {
assertFalse("Non-matching bean must *not* be advised (proxied)", this.testBeanContainingNestedBean.getDoctor() instanceof Advised);
boolean condition = this.testBeanContainingNestedBean.getDoctor() instanceof Advised;
assertThat(condition).as("Non-matching bean must *not* be advised (proxied)").isFalse();
}
@Test
public void testMatchingFactoryBeanObject() {
assertTrue("Matching bean must be advised (proxied)", this.testFactoryBean1 instanceof Advised);
assertEquals("myValue", this.testFactoryBean1.get("myKey"));
assertEquals("myValue", this.testFactoryBean1.get("myKey"));
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount());
boolean condition1 = this.testFactoryBean1 instanceof Advised;
assertThat(condition1).as("Matching bean must be advised (proxied)").isTrue();
assertThat(this.testFactoryBean1.get("myKey")).isEqualTo("myValue");
assertThat(this.testFactoryBean1.get("myKey")).isEqualTo("myValue");
assertThat(this.counterAspect.getCount()).as("Advice not executed: must have been").isEqualTo(2);
FactoryBean<?> fb = (FactoryBean<?>) ctx.getBean("&testFactoryBean1");
assertTrue("FactoryBean itself must *not* be advised", !(fb instanceof Advised));
boolean condition = !(fb instanceof Advised);
assertThat(condition).as("FactoryBean itself must *not* be advised").isTrue();
}
@Test
public void testMatchingFactoryBeanItself() {
assertTrue("Matching bean must *not* be advised (proxied)", !(this.testFactoryBean2 instanceof Advised));
boolean condition1 = !(this.testFactoryBean2 instanceof Advised);
assertThat(condition1).as("Matching bean must *not* be advised (proxied)").isTrue();
FactoryBean<?> fb = (FactoryBean<?>) ctx.getBean("&testFactoryBean2");
assertTrue("FactoryBean itself must be advised", fb instanceof Advised);
assertTrue(Map.class.isAssignableFrom(fb.getObjectType()));
assertTrue(Map.class.isAssignableFrom(fb.getObjectType()));
assertEquals("Advice not executed: must have been", 2, this.counterAspect.getCount());
boolean condition = fb instanceof Advised;
assertThat(condition).as("FactoryBean itself must be advised").isTrue();
assertThat(Map.class.isAssignableFrom(fb.getObjectType())).isTrue();
assertThat(Map.class.isAssignableFrom(fb.getObjectType())).isTrue();
assertThat(this.counterAspect.getCount()).as("Advice not executed: must have been").isEqualTo(2);
}
@Test
public void testPointcutAdvisorCombination() {
assertTrue("Matching bean must be advised (proxied)", this.interceptThis instanceof Advised);
assertFalse("Non-matching bean must *not* be advised (proxied)", this.dontInterceptThis instanceof Advised);
boolean condition = this.interceptThis instanceof Advised;
assertThat(condition).as("Matching bean must be advised (proxied)").isTrue();
boolean condition1 = this.dontInterceptThis instanceof Advised;
assertThat(condition1).as("Non-matching bean must *not* be advised (proxied)").isFalse();
interceptThis.setAge(20);
assertEquals(1, testInterceptor.interceptionCount);
assertThat(testInterceptor.interceptionCount).isEqualTo(1);
dontInterceptThis.setAge(20);
assertEquals(1, testInterceptor.interceptionCount);
assertThat(testInterceptor.interceptionCount).isEqualTo(1);
}

View File

@@ -26,7 +26,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -52,7 +52,7 @@ public class BeforeAdviceBindingTests {
new ClassPathXmlApplicationContext(getClass().getSimpleName() + ".xml", getClass());
testBeanProxy = (ITestBean) ctx.getBean("testBean");
assertTrue(AopUtils.isAopProxy(testBeanProxy));
assertThat(AopUtils.isAopProxy(testBeanProxy)).isTrue();
// we need the real target too, not just the proxy...
testBeanTarget = (TestBean) ((Advised) testBeanProxy).getTargetSource().getTarget();

View File

@@ -25,7 +25,7 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Adrian Colyer
@@ -49,12 +49,14 @@ public class DeclarationOrderIndependenceTests {
@Test
public void testTargetIsSerializable() {
assertTrue("target bean is serializable",this.target instanceof Serializable);
boolean condition = this.target instanceof Serializable;
assertThat(condition).as("target bean is serializable").isTrue();
}
@Test
public void testTargetIsBeanNameAware() {
assertTrue("target bean is bean name aware",this.target instanceof BeanNameAware);
boolean condition = this.target instanceof BeanNameAware;
assertThat(condition).as("target bean is bean name aware").isTrue();
}
@Test
@@ -62,7 +64,7 @@ public class DeclarationOrderIndependenceTests {
AspectCollaborator collab = new AspectCollaborator();
this.aspect.setCollaborator(collab);
this.target.doSomething();
assertTrue("before advice fired",collab.beforeFired);
assertThat(collab.beforeFired).as("before advice fired").isTrue();
}
@Test
@@ -70,7 +72,7 @@ public class DeclarationOrderIndependenceTests {
AspectCollaborator collab = new AspectCollaborator();
this.aspect.setCollaborator(collab);
this.target.getX();
assertTrue("around advice fired",collab.aroundFired);
assertThat(collab.aroundFired).as("around advice fired").isTrue();
}
@Test
@@ -78,7 +80,7 @@ public class DeclarationOrderIndependenceTests {
AspectCollaborator collab = new AspectCollaborator();
this.aspect.setCollaborator(collab);
this.target.getX();
assertTrue("after returning advice fired",collab.afterReturningFired);
assertThat(collab.afterReturningFired).as("after returning advice fired").isTrue();
}

View File

@@ -21,8 +21,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Ramnivas Laddad
@@ -47,13 +46,14 @@ public class DeclareParentsDelegateRefTests {
@Test
public void testIntroductionWasMade() {
assertTrue("Introduction must have been made", noMethodsBean instanceof ICounter);
boolean condition = noMethodsBean instanceof ICounter;
assertThat(condition).as("Introduction must have been made").isTrue();
}
@Test
public void testIntroductionDelegation() {
((ICounter)noMethodsBean).increment();
assertEquals("Delegate's counter should be updated", 1, counter.getCount());
assertThat(counter.getCount()).as("Delegate's counter should be updated").isEqualTo(1);
}
}

View File

@@ -24,9 +24,8 @@ import org.springframework.aop.support.AopUtils;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Rod Johnson
@@ -50,9 +49,10 @@ public class DeclareParentsTests {
@Test
public void testIntroductionWasMade() {
assertTrue(AopUtils.isAopProxy(testBeanProxy));
assertFalse("Introduction should not be proxied", AopUtils.isAopProxy(introductionObject));
assertTrue("Introduction must have been made", testBeanProxy instanceof Lockable);
assertThat(AopUtils.isAopProxy(testBeanProxy)).isTrue();
assertThat(AopUtils.isAopProxy(introductionObject)).as("Introduction should not be proxied").isFalse();
boolean condition = testBeanProxy instanceof Lockable;
assertThat(condition).as("Introduction must have been made").isTrue();
}
// TODO if you change type pattern from org.springframework.beans..*
@@ -62,7 +62,7 @@ public class DeclareParentsTests {
@Test
public void testLockingWorks() {
Lockable lockable = (Lockable) testBeanProxy;
assertFalse(lockable.locked());
assertThat(lockable.locked()).isFalse();
// Invoke a non-advised method
testBeanProxy.getAge();

View File

@@ -21,7 +21,7 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for overloaded advice.
@@ -38,9 +38,9 @@ public class OverloadedAdviceTests {
}
catch (BeanCreationException ex) {
Throwable cause = ex.getRootCause();
assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException);
assertTrue("invalidAbsoluteTypeName should be detected by AJ",
cause.getMessage().contains("invalidAbsoluteTypeName"));
boolean condition = cause instanceof IllegalArgumentException;
assertThat(condition).as("Should be IllegalArgumentException").isTrue();
assertThat(cause.getMessage().contains("invalidAbsoluteTypeName")).as("invalidAbsoluteTypeName should be detected by AJ").isTrue();
}
}
@@ -51,9 +51,9 @@ public class OverloadedAdviceTests {
}
catch (BeanCreationException ex) {
Throwable cause = ex.getRootCause();
assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException);
assertTrue("Cannot resolve method 'myBeforeAdvice' to a unique method",
cause.getMessage().contains("Cannot resolve method 'myBeforeAdvice' to a unique method"));
boolean condition = cause instanceof IllegalArgumentException;
assertThat(condition).as("Should be IllegalArgumentException").isTrue();
assertThat(cause.getMessage().contains("Cannot resolve method 'myBeforeAdvice' to a unique method")).as("Cannot resolve method 'myBeforeAdvice' to a unique method").isTrue();
}
}

View File

@@ -24,8 +24,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.Ordered;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for SPR-3522. Arguments changed on a call to proceed should be
@@ -56,28 +55,28 @@ public class ProceedTests {
@Test
public void testSimpleProceedWithChangedArgs() {
this.testBean.setName("abc");
assertEquals("Name changed in around advice", "ABC", this.testBean.getName());
assertThat(this.testBean.getName()).as("Name changed in around advice").isEqualTo("ABC");
}
@Test
public void testGetArgsIsDefensive() {
this.testBean.setAge(5);
assertEquals("getArgs is defensive", 5, this.testBean.getAge());
assertThat(this.testBean.getAge()).as("getArgs is defensive").isEqualTo(5);
}
@Test
public void testProceedWithArgsInSameAspect() {
this.testBean.setMyFloat(1.0F);
assertTrue("value changed in around advice", this.testBean.getMyFloat() > 1.9F);
assertTrue("changed value visible to next advice in chain", this.firstTestAspect.getLastBeforeFloatValue() > 1.9F);
assertThat(this.testBean.getMyFloat() > 1.9F).as("value changed in around advice").isTrue();
assertThat(this.firstTestAspect.getLastBeforeFloatValue() > 1.9F).as("changed value visible to next advice in chain").isTrue();
}
@Test
public void testProceedWithArgsAcrossAspects() {
this.testBean.setSex("male");
assertEquals("value changed in around advice","MALE", this.testBean.getSex());
assertEquals("changed value visible to next before advice in chain","MALE", this.secondTestAspect.getLastBeforeStringValue());
assertEquals("changed value visible to next around advice in chain","MALE", this.secondTestAspect.getLastAroundStringValue());
assertThat(this.testBean.getSex()).as("value changed in around advice").isEqualTo("MALE");
assertThat(this.secondTestAspect.getLastBeforeStringValue()).as("changed value visible to next before advice in chain").isEqualTo("MALE");
assertThat(this.secondTestAspect.getLastAroundStringValue()).as("changed value visible to next around advice in chain").isEqualTo("MALE");
}

View File

@@ -26,8 +26,7 @@ import org.springframework.aop.framework.Advised;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Check that an aspect that depends on another bean, where the referenced bean
@@ -66,23 +65,25 @@ public class PropertyDependentAspectTests {
private void checkXmlAspect(String appContextFile) {
ApplicationContext context = new ClassPathXmlApplicationContext(appContextFile, getClass());
ICounter counter = (ICounter) context.getBean("counter");
assertTrue("Proxy didn't get created", counter instanceof Advised);
boolean condition = counter instanceof Advised;
assertThat(condition).as("Proxy didn't get created").isTrue();
counter.increment();
JoinPointMonitorAspect callCountingAspect = (JoinPointMonitorAspect)context.getBean("monitoringAspect");
assertEquals("Advise didn't get executed", 1, callCountingAspect.beforeExecutions);
assertEquals("Advise didn't get executed", 1, callCountingAspect.aroundExecutions);
assertThat(callCountingAspect.beforeExecutions).as("Advise didn't get executed").isEqualTo(1);
assertThat(callCountingAspect.aroundExecutions).as("Advise didn't get executed").isEqualTo(1);
}
private void checkAtAspectJAspect(String appContextFile) {
ApplicationContext context = new ClassPathXmlApplicationContext(appContextFile, getClass());
ICounter counter = (ICounter) context.getBean("counter");
assertTrue("Proxy didn't get created", counter instanceof Advised);
boolean condition = counter instanceof Advised;
assertThat(condition).as("Proxy didn't get created").isTrue();
counter.increment();
JoinPointMonitorAtAspectJAspect callCountingAspect = (JoinPointMonitorAtAspectJAspect)context.getBean("monitoringAspect");
assertEquals("Advise didn't get executed", 1, callCountingAspect.beforeExecutions);
assertEquals("Advise didn't get executed", 1, callCountingAspect.aroundExecutions);
assertThat(callCountingAspect.beforeExecutions).as("Advise didn't get executed").isEqualTo(1);
assertThat(callCountingAspect.aroundExecutions).as("Advise didn't get executed").isEqualTo(1);
}
}

View File

@@ -24,8 +24,7 @@ import org.junit.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Adrian Colyer
@@ -52,20 +51,20 @@ public class SubtypeSensitiveMatchingTests {
@Test
public void testBeansAreProxiedOnStaticMatch() {
assertTrue("bean with serializable type should be proxied",
this.serializableBean instanceof Advised);
boolean condition = this.serializableBean instanceof Advised;
assertThat(condition).as("bean with serializable type should be proxied").isTrue();
}
@Test
public void testBeansThatDoNotMatchBasedSolelyOnRuntimeTypeAreNotProxied() {
assertFalse("bean with non-serializable type should not be proxied",
this.nonSerializableBean instanceof Advised);
boolean condition = this.nonSerializableBean instanceof Advised;
assertThat(condition).as("bean with non-serializable type should not be proxied").isFalse();
}
@Test
public void testBeansThatDoNotMatchBasedOnOtherTestAreProxied() {
assertTrue("bean with args check should be proxied",
this.bar instanceof Advised);
boolean condition = this.bar instanceof Advised;
assertThat(condition).as("bean with args check should be proxied").isTrue();
}
}

View File

@@ -23,7 +23,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for target selection matching (see SPR-3783).
@@ -64,17 +64,17 @@ public class TargetPointcutSelectionTests {
@Test
public void targetSelectionForMatchedType() {
testImpl1.interfaceMethod();
assertEquals("Should have been advised by POJO advice for impl", 1, testAspectForTestImpl1.count);
assertEquals("Should have been advised by POJO advice for base type", 1, testAspectForAbstractTestImpl.count);
assertEquals("Should have been advised by advisor", 1, testInterceptor.count);
assertThat(testAspectForTestImpl1.count).as("Should have been advised by POJO advice for impl").isEqualTo(1);
assertThat(testAspectForAbstractTestImpl.count).as("Should have been advised by POJO advice for base type").isEqualTo(1);
assertThat(testInterceptor.count).as("Should have been advised by advisor").isEqualTo(1);
}
@Test
public void targetNonSelectionForMismatchedType() {
testImpl2.interfaceMethod();
assertEquals("Shouldn't have been advised by POJO advice for impl", 0, testAspectForTestImpl1.count);
assertEquals("Should have been advised by POJO advice for base type", 1, testAspectForAbstractTestImpl.count);
assertEquals("Shouldn't have been advised by advisor", 0, testInterceptor.count);
assertThat(testAspectForTestImpl1.count).as("Shouldn't have been advised by POJO advice for impl").isEqualTo(0);
assertThat(testAspectForAbstractTestImpl.count).as("Should have been advised by POJO advice for base type").isEqualTo(1);
assertThat(testInterceptor.count).as("Shouldn't have been advised by advisor").isEqualTo(0);
}

View File

@@ -25,7 +25,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Ramnivas Laddad
@@ -57,56 +57,56 @@ public class ThisAndTargetSelectionOnlyPointcutsAtAspectJTests {
@Test
public void thisAsClassDoesNotMatch() {
testBean.doIt();
assertEquals(0, counter.thisAsClassCounter);
assertThat(counter.thisAsClassCounter).isEqualTo(0);
}
@Test
public void thisAsInterfaceMatch() {
testBean.doIt();
assertEquals(1, counter.thisAsInterfaceCounter);
assertThat(counter.thisAsInterfaceCounter).isEqualTo(1);
}
@Test
public void targetAsClassDoesMatch() {
testBean.doIt();
assertEquals(1, counter.targetAsClassCounter);
assertThat(counter.targetAsClassCounter).isEqualTo(1);
}
@Test
public void targetAsInterfaceMatch() {
testBean.doIt();
assertEquals(1, counter.targetAsInterfaceCounter);
assertThat(counter.targetAsInterfaceCounter).isEqualTo(1);
}
@Test
public void thisAsClassAndTargetAsClassCounterNotMatch() {
testBean.doIt();
assertEquals(0, counter.thisAsClassAndTargetAsClassCounter);
assertThat(counter.thisAsClassAndTargetAsClassCounter).isEqualTo(0);
}
@Test
public void thisAsInterfaceAndTargetAsInterfaceCounterMatch() {
testBean.doIt();
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
assertThat(counter.thisAsInterfaceAndTargetAsInterfaceCounter).isEqualTo(1);
}
@Test
public void thisAsInterfaceAndTargetAsClassCounterMatch() {
testBean.doIt();
assertEquals(1, counter.thisAsInterfaceAndTargetAsInterfaceCounter);
assertThat(counter.thisAsInterfaceAndTargetAsInterfaceCounter).isEqualTo(1);
}
@Test
public void atTargetClassAnnotationMatch() {
testAnnotatedClassBean.doIt();
assertEquals(1, counter.atTargetClassAnnotationCounter);
assertThat(counter.atTargetClassAnnotationCounter).isEqualTo(1);
}
@Test
public void atAnnotationMethodAnnotationMatch() {
testAnnotatedMethodBean.doIt();
assertEquals(1, counter.atAnnotationMethodAnnotationCounter);
assertThat(counter.atAnnotationMethodAnnotationCounter).isEqualTo(1);
}
public static interface TestInterface {

View File

@@ -21,7 +21,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Ramnivas Laddad
@@ -66,43 +66,43 @@ public class ThisAndTargetSelectionOnlyPointcutsTests {
@Test
public void testThisAsClassDoesNotMatch() {
testBean.doIt();
assertEquals(0, thisAsClassCounter.getCount());
assertThat(thisAsClassCounter.getCount()).isEqualTo(0);
}
@Test
public void testThisAsInterfaceMatch() {
testBean.doIt();
assertEquals(1, thisAsInterfaceCounter.getCount());
assertThat(thisAsInterfaceCounter.getCount()).isEqualTo(1);
}
@Test
public void testTargetAsClassDoesMatch() {
testBean.doIt();
assertEquals(1, targetAsClassCounter.getCount());
assertThat(targetAsClassCounter.getCount()).isEqualTo(1);
}
@Test
public void testTargetAsInterfaceMatch() {
testBean.doIt();
assertEquals(1, targetAsInterfaceCounter.getCount());
assertThat(targetAsInterfaceCounter.getCount()).isEqualTo(1);
}
@Test
public void testThisAsClassAndTargetAsClassCounterNotMatch() {
testBean.doIt();
assertEquals(0, thisAsClassAndTargetAsClassCounter.getCount());
assertThat(thisAsClassAndTargetAsClassCounter.getCount()).isEqualTo(0);
}
@Test
public void testThisAsInterfaceAndTargetAsInterfaceCounterMatch() {
testBean.doIt();
assertEquals(1, thisAsInterfaceAndTargetAsInterfaceCounter.getCount());
assertThat(thisAsInterfaceAndTargetAsInterfaceCounter.getCount()).isEqualTo(1);
}
@Test
public void testThisAsInterfaceAndTargetAsClassCounterMatch() {
testBean.doIt();
assertEquals(1, thisAsInterfaceAndTargetAsInterfaceCounter.getCount());
assertThat(thisAsInterfaceAndTargetAsInterfaceCounter.getCount()).isEqualTo(1);
}
}

View File

@@ -21,7 +21,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Adrian Colyer
@@ -42,13 +42,13 @@ public class AnnotationBindingTests {
@Test
public void testAnnotationBindingInAroundAdvice() {
assertEquals("this value", testBean.doThis());
assertEquals("that value", testBean.doThat());
assertThat(testBean.doThis()).isEqualTo("this value");
assertThat(testBean.doThat()).isEqualTo("that value");
}
@Test
public void testNoMatchingWithoutAnnotationPresent() {
assertEquals("doTheOther", testBean.doTheOther());
assertThat(testBean.doTheOther()).isEqualTo("doTheOther");
}
}

View File

@@ -23,7 +23,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
@@ -45,12 +45,12 @@ public class AnnotationPointcutTests {
@Test
public void testAnnotationBindingInAroundAdvice() {
assertEquals("this value", testBean.doThis());
assertThat(testBean.doThis()).isEqualTo("this value");
}
@Test
public void testNoMatchingWithoutAnnotationPresent() {
assertEquals("doTheOther", testBean.doTheOther());
assertThat(testBean.doTheOther()).isEqualTo("doTheOther");
}
}

View File

@@ -23,8 +23,7 @@ import org.springframework.aop.framework.Advised;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test for ensuring the aspects aren't advised. See SPR-3893 for more details.
@@ -42,8 +41,10 @@ public class AspectImplementingInterfaceTests {
ITestBean testBean = (ITestBean) ctx.getBean("testBean");
AnInterface interfaceExtendingAspect = (AnInterface) ctx.getBean("interfaceExtendingAspect");
assertTrue(testBean instanceof Advised);
assertFalse(interfaceExtendingAspect instanceof Advised);
boolean condition = testBean instanceof Advised;
assertThat(condition).isTrue();
boolean condition1 = interfaceExtendingAspect instanceof Advised;
assertThat(condition1).isFalse();
}
}

View File

@@ -22,8 +22,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rod Johnson
@@ -38,11 +37,11 @@ public class AspectJAutoProxyCreatorAndLazyInitTargetSourceTests {
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
ITestBean adrian = (ITestBean) ctx.getBean("adrian");
assertEquals(0, LazyTestBean.instantiations);
assertNotNull(adrian);
assertThat(LazyTestBean.instantiations).isEqualTo(0);
assertThat(adrian).isNotNull();
adrian.getAge();
assertEquals(68, adrian.getAge());
assertEquals(1, LazyTestBean.instantiations);
assertThat(adrian.getAge()).isEqualTo(68);
assertThat(LazyTestBean.instantiations).isEqualTo(1);
}
}

View File

@@ -59,10 +59,7 @@ import org.springframework.tests.sample.beans.NestedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.StopWatch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for AspectJ auto-proxying. Includes mixing with Spring AOP Advisors
@@ -83,10 +80,10 @@ public class AspectJAutoProxyCreatorTests {
ClassPathXmlApplicationContext bf = newContext("aspects.xml");
ITestBean tb = (ITestBean) bf.getBean("adrian");
assertEquals(68, tb.getAge());
assertThat(tb.getAge()).isEqualTo(68);
MethodInvokingFactoryBean factoryBean = (MethodInvokingFactoryBean) bf.getBean("&factoryBean");
assertTrue(AopUtils.isAopProxy(factoryBean.getTargetObject()));
assertEquals(68, ((ITestBean) factoryBean.getTargetObject()).getAge());
assertThat(AopUtils.isAopProxy(factoryBean.getTargetObject())).isTrue();
assertThat(((ITestBean) factoryBean.getTargetObject()).getAge()).isEqualTo(68);
}
@Test
@@ -95,7 +92,7 @@ public class AspectJAutoProxyCreatorTests {
ITestBean tb = (ITestBean) bf.getBean("adrian");
tb.setAge(10);
assertEquals(20, tb.getAge());
assertThat(tb.getAge()).isEqualTo(20);
}
@Test
@@ -103,7 +100,7 @@ public class AspectJAutoProxyCreatorTests {
ClassPathXmlApplicationContext bf = newContext("aspectsWithOrdering.xml");
ITestBean tb = (ITestBean) bf.getBean("adrian");
assertEquals(71, tb.getAge());
assertThat(tb.getAge()).isEqualTo(71);
}
@Test
@@ -148,7 +145,7 @@ public class AspectJAutoProxyCreatorTests {
for (int i = 0; i < 100000; i++) {
INestedTestBean shouldNotBeWeaved = (INestedTestBean) ac.getBean("i21");
if (i < 10) {
assertFalse(AopUtils.isAopProxy(shouldNotBeWeaved));
assertThat(AopUtils.isAopProxy(shouldNotBeWeaved)).isFalse();
}
}
sw.stop();
@@ -204,17 +201,17 @@ public class AspectJAutoProxyCreatorTests {
TestBeanAdvisor tba = (TestBeanAdvisor) ac.getBean("advisor");
MultiplyReturnValue mrv = (MultiplyReturnValue) ac.getBean("aspect");
assertEquals(3, mrv.getMultiple());
assertThat(mrv.getMultiple()).isEqualTo(3);
tba.count = 0;
mrv.invocations = 0;
assertTrue("Autoproxying must apply from @AspectJ aspect", AopUtils.isAopProxy(shouldBeWeaved));
assertEquals("Adrian", shouldBeWeaved.getName());
assertEquals(0, mrv.invocations);
assertEquals(34 * mrv.getMultiple(), shouldBeWeaved.getAge());
assertEquals("Spring advisor must be invoked", 2, tba.count);
assertEquals("Must be able to hold state in aspect", 1, mrv.invocations);
assertThat(AopUtils.isAopProxy(shouldBeWeaved)).as("Autoproxying must apply from @AspectJ aspect").isTrue();
assertThat(shouldBeWeaved.getName()).isEqualTo("Adrian");
assertThat(mrv.invocations).isEqualTo(0);
assertThat(shouldBeWeaved.getAge()).isEqualTo((34 * mrv.getMultiple()));
assertThat(tba.count).as("Spring advisor must be invoked").isEqualTo(2);
assertThat(mrv.invocations).as("Must be able to hold state in aspect").isEqualTo(1);
}
@Test
@@ -222,19 +219,19 @@ public class AspectJAutoProxyCreatorTests {
ClassPathXmlApplicationContext bf = newContext("perthis.xml");
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
assertTrue(AopUtils.isAopProxy(adrian1));
assertThat(AopUtils.isAopProxy(adrian1)).isTrue();
assertEquals(0, adrian1.getAge());
assertEquals(1, adrian1.getAge());
assertThat(adrian1.getAge()).isEqualTo(0);
assertThat(adrian1.getAge()).isEqualTo(1);
ITestBean adrian2 = (ITestBean) bf.getBean("adrian");
assertNotSame(adrian1, adrian2);
assertTrue(AopUtils.isAopProxy(adrian1));
assertEquals(0, adrian2.getAge());
assertEquals(1, adrian2.getAge());
assertEquals(2, adrian2.getAge());
assertEquals(3, adrian2.getAge());
assertEquals(2, adrian1.getAge());
assertThat(adrian2).isNotSameAs(adrian1);
assertThat(AopUtils.isAopProxy(adrian1)).isTrue();
assertThat(adrian2.getAge()).isEqualTo(0);
assertThat(adrian2.getAge()).isEqualTo(1);
assertThat(adrian2.getAge()).isEqualTo(2);
assertThat(adrian2.getAge()).isEqualTo(3);
assertThat(adrian1.getAge()).isEqualTo(2);
}
@Test
@@ -242,35 +239,35 @@ public class AspectJAutoProxyCreatorTests {
ClassPathXmlApplicationContext bf = newContext("pertarget.xml");
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
assertTrue(AopUtils.isAopProxy(adrian1));
assertThat(AopUtils.isAopProxy(adrian1)).isTrue();
// Does not trigger advice or count
int explicitlySetAge = 25;
adrian1.setAge(explicitlySetAge);
assertEquals("Setter does not initiate advice", explicitlySetAge, adrian1.getAge());
assertThat(adrian1.getAge()).as("Setter does not initiate advice").isEqualTo(explicitlySetAge);
// Fire aspect
AspectMetadata am = new AspectMetadata(PerTargetAspect.class, "someBean");
assertTrue(am.getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
assertThat(am.getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
adrian1.getSpouse();
assertEquals("Advice has now been instantiated", 0, adrian1.getAge());
assertThat(adrian1.getAge()).as("Advice has now been instantiated").isEqualTo(0);
adrian1.setAge(11);
assertEquals("Any int setter increments", 2, adrian1.getAge());
assertThat(adrian1.getAge()).as("Any int setter increments").isEqualTo(2);
adrian1.setName("Adrian");
//assertEquals("Any other setter does not increment", 2, adrian1.getAge());
ITestBean adrian2 = (ITestBean) bf.getBean("adrian");
assertNotSame(adrian1, adrian2);
assertTrue(AopUtils.isAopProxy(adrian1));
assertEquals(34, adrian2.getAge());
assertThat(adrian2).isNotSameAs(adrian1);
assertThat(AopUtils.isAopProxy(adrian1)).isTrue();
assertThat(adrian2.getAge()).isEqualTo(34);
adrian2.getSpouse();
assertEquals("Aspect now fired", 0, adrian2.getAge());
assertEquals(1, adrian2.getAge());
assertEquals(2, adrian2.getAge());
assertEquals(3, adrian1.getAge());
assertThat(adrian2.getAge()).as("Aspect now fired").isEqualTo(0);
assertThat(adrian2.getAge()).isEqualTo(1);
assertThat(adrian2.getAge()).isEqualTo(2);
assertThat(adrian1.getAge()).isEqualTo(3);
}
@Test
@@ -288,7 +285,7 @@ public class AspectJAutoProxyCreatorTests {
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
testAgeAspect(adrian1, 0, 1);
ITestBean adrian2 = (ITestBean) bf.getBean("adrian");
assertNotSame(adrian1, adrian2);
assertThat(adrian2).isNotSameAs(adrian1);
testAgeAspect(adrian2, 2, 1);
}
@@ -299,19 +296,19 @@ public class AspectJAutoProxyCreatorTests {
ITestBean adrian1 = (ITestBean) bf.getBean("adrian");
testAgeAspect(adrian1, 0, 1);
ITestBean adrian2 = (ITestBean) bf.getBean("adrian");
assertNotSame(adrian1, adrian2);
assertThat(adrian2).isNotSameAs(adrian1);
testAgeAspect(adrian2, 0, 1);
}
private void testAgeAspect(ITestBean adrian, int start, int increment) {
assertTrue(AopUtils.isAopProxy(adrian));
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
adrian.setName("");
assertEquals(start, adrian.age());
assertThat(adrian.age()).isEqualTo(start);
int newAge = 32;
adrian.setAge(newAge);
assertEquals(start + increment, adrian.age());
assertThat(adrian.age()).isEqualTo((start + increment));
adrian.setAge(0);
assertEquals(start + increment * 2, adrian.age());
assertThat(adrian.age()).isEqualTo((start + increment * 2));
}
@Test
@@ -323,7 +320,7 @@ public class AspectJAutoProxyCreatorTests {
AdviceUsingThisJoinPoint aspectInstance = (AdviceUsingThisJoinPoint) bf.getBean("aspect");
//(AdviceUsingThisJoinPoint) Aspects.aspectOf(AdviceUsingThisJoinPoint.class);
//assertEquals("method-execution(int TestBean.getAge())",aspectInstance.getLastMethodEntered());
assertTrue(aspectInstance.getLastMethodEntered().indexOf("TestBean.getAge())") != 0);
assertThat(aspectInstance.getLastMethodEntered().indexOf("TestBean.getAge())") != 0).isTrue();
}
@Test
@@ -331,8 +328,8 @@ public class AspectJAutoProxyCreatorTests {
ClassPathXmlApplicationContext bf = newContext("usesInclude.xml");
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertTrue(AopUtils.isAopProxy(adrian));
assertEquals(68, adrian.getAge());
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
assertThat(adrian.getAge()).isEqualTo(68);
}
@Test
@@ -340,8 +337,8 @@ public class AspectJAutoProxyCreatorTests {
ClassPathXmlApplicationContext bf = newContext("aspectsWithCGLIB.xml");
ProxyConfig pc = (ProxyConfig) bf.getBean(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
assertTrue("should be proxying classes", pc.isProxyTargetClass());
assertTrue("should expose proxy", pc.isExposeProxy());
assertThat(pc.isProxyTargetClass()).as("should be proxying classes").isTrue();
assertThat(pc.isExposeProxy()).as("should expose proxy").isTrue();
}
@Test
@@ -349,8 +346,8 @@ public class AspectJAutoProxyCreatorTests {
ClassPathXmlApplicationContext bf = newContext("aspectsWithAbstractBean.xml");
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertTrue(AopUtils.isAopProxy(adrian));
assertEquals(68, adrian.getAge());
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
assertThat(adrian.getAge()).isEqualTo(68);
}
@Test
@@ -360,10 +357,10 @@ public class AspectJAutoProxyCreatorTests {
UnreliableBean bean = (UnreliableBean) bf.getBean("unreliableBean");
RetryAspect aspect = (RetryAspect) bf.getBean("retryAspect");
int attempts = bean.unreliable();
assertEquals(2, attempts);
assertEquals(2, aspect.getBeginCalls());
assertEquals(1, aspect.getRollbackCalls());
assertEquals(1, aspect.getCommitCalls());
assertThat(attempts).isEqualTo(2);
assertThat(aspect.getBeginCalls()).isEqualTo(2);
assertThat(aspect.getRollbackCalls()).isEqualTo(1);
assertThat(aspect.getCommitCalls()).isEqualTo(1);
}
@Test
@@ -371,7 +368,7 @@ public class AspectJAutoProxyCreatorTests {
ClassPathXmlApplicationContext bf = newContext("withBeanNameAutoProxyCreator.xml");
ITestBean tb = (ITestBean) bf.getBean("adrian");
assertEquals(68, tb.getAge());
assertThat(tb.getAge()).isEqualTo(68);
}
@@ -393,8 +390,8 @@ public class AspectJAutoProxyCreatorTests {
private void assertStopWatchTimeLimit(final StopWatch sw, final long maxTimeMillis) {
long totalTimeMillis = sw.getTotalTimeMillis();
assertTrue("'" + sw.getLastTaskName() + "' took too long: expected less than<" + maxTimeMillis +
"> ms, actual<" + totalTimeMillis + "> ms.", totalTimeMillis < maxTimeMillis);
assertThat(totalTimeMillis < maxTimeMillis).as("'" + sw.getLastTaskName() + "' took too long: expected less than<" + maxTimeMillis +
"> ms, actual<" + totalTimeMillis + "> ms.").isTrue();
}
}

View File

@@ -26,9 +26,7 @@ import org.springframework.aop.support.AopUtils;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Harrop
@@ -45,7 +43,7 @@ public class AtAspectJAfterThrowingTests {
ITestBean bean = (ITestBean) ctx.getBean("testBean");
ExceptionHandlingAspect aspect = (ExceptionHandlingAspect) ctx.getBean("aspect");
assertTrue(AopUtils.isAopProxy(bean));
assertThat(AopUtils.isAopProxy(bean)).isTrue();
try {
bean.unreliableFileOperation();
}
@@ -53,8 +51,8 @@ public class AtAspectJAfterThrowingTests {
//
}
assertEquals(1, aspect.handled);
assertNotNull(aspect.lastException);
assertThat(aspect.handled).isEqualTo(1);
assertThat(aspect.lastException).isNotNull();
}
}

View File

@@ -26,7 +26,7 @@ import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Adrian Colyer
@@ -48,14 +48,14 @@ public class AtAspectJAnnotationBindingTests {
@Test
public void testAnnotationBindingInAroundAdvice() {
assertEquals("this value doThis", testBean.doThis());
assertEquals("that value doThat", testBean.doThat());
assertEquals(2, testBean.doArray().length);
assertThat(testBean.doThis()).isEqualTo("this value doThis");
assertThat(testBean.doThat()).isEqualTo("that value doThat");
assertThat(testBean.doArray().length).isEqualTo(2);
}
@Test
public void testNoMatchingWithoutAnnotationPresent() {
assertEquals("doTheOther", testBean.doTheOther());
assertThat(testBean.doTheOther()).isEqualTo("doTheOther");
}
@Test

View File

@@ -36,8 +36,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.util.StopWatch;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for AspectJ auto proxying. Includes mixing with Spring AOP
@@ -108,8 +107,8 @@ public class BenchmarkTests {
sw.start(howmany + " repeated around advice invocations with " + technology);
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertTrue(AopUtils.isAopProxy(adrian));
assertEquals(68, adrian.getAge());
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
assertThat(adrian.getAge()).isEqualTo(68);
for (int i = 0; i < howmany; i++) {
adrian.getAge();
@@ -127,10 +126,10 @@ public class BenchmarkTests {
sw.start(howmany + " repeated before advice invocations with " + technology);
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertTrue(AopUtils.isAopProxy(adrian));
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
Advised a = (Advised) adrian;
assertTrue(a.getAdvisors().length >= 3);
assertEquals("adrian", adrian.getName());
assertThat(a.getAdvisors().length >= 3).isTrue();
assertThat(adrian.getName()).isEqualTo("adrian");
for (int i = 0; i < howmany; i++) {
adrian.getName();
@@ -148,9 +147,9 @@ public class BenchmarkTests {
sw.start(howmany + " repeated after returning advice invocations with " + technology);
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertTrue(AopUtils.isAopProxy(adrian));
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
Advised a = (Advised) adrian;
assertTrue(a.getAdvisors().length >= 3);
assertThat(a.getAdvisors().length >= 3).isTrue();
// Hits joinpoint
adrian.setAge(25);
@@ -170,9 +169,9 @@ public class BenchmarkTests {
sw.start(howmany + " repeated mixed invocations with " + technology);
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertTrue(AopUtils.isAopProxy(adrian));
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
Advised a = (Advised) adrian;
assertTrue(a.getAdvisors().length >= 3);
assertThat(a.getAdvisors().length >= 3).isTrue();
for (int i = 0; i < howmany; i++) {
// Hit all 3 joinpoints

View File

@@ -29,7 +29,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.Employee;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests ensuring that after-returning advice for generic parameters bound to
@@ -62,42 +62,42 @@ public class AfterReturningGenericTypeMatchingTests {
@Test
public void testReturnTypeExactMatching() {
testBean.getStrings();
assertEquals(1, counterAspect.getStringsInvocationsCount);
assertEquals(0, counterAspect.getIntegersInvocationsCount);
assertThat(counterAspect.getStringsInvocationsCount).isEqualTo(1);
assertThat(counterAspect.getIntegersInvocationsCount).isEqualTo(0);
counterAspect.reset();
testBean.getIntegers();
assertEquals(0, counterAspect.getStringsInvocationsCount);
assertEquals(1, counterAspect.getIntegersInvocationsCount);
assertThat(counterAspect.getStringsInvocationsCount).isEqualTo(0);
assertThat(counterAspect.getIntegersInvocationsCount).isEqualTo(1);
}
@Test
public void testReturnTypeRawMatching() {
testBean.getStrings();
assertEquals(1, counterAspect.getRawsInvocationsCount);
assertThat(counterAspect.getRawsInvocationsCount).isEqualTo(1);
counterAspect.reset();
testBean.getIntegers();
assertEquals(1, counterAspect.getRawsInvocationsCount);
assertThat(counterAspect.getRawsInvocationsCount).isEqualTo(1);
}
@Test
public void testReturnTypeUpperBoundMatching() {
testBean.getIntegers();
assertEquals(1, counterAspect.getNumbersInvocationsCount);
assertThat(counterAspect.getNumbersInvocationsCount).isEqualTo(1);
}
@Test
public void testReturnTypeLowerBoundMatching() {
testBean.getTestBeans();
assertEquals(1, counterAspect.getTestBeanInvocationsCount);
assertThat(counterAspect.getTestBeanInvocationsCount).isEqualTo(1);
counterAspect.reset();
testBean.getEmployees();
assertEquals(0, counterAspect.getTestBeanInvocationsCount);
assertThat(counterAspect.getTestBeanInvocationsCount).isEqualTo(0);
}
}

View File

@@ -18,7 +18,7 @@ package org.springframework.aop.aspectj.generic;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for AspectJ pointcut expression matching when working with bridge methods.
@@ -35,13 +35,13 @@ public class GenericBridgeMethodMatchingClassProxyTests extends GenericBridgeMet
@Test
public void testGenericDerivedInterfaceMethodThroughClass() {
((DerivedStringParameterizedClass) testBean).genericDerivedInterfaceMethod("");
assertEquals(1, counterAspect.count);
assertThat(counterAspect.count).isEqualTo(1);
}
@Test
public void testGenericBaseInterfaceMethodThroughClass() {
((DerivedStringParameterizedClass) testBean).genericBaseInterfaceMethod("");
assertEquals(1, counterAspect.count);
assertThat(counterAspect.count).isEqualTo(1);
}
}

View File

@@ -22,7 +22,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for AspectJ pointcut expression matching when working with bridge methods.
@@ -62,13 +62,13 @@ public class GenericBridgeMethodMatchingTests {
@Test
public void testGenericDerivedInterfaceMethodThroughInterface() {
testBean.genericDerivedInterfaceMethod("");
assertEquals(1, counterAspect.count);
assertThat(counterAspect.count).isEqualTo(1);
}
@Test
public void testGenericBaseInterfaceMethodThroughInterface() {
testBean.genericBaseInterfaceMethod("");
assertEquals(1, counterAspect.count);
assertThat(counterAspect.count).isEqualTo(1);
}
}

View File

@@ -25,7 +25,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests that poitncut matching is correct with generic method parameter.
@@ -57,19 +57,19 @@ public class GenericParameterMatchingTests {
@Test
public void testGenericInterfaceGenericArgExecution() {
testBean.save("");
assertEquals(1, counterAspect.genericInterfaceGenericArgExecutionCount);
assertThat(counterAspect.genericInterfaceGenericArgExecutionCount).isEqualTo(1);
}
@Test
public void testGenericInterfaceGenericCollectionArgExecution() {
testBean.saveAll(null);
assertEquals(1, counterAspect.genericInterfaceGenericCollectionArgExecutionCount);
assertThat(counterAspect.genericInterfaceGenericCollectionArgExecutionCount).isEqualTo(1);
}
@Test
public void testGenericInterfaceSubtypeGenericCollectionArgExecution() {
testBean.saveAll(null);
assertEquals(1, counterAspect.genericInterfaceSubtypeGenericCollectionArgExecutionCount);
assertThat(counterAspect.genericInterfaceSubtypeGenericCollectionArgExecutionCount).isEqualTo(1);
}

View File

@@ -22,7 +22,7 @@ import org.springframework.aop.framework.Advised;
import org.springframework.aop.support.AopUtils;
import org.springframework.tests.sample.beans.ITestBean;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Harrop
@@ -33,8 +33,8 @@ public class AopNamespaceHandlerProxyTargetClassTests extends AopNamespaceHandle
@Test
public void testIsClassProxy() {
ITestBean bean = getTestBean();
assertTrue("Should be a CGLIB proxy", AopUtils.isCglibProxy(bean));
assertTrue("Should expose proxy", ((Advised) bean).isExposeProxy());
assertThat(AopUtils.isCglibProxy(bean)).as("Should be a CGLIB proxy").isTrue();
assertThat(((Advised) bean).isExposeProxy()).as("Should expose proxy").isTrue();
}
}

View File

@@ -29,8 +29,7 @@ import org.springframework.tests.aop.advice.CountingBeforeAdvice;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for aop namespace.
@@ -57,13 +56,13 @@ public class AopNamespaceHandlerTests {
public void testIsProxy() throws Exception {
ITestBean bean = getTestBean();
assertTrue("Bean is not a proxy", AopUtils.isAopProxy(bean));
assertThat(AopUtils.isAopProxy(bean)).as("Bean is not a proxy").isTrue();
// check the advice details
Advised advised = (Advised) bean;
Advisor[] advisors = advised.getAdvisors();
assertTrue("Advisors should not be empty", advisors.length > 0);
assertThat(advisors.length > 0).as("Advisors should not be empty").isTrue();
}
@Test
@@ -73,18 +72,18 @@ public class AopNamespaceHandlerTests {
ITestBean bean = getTestBean();
assertEquals("Incorrect initial getAge count", 0, getAgeCounter.getCalls("getAge"));
assertEquals("Incorrect initial getName count", 0, getNameCounter.getCalls("getName"));
assertThat(getAgeCounter.getCalls("getAge")).as("Incorrect initial getAge count").isEqualTo(0);
assertThat(getNameCounter.getCalls("getName")).as("Incorrect initial getName count").isEqualTo(0);
bean.getAge();
assertEquals("Incorrect getAge count on getAge counter", 1, getAgeCounter.getCalls("getAge"));
assertEquals("Incorrect getAge count on getName counter", 0, getNameCounter.getCalls("getAge"));
assertThat(getAgeCounter.getCalls("getAge")).as("Incorrect getAge count on getAge counter").isEqualTo(1);
assertThat(getNameCounter.getCalls("getAge")).as("Incorrect getAge count on getName counter").isEqualTo(0);
bean.getName();
assertEquals("Incorrect getName count on getName counter", 1, getNameCounter.getCalls("getName"));
assertEquals("Incorrect getName count on getAge counter", 0, getAgeCounter.getCalls("getName"));
assertThat(getNameCounter.getCalls("getName")).as("Incorrect getName count on getName counter").isEqualTo(1);
assertThat(getAgeCounter.getCalls("getName")).as("Incorrect getName count on getAge counter").isEqualTo(0);
}
@Test
@@ -93,18 +92,18 @@ public class AopNamespaceHandlerTests {
CountingAspectJAdvice advice = (CountingAspectJAdvice) this.context.getBean("countingAdvice");
assertEquals("Incorrect before count", 0, advice.getBeforeCount());
assertEquals("Incorrect after count", 0, advice.getAfterCount());
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(0);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(0);
bean.setName("Sally");
assertEquals("Incorrect before count", 1, advice.getBeforeCount());
assertEquals("Incorrect after count", 1, advice.getAfterCount());
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(1);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(1);
bean.getName();
assertEquals("Incorrect before count", 1, advice.getBeforeCount());
assertEquals("Incorrect after count", 1, advice.getAfterCount());
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(1);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(1);
}
@Test
@@ -113,18 +112,18 @@ public class AopNamespaceHandlerTests {
CountingAspectJAdvice advice = (CountingAspectJAdvice) this.context.getBean("countingAdvice");
assertEquals("Incorrect before count", 0, advice.getBeforeCount());
assertEquals("Incorrect after count", 0, advice.getAfterCount());
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(0);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(0);
bean.setName("Sally");
assertEquals("Incorrect before count", 1, advice.getBeforeCount());
assertEquals("Incorrect after count", 1, advice.getAfterCount());
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(1);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(1);
bean.getName();
assertEquals("Incorrect before count", 1, advice.getBeforeCount());
assertEquals("Incorrect after count", 1, advice.getAfterCount());
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(1);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(1);
}
@Test
@@ -133,18 +132,18 @@ public class AopNamespaceHandlerTests {
CountingAspectJAdvice advice = (CountingAspectJAdvice) this.context.getBean("countingAdvice");
assertEquals("Incorrect before count", 0, advice.getBeforeCount());
assertEquals("Incorrect after count", 0, advice.getAfterCount());
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(0);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(0);
bean.setName("Sally");
assertEquals("Incorrect before count", 1, advice.getBeforeCount());
assertEquals("Incorrect after count", 1, advice.getAfterCount());
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(1);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(1);
bean.getName();
assertEquals("Incorrect before count", 1, advice.getBeforeCount());
assertEquals("Incorrect after count", 1, advice.getAfterCount());
assertThat(advice.getBeforeCount()).as("Incorrect before count").isEqualTo(1);
assertThat(advice.getAfterCount()).as("Incorrect after count").isEqualTo(1);
}
}

View File

@@ -23,10 +23,8 @@ import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -49,12 +47,12 @@ public class MethodLocatingFactoryBeanTests {
@Test
public void testIsSingleton() {
assertTrue(factory.isSingleton());
assertThat(factory.isSingleton()).isTrue();
}
@Test
public void testGetObjectType() {
assertEquals(Method.class, factory.getObjectType());
assertThat(factory.getObjectType()).isEqualTo(Method.class);
}
@Test
@@ -104,10 +102,11 @@ public class MethodLocatingFactoryBeanTests {
factory.setMethodName("toString()");
factory.setBeanFactory(beanFactory);
Object result = factory.getObject();
assertNotNull(result);
assertTrue(result instanceof Method);
assertThat(result).isNotNull();
boolean condition = result instanceof Method;
assertThat(condition).isTrue();
Method method = (Method) result;
assertEquals("Bingo", method.invoke("Bingo"));
assertThat(method.invoke("Bingo")).isEqualTo("Bingo");
}
@Test

View File

@@ -39,10 +39,6 @@ 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.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* Additional and overridden tests for CGLIB proxies.
@@ -64,7 +60,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
protected Object createProxy(ProxyCreatorSupport as) {
as.setProxyTargetClass(true);
Object proxy = as.createAopProxy().getProxy();
assertTrue(AopUtils.isCglibProxy(proxy));
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
return proxy;
}
@@ -107,9 +103,9 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
AopProxy aop = new CglibAopProxy(as);
ProtectedMethodTestBean proxy = (ProtectedMethodTestBean) aop.getProxy();
assertTrue(AopUtils.isCglibProxy(proxy));
assertEquals(proxy.getClass().getClassLoader(), bean.getClass().getClassLoader());
assertEquals("foo", proxy.getString());
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
assertThat(bean.getClass().getClassLoader()).isEqualTo(proxy.getClass().getClassLoader());
assertThat(proxy.getString()).isEqualTo("foo");
}
@Test
@@ -124,9 +120,9 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
AopProxy aop = new CglibAopProxy(as);
PackageMethodTestBean proxy = (PackageMethodTestBean) aop.getProxy();
assertTrue(AopUtils.isCglibProxy(proxy));
assertEquals(proxy.getClass().getClassLoader(), bean.getClass().getClassLoader());
assertEquals("foo", proxy.getString());
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
assertThat(bean.getClass().getClassLoader()).isEqualTo(proxy.getClass().getClassLoader());
assertThat(proxy.getString()).isEqualTo("foo");
}
@Test
@@ -139,12 +135,12 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
AopProxy aop = new CglibAopProxy(pc);
Object proxy = aop.getProxy();
assertTrue(AopUtils.isCglibProxy(proxy));
assertTrue(proxy instanceof ITestBean);
assertTrue(proxy instanceof TestBean);
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
assertThat(proxy instanceof ITestBean).isTrue();
assertThat(proxy instanceof TestBean).isTrue();
TestBean tb = (TestBean) proxy;
assertEquals(32, tb.getAge());
assertThat(tb.getAge()).isEqualTo(32);
}
@Test
@@ -158,7 +154,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
AopProxy aop = new CglibAopProxy(as);
CglibTestBean proxy = (CglibTestBean) aop.getProxy();
assertEquals("The name property has been overwritten by the constructor", "Rob Harrop", proxy.getName());
assertThat(proxy.getName()).as("The name property has been overwritten by the constructor").isEqualTo("Rob Harrop");
}
@Test
@@ -172,7 +168,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
AopProxy aop = new CglibAopProxy(as);
PrivateCglibTestBean proxy = (PrivateCglibTestBean) aop.getProxy();
assertEquals("The name property has been overwritten by the constructor", "Rob Harrop", proxy.toString());
assertThat(proxy.toString()).as("The name property has been overwritten by the constructor").isEqualTo("Rob Harrop");
}
@Test
@@ -186,8 +182,8 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
CglibAopProxy aop = new CglibAopProxy(pc);
CglibTestBean proxy = (CglibTestBean) aop.getProxy();
assertNotNull("Proxy should not be null", proxy);
assertEquals("Constructor overrode the value of name", "Rob Harrop", proxy.getName());
assertThat(proxy).as("Proxy should not be null").isNotNull();
assertThat(proxy.getName()).as("Constructor overrode the value of name").isEqualTo("Rob Harrop");
}
@Test
@@ -199,9 +195,9 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
ITestBean proxy1 = getAdvisedProxy(target);
ITestBean proxy2 = getAdvisedProxy(target2);
assertSame(proxy1.getClass(), proxy2.getClass());
assertEquals(target.getAge(), proxy1.getAge());
assertEquals(target2.getAge(), proxy2.getAge());
assertThat(proxy2.getClass()).isSameAs(proxy1.getClass());
assertThat(proxy1.getAge()).isEqualTo(target.getAge());
assertThat(proxy2.getAge()).isEqualTo(target2.getAge());
}
private ITestBean getAdvisedProxy(TestBean target) {
@@ -245,7 +241,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
ITestBean proxy1 = getIntroductionAdvisorProxy(target1);
ITestBean proxy2 = getIntroductionAdvisorProxy(target2);
assertSame("Incorrect duplicate creation of proxy classes", proxy1.getClass(), proxy2.getClass());
assertThat(proxy2.getClass()).as("Incorrect duplicate creation of proxy classes").isSameAs(proxy1.getClass());
}
private ITestBean getIntroductionAdvisorProxy(TestBean target) {
@@ -272,7 +268,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
aop.setConstructorArguments(new Object[] {"Rob Harrop", 22}, new Class<?>[] {String.class, int.class});
NoArgCtorTestBean proxy = (NoArgCtorTestBean) aop.getProxy();
assertNotNull(proxy);
assertThat(proxy).isNotNull();
}
@Test
@@ -316,7 +312,7 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
cglib = new CglibAopProxy(as);
ITestBean proxy2 = (ITestBean) cglib.getProxy();
assertTrue(proxy2 instanceof Serializable);
assertThat(proxy2 instanceof Serializable).isTrue();
}
@Test
@@ -335,11 +331,11 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
proxy.doTest();
}
catch (Exception ex) {
assertTrue("Invalid exception class", ex instanceof ApplicationContextException);
assertThat(ex instanceof ApplicationContextException).as("Invalid exception class").isTrue();
}
assertTrue("Catch was not invoked", proxy.isCatchInvoked());
assertTrue("Finally was not invoked", proxy.isFinallyInvoked());
assertThat(proxy.isCatchInvoked()).as("Catch was not invoked").isTrue();
assertThat(proxy.isFinallyInvoked()).as("Finally was not invoked").isTrue();
}
@Test
@@ -361,14 +357,14 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
pf.setProxyTargetClass(true);
TestBean proxy = (TestBean) pf.getProxy();
assertTrue(AopUtils.isCglibProxy(proxy));
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
proxy.getAge();
assertEquals(0, cba.getCalls());
assertThat(cba.getCalls()).isEqualTo(0);
((Advised) proxy).addAdvice(cba);
proxy.getAge();
assertEquals(1, cba.getCalls());
assertThat(cba.getCalls()).isEqualTo(1);
}
@Test
@@ -379,22 +375,22 @@ public class CglibProxyTests extends AbstractAopProxyTests implements Serializab
proxyFactory.setProxyTargetClass(true);
MyBean proxy = (MyBean) proxyFactory.getProxy();
assertEquals(4, proxy.add(1, 3));
assertEquals(1, advice.getCalls("add"));
assertThat(proxy.add(1, 3)).isEqualTo(4);
assertThat(advice.getCalls("add")).isEqualTo(1);
}
@Test
public void testProxyTargetClassInCaseOfNoInterfaces() {
ProxyFactory proxyFactory = new ProxyFactory(new MyBean());
MyBean proxy = (MyBean) proxyFactory.getProxy();
assertEquals(4, proxy.add(1, 3));
assertThat(proxy.add(1, 3)).isEqualTo(4);
}
@Test // SPR-13328
public void testVarargsWithEnumArray() {
ProxyFactory proxyFactory = new ProxyFactory(new MyBean());
MyBean proxy = (MyBean) proxyFactory.getProxy();
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
assertThat(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
}

View File

@@ -28,11 +28,8 @@ import org.springframework.tests.sample.beans.IOther;
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.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @author Rod Johnson
@@ -45,9 +42,9 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
@Override
protected Object createProxy(ProxyCreatorSupport as) {
assertFalse("Not forcible CGLIB", as.isProxyTargetClass());
assertThat(as.isProxyTargetClass()).as("Not forcible CGLIB").isFalse();
Object proxy = as.createAopProxy().getProxy();
assertTrue("Should be a JDK proxy: " + proxy.getClass(), AopUtils.isJdkDynamicProxy(proxy));
assertThat(AopUtils.isJdkDynamicProxy(proxy)).as("Should be a JDK proxy: " + proxy.getClass()).isTrue();
return proxy;
}
@@ -72,8 +69,10 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
JdkDynamicAopProxy aop = new JdkDynamicAopProxy(pc);
Object proxy = aop.getProxy();
assertTrue(proxy instanceof ITestBean);
assertFalse(proxy instanceof TestBean);
boolean condition = proxy instanceof ITestBean;
assertThat(condition).isTrue();
boolean condition1 = proxy instanceof TestBean;
assertThat(condition1).isFalse();
}
@Test
@@ -87,7 +86,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
AopProxy aop = createAopProxy(pc);
ITestBean tb = (ITestBean) aop.getProxy();
assertEquals("correct return value", age, tb.getAge());
assertThat(tb.getAge()).as("correct return value").isEqualTo(age);
}
@Test
@@ -95,9 +94,8 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
final ExposedInvocationTestBean expectedTarget = new ExposedInvocationTestBean() {
@Override
protected void assertions(MethodInvocation invocation) {
assertEquals(this, invocation.getThis());
assertEquals("Invocation should be on ITestBean: " + invocation.getMethod(),
ITestBean.class, invocation.getMethod().getDeclaringClass());
assertThat(invocation.getThis()).isEqualTo(this);
assertThat(invocation.getMethod().getDeclaringClass()).as("Invocation should be on ITestBean: " + invocation.getMethod()).isEqualTo(ITestBean.class);
}
};
@@ -107,7 +105,7 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
// Assert that target matches BEFORE invocation returns
assertEquals("Target is correct", expectedTarget, invocation.getThis());
assertThat(invocation.getThis()).as("Target is correct").isEqualTo(expectedTarget);
return super.invoke(invocation);
}
};
@@ -127,8 +125,8 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
as.setTarget(bean);
Foo proxy = (Foo) createProxy(as);
assertSame("Target should be returned when return types are incompatible", bean, proxy.getBarThis());
assertSame("Proxy should be returned when return types are compatible", proxy, proxy.getFooThis());
assertThat(proxy.getBarThis()).as("Target should be returned when return types are incompatible").isSameAs(bean);
assertThat(proxy.getFooThis()).as("Proxy should be returned when return types are compatible").isSameAs(proxy);
}
@Test
@@ -138,15 +136,15 @@ public class JdkDynamicProxyTests extends AbstractAopProxyTests implements Seria
JdkDynamicAopProxy aopProxy = new JdkDynamicAopProxy(as);
Named proxy = (Named) aopProxy.getProxy();
Named named = new Person();
assertEquals("equals()", proxy, named);
assertEquals("hashCode()", proxy.hashCode(), named.hashCode());
assertThat(proxy).isEqualTo(named);
assertThat(named.hashCode()).isEqualTo(proxy.hashCode());
}
@Test // SPR-13328
public void testVarargsWithEnumArray() {
ProxyFactory proxyFactory = new ProxyFactory(new VarargTestBean());
VarargTestInterface proxy = (VarargTestInterface) proxyFactory.getProxy();
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
assertThat(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
}

View File

@@ -63,12 +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.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @since 13.03.2003
@@ -109,25 +103,25 @@ public class ProxyFactoryBeanTests {
@Test
public void testIsDynamicProxyWhenInterfaceSpecified() {
ITestBean test1 = (ITestBean) factory.getBean("test1");
assertTrue("test1 is a dynamic proxy", Proxy.isProxyClass(test1.getClass()));
assertThat(Proxy.isProxyClass(test1.getClass())).as("test1 is a dynamic proxy").isTrue();
}
@Test
public void testIsDynamicProxyWhenInterfaceSpecifiedForPrototype() {
ITestBean test1 = (ITestBean) factory.getBean("test2");
assertTrue("test2 is a dynamic proxy", Proxy.isProxyClass(test1.getClass()));
assertThat(Proxy.isProxyClass(test1.getClass())).as("test2 is a dynamic proxy").isTrue();
}
@Test
public void testIsDynamicProxyWhenAutodetectingInterfaces() {
ITestBean test1 = (ITestBean) factory.getBean("test3");
assertTrue("test3 is a dynamic proxy", Proxy.isProxyClass(test1.getClass()));
assertThat(Proxy.isProxyClass(test1.getClass())).as("test3 is a dynamic proxy").isTrue();
}
@Test
public void testIsDynamicProxyWhenAutodetectingInterfacesForPrototype() {
ITestBean test1 = (ITestBean) factory.getBean("test4");
assertTrue("test4 is a dynamic proxy", Proxy.isProxyClass(test1.getClass()));
assertThat(Proxy.isProxyClass(test1.getClass())).as("test4 is a dynamic proxy").isTrue();
}
/**
@@ -167,14 +161,14 @@ public class ProxyFactoryBeanTests {
// We have a counting before advice here
CountingBeforeAdvice cba = (CountingBeforeAdvice) bf.getBean("countingBeforeAdvice");
assertEquals(0, cba.getCalls());
assertThat(cba.getCalls()).isEqualTo(0);
ITestBean tb = (ITestBean) bf.getBean("directTarget");
assertTrue(tb.getName().equals("Adam"));
assertEquals(1, cba.getCalls());
assertThat(tb.getName().equals("Adam")).isTrue();
assertThat(cba.getCalls()).isEqualTo(1);
ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&directTarget");
assertTrue("Has correct object type", TestBean.class.isAssignableFrom(pfb.getObjectType()));
assertThat(TestBean.class.isAssignableFrom(pfb.getObjectType())).as("Has correct object type").isTrue();
}
@Test
@@ -182,9 +176,9 @@ public class ProxyFactoryBeanTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(TARGETSOURCE_CONTEXT, CLASS));
ITestBean tb = (ITestBean) bf.getBean("viaTargetSource");
assertTrue(tb.getName().equals("Adam"));
assertThat(tb.getName().equals("Adam")).isTrue();
ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&viaTargetSource");
assertTrue("Has correct object type", TestBean.class.isAssignableFrom(pfb.getObjectType()));
assertThat(TestBean.class.isAssignableFrom(pfb.getObjectType())).as("Has correct object type").isTrue();
}
@Test
@@ -197,7 +191,7 @@ public class ProxyFactoryBeanTests {
tb.getName())
.withMessage("getName");
FactoryBean<?> pfb = (ProxyFactoryBean) bf.getBean("&noTarget");
assertTrue("Has correct object type", ITestBean.class.isAssignableFrom(pfb.getObjectType()));
assertThat(ITestBean.class.isAssignableFrom(pfb.getObjectType())).as("Has correct object type").isTrue();
}
/**
@@ -209,33 +203,33 @@ public class ProxyFactoryBeanTests {
ITestBean test1 = (ITestBean) factory.getBean("test1");
ITestBean test1_1 = (ITestBean) factory.getBean("test1");
//assertTrue("Singleton instances ==", test1 == test1_1);
assertEquals("Singleton instances ==", test1, test1_1);
assertThat(test1_1).as("Singleton instances ==").isEqualTo(test1);
test1.setAge(25);
assertEquals(test1.getAge(), test1_1.getAge());
assertThat(test1_1.getAge()).isEqualTo(test1.getAge());
test1.setAge(250);
assertEquals(test1.getAge(), test1_1.getAge());
assertThat(test1_1.getAge()).isEqualTo(test1.getAge());
Advised pc1 = (Advised) test1;
Advised pc2 = (Advised) test1_1;
assertArrayEquals(pc1.getAdvisors(), pc2.getAdvisors());
assertThat(pc2.getAdvisors()).isEqualTo(pc1.getAdvisors());
int oldLength = pc1.getAdvisors().length;
NopInterceptor di = new NopInterceptor();
pc1.addAdvice(1, di);
assertArrayEquals(pc1.getAdvisors(), pc2.getAdvisors());
assertEquals("Now have one more advisor", oldLength + 1, pc2.getAdvisors().length);
assertEquals(di.getCount(), 0);
assertThat(pc2.getAdvisors()).isEqualTo(pc1.getAdvisors());
assertThat(pc2.getAdvisors().length).as("Now have one more advisor").isEqualTo((oldLength + 1));
assertThat(0).isEqualTo(di.getCount());
test1.setAge(5);
assertEquals(test1_1.getAge(), test1.getAge());
assertEquals(di.getCount(), 3);
assertThat(test1.getAge()).isEqualTo(test1_1.getAge());
assertThat(3).isEqualTo(di.getCount());
}
@Test
public void testPrototypeInstancesAreNotEqual() {
assertTrue("Has correct object type", ITestBean.class.isAssignableFrom(factory.getType("prototype")));
assertThat(ITestBean.class.isAssignableFrom(factory.getType("prototype"))).as("Has correct object type").isTrue();
ITestBean test2 = (ITestBean) factory.getBean("prototype");
ITestBean test2_1 = (ITestBean) factory.getBean("prototype");
assertTrue("Prototype instances !=", test2 != test2_1);
assertTrue("Prototype instances equal", test2.equals(test2_1));
assertTrue("Has correct object type", ITestBean.class.isAssignableFrom(factory.getType("prototype")));
assertThat(test2 != test2_1).as("Prototype instances !=").isTrue();
assertThat(test2.equals(test2_1)).as("Prototype instances equal").isTrue();
assertThat(ITestBean.class.isAssignableFrom(factory.getType("prototype"))).as("Has correct object type").isTrue();
}
/**
@@ -252,22 +246,22 @@ public class ProxyFactoryBeanTests {
// Check it works without AOP
SideEffectBean raw = (SideEffectBean) bf.getBean("prototypeTarget");
assertEquals(INITIAL_COUNT, raw.getCount());
assertThat(raw.getCount()).isEqualTo(INITIAL_COUNT);
raw.doWork();
assertEquals(INITIAL_COUNT+1, raw.getCount());
assertThat(raw.getCount()).isEqualTo(INITIAL_COUNT+1);
raw = (SideEffectBean) bf.getBean("prototypeTarget");
assertEquals(INITIAL_COUNT, raw.getCount());
assertThat(raw.getCount()).isEqualTo(INITIAL_COUNT);
// Now try with advised instances
SideEffectBean prototype2FirstInstance = (SideEffectBean) bf.getBean(beanName);
assertEquals(INITIAL_COUNT, prototype2FirstInstance.getCount());
assertThat(prototype2FirstInstance.getCount()).isEqualTo(INITIAL_COUNT);
prototype2FirstInstance.doWork();
assertEquals(INITIAL_COUNT + 1, prototype2FirstInstance.getCount());
assertThat(prototype2FirstInstance.getCount()).isEqualTo(INITIAL_COUNT + 1);
SideEffectBean prototype2SecondInstance = (SideEffectBean) bf.getBean(beanName);
assertFalse("Prototypes are not ==", prototype2FirstInstance == prototype2SecondInstance);
assertEquals(INITIAL_COUNT, prototype2SecondInstance.getCount());
assertEquals(INITIAL_COUNT + 1, prototype2FirstInstance.getCount());
assertThat(prototype2FirstInstance == prototype2SecondInstance).as("Prototypes are not ==").isFalse();
assertThat(prototype2SecondInstance.getCount()).isEqualTo(INITIAL_COUNT);
assertThat(prototype2FirstInstance.getCount()).isEqualTo(INITIAL_COUNT + 1);
return prototype2FirstInstance;
}
@@ -275,8 +269,8 @@ public class ProxyFactoryBeanTests {
@Test
public void testCglibPrototypeInstance() {
Object prototype = testPrototypeInstancesAreIndependent("cglibPrototype");
assertTrue("It's a cglib proxy", AopUtils.isCglibProxy(prototype));
assertFalse("It's not a dynamic proxy", AopUtils.isJdkDynamicProxy(prototype));
assertThat(AopUtils.isCglibProxy(prototype)).as("It's a cglib proxy").isTrue();
assertThat(AopUtils.isJdkDynamicProxy(prototype)).as("It's not a dynamic proxy").isFalse();
}
/**
@@ -288,19 +282,19 @@ public class ProxyFactoryBeanTests {
TestBean target = (TestBean) factory.getBean("test");
target.setName(name);
ITestBean autoInvoker = (ITestBean) factory.getBean("autoInvoker");
assertTrue(autoInvoker.getName().equals(name));
assertThat(autoInvoker.getName().equals(name)).isTrue();
}
@Test
public void testCanGetFactoryReferenceAndManipulate() {
ProxyFactoryBean config = (ProxyFactoryBean) factory.getBean("&test1");
assertTrue("Has correct object type", ITestBean.class.isAssignableFrom(config.getObjectType()));
assertTrue("Has correct object type", ITestBean.class.isAssignableFrom(factory.getType("test1")));
assertThat(ITestBean.class.isAssignableFrom(config.getObjectType())).as("Has correct object type").isTrue();
assertThat(ITestBean.class.isAssignableFrom(factory.getType("test1"))).as("Has correct object type").isTrue();
// Trigger lazy initialization.
config.getObject();
assertEquals("Have one advisors", 1, config.getAdvisors().length);
assertTrue("Has correct object type", ITestBean.class.isAssignableFrom(config.getObjectType()));
assertTrue("Has correct object type", ITestBean.class.isAssignableFrom(factory.getType("test1")));
assertThat(config.getAdvisors().length).as("Have one advisors").isEqualTo(1);
assertThat(ITestBean.class.isAssignableFrom(config.getObjectType())).as("Has correct object type").isTrue();
assertThat(ITestBean.class.isAssignableFrom(factory.getType("test1"))).as("Has correct object type").isTrue();
ITestBean tb = (ITestBean) factory.getBean("test1");
// no exception
@@ -314,7 +308,7 @@ public class ProxyFactoryBeanTests {
throw ex;
}
});
assertEquals("Have correct advisor count", 2, config.getAdvisors().length);
assertThat(config.getAdvisors().length).as("Have correct advisor count").isEqualTo(2);
ITestBean tb1 = (ITestBean) factory.getBean("test1");
assertThatExceptionOfType(Exception.class).isThrownBy(
@@ -331,10 +325,10 @@ public class ProxyFactoryBeanTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(INNER_BEAN_TARGET_CONTEXT, CLASS));
ITestBean itb = (ITestBean) bf.getBean("testBean");
assertEquals("innerBeanTarget", itb.getName());
assertEquals("Only have proxy and interceptor: no target", 3, bf.getBeanDefinitionCount());
assertThat(itb.getName()).isEqualTo("innerBeanTarget");
assertThat(bf.getBeanDefinitionCount()).as("Only have proxy and interceptor: no target").isEqualTo(3);
DependsOnITestBean doit = (DependsOnITestBean) bf.getBean("autowireCheck");
assertSame(itb, doit.tb);
assertThat(doit.tb).isSameAs(itb);
}
/**
@@ -354,47 +348,47 @@ public class ProxyFactoryBeanTests {
// Add to head of interceptor chain
int oldCount = config.getAdvisors().length;
config.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
assertTrue(config.getAdvisors().length == oldCount + 1);
assertThat(config.getAdvisors().length == oldCount + 1).isTrue();
TimeStamped ts = (TimeStamped) factory.getBean("test2");
assertEquals(time, ts.getTimeStamp());
assertThat(ts.getTimeStamp()).isEqualTo(time);
// Can remove
config.removeAdvice(ti);
assertTrue(config.getAdvisors().length == oldCount);
assertThat(config.getAdvisors().length == oldCount).isTrue();
// Check no change on existing object reference
assertTrue(ts.getTimeStamp() == time);
assertThat(ts.getTimeStamp() == time).isTrue();
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());
assertTrue(config.getAdvisors().length == oldCount);
assertThat(config.getAdvisors().length == oldCount).isTrue();
ITestBean it = (ITestBean) ts;
DebugInterceptor debugInterceptor = new DebugInterceptor();
config.addAdvice(0, debugInterceptor);
it.getSpouse();
// Won't affect existing reference
assertTrue(debugInterceptor.getCount() == 0);
assertThat(debugInterceptor.getCount() == 0).isTrue();
it = (ITestBean) factory.getBean("test2");
it.getSpouse();
assertEquals(1, debugInterceptor.getCount());
assertThat(debugInterceptor.getCount()).isEqualTo(1);
config.removeAdvice(debugInterceptor);
it.getSpouse();
// Still invoked with old reference
assertEquals(2, debugInterceptor.getCount());
assertThat(debugInterceptor.getCount()).isEqualTo(2);
// not invoked with new object
it = (ITestBean) factory.getBean("test2");
it.getSpouse();
assertEquals(2, debugInterceptor.getCount());
assertThat(debugInterceptor.getCount()).isEqualTo(2);
// Our own timestamped reference should still work
assertEquals(time, ts.getTimeStamp());
assertThat(ts.getTimeStamp()).isEqualTo(time);
}
/**
@@ -408,26 +402,26 @@ public class ProxyFactoryBeanTests {
it.getAge();
NopInterceptor di = new NopInterceptor();
pc.addAdvice(0, di);
assertEquals(0, di.getCount());
assertThat(di.getCount()).isEqualTo(0);
it.setAge(25);
assertEquals(25, it.getAge());
assertEquals(2, di.getCount());
assertThat(it.getAge()).isEqualTo(25);
assertThat(di.getCount()).isEqualTo(2);
}
@Test
public void testMethodPointcuts() {
ITestBean tb = (ITestBean) factory.getBean("pointcuts");
PointcutForVoid.reset();
assertTrue("No methods intercepted", PointcutForVoid.methodNames.isEmpty());
assertThat(PointcutForVoid.methodNames.isEmpty()).as("No methods intercepted").isTrue();
tb.getAge();
assertTrue("Not void: shouldn't have intercepted", PointcutForVoid.methodNames.isEmpty());
assertThat(PointcutForVoid.methodNames.isEmpty()).as("Not void: shouldn't have intercepted").isTrue();
tb.setAge(1);
tb.getAge();
tb.setName("Tristan");
tb.toString();
assertEquals("Recorded wrong number of invocations", 2, PointcutForVoid.methodNames.size());
assertTrue(PointcutForVoid.methodNames.get(0).equals("setAge"));
assertTrue(PointcutForVoid.methodNames.get(1).equals("setName"));
assertThat(PointcutForVoid.methodNames.size()).as("Recorded wrong number of invocations").isEqualTo(2);
assertThat(PointcutForVoid.methodNames.get(0).equals("setAge")).isTrue();
assertThat(PointcutForVoid.methodNames.get(1).equals("setName")).isTrue();
}
@Test
@@ -436,20 +430,20 @@ public class ProxyFactoryBeanTests {
new XmlBeanDefinitionReader(f).loadBeanDefinitions(new ClassPathResource(THROWS_ADVICE_CONTEXT, CLASS));
MyThrowsHandler th = (MyThrowsHandler) f.getBean("throwsAdvice");
CountingBeforeAdvice cba = (CountingBeforeAdvice) f.getBean("countingBeforeAdvice");
assertEquals(0, cba.getCalls());
assertEquals(0, th.getCalls());
assertThat(cba.getCalls()).isEqualTo(0);
assertThat(th.getCalls()).isEqualTo(0);
IEcho echo = (IEcho) f.getBean("throwsAdvised");
int i = 12;
echo.setA(i);
assertEquals(i, echo.getA());
assertEquals(2, cba.getCalls());
assertEquals(0, th.getCalls());
assertThat(echo.getA()).isEqualTo(i);
assertThat(cba.getCalls()).isEqualTo(2);
assertThat(th.getCalls()).isEqualTo(0);
Exception expected = new Exception();
assertThatExceptionOfType(Exception.class).isThrownBy(() ->
echo.echoException(1, expected))
.matches(expected::equals);
// No throws handler method: count should still be 0
assertEquals(0, th.getCalls());
assertThat(th.getCalls()).isEqualTo(0);
// Handler knows how to handle this exception
FileNotFoundException expectedFileNotFound = new FileNotFoundException();
@@ -458,7 +452,7 @@ public class ProxyFactoryBeanTests {
.matches(expectedFileNotFound::equals);
// One match
assertEquals(1, th.getCalls("ioException"));
assertThat(th.getCalls("ioException")).isEqualTo(1);
}
// These two fail the whole bean factory
@@ -505,17 +499,17 @@ public class ProxyFactoryBeanTests {
@Test
public void testGlobalsCanAddAspectInterfaces() {
AddedGlobalInterface agi = (AddedGlobalInterface) factory.getBean("autoInvoker");
assertTrue(agi.globalsAdded() == -1);
assertThat(agi.globalsAdded() == -1).isTrue();
ProxyFactoryBean pfb = (ProxyFactoryBean) factory.getBean("&validGlobals");
// Trigger lazy initialization.
pfb.getObject();
// 2 globals + 2 explicit
assertEquals("Have 2 globals and 2 explicit advisors", 3, pfb.getAdvisors().length);
assertThat(pfb.getAdvisors().length).as("Have 2 globals and 2 explicit advisors").isEqualTo(3);
ApplicationListener<?> l = (ApplicationListener<?>) factory.getBean("validGlobals");
agi = (AddedGlobalInterface) l;
assertTrue(agi.globalsAdded() == -1);
assertThat(agi.globalsAdded() == -1).isTrue();
assertThat(factory.getBean("test1")).as("Aspect interface should't be implemeneted without globals")
.isNotInstanceOf(AddedGlobalInterface.class);
@@ -526,22 +520,22 @@ public class ProxyFactoryBeanTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializableSingleton");
assertSame("Should be a Singleton", p, bf.getBean("serializableSingleton"));
assertThat(bf.getBean("serializableSingleton")).as("Should be a Singleton").isSameAs(p);
Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
assertEquals(p, p2);
assertNotSame(p, p2);
assertEquals("serializableSingleton", p2.getName());
assertThat(p2).isEqualTo(p);
assertThat(p2).isNotSameAs(p);
assertThat(p2.getName()).isEqualTo("serializableSingleton");
// Add unserializable advice
Advice nop = new NopInterceptor();
((Advised) p).addAdvice(nop);
// Check it still works
assertEquals(p2.getName(), p2.getName());
assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));
assertThat(p2.getName()).isEqualTo(p2.getName());
assertThat(SerializationTestUtils.isSerializable(p)).as("Not serializable because an interceptor isn't serializable").isFalse();
// Remove offending interceptor...
assertTrue(((Advised) p).removeAdvice(nop));
assertTrue("Serializable again because offending interceptor was removed", SerializationTestUtils.isSerializable(p));
assertThat(((Advised) p).removeAdvice(nop)).isTrue();
assertThat(SerializationTestUtils.isSerializable(p)).as("Serializable again because offending interceptor was removed").isTrue();
}
@Test
@@ -549,11 +543,11 @@ public class ProxyFactoryBeanTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("serializablePrototype");
assertNotSame("Should not be a Singleton", p, bf.getBean("serializablePrototype"));
assertThat(bf.getBean("serializablePrototype")).as("Should not be a Singleton").isNotSameAs(p);
Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
assertEquals(p, p2);
assertNotSame(p, p2);
assertEquals("serializablePrototype", p2.getName());
assertThat(p2).isEqualTo(p);
assertThat(p2).isNotSameAs(p);
assertThat(p2.getName()).isEqualTo("serializablePrototype");
}
@Test
@@ -564,9 +558,9 @@ public class ProxyFactoryBeanTests {
ProxyFactoryBean pfb = (ProxyFactoryBean) bf.getBean("&serializableSingleton");
ProxyFactoryBean pfb2 = (ProxyFactoryBean) SerializationTestUtils.serializeAndDeserialize(pfb);
Person p2 = (Person) pfb2.getObject();
assertEquals(p, p2);
assertNotSame(p, p2);
assertEquals("serializableSingleton", p2.getName());
assertThat(p2).isEqualTo(p);
assertThat(p2).isNotSameAs(p);
assertThat(p2.getName()).isEqualTo("serializableSingleton");
}
@Test
@@ -574,7 +568,7 @@ public class ProxyFactoryBeanTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(SERIALIZATION_CONTEXT, CLASS));
Person p = (Person) bf.getBean("interceptorNotSerializableSingleton");
assertFalse("Not serializable because an interceptor isn't serializable", SerializationTestUtils.isSerializable(p));
assertThat(SerializationTestUtils.isSerializable(p)).as("Not serializable because an interceptor isn't serializable").isFalse();
}
@Test
@@ -588,8 +582,8 @@ public class ProxyFactoryBeanTests {
bean1.setAge(3);
bean2.setAge(4);
assertEquals(3, bean1.getAge());
assertEquals(4, bean2.getAge());
assertThat(bean1.getAge()).isEqualTo(3);
assertThat(bean2.getAge()).isEqualTo(4);
((Lockable) bean1).lock();
@@ -610,7 +604,7 @@ public class ProxyFactoryBeanTests {
bean1.setAge(1);
bean2.setAge(2);
assertEquals(2, bean1.getAge());
assertThat(bean1.getAge()).isEqualTo(2);
((Lockable) bean1).lock();
@@ -638,7 +632,7 @@ public class ProxyFactoryBeanTests {
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(FROZEN_CONTEXT, CLASS));
Advised advised = (Advised)bf.getBean("frozen");
assertTrue("The proxy should be frozen", advised.isFrozen());
assertThat(advised.isFrozen()).as("The proxy should be frozen").isTrue();
}
@Test
@@ -648,7 +642,7 @@ public class ProxyFactoryBeanTests {
fb.addAdvice(new DebugInterceptor());
fb.setBeanFactory(new DefaultListableBeanFactory());
ITestBean proxy = (ITestBean) fb.getObject();
assertTrue(AopUtils.isJdkDynamicProxy(proxy));
assertThat(AopUtils.isJdkDynamicProxy(proxy)).isTrue();
}

View File

@@ -37,9 +37,7 @@ import org.springframework.tests.aop.interceptor.NopInterceptor;
import org.springframework.tests.sample.beans.CountingTestBean;
import org.springframework.tests.sample.beans.ITestBean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for auto proxy creation by advisor recognition.
@@ -80,7 +78,7 @@ public class AdvisorAutoProxyCreatorTests {
public void testCommonInterceptorAndAdvisor() throws Exception {
BeanFactory bf = new ClassPathXmlApplicationContext(COMMON_INTERCEPTORS_CONTEXT, CLASS);
ITestBean test1 = (ITestBean) bf.getBean("test1");
assertTrue(AopUtils.isAopProxy(test1));
assertThat(AopUtils.isAopProxy(test1)).isTrue();
Lockable lockable1 = (Lockable) test1;
NopInterceptor nop1 = (NopInterceptor) bf.getBean("nopInterceptor");
@@ -90,30 +88,31 @@ public class AdvisorAutoProxyCreatorTests {
Lockable lockable2 = (Lockable) test2;
// Locking should be independent; nop is shared
assertFalse(lockable1.locked());
assertFalse(lockable2.locked());
assertThat(lockable1.locked()).isFalse();
assertThat(lockable2.locked()).isFalse();
// equals 2 calls on shared nop, because it's first and sees calls
// against the Lockable interface introduced by the specific advisor
assertEquals(2, nop1.getCount());
assertEquals(0, nop2.getCount());
assertThat(nop1.getCount()).isEqualTo(2);
assertThat(nop2.getCount()).isEqualTo(0);
lockable1.lock();
assertTrue(lockable1.locked());
assertFalse(lockable2.locked());
assertEquals(5, nop1.getCount());
assertEquals(0, nop2.getCount());
assertThat(lockable1.locked()).isTrue();
assertThat(lockable2.locked()).isFalse();
assertThat(nop1.getCount()).isEqualTo(5);
assertThat(nop2.getCount()).isEqualTo(0);
PackageVisibleMethod packageVisibleMethod = (PackageVisibleMethod) bf.getBean("packageVisibleMethod");
assertEquals(5, nop1.getCount());
assertEquals(0, nop2.getCount());
assertThat(nop1.getCount()).isEqualTo(5);
assertThat(nop2.getCount()).isEqualTo(0);
packageVisibleMethod.doSomething();
assertEquals(6, nop1.getCount());
assertEquals(1, nop2.getCount());
assertTrue(packageVisibleMethod instanceof Lockable);
assertThat(nop1.getCount()).isEqualTo(6);
assertThat(nop2.getCount()).isEqualTo(1);
boolean condition = packageVisibleMethod instanceof Lockable;
assertThat(condition).isTrue();
Lockable lockable3 = (Lockable) packageVisibleMethod;
lockable3.lock();
assertTrue(lockable3.locked());
assertThat(lockable3.locked()).isTrue();
lockable3.unlock();
assertFalse(lockable3.locked());
assertThat(lockable3.locked()).isFalse();
}
/**
@@ -124,9 +123,9 @@ public class AdvisorAutoProxyCreatorTests {
public void testCustomTargetSourceNoMatch() throws Exception {
BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
ITestBean test = (ITestBean) bf.getBean("test");
assertFalse(AopUtils.isAopProxy(test));
assertEquals("Rod", test.getName());
assertEquals("Kerry", test.getSpouse().getName());
assertThat(AopUtils.isAopProxy(test)).isFalse();
assertThat(test.getName()).isEqualTo("Rod");
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
}
@Test
@@ -134,13 +133,14 @@ public class AdvisorAutoProxyCreatorTests {
CountingTestBean.count = 0;
BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
ITestBean test = (ITestBean) bf.getBean("prototypeTest");
assertTrue(AopUtils.isAopProxy(test));
assertThat(AopUtils.isAopProxy(test)).isTrue();
Advised advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
assertEquals("Rod", test.getName());
boolean condition = advised.getTargetSource() instanceof PrototypeTargetSource;
assertThat(condition).isTrue();
assertThat(test.getName()).isEqualTo("Rod");
// Check that references survived prototype creation
assertEquals("Kerry", test.getSpouse().getName());
assertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count);
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
assertThat(CountingTestBean.count).as("Only 2 CountingTestBeans instantiated").isEqualTo(2);
CountingTestBean.count = 0;
}
@@ -149,13 +149,14 @@ public class AdvisorAutoProxyCreatorTests {
CountingTestBean.count = 0;
BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
ITestBean test = (ITestBean) bf.getBean("lazyInitTest");
assertTrue(AopUtils.isAopProxy(test));
assertThat(AopUtils.isAopProxy(test)).isTrue();
Advised advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof LazyInitTargetSource);
assertEquals("No CountingTestBean instantiated yet", 0, CountingTestBean.count);
assertEquals("Rod", test.getName());
assertEquals("Kerry", test.getSpouse().getName());
assertEquals("Only 1 CountingTestBean instantiated", 1, CountingTestBean.count);
boolean condition = advised.getTargetSource() instanceof LazyInitTargetSource;
assertThat(condition).isTrue();
assertThat(CountingTestBean.count).as("No CountingTestBean instantiated yet").isEqualTo(0);
assertThat(test.getName()).isEqualTo("Rod");
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
assertThat(CountingTestBean.count).as("Only 1 CountingTestBean instantiated").isEqualTo(1);
CountingTestBean.count = 0;
}
@@ -164,43 +165,46 @@ public class AdvisorAutoProxyCreatorTests {
ClassPathXmlApplicationContext bf =
new ClassPathXmlApplicationContext(QUICK_TARGETSOURCE_CONTEXT, CLASS);
ITestBean test = (ITestBean) bf.getBean("test");
assertFalse(AopUtils.isAopProxy(test));
assertEquals("Rod", test.getName());
assertThat(AopUtils.isAopProxy(test)).isFalse();
assertThat(test.getName()).isEqualTo("Rod");
// Check that references survived pooling
assertEquals("Kerry", test.getSpouse().getName());
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
// Now test the pooled one
test = (ITestBean) bf.getBean(":test");
assertTrue(AopUtils.isAopProxy(test));
assertThat(AopUtils.isAopProxy(test)).isTrue();
Advised advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof CommonsPool2TargetSource);
assertEquals("Rod", test.getName());
boolean condition2 = advised.getTargetSource() instanceof CommonsPool2TargetSource;
assertThat(condition2).isTrue();
assertThat(test.getName()).isEqualTo("Rod");
// Check that references survived pooling
assertEquals("Kerry", test.getSpouse().getName());
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
// Now test the ThreadLocal one
test = (ITestBean) bf.getBean("%test");
assertTrue(AopUtils.isAopProxy(test));
assertThat(AopUtils.isAopProxy(test)).isTrue();
advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof ThreadLocalTargetSource);
assertEquals("Rod", test.getName());
boolean condition1 = advised.getTargetSource() instanceof ThreadLocalTargetSource;
assertThat(condition1).isTrue();
assertThat(test.getName()).isEqualTo("Rod");
// Check that references survived pooling
assertEquals("Kerry", test.getSpouse().getName());
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
// Now test the Prototype TargetSource
test = (ITestBean) bf.getBean("!test");
assertTrue(AopUtils.isAopProxy(test));
assertThat(AopUtils.isAopProxy(test)).isTrue();
advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
assertEquals("Rod", test.getName());
boolean condition = advised.getTargetSource() instanceof PrototypeTargetSource;
assertThat(condition).isTrue();
assertThat(test.getName()).isEqualTo("Rod");
// Check that references survived pooling
assertEquals("Kerry", test.getSpouse().getName());
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
ITestBean test2 = (ITestBean) bf.getBean("!test");
assertFalse("Prototypes cannot be the same object", test == test2);
assertEquals("Rod", test2.getName());
assertEquals("Kerry", test2.getSpouse().getName());
assertThat(test == test2).as("Prototypes cannot be the same object").isFalse();
assertThat(test2.getName()).isEqualTo("Rod");
assertThat(test2.getSpouse().getName()).isEqualTo("Kerry");
bf.close();
}
@@ -209,14 +213,14 @@ public class AdvisorAutoProxyCreatorTests {
BeanFactory beanFactory = new ClassPathXmlApplicationContext(OPTIMIZED_CONTEXT, CLASS);
ITestBean testBean = (ITestBean) beanFactory.getBean("optimizedTestBean");
assertTrue(AopUtils.isAopProxy(testBean));
assertThat(AopUtils.isAopProxy(testBean)).isTrue();
CountingBeforeAdvice beforeAdvice = (CountingBeforeAdvice) beanFactory.getBean("countingAdvice");
testBean.setAge(23);
testBean.getAge();
assertEquals("Incorrect number of calls to proxy", 2, beforeAdvice.getCalls());
assertThat(beforeAdvice.getCalls()).as("Incorrect number of calls to proxy").isEqualTo(2);
}
}

View File

@@ -49,10 +49,7 @@ import org.springframework.tests.sample.beans.TestBean;
import org.springframework.tests.sample.beans.factory.DummyFactory;
import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
@@ -85,31 +82,31 @@ public class AutoProxyCreatorTests {
MessageSource messageSource = (MessageSource) sac.getBean("messageSource");
ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
assertFalse(Proxy.isProxyClass(messageSource.getClass()));
assertTrue(Proxy.isProxyClass(singletonToBeProxied.getClass()));
assertTrue(Proxy.isProxyClass(singletonToBeProxied.getSpouse().getClass()));
assertThat(Proxy.isProxyClass(messageSource.getClass())).isFalse();
assertThat(Proxy.isProxyClass(singletonToBeProxied.getClass())).isTrue();
assertThat(Proxy.isProxyClass(singletonToBeProxied.getSpouse().getClass())).isTrue();
// test whether autowiring succeeded with auto proxy creation
assertEquals(sac.getBean("autowiredIndexedTestBean"), singletonToBeProxied.getNestedIndexedBean());
assertThat(singletonToBeProxied.getNestedIndexedBean()).isEqualTo(sac.getBean("autowiredIndexedTestBean"));
TestInterceptor ti = (TestInterceptor) sac.getBean("testInterceptor");
// already 2: getSpouse + getNestedIndexedBean calls above
assertEquals(2, ti.nrOfInvocations);
assertThat(ti.nrOfInvocations).isEqualTo(2);
singletonToBeProxied.getName();
singletonToBeProxied.getSpouse().getName();
assertEquals(5, ti.nrOfInvocations);
assertThat(ti.nrOfInvocations).isEqualTo(5);
ITestBean tb = (ITestBean) sac.getBean("singletonFactoryToBeProxied");
assertTrue(AopUtils.isJdkDynamicProxy(tb));
assertEquals(5, ti.nrOfInvocations);
assertThat(AopUtils.isJdkDynamicProxy(tb)).isTrue();
assertThat(ti.nrOfInvocations).isEqualTo(5);
tb.getAge();
assertEquals(6, ti.nrOfInvocations);
assertThat(ti.nrOfInvocations).isEqualTo(6);
ITestBean tb2 = (ITestBean) sac.getBean("singletonFactoryToBeProxied");
assertSame(tb, tb2);
assertEquals(6, ti.nrOfInvocations);
assertThat(tb2).isSameAs(tb);
assertThat(ti.nrOfInvocations).isEqualTo(6);
tb2.getAge();
assertEquals(7, ti.nrOfInvocations);
assertThat(ti.nrOfInvocations).isEqualTo(7);
}
@Test
@@ -130,20 +127,20 @@ public class AutoProxyCreatorTests {
sac.refresh();
ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
assertTrue(Proxy.isProxyClass(singletonToBeProxied.getClass()));
assertThat(Proxy.isProxyClass(singletonToBeProxied.getClass())).isTrue();
TestInterceptor ti = (TestInterceptor) sac.getBean("testInterceptor");
int initialNr = ti.nrOfInvocations;
singletonToBeProxied.getName();
assertEquals(initialNr + 1, ti.nrOfInvocations);
assertThat(ti.nrOfInvocations).isEqualTo((initialNr + 1));
FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
assertTrue(Proxy.isProxyClass(factory.getClass()));
assertThat(Proxy.isProxyClass(factory.getClass())).isTrue();
TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
assertFalse(AopUtils.isAopProxy(tb));
assertEquals(initialNr + 3, ti.nrOfInvocations);
assertThat(AopUtils.isAopProxy(tb)).isFalse();
assertThat(ti.nrOfInvocations).isEqualTo((initialNr + 3));
tb.getAge();
assertEquals(initialNr + 3, ti.nrOfInvocations);
assertThat(ti.nrOfInvocations).isEqualTo((initialNr + 3));
}
@Test
@@ -164,21 +161,21 @@ public class AutoProxyCreatorTests {
ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor");
ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied");
assertFalse(AopUtils.isCglibProxy(messageSource));
assertTrue(AopUtils.isCglibProxy(noInterfaces));
assertTrue(AopUtils.isCglibProxy(containerCallbackInterfacesOnly));
assertTrue(AopUtils.isCglibProxy(singletonNoInterceptor));
assertTrue(AopUtils.isCglibProxy(singletonToBeProxied));
assertTrue(AopUtils.isCglibProxy(prototypeToBeProxied));
assertThat(AopUtils.isCglibProxy(messageSource)).isFalse();
assertThat(AopUtils.isCglibProxy(noInterfaces)).isTrue();
assertThat(AopUtils.isCglibProxy(containerCallbackInterfacesOnly)).isTrue();
assertThat(AopUtils.isCglibProxy(singletonNoInterceptor)).isTrue();
assertThat(AopUtils.isCglibProxy(singletonToBeProxied)).isTrue();
assertThat(AopUtils.isCglibProxy(prototypeToBeProxied)).isTrue();
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
assertEquals(0, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
singletonNoInterceptor.getName();
assertEquals(0, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
singletonToBeProxied.getAge();
assertEquals(1, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(1);
prototypeToBeProxied.getSpouse();
assertEquals(2, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
}
@Test
@@ -199,21 +196,21 @@ public class AutoProxyCreatorTests {
ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor");
ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied");
assertFalse(AopUtils.isCglibProxy(messageSource));
assertTrue(AopUtils.isCglibProxy(noInterfaces));
assertTrue(AopUtils.isCglibProxy(containerCallbackInterfacesOnly));
assertFalse(AopUtils.isCglibProxy(singletonNoInterceptor));
assertFalse(AopUtils.isCglibProxy(singletonToBeProxied));
assertFalse(AopUtils.isCglibProxy(prototypeToBeProxied));
assertThat(AopUtils.isCglibProxy(messageSource)).isFalse();
assertThat(AopUtils.isCglibProxy(noInterfaces)).isTrue();
assertThat(AopUtils.isCglibProxy(containerCallbackInterfacesOnly)).isTrue();
assertThat(AopUtils.isCglibProxy(singletonNoInterceptor)).isFalse();
assertThat(AopUtils.isCglibProxy(singletonToBeProxied)).isFalse();
assertThat(AopUtils.isCglibProxy(prototypeToBeProxied)).isFalse();
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
assertEquals(0, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
singletonNoInterceptor.getName();
assertEquals(0, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
singletonToBeProxied.getAge();
assertEquals(1, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(1);
prototypeToBeProxied.getSpouse();
assertEquals(2, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
}
@Test
@@ -239,21 +236,21 @@ public class AutoProxyCreatorTests {
ITestBean singletonNoInterceptor = (ITestBean) sac.getBean("singletonNoInterceptor");
ITestBean singletonToBeProxied = (ITestBean) sac.getBean("singletonToBeProxied");
ITestBean prototypeToBeProxied = (ITestBean) sac.getBean("prototypeToBeProxied");
assertFalse(AopUtils.isCglibProxy(messageSource));
assertTrue(AopUtils.isCglibProxy(noInterfaces));
assertTrue(AopUtils.isCglibProxy(containerCallbackInterfacesOnly));
assertFalse(AopUtils.isCglibProxy(singletonNoInterceptor));
assertFalse(AopUtils.isCglibProxy(singletonToBeProxied));
assertFalse(AopUtils.isCglibProxy(prototypeToBeProxied));
assertThat(AopUtils.isCglibProxy(messageSource)).isFalse();
assertThat(AopUtils.isCglibProxy(noInterfaces)).isTrue();
assertThat(AopUtils.isCglibProxy(containerCallbackInterfacesOnly)).isTrue();
assertThat(AopUtils.isCglibProxy(singletonNoInterceptor)).isFalse();
assertThat(AopUtils.isCglibProxy(singletonToBeProxied)).isFalse();
assertThat(AopUtils.isCglibProxy(prototypeToBeProxied)).isFalse();
TestAutoProxyCreator tapc = (TestAutoProxyCreator) sac.getBean("testAutoProxyCreator");
assertEquals(0, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
singletonNoInterceptor.getName();
assertEquals(0, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
singletonToBeProxied.getAge();
assertEquals(1, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(1);
prototypeToBeProxied.getSpouse();
assertEquals(2, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
}
@Test
@@ -267,10 +264,10 @@ public class AutoProxyCreatorTests {
tapc.testInterceptor.nrOfInvocations = 0;
PackageVisibleMethod tb = (PackageVisibleMethod) sac.getBean("packageVisibleMethodToBeProxied");
assertTrue(AopUtils.isCglibProxy(tb));
assertEquals(0, tapc.testInterceptor.nrOfInvocations);
assertThat(AopUtils.isCglibProxy(tb)).isTrue();
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
tb.doSomething();
assertEquals(1, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(1);
}
@Test
@@ -284,13 +281,13 @@ public class AutoProxyCreatorTests {
tapc.testInterceptor.nrOfInvocations = 0;
FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
assertTrue(AopUtils.isCglibProxy(factory));
assertThat(AopUtils.isCglibProxy(factory)).isTrue();
TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
assertTrue(AopUtils.isCglibProxy(tb));
assertEquals(2, tapc.testInterceptor.nrOfInvocations);
assertThat(AopUtils.isCglibProxy(tb)).isTrue();
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
tb.getAge();
assertEquals(3, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(3);
}
@Test
@@ -308,13 +305,13 @@ public class AutoProxyCreatorTests {
tapc.testInterceptor.nrOfInvocations = 0;
FactoryBean<?> prototypeFactory = (FactoryBean<?>) sac.getBean("&prototypeFactoryToBeProxied");
assertTrue(AopUtils.isCglibProxy(prototypeFactory));
assertThat(AopUtils.isCglibProxy(prototypeFactory)).isTrue();
TestBean tb = (TestBean) sac.getBean("prototypeFactoryToBeProxied");
assertTrue(AopUtils.isCglibProxy(tb));
assertThat(AopUtils.isCglibProxy(tb)).isTrue();
assertEquals(2, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
tb.getAge();
assertEquals(3, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(3);
}
@Test
@@ -333,19 +330,19 @@ public class AutoProxyCreatorTests {
tapc.testInterceptor.nrOfInvocations = 0;
FactoryBean<?> factory = (FactoryBean<?>) sac.getBean("&singletonFactoryToBeProxied");
assertFalse(AopUtils.isAopProxy(factory));
assertThat(AopUtils.isAopProxy(factory)).isFalse();
TestBean tb = (TestBean) sac.getBean("singletonFactoryToBeProxied");
assertTrue(AopUtils.isCglibProxy(tb));
assertEquals(0, tapc.testInterceptor.nrOfInvocations);
assertThat(AopUtils.isCglibProxy(tb)).isTrue();
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
tb.getAge();
assertEquals(1, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(1);
TestBean tb2 = (TestBean) sac.getBean("singletonFactoryToBeProxied");
assertSame(tb, tb2);
assertEquals(1, tapc.testInterceptor.nrOfInvocations);
assertThat(tb2).isSameAs(tb);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(1);
tb2.getAge();
assertEquals(2, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
}
@Test
@@ -366,13 +363,13 @@ public class AutoProxyCreatorTests {
tapc.testInterceptor.nrOfInvocations = 0;
FactoryBean<?> prototypeFactory = (FactoryBean<?>) sac.getBean("&prototypeFactoryToBeProxied");
assertTrue(AopUtils.isCglibProxy(prototypeFactory));
assertThat(AopUtils.isCglibProxy(prototypeFactory)).isTrue();
TestBean tb = (TestBean) sac.getBean("prototypeFactoryToBeProxied");
assertFalse(AopUtils.isCglibProxy(tb));
assertThat(AopUtils.isCglibProxy(tb)).isFalse();
assertEquals(2, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
tb.getAge();
assertEquals(2, tapc.testInterceptor.nrOfInvocations);
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
}

View File

@@ -25,8 +25,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
/**
* @author Juergen Hoeller
@@ -41,7 +41,7 @@ public class BeanNameAutoProxyCreatorInitTests {
new ClassPathXmlApplicationContext(getClass().getSimpleName() + "-context.xml", getClass());
TestBean bean = (TestBean) ctx.getBean("bean");
bean.setName("foo");
assertEquals("foo", bean.getName());
assertThat(bean.getName()).isEqualTo("foo");
assertThatIllegalArgumentException().isThrownBy(() ->
bean.setName(null));
}

View File

@@ -32,10 +32,8 @@ 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.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Rod Johnson
@@ -58,51 +56,52 @@ public class BeanNameAutoProxyCreatorTests {
@Test
public void testNoProxy() {
TestBean tb = (TestBean) beanFactory.getBean("noproxy");
assertFalse(AopUtils.isAopProxy(tb));
assertEquals("noproxy", tb.getName());
assertThat(AopUtils.isAopProxy(tb)).isFalse();
assertThat(tb.getName()).isEqualTo("noproxy");
}
@Test
public void testJdkProxyWithExactNameMatch() {
ITestBean tb = (ITestBean) beanFactory.getBean("onlyJdk");
jdkAssertions(tb, 1);
assertEquals("onlyJdk", tb.getName());
assertThat(tb.getName()).isEqualTo("onlyJdk");
}
@Test
public void testJdkProxyWithDoubleProxying() {
ITestBean tb = (ITestBean) beanFactory.getBean("doubleJdk");
jdkAssertions(tb, 2);
assertEquals("doubleJdk", tb.getName());
assertThat(tb.getName()).isEqualTo("doubleJdk");
}
@Test
public void testJdkIntroduction() {
ITestBean tb = (ITestBean) beanFactory.getBean("introductionUsingJdk");
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
assertEquals(0, nop.getCount());
assertTrue(AopUtils.isJdkDynamicProxy(tb));
assertThat(nop.getCount()).isEqualTo(0);
assertThat(AopUtils.isJdkDynamicProxy(tb)).isTrue();
int age = 5;
tb.setAge(age);
assertEquals(age, tb.getAge());
assertTrue("Introduction was made", tb instanceof TimeStamped);
assertEquals(0, ((TimeStamped) tb).getTimeStamp());
assertEquals(3, nop.getCount());
assertEquals("introductionUsingJdk", tb.getName());
assertThat(tb.getAge()).isEqualTo(age);
boolean condition = tb instanceof TimeStamped;
assertThat(condition).as("Introduction was made").isTrue();
assertThat(((TimeStamped) tb).getTimeStamp()).isEqualTo(0);
assertThat(nop.getCount()).isEqualTo(3);
assertThat(tb.getName()).isEqualTo("introductionUsingJdk");
ITestBean tb2 = (ITestBean) beanFactory.getBean("second-introductionUsingJdk");
// Check two per-instance mixins were distinct
Lockable lockable1 = (Lockable) tb;
Lockable lockable2 = (Lockable) tb2;
assertFalse(lockable1.locked());
assertFalse(lockable2.locked());
assertThat(lockable1.locked()).isFalse();
assertThat(lockable2.locked()).isFalse();
tb.setAge(65);
assertEquals(65, tb.getAge());
assertThat(tb.getAge()).isEqualTo(65);
lockable1.lock();
assertTrue(lockable1.locked());
assertThat(lockable1.locked()).isTrue();
// Shouldn't affect second
assertFalse(lockable2.locked());
assertThat(lockable2.locked()).isFalse();
// Can still mod second object
tb2.setAge(12);
// But can't mod first
@@ -114,28 +113,29 @@ public class BeanNameAutoProxyCreatorTests {
public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() {
ITestBean tb = (ITestBean) beanFactory.getBean("factory-introductionUsingJdk");
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
assertEquals("NOP should not have done any work yet", 0, nop.getCount());
assertTrue(AopUtils.isJdkDynamicProxy(tb));
assertThat(nop.getCount()).as("NOP should not have done any work yet").isEqualTo(0);
assertThat(AopUtils.isJdkDynamicProxy(tb)).isTrue();
int age = 5;
tb.setAge(age);
assertEquals(age, tb.getAge());
assertTrue("Introduction was made", tb instanceof TimeStamped);
assertEquals(0, ((TimeStamped) tb).getTimeStamp());
assertEquals(3, nop.getCount());
assertThat(tb.getAge()).isEqualTo(age);
boolean condition = tb instanceof TimeStamped;
assertThat(condition).as("Introduction was made").isTrue();
assertThat(((TimeStamped) tb).getTimeStamp()).isEqualTo(0);
assertThat(nop.getCount()).isEqualTo(3);
ITestBean tb2 = (ITestBean) beanFactory.getBean("second-introductionUsingJdk");
// Check two per-instance mixins were distinct
Lockable lockable1 = (Lockable) tb;
Lockable lockable2 = (Lockable) tb2;
assertFalse(lockable1.locked());
assertFalse(lockable2.locked());
assertThat(lockable1.locked()).isFalse();
assertThat(lockable2.locked()).isFalse();
tb.setAge(65);
assertEquals(65, tb.getAge());
assertThat(tb.getAge()).isEqualTo(65);
lockable1.lock();
assertTrue(lockable1.locked());
assertThat(lockable1.locked()).isTrue();
// Shouldn't affect second
assertFalse(lockable2.locked());
assertThat(lockable2.locked()).isFalse();
// Can still mod second object
tb2.setAge(12);
// But can't mod first
@@ -147,31 +147,31 @@ public class BeanNameAutoProxyCreatorTests {
public void testJdkProxyWithWildcardMatch() {
ITestBean tb = (ITestBean) beanFactory.getBean("jdk1");
jdkAssertions(tb, 1);
assertEquals("jdk1", tb.getName());
assertThat(tb.getName()).isEqualTo("jdk1");
}
@Test
public void testCglibProxyWithWildcardMatch() {
TestBean tb = (TestBean) beanFactory.getBean("cglib1");
cglibAssertions(tb);
assertEquals("cglib1", tb.getName());
assertThat(tb.getName()).isEqualTo("cglib1");
}
@Test
public void testWithFrozenProxy() {
ITestBean testBean = (ITestBean) beanFactory.getBean("frozenBean");
assertTrue(((Advised)testBean).isFrozen());
assertThat(((Advised)testBean).isFrozen()).isTrue();
}
private void jdkAssertions(ITestBean tb, int nopInterceptorCount) {
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("nopInterceptor");
assertEquals(0, nop.getCount());
assertTrue(AopUtils.isJdkDynamicProxy(tb));
assertThat(nop.getCount()).isEqualTo(0);
assertThat(AopUtils.isJdkDynamicProxy(tb)).isTrue();
int age = 5;
tb.setAge(age);
assertEquals(age, tb.getAge());
assertEquals(2 * nopInterceptorCount, nop.getCount());
assertThat(tb.getAge()).isEqualTo(age);
assertThat(nop.getCount()).isEqualTo((2 * nopInterceptorCount));
}
/**
@@ -180,14 +180,14 @@ public class BeanNameAutoProxyCreatorTests {
private void cglibAssertions(TestBean tb) {
CountingBeforeAdvice cba = (CountingBeforeAdvice) beanFactory.getBean("countingBeforeAdvice");
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("nopInterceptor");
assertEquals(0, cba.getCalls());
assertEquals(0, nop.getCount());
assertTrue(AopUtils.isCglibProxy(tb));
assertThat(cba.getCalls()).isEqualTo(0);
assertThat(nop.getCount()).isEqualTo(0);
assertThat(AopUtils.isCglibProxy(tb)).isTrue();
int age = 5;
tb.setAge(age);
assertEquals(age, tb.getAge());
assertEquals(2, nop.getCount());
assertEquals(2, cba.getCalls());
assertThat(tb.getAge()).isEqualTo(age);
assertThat(nop.getCount()).isEqualTo(2);
assertThat(cba.getCalls()).isEqualTo(2);
}
}

View File

@@ -32,9 +32,7 @@ import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Harrop
@@ -57,7 +55,8 @@ public class ScopedProxyTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(MAP_CONTEXT);
Object baseMap = bf.getBean("singletonMap");
assertTrue(baseMap instanceof Map);
boolean condition = baseMap instanceof Map;
assertThat(condition).isTrue();
}
@Test
@@ -65,8 +64,10 @@ public class ScopedProxyTests {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(MAP_CONTEXT);
Object simpleMap = bf.getBean("simpleMap");
assertTrue(simpleMap instanceof Map);
assertTrue(simpleMap instanceof HashMap);
boolean condition1 = simpleMap instanceof Map;
assertThat(condition1).isTrue();
boolean condition = simpleMap instanceof HashMap;
assertThat(condition).isTrue();
}
@Test
@@ -78,11 +79,11 @@ public class ScopedProxyTests {
ctx.refresh();
ITestBean bean = (ITestBean) ctx.getBean("testBean");
assertEquals("male", bean.getName());
assertEquals(99, bean.getAge());
assertThat(bean.getName()).isEqualTo("male");
assertThat(bean.getAge()).isEqualTo(99);
assertTrue(scope.getMap().containsKey("scopedTarget.testBean"));
assertEquals(TestBean.class, scope.getMap().get("scopedTarget.testBean").getClass());
assertThat(scope.getMap().containsKey("scopedTarget.testBean")).isTrue();
assertThat(scope.getMap().get("scopedTarget.testBean").getClass()).isEqualTo(TestBean.class);
}
@Test
@@ -94,23 +95,25 @@ public class ScopedProxyTests {
bf.registerScope("request", scope);
ITestBean bean = (ITestBean) bf.getBean("testBean");
assertNotNull(bean);
assertTrue(AopUtils.isJdkDynamicProxy(bean));
assertTrue(bean instanceof ScopedObject);
assertThat(bean).isNotNull();
assertThat(AopUtils.isJdkDynamicProxy(bean)).isTrue();
boolean condition1 = bean instanceof ScopedObject;
assertThat(condition1).isTrue();
ScopedObject scoped = (ScopedObject) bean;
assertEquals(TestBean.class, scoped.getTargetObject().getClass());
assertThat(scoped.getTargetObject().getClass()).isEqualTo(TestBean.class);
bean.setAge(101);
assertTrue(scope.getMap().containsKey("testBeanTarget"));
assertEquals(TestBean.class, scope.getMap().get("testBeanTarget").getClass());
assertThat(scope.getMap().containsKey("testBeanTarget")).isTrue();
assertThat(scope.getMap().get("testBeanTarget").getClass()).isEqualTo(TestBean.class);
ITestBean deserialized = (ITestBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertNotNull(deserialized);
assertTrue(AopUtils.isJdkDynamicProxy(deserialized));
assertEquals(101, bean.getAge());
assertTrue(deserialized instanceof ScopedObject);
assertThat(deserialized).isNotNull();
assertThat(AopUtils.isJdkDynamicProxy(deserialized)).isTrue();
assertThat(bean.getAge()).isEqualTo(101);
boolean condition = deserialized instanceof ScopedObject;
assertThat(condition).isTrue();
ScopedObject scopedDeserialized = (ScopedObject) deserialized;
assertEquals(TestBean.class, scopedDeserialized.getTargetObject().getClass());
assertThat(scopedDeserialized.getTargetObject().getClass()).isEqualTo(TestBean.class);
bf.setSerializationId(null);
}
@@ -124,22 +127,24 @@ public class ScopedProxyTests {
bf.registerScope("request", scope);
TestBean tb = (TestBean) bf.getBean("testBean");
assertTrue(AopUtils.isCglibProxy(tb.getFriends()));
assertTrue(tb.getFriends() instanceof ScopedObject);
assertThat(AopUtils.isCglibProxy(tb.getFriends())).isTrue();
boolean condition1 = tb.getFriends() instanceof ScopedObject;
assertThat(condition1).isTrue();
ScopedObject scoped = (ScopedObject) tb.getFriends();
assertEquals(ArrayList.class, scoped.getTargetObject().getClass());
assertThat(scoped.getTargetObject().getClass()).isEqualTo(ArrayList.class);
tb.getFriends().add("myFriend");
assertTrue(scope.getMap().containsKey("scopedTarget.scopedList"));
assertEquals(ArrayList.class, scope.getMap().get("scopedTarget.scopedList").getClass());
assertThat(scope.getMap().containsKey("scopedTarget.scopedList")).isTrue();
assertThat(scope.getMap().get("scopedTarget.scopedList").getClass()).isEqualTo(ArrayList.class);
ArrayList<?> deserialized = (ArrayList<?>) SerializationTestUtils.serializeAndDeserialize(tb.getFriends());
assertNotNull(deserialized);
assertTrue(AopUtils.isCglibProxy(deserialized));
assertTrue(deserialized.contains("myFriend"));
assertTrue(deserialized instanceof ScopedObject);
assertThat(deserialized).isNotNull();
assertThat(AopUtils.isCglibProxy(deserialized)).isTrue();
assertThat(deserialized.contains("myFriend")).isTrue();
boolean condition = deserialized instanceof ScopedObject;
assertThat(condition).isTrue();
ScopedObject scopedDeserialized = (ScopedObject) deserialized;
assertEquals(ArrayList.class, scopedDeserialized.getTargetObject().getClass());
assertThat(scopedDeserialized.getTargetObject().getClass()).isEqualTo(ArrayList.class);
bf.setSerializationId(null);
}

View File

@@ -32,10 +32,8 @@ import org.springframework.tests.sample.beans.SerializablePerson;
import org.springframework.tests.sample.beans.SideEffectBean;
import org.springframework.util.SerializationTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Tests for pooling invoker interceptor.
@@ -74,9 +72,9 @@ public class CommonsPool2TargetSourceTests {
private void testFunctionality(String name) {
SideEffectBean pooled = (SideEffectBean) beanFactory.getBean(name);
assertEquals(INITIAL_COUNT, pooled.getCount());
assertThat(pooled.getCount()).isEqualTo(INITIAL_COUNT);
pooled.doWork();
assertEquals(INITIAL_COUNT + 1, pooled.getCount());
assertThat(pooled.getCount()).isEqualTo((INITIAL_COUNT + 1));
pooled = (SideEffectBean) beanFactory.getBean(name);
// Just check that it works--we can't make assumptions
@@ -98,16 +96,16 @@ public class CommonsPool2TargetSourceTests {
@Test
public void testConfigMixin() {
SideEffectBean pooled = (SideEffectBean) beanFactory.getBean("pooledWithMixin");
assertEquals(INITIAL_COUNT, pooled.getCount());
assertThat(pooled.getCount()).isEqualTo(INITIAL_COUNT);
PoolingConfig conf = (PoolingConfig) beanFactory.getBean("pooledWithMixin");
// TODO one invocation from setup
//assertEquals(1, conf.getInvocations());
pooled.doWork();
// assertEquals("No objects active", 0, conf.getActive());
assertEquals("Correct target source", 25, conf.getMaxSize());
assertThat(conf.getMaxSize()).as("Correct target source").isEqualTo(25);
// assertTrue("Some free", conf.getFree() > 0);
//assertEquals(2, conf.getInvocations());
assertEquals(25, conf.getMaxSize());
assertThat(conf.getMaxSize()).isEqualTo(25);
}
@Test
@@ -115,7 +113,8 @@ public class CommonsPool2TargetSourceTests {
CommonsPool2TargetSource cpts = (CommonsPool2TargetSource) beanFactory.getBean("personPoolTargetSource");
SingletonTargetSource serialized = (SingletonTargetSource) SerializationTestUtils.serializeAndDeserialize(cpts);
assertTrue(serialized.getTarget() instanceof Person);
boolean condition = serialized.getTarget() instanceof Person;
assertThat(condition).isTrue();
}
@@ -124,13 +123,15 @@ public class CommonsPool2TargetSourceTests {
Person pooled = (Person) beanFactory.getBean("pooledPerson");
//System.out.println(((Advised) pooled).toProxyConfigString());
assertTrue(((Advised) pooled).getTargetSource() instanceof CommonsPool2TargetSource);
boolean condition1 = ((Advised) pooled).getTargetSource() instanceof CommonsPool2TargetSource;
assertThat(condition1).isTrue();
//((Advised) pooled).setTargetSource(new SingletonTargetSource(new SerializablePerson()));
Person serialized = (Person) SerializationTestUtils.serializeAndDeserialize(pooled);
assertTrue(((Advised) serialized).getTargetSource() instanceof SingletonTargetSource);
boolean condition = ((Advised) serialized).getTargetSource() instanceof SingletonTargetSource;
assertThat(condition).isTrue();
serialized.setAge(25);
assertEquals(25, serialized.getAge());
assertThat(serialized.getAge()).isEqualTo(25);
}
@Test
@@ -146,7 +147,7 @@ public class CommonsPool2TargetSourceTests {
for (int x = 0; x < maxSize; x++) {
Object instance = targetSource.getTarget();
assertNotNull(instance);
assertThat(instance).isNotNull();
pooledInstances[x] = instance;
}
@@ -174,7 +175,7 @@ public class CommonsPool2TargetSourceTests {
for (int x = 0; x < maxSize; x++) {
Object instance = targetSource.getTarget();
assertNotNull(instance);
assertThat(instance).isNotNull();
pooledInstances[x] = instance;
}
@@ -197,7 +198,7 @@ public class CommonsPool2TargetSourceTests {
public void testSetWhenExhaustedAction() {
CommonsPool2TargetSource targetSource = new CommonsPool2TargetSource();
targetSource.setBlockWhenExhausted(true);
assertEquals(true, targetSource.isBlockWhenExhausted());
assertThat(targetSource.isBlockWhenExhausted()).isEqualTo(true);
}
@Test
@@ -208,9 +209,11 @@ public class CommonsPool2TargetSourceTests {
Object first = targetSource.getTarget();
Object second = targetSource.getTarget();
assertTrue(first instanceof SerializablePerson);
assertTrue(second instanceof SerializablePerson);
assertEquals(first, second);
boolean condition1 = first instanceof SerializablePerson;
assertThat(condition1).isTrue();
boolean condition = second instanceof SerializablePerson;
assertThat(condition).isTrue();
assertThat(second).isEqualTo(first);
targetSource.releaseTarget(first);
targetSource.releaseTarget(second);

View File

@@ -24,7 +24,7 @@ import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.stereotype.Component;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
public class BridgeMethodAutowiringTests {
@@ -33,7 +33,7 @@ public class BridgeMethodAutowiringTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(UserServiceImpl.class, Foo.class);
ctx.refresh();
assertNotNull(ctx.getBean(UserServiceImpl.class).object);
assertThat(ctx.getBean(UserServiceImpl.class).object).isNotNull();
}

View File

@@ -37,7 +37,6 @@ import org.springframework.context.support.GenericApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
/**
* Integration tests for handling JSR-303 {@link javax.inject.Qualifier} annotations.
@@ -115,7 +114,7 @@ public class InjectAnnotationAutowireContextTests {
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
context.refresh();
QualifiedFieldTestBean bean = (QualifiedFieldTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -132,7 +131,7 @@ public class InjectAnnotationAutowireContextTests {
context.refresh();
QualifiedMethodParameterTestBean bean =
(QualifiedMethodParameterTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -149,7 +148,7 @@ public class InjectAnnotationAutowireContextTests {
context.refresh();
QualifiedMethodParameterTestBean bean =
(QualifiedMethodParameterTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -169,7 +168,7 @@ public class InjectAnnotationAutowireContextTests {
context.refresh();
QualifiedMethodParameterTestBean bean =
(QualifiedMethodParameterTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -186,7 +185,7 @@ public class InjectAnnotationAutowireContextTests {
context.refresh();
QualifiedConstructorArgumentTestBean bean =
(QualifiedConstructorArgumentTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -269,7 +268,7 @@ public class InjectAnnotationAutowireContextTests {
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
context.refresh();
QualifiedFieldTestBean bean = (QualifiedFieldTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -290,7 +289,7 @@ public class InjectAnnotationAutowireContextTests {
context.refresh();
QualifiedMethodParameterTestBean bean =
(QualifiedMethodParameterTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -311,7 +310,7 @@ public class InjectAnnotationAutowireContextTests {
context.refresh();
QualifiedConstructorArgumentTestBean bean =
(QualifiedConstructorArgumentTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -333,7 +332,7 @@ public class InjectAnnotationAutowireContextTests {
context.refresh();
QualifiedFieldWithDefaultValueTestBean bean =
(QualifiedFieldWithDefaultValueTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -379,7 +378,7 @@ public class InjectAnnotationAutowireContextTests {
context.refresh();
QualifiedFieldWithDefaultValueTestBean bean =
(QualifiedFieldWithDefaultValueTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -405,7 +404,7 @@ public class InjectAnnotationAutowireContextTests {
context.refresh();
QualifiedFieldWithMultipleAttributesTestBean bean =
(QualifiedFieldWithMultipleAttributesTestBean) context.getBean("autowired");
assertEquals(MARK, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(MARK);
}
@Test
@@ -461,7 +460,7 @@ public class InjectAnnotationAutowireContextTests {
context.refresh();
QualifiedFieldWithMultipleAttributesTestBean bean =
(QualifiedFieldWithMultipleAttributesTestBean) context.getBean("autowired");
assertEquals(MARK, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(MARK);
}
@Test

View File

@@ -36,7 +36,6 @@ import org.springframework.context.support.GenericApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
/**
* Integration tests for handling {@link Qualifier} annotations.
@@ -118,7 +117,7 @@ public class QualifierAnnotationAutowireContextTests {
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
context.refresh();
QualifiedFieldTestBean bean = (QualifiedFieldTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -135,7 +134,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedMethodParameterTestBean bean =
(QualifiedMethodParameterTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -152,7 +151,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedMethodParameterTestBean bean =
(QualifiedMethodParameterTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -172,7 +171,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedMethodParameterTestBean bean =
(QualifiedMethodParameterTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -189,7 +188,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedConstructorArgumentTestBean bean =
(QualifiedConstructorArgumentTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -272,7 +271,7 @@ public class QualifierAnnotationAutowireContextTests {
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
context.refresh();
QualifiedFieldTestBean bean = (QualifiedFieldTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -292,7 +291,7 @@ public class QualifierAnnotationAutowireContextTests {
AnnotationConfigUtils.registerAnnotationConfigProcessors(context);
context.refresh();
MetaQualifiedFieldTestBean bean = (MetaQualifiedFieldTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -313,7 +312,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedMethodParameterTestBean bean =
(QualifiedMethodParameterTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -334,7 +333,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedConstructorArgumentTestBean bean =
(QualifiedConstructorArgumentTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -356,7 +355,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedFieldWithDefaultValueTestBean bean =
(QualifiedFieldWithDefaultValueTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -402,7 +401,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedFieldWithDefaultValueTestBean bean =
(QualifiedFieldWithDefaultValueTestBean) context.getBean("autowired");
assertEquals(JUERGEN, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(JUERGEN);
}
@Test
@@ -428,7 +427,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedFieldWithMultipleAttributesTestBean bean =
(QualifiedFieldWithMultipleAttributesTestBean) context.getBean("autowired");
assertEquals(MARK, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(MARK);
}
@Test
@@ -484,7 +483,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedFieldWithMultipleAttributesTestBean bean =
(QualifiedFieldWithMultipleAttributesTestBean) context.getBean("autowired");
assertEquals(MARK, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(MARK);
}
@Test
@@ -534,7 +533,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedFieldWithBaseQualifierDefaultValueTestBean bean =
(QualifiedFieldWithBaseQualifierDefaultValueTestBean) context.getBean("autowired");
assertEquals(MARK, bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo(MARK);
}
@Test
@@ -556,7 +555,7 @@ public class QualifierAnnotationAutowireContextTests {
context.refresh();
QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean bean =
(QualifiedConstructorArgumentWithBaseQualifierNonDefaultValueTestBean) context.getBean("autowired");
assertEquals("the real juergen", bean.getPerson().getName());
assertThat(bean.getPerson().getName()).isEqualTo("the real juergen");
}
@Test

View File

@@ -24,7 +24,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests lookup methods wrapped by a CGLIB proxy (see SPR-391).
@@ -52,8 +52,8 @@ public class LookupMethodWrappedByCglibProxyTests {
public void testAutoProxiedLookup() {
OverloadLookup olup = (OverloadLookup) applicationContext.getBean("autoProxiedOverload");
ITestBean jenny = olup.newTestBean();
assertEquals("Jenny", jenny.getName());
assertEquals("foo", olup.testMethod());
assertThat(jenny.getName()).isEqualTo("Jenny");
assertThat(olup.testMethod()).isEqualTo("foo");
assertInterceptorCount(2);
}
@@ -61,14 +61,14 @@ public class LookupMethodWrappedByCglibProxyTests {
public void testRegularlyProxiedLookup() {
OverloadLookup olup = (OverloadLookup) applicationContext.getBean("regularlyProxiedOverload");
ITestBean jenny = olup.newTestBean();
assertEquals("Jenny", jenny.getName());
assertEquals("foo", olup.testMethod());
assertThat(jenny.getName()).isEqualTo("Jenny");
assertThat(olup.testMethod()).isEqualTo("foo");
assertInterceptorCount(2);
}
private void assertInterceptorCount(int count) {
DebugInterceptor interceptor = getInterceptor();
assertEquals("Interceptor count is incorrect", count, interceptor.getCount());
assertThat(interceptor.getCount()).as("Interceptor count is incorrect").isEqualTo(count);
}
private void resetInterceptor() {

View File

@@ -35,10 +35,8 @@ import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.context.support.StaticApplicationContext;
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.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.springframework.util.ClassUtils.convertClassNameToResourcePath;
/**
@@ -73,7 +71,7 @@ public class QualifierAnnotationTests {
context.refresh();
QualifiedByValueTestBean testBean = (QualifiedByValueTestBean) context.getBean("testBean");
Person person = testBean.getLarry();
assertEquals("Larry", person.getName());
assertThat(person.getName()).isEqualTo("Larry");
}
@Test
@@ -98,7 +96,7 @@ public class QualifierAnnotationTests {
context.refresh();
QualifiedByParentValueTestBean testBean = (QualifiedByParentValueTestBean) context.getBean("testBean");
Person person = testBean.getLarry();
assertEquals("ParentLarry", person.getName());
assertThat(person.getName()).isEqualTo("ParentLarry");
}
@Test
@@ -110,8 +108,8 @@ public class QualifierAnnotationTests {
context.refresh();
QualifiedByBeanNameTestBean testBean = (QualifiedByBeanNameTestBean) context.getBean("testBean");
Person person = testBean.getLarry();
assertEquals("LarryBean", person.getName());
assertTrue(testBean.myProps != null && testBean.myProps.isEmpty());
assertThat(person.getName()).isEqualTo("LarryBean");
assertThat(testBean.myProps != null && testBean.myProps.isEmpty()).isTrue();
}
@Test
@@ -123,7 +121,7 @@ public class QualifierAnnotationTests {
context.refresh();
QualifiedByFieldNameTestBean testBean = (QualifiedByFieldNameTestBean) context.getBean("testBean");
Person person = testBean.getLarry();
assertEquals("LarryBean", person.getName());
assertThat(person.getName()).isEqualTo("LarryBean");
}
@Test
@@ -135,7 +133,7 @@ public class QualifierAnnotationTests {
context.refresh();
QualifiedByParameterNameTestBean testBean = (QualifiedByParameterNameTestBean) context.getBean("testBean");
Person person = testBean.getLarry();
assertEquals("LarryBean", person.getName());
assertThat(person.getName()).isEqualTo("LarryBean");
}
@Test
@@ -147,7 +145,7 @@ public class QualifierAnnotationTests {
context.refresh();
QualifiedByAliasTestBean testBean = (QualifiedByAliasTestBean) context.getBean("testBean");
Person person = testBean.getStooge();
assertEquals("LarryBean", person.getName());
assertThat(person.getName()).isEqualTo("LarryBean");
}
@Test
@@ -159,7 +157,7 @@ public class QualifierAnnotationTests {
context.refresh();
QualifiedByAnnotationTestBean testBean = (QualifiedByAnnotationTestBean) context.getBean("testBean");
Person person = testBean.getLarry();
assertEquals("LarrySpecial", person.getName());
assertThat(person.getName()).isEqualTo("LarrySpecial");
}
@Test
@@ -171,7 +169,7 @@ public class QualifierAnnotationTests {
context.refresh();
QualifiedByCustomValueTestBean testBean = (QualifiedByCustomValueTestBean) context.getBean("testBean");
Person person = testBean.getCurly();
assertEquals("Curly", person.getName());
assertThat(person.getName()).isEqualTo("Curly");
}
@Test
@@ -183,7 +181,7 @@ public class QualifierAnnotationTests {
context.refresh();
QualifiedByAnnotationValueTestBean testBean = (QualifiedByAnnotationValueTestBean) context.getBean("testBean");
Person person = testBean.getLarry();
assertEquals("LarrySpecial", person.getName());
assertThat(person.getName()).isEqualTo("LarrySpecial");
}
@Test
@@ -210,8 +208,8 @@ public class QualifierAnnotationTests {
MultiQualifierClient testBean = (MultiQualifierClient) context.getBean("testBean");
assertNotNull( testBean.factoryTheta);
assertNotNull( testBean.implTheta);
assertThat(testBean.factoryTheta).isNotNull();
assertThat(testBean.implTheta).isNotNull();
}
@Test

View File

@@ -22,7 +22,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.sample.beans.ITestBean;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for combining the expression language and the p namespace. Due to the required EL dependency, this test is in
@@ -39,8 +39,8 @@ public class SimplePropertyNamespaceHandlerWithExpressionLanguageTests {
getClass());
ITestBean foo = applicationContext.getBean("foo", ITestBean.class);
ITestBean bar = applicationContext.getBean("bar", ITestBean.class);
assertEquals("Invalid name", "Baz", foo.getName());
assertEquals("Invalid name", "Baz", bar.getName());
assertThat(foo.getName()).as("Invalid name").isEqualTo("Baz");
assertThat(bar.getName()).as("Invalid name").isEqualTo("Baz");
}
}

View File

@@ -62,9 +62,6 @@ import org.springframework.tests.sample.beans.TestBean;
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.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for custom XML namespace handler implementations.
@@ -116,17 +113,17 @@ public class CustomNamespaceHandlerTests {
public void testProxyingDecorator() throws Exception {
ITestBean bean = (ITestBean) this.beanFactory.getBean("debuggingTestBean");
assertTestBean(bean);
assertTrue(AopUtils.isAopProxy(bean));
assertThat(AopUtils.isAopProxy(bean)).isTrue();
Advisor[] advisors = ((Advised) bean).getAdvisors();
assertEquals("Incorrect number of advisors", 1, advisors.length);
assertEquals("Incorrect advice class", DebugInterceptor.class, advisors[0].getAdvice().getClass());
assertThat(advisors.length).as("Incorrect number of advisors").isEqualTo(1);
assertThat(advisors[0].getAdvice().getClass()).as("Incorrect advice class").isEqualTo(DebugInterceptor.class);
}
@Test
public void testProxyingDecoratorNoInstance() throws Exception {
String[] beanNames = this.beanFactory.getBeanNamesForType(ApplicationListener.class);
assertTrue(Arrays.asList(beanNames).contains("debuggingTestBeanNoInstance"));
assertEquals(ApplicationListener.class, this.beanFactory.getType("debuggingTestBeanNoInstance"));
assertThat(Arrays.asList(beanNames).contains("debuggingTestBeanNoInstance")).isTrue();
assertThat(this.beanFactory.getType("debuggingTestBeanNoInstance")).isEqualTo(ApplicationListener.class);
assertThatExceptionOfType(BeanCreationException.class).isThrownBy(() ->
this.beanFactory.getBean("debuggingTestBeanNoInstance"))
.satisfies(ex -> assertThat(ex.getRootCause()).isInstanceOf(BeanInstantiationException.class));
@@ -136,44 +133,44 @@ public class CustomNamespaceHandlerTests {
public void testChainedDecorators() throws Exception {
ITestBean bean = (ITestBean) this.beanFactory.getBean("chainedTestBean");
assertTestBean(bean);
assertTrue(AopUtils.isAopProxy(bean));
assertThat(AopUtils.isAopProxy(bean)).isTrue();
Advisor[] advisors = ((Advised) bean).getAdvisors();
assertEquals("Incorrect number of advisors", 2, advisors.length);
assertEquals("Incorrect advice class", DebugInterceptor.class, advisors[0].getAdvice().getClass());
assertEquals("Incorrect advice class", NopInterceptor.class, advisors[1].getAdvice().getClass());
assertThat(advisors.length).as("Incorrect number of advisors").isEqualTo(2);
assertThat(advisors[0].getAdvice().getClass()).as("Incorrect advice class").isEqualTo(DebugInterceptor.class);
assertThat(advisors[1].getAdvice().getClass()).as("Incorrect advice class").isEqualTo(NopInterceptor.class);
}
@Test
public void testDecorationViaAttribute() throws Exception {
BeanDefinition beanDefinition = this.beanFactory.getBeanDefinition("decorateWithAttribute");
assertEquals("foo", beanDefinition.getAttribute("objectName"));
assertThat(beanDefinition.getAttribute("objectName")).isEqualTo("foo");
}
@Test // SPR-2728
public void testCustomElementNestedWithinUtilList() throws Exception {
List<?> things = (List<?>) this.beanFactory.getBean("list.of.things");
assertNotNull(things);
assertEquals(2, things.size());
assertThat(things).isNotNull();
assertThat(things.size()).isEqualTo(2);
}
@Test // SPR-2728
public void testCustomElementNestedWithinUtilSet() throws Exception {
Set<?> things = (Set<?>) this.beanFactory.getBean("set.of.things");
assertNotNull(things);
assertEquals(2, things.size());
assertThat(things).isNotNull();
assertThat(things.size()).isEqualTo(2);
}
@Test // SPR-2728
public void testCustomElementNestedWithinUtilMap() throws Exception {
Map<?, ?> things = (Map<?, ?>) this.beanFactory.getBean("map.of.things");
assertNotNull(things);
assertEquals(2, things.size());
assertThat(things).isNotNull();
assertThat(things.size()).isEqualTo(2);
}
private void assertTestBean(ITestBean bean) {
assertEquals("Invalid name", "Rob Harrop", bean.getName());
assertEquals("Invalid age", 23, bean.getAge());
assertThat(bean.getName()).as("Invalid name").isEqualTo("Rob Harrop");
assertThat(bean.getAge()).as("Invalid age").isEqualTo(23);
}
private Resource getResource() {

View File

@@ -25,10 +25,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.junit.Test;
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;
import static org.junit.Assert.assertSame;
/**
* @author Stephane Nicoll
@@ -44,12 +40,12 @@ public abstract class AbstractCacheTests<T extends Cache> {
@Test
public void testCacheName() throws Exception {
assertEquals(CACHE_NAME, getCache().getName());
assertThat(getCache().getName()).isEqualTo(CACHE_NAME);
}
@Test
public void testNativeCache() throws Exception {
assertSame(getNativeCache(), getCache().getNativeCache());
assertThat(getCache().getNativeCache()).isSameAs(getNativeCache());
}
@Test
@@ -59,21 +55,21 @@ public abstract class AbstractCacheTests<T extends Cache> {
String key = createRandomKey();
Object value = "george";
assertNull(cache.get(key));
assertNull(cache.get(key, String.class));
assertNull(cache.get(key, Object.class));
assertThat((Object) cache.get(key)).isNull();
assertThat(cache.get(key, String.class)).isNull();
assertThat(cache.get(key, Object.class)).isNull();
cache.put(key, value);
assertEquals(value, cache.get(key).get());
assertEquals(value, cache.get(key, String.class));
assertEquals(value, cache.get(key, Object.class));
assertEquals(value, cache.get(key, (Class<?>) null));
assertThat(cache.get(key).get()).isEqualTo(value);
assertThat(cache.get(key, String.class)).isEqualTo(value);
assertThat(cache.get(key, Object.class)).isEqualTo(value);
assertThat(cache.get(key, (Class<?>) null)).isEqualTo(value);
cache.put(key, null);
assertNotNull(cache.get(key));
assertNull(cache.get(key).get());
assertNull(cache.get(key, String.class));
assertNull(cache.get(key, Object.class));
assertThat(cache.get(key)).isNotNull();
assertThat(cache.get(key).get()).isNull();
assertThat(cache.get(key, String.class)).isNull();
assertThat(cache.get(key, Object.class)).isNull();
}
@Test
@@ -83,11 +79,12 @@ public abstract class AbstractCacheTests<T extends Cache> {
String key = createRandomKey();
Object value = "initialValue";
assertNull(cache.get(key));
assertNull(cache.putIfAbsent(key, value));
assertEquals(value, cache.get(key).get());
assertEquals("initialValue", cache.putIfAbsent(key, "anotherValue").get());
assertEquals(value, cache.get(key).get()); // not changed
assertThat(cache.get(key)).isNull();
assertThat(cache.putIfAbsent(key, value)).isNull();
assertThat(cache.get(key).get()).isEqualTo(value);
assertThat(cache.putIfAbsent(key, "anotherValue").get()).isEqualTo("initialValue");
// not changed
assertThat(cache.get(key).get()).isEqualTo(value);
}
@Test
@@ -97,7 +94,7 @@ public abstract class AbstractCacheTests<T extends Cache> {
String key = createRandomKey();
Object value = "george";
assertNull(cache.get(key));
assertThat((Object) cache.get(key)).isNull();
cache.put(key, value);
}
@@ -105,13 +102,13 @@ public abstract class AbstractCacheTests<T extends Cache> {
public void testCacheClear() throws Exception {
T cache = getCache();
assertNull(cache.get("enescu"));
assertThat((Object) cache.get("enescu")).isNull();
cache.put("enescu", "george");
assertNull(cache.get("vlaicu"));
assertThat((Object) cache.get("vlaicu")).isNull();
cache.put("vlaicu", "aurel");
cache.clear();
assertNull(cache.get("vlaicu"));
assertNull(cache.get("enescu"));
assertThat((Object) cache.get("vlaicu")).isNull();
assertThat((Object) cache.get("enescu")).isNull();
}
@Test
@@ -129,10 +126,10 @@ public abstract class AbstractCacheTests<T extends Cache> {
String key = createRandomKey();
assertNull(cache.get(key));
assertThat((Object) cache.get(key)).isNull();
Object value = cache.get(key, () -> returnValue);
assertEquals(returnValue, value);
assertEquals(value, cache.get(key).get());
assertThat(value).isEqualTo(returnValue);
assertThat(cache.get(key).get()).isEqualTo(value);
}
@Test
@@ -154,7 +151,7 @@ public abstract class AbstractCacheTests<T extends Cache> {
Object value = cache.get(key, () -> {
throw new IllegalStateException("Should not have been invoked");
});
assertEquals(initialValue, value);
assertThat(value).isEqualTo(initialValue);
}
@Test
@@ -162,7 +159,7 @@ public abstract class AbstractCacheTests<T extends Cache> {
T cache = getCache();
String key = createRandomKey();
assertNull(cache.get(key));
assertThat((Object) cache.get(key)).isNull();
try {
cache.get(key, () -> {
@@ -170,8 +167,8 @@ public abstract class AbstractCacheTests<T extends Cache> {
});
}
catch (Cache.ValueRetrievalException ex) {
assertNotNull(ex.getCause());
assertEquals(UnsupportedOperationException.class, ex.getCause().getClass());
assertThat(ex.getCause()).isNotNull();
assertThat(ex.getCause().getClass()).isEqualTo(UnsupportedOperationException.class);
}
}
@@ -205,7 +202,7 @@ public abstract class AbstractCacheTests<T extends Cache> {
}
latch.await();
assertEquals(10, results.size());
assertThat(results.size()).isEqualTo(10);
results.forEach(r -> assertThat(r).isEqualTo(1)); // Only one method got invoked
}

View File

@@ -41,11 +41,8 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -74,7 +71,7 @@ public class CacheReproTests {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Spr11249Config.class);
Spr11249Service bean = context.getBean(Spr11249Service.class);
Object result = bean.doSomething("op", 2, 3);
assertSame(result, bean.doSomething("op", 2, 3));
assertThat(bean.doSomething("op", 2, 3)).isSameAs(result);
context.close();
}
@@ -89,7 +86,7 @@ public class CacheReproTests {
verify(cache, times(1)).get(key); // first call: cache miss
Object cachedResult = bean.getSimple("1");
assertSame(result, cachedResult);
assertThat(cachedResult).isSameAs(result);
verify(cache, times(2)).get(key); // second call: cache hit
context.close();
@@ -106,7 +103,7 @@ public class CacheReproTests {
verify(cache, times(0)).get(key); // no cache hit at all, caching disabled
Object cachedResult = bean.getNeverCache("1");
assertNotSame(result, cachedResult);
assertThat(cachedResult).isNotSameAs(result);
verify(cache, times(0)).get(key); // caching disabled
context.close();
@@ -118,9 +115,9 @@ public class CacheReproTests {
MyCacheResolver cacheResolver = context.getBean(MyCacheResolver.class);
Spr13081Service bean = context.getBean(Spr13081Service.class);
assertNull(cacheResolver.getCache("foo").get("foo"));
assertThat(cacheResolver.getCache("foo").get("foo")).isNull();
Object result = bean.getSimple("foo"); // cache name = id
assertEquals(result, cacheResolver.getCache("foo").get("foo").get());
assertThat(cacheResolver.getCache("foo").get("foo").get()).isEqualTo(result);
}
@Test
@@ -141,13 +138,13 @@ public class CacheReproTests {
TestBean tb = new TestBean("tb1");
bean.insertItem(tb);
assertSame(tb, bean.findById("tb1").get());
assertSame(tb, cache.get("tb1").get());
assertThat(bean.findById("tb1").get()).isSameAs(tb);
assertThat(cache.get("tb1").get()).isSameAs(tb);
cache.clear();
TestBean tb2 = bean.findById("tb1").get();
assertNotSame(tb, tb2);
assertSame(tb2, cache.get("tb1").get());
assertThat(tb2).isNotSameAs(tb);
assertThat(cache.get("tb1").get()).isSameAs(tb2);
}
@Test
@@ -158,13 +155,13 @@ public class CacheReproTests {
TestBean tb = new TestBean("tb1");
bean.insertItem(tb);
assertSame(tb, bean.findById("tb1").get());
assertSame(tb, cache.get("tb1").get());
assertThat(bean.findById("tb1").get()).isSameAs(tb);
assertThat(cache.get("tb1").get()).isSameAs(tb);
cache.clear();
TestBean tb2 = bean.findById("tb1").get();
assertNotSame(tb, tb2);
assertSame(tb2, cache.get("tb1").get());
assertThat(tb2).isNotSameAs(tb);
assertThat(cache.get("tb1").get()).isSameAs(tb2);
}
@Test
@@ -175,8 +172,8 @@ public class CacheReproTests {
TestBean tb = new TestBean("tb1");
bean.insertItem(tb);
assertSame(tb, bean.findById("tb1").get());
assertSame(tb, cache.get("tb1").get());
assertThat(bean.findById("tb1").get()).isSameAs(tb);
assertThat(cache.get("tb1").get()).isSameAs(tb);
}
@Test
@@ -187,8 +184,8 @@ public class CacheReproTests {
TestBean tb = new TestBean("tb1");
bean.insertItem(tb);
assertSame(tb, bean.findById("tb1").get());
assertSame(tb, cache.get("tb1").get());
assertThat(bean.findById("tb1").get()).isSameAs(tb);
assertThat(cache.get("tb1").get()).isSameAs(tb);
}

View File

@@ -22,9 +22,7 @@ import java.util.List;
import org.springframework.cache.concurrent.ConcurrentMapCache;
import org.springframework.cache.support.SimpleCacheManager;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* General cache-related test utilities.
@@ -54,7 +52,7 @@ public class CacheTestUtils {
*/
public static void assertCacheMiss(Object key, Cache... caches) {
for (Cache cache : caches) {
assertNull("No entry in " + cache + " should have been found with key " + key, cache.get(key));
assertThat(cache.get(key)).as("No entry in " + cache + " should have been found with key " + key).isNull();
}
}
@@ -64,8 +62,8 @@ public class CacheTestUtils {
public static void assertCacheHit(Object key, Object value, Cache... caches) {
for (Cache cache : caches) {
Cache.ValueWrapper wrapper = cache.get(key);
assertNotNull("An entry in " + cache + " should have been found with key " + key, wrapper);
assertEquals("Wrong value in " + cache + " for entry with key " + key, value, wrapper.get());
assertThat(wrapper).as("An entry in " + cache + " should have been found with key " + key).isNotNull();
assertThat(wrapper.get()).as("Wrong value in " + cache + " for entry with key " + key).isEqualTo(value);
}
}

View File

@@ -22,12 +22,7 @@ import org.junit.Test;
import org.springframework.cache.support.NoOpCacheManager;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link NoOpCacheManager}.
@@ -42,28 +37,28 @@ public class NoOpCacheManagerTests {
@Test
public void testGetCache() throws Exception {
Cache cache = this.manager.getCache("bucket");
assertNotNull(cache);
assertSame(cache, this.manager.getCache("bucket"));
assertThat(cache).isNotNull();
assertThat(this.manager.getCache("bucket")).isSameAs(cache);
}
@Test
public void testNoOpCache() throws Exception {
String name = createRandomKey();
Cache cache = this.manager.getCache(name);
assertEquals(name, cache.getName());
assertThat(cache.getName()).isEqualTo(name);
Object key = new Object();
cache.put(key, new Object());
assertNull(cache.get(key));
assertNull(cache.get(key, Object.class));
assertSame(cache, cache.getNativeCache());
assertThat(cache.get(key)).isNull();
assertThat(cache.get(key, Object.class)).isNull();
assertThat(cache.getNativeCache()).isSameAs(cache);
}
@Test
public void testCacheName() throws Exception {
String name = "bucket";
assertFalse(this.manager.getCacheNames().contains(name));
assertThat(this.manager.getCacheNames().contains(name)).isFalse();
this.manager.getCache(name);
assertTrue(this.manager.getCacheNames().contains(name));
assertThat(this.manager.getCacheNames().contains(name)).isTrue();
}
@Test
@@ -72,7 +67,7 @@ public class NoOpCacheManagerTests {
Cache cache = this.manager.getCache(name);
Object returnValue = new Object();
Object value = cache.get(new Object(), () -> returnValue);
assertEquals(returnValue, value);
assertThat(value).isEqualTo(returnValue);
}
@Test
@@ -85,8 +80,8 @@ public class NoOpCacheManagerTests {
});
}
catch (Cache.ValueRetrievalException ex) {
assertNotNull(ex.getCause());
assertEquals(UnsupportedOperationException.class, ex.getCause().getClass());
assertThat(ex.getCause()).isNotNull();
assertThat(ex.getCause().getClass()).isEqualTo(UnsupportedOperationException.class);
}
}

View File

@@ -35,10 +35,6 @@ 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.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @author Costin Leau
@@ -53,23 +49,23 @@ public class AnnotationCacheOperationSourceTests {
@Test
public void singularAnnotation() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singular", 1);
assertTrue(ops.iterator().next() instanceof CacheableOperation);
assertThat(ops.iterator().next() instanceof CacheableOperation).isTrue();
}
@Test
public void multipleAnnotation() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multiple", 2);
Iterator<CacheOperation> it = ops.iterator();
assertTrue(it.next() instanceof CacheableOperation);
assertTrue(it.next() instanceof CacheEvictOperation);
assertThat(it.next() instanceof CacheableOperation).isTrue();
assertThat(it.next() instanceof CacheEvictOperation).isTrue();
}
@Test
public void caching() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "caching", 2);
Iterator<CacheOperation> it = ops.iterator();
assertTrue(it.next() instanceof CacheableOperation);
assertTrue(it.next() instanceof CacheEvictOperation);
assertThat(it.next() instanceof CacheableOperation).isTrue();
assertThat(it.next() instanceof CacheEvictOperation).isTrue();
}
@Test
@@ -80,20 +76,20 @@ public class AnnotationCacheOperationSourceTests {
@Test
public void singularStereotype() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "singleStereotype", 1);
assertTrue(ops.iterator().next() instanceof CacheEvictOperation);
assertThat(ops.iterator().next() instanceof CacheEvictOperation).isTrue();
}
@Test
public void multipleStereotypes() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "multipleStereotype", 3);
Iterator<CacheOperation> it = ops.iterator();
assertTrue(it.next() instanceof CacheableOperation);
assertThat(it.next() instanceof CacheableOperation).isTrue();
CacheOperation next = it.next();
assertTrue(next instanceof CacheEvictOperation);
assertTrue(next.getCacheNames().contains("foo"));
assertThat(next instanceof CacheEvictOperation).isTrue();
assertThat(next.getCacheNames().contains("foo")).isTrue();
next = it.next();
assertTrue(next instanceof CacheEvictOperation);
assertTrue(next.getCacheNames().contains("bar"));
assertThat(next instanceof CacheEvictOperation).isTrue();
assertThat(next.getCacheNames().contains("bar")).isTrue();
}
@Test
@@ -142,14 +138,14 @@ public class AnnotationCacheOperationSourceTests {
public void customKeyGenerator() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGenerator", 1);
CacheOperation cacheOperation = ops.iterator().next();
assertEquals("Custom key generator not set", "custom", cacheOperation.getKeyGenerator());
assertThat(cacheOperation.getKeyGenerator()).as("Custom key generator not set").isEqualTo("custom");
}
@Test
public void customKeyGeneratorInherited() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customKeyGeneratorInherited", 1);
CacheOperation cacheOperation = ops.iterator().next();
assertEquals("Custom key generator not set", "custom", cacheOperation.getKeyGenerator());
assertThat(cacheOperation.getKeyGenerator()).as("Custom key generator not set").isEqualTo("custom");
}
@Test
@@ -162,28 +158,28 @@ public class AnnotationCacheOperationSourceTests {
public void customCacheManager() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheManager", 1);
CacheOperation cacheOperation = ops.iterator().next();
assertEquals("Custom cache manager not set", "custom", cacheOperation.getCacheManager());
assertThat(cacheOperation.getCacheManager()).as("Custom cache manager not set").isEqualTo("custom");
}
@Test
public void customCacheManagerInherited() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheManagerInherited", 1);
CacheOperation cacheOperation = ops.iterator().next();
assertEquals("Custom cache manager not set", "custom", cacheOperation.getCacheManager());
assertThat(cacheOperation.getCacheManager()).as("Custom cache manager not set").isEqualTo("custom");
}
@Test
public void customCacheResolver() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheResolver", 1);
CacheOperation cacheOperation = ops.iterator().next();
assertEquals("Custom cache resolver not set", "custom", cacheOperation.getCacheResolver());
assertThat(cacheOperation.getCacheResolver()).as("Custom cache resolver not set").isEqualTo("custom");
}
@Test
public void customCacheResolverInherited() {
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "customCacheResolverInherited", 1);
CacheOperation cacheOperation = ops.iterator().next();
assertEquals("Custom cache resolver not set", "custom", cacheOperation.getCacheResolver());
assertThat(cacheOperation.getCacheResolver()).as("Custom cache resolver not set").isEqualTo("custom");
}
@Test
@@ -225,8 +221,8 @@ public class AnnotationCacheOperationSourceTests {
// Valid as a CacheResolver might return the cache names to use with other info
Collection<CacheOperation> ops = getOps(AnnotatedClass.class, "noCacheNameSpecified");
CacheOperation cacheOperation = ops.iterator().next();
assertNotNull("cache names set must not be null", cacheOperation.getCacheNames());
assertEquals("no cache names specified", 0, cacheOperation.getCacheNames().size());
assertThat(cacheOperation.getCacheNames()).as("cache names set must not be null").isNotNull();
assertThat(cacheOperation.getCacheNames().size()).as("no cache names specified").isEqualTo(0);
}
@Test
@@ -253,9 +249,9 @@ public class AnnotationCacheOperationSourceTests {
@Test
public void cacheAnnotationOverride() {
Collection<CacheOperation> ops = getOps(InterfaceCacheConfig.class, "interfaceCacheableOverride");
assertSame(1, ops.size());
assertThat(ops.size()).isSameAs(1);
CacheOperation cacheOperation = ops.iterator().next();
assertTrue(cacheOperation instanceof CacheableOperation);
assertThat(cacheOperation instanceof CacheableOperation).isTrue();
}
@Test
@@ -282,7 +278,7 @@ public class AnnotationCacheOperationSourceTests {
private Collection<CacheOperation> getOps(Class<?> target, String name, int expectedNumberOfOperations) {
Collection<CacheOperation> result = getOps(target, name);
assertEquals("Wrong number of operation(s) for '" + name + "'", expectedNumberOfOperations, result.size());
assertThat(result.size()).as("Wrong number of operation(s) for '" + name + "'").isEqualTo(expectedNumberOfOperations);
return result;
}
@@ -299,13 +295,11 @@ public class AnnotationCacheOperationSourceTests {
private void assertSharedConfig(CacheOperation actual, String keyGenerator, String cacheManager,
String cacheResolver, String... cacheNames) {
assertEquals("Wrong key manager", keyGenerator, actual.getKeyGenerator());
assertEquals("Wrong cache manager", cacheManager, actual.getCacheManager());
assertEquals("Wrong cache resolver", cacheResolver, actual.getCacheResolver());
assertEquals("Wrong number of cache names", cacheNames.length, actual.getCacheNames().size());
Arrays.stream(cacheNames).forEach(cacheName ->
assertTrue("Cache '" + cacheName + "' not found in " + actual.getCacheNames(),
actual.getCacheNames().contains(cacheName)));
assertThat(actual.getKeyGenerator()).as("Wrong key manager").isEqualTo(keyGenerator);
assertThat(actual.getCacheManager()).as("Wrong cache manager").isEqualTo(cacheManager);
assertThat(actual.getCacheResolver()).as("Wrong cache resolver").isEqualTo(cacheResolver);
assertThat(actual.getCacheNames().size()).as("Wrong number of cache names").isEqualTo(cacheNames.length);
Arrays.stream(cacheNames).forEach(cacheName -> assertThat(actual.getCacheNames().contains(cacheName)).as("Cache '" + cacheName + "' not found in " + actual.getCacheNames()).isTrue());
}

View File

@@ -21,11 +21,7 @@ import org.junit.Test;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
@@ -37,102 +33,111 @@ public class ConcurrentMapCacheManagerTests {
public void testDynamicMode() {
CacheManager cm = new ConcurrentMapCacheManager();
Cache cache1 = cm.getCache("c1");
assertTrue(cache1 instanceof ConcurrentMapCache);
boolean condition2 = cache1 instanceof ConcurrentMapCache;
assertThat(condition2).isTrue();
Cache cache1again = cm.getCache("c1");
assertSame(cache1again, cache1);
assertThat(cache1).isSameAs(cache1again);
Cache cache2 = cm.getCache("c2");
assertTrue(cache2 instanceof ConcurrentMapCache);
boolean condition1 = cache2 instanceof ConcurrentMapCache;
assertThat(condition1).isTrue();
Cache cache2again = cm.getCache("c2");
assertSame(cache2again, cache2);
assertThat(cache2).isSameAs(cache2again);
Cache cache3 = cm.getCache("c3");
assertTrue(cache3 instanceof ConcurrentMapCache);
boolean condition = cache3 instanceof ConcurrentMapCache;
assertThat(condition).isTrue();
Cache cache3again = cm.getCache("c3");
assertSame(cache3again, cache3);
assertThat(cache3).isSameAs(cache3again);
cache1.put("key1", "value1");
assertEquals("value1", cache1.get("key1").get());
assertThat(cache1.get("key1").get()).isEqualTo("value1");
cache1.put("key2", 2);
assertEquals(2, cache1.get("key2").get());
assertThat(cache1.get("key2").get()).isEqualTo(2);
cache1.put("key3", null);
assertNull(cache1.get("key3").get());
assertThat(cache1.get("key3").get()).isNull();
cache1.put("key3", null);
assertNull(cache1.get("key3").get());
assertThat(cache1.get("key3").get()).isNull();
cache1.evict("key3");
assertNull(cache1.get("key3"));
assertThat(cache1.get("key3")).isNull();
assertEquals("value1", cache1.putIfAbsent("key1", "value1x").get());
assertEquals("value1", cache1.get("key1").get());
assertEquals(2, cache1.putIfAbsent("key2", 2.1).get());
assertNull(cache1.putIfAbsent("key3", null));
assertNull(cache1.get("key3").get());
assertNull(cache1.putIfAbsent("key3", null).get());
assertNull(cache1.get("key3").get());
assertThat(cache1.putIfAbsent("key1", "value1x").get()).isEqualTo("value1");
assertThat(cache1.get("key1").get()).isEqualTo("value1");
assertThat(cache1.putIfAbsent("key2", 2.1).get()).isEqualTo(2);
assertThat(cache1.putIfAbsent("key3", null)).isNull();
assertThat(cache1.get("key3").get()).isNull();
assertThat(cache1.putIfAbsent("key3", null).get()).isNull();
assertThat(cache1.get("key3").get()).isNull();
cache1.evict("key3");
assertNull(cache1.get("key3"));
assertThat(cache1.get("key3")).isNull();
}
@Test
public void testStaticMode() {
ConcurrentMapCacheManager cm = new ConcurrentMapCacheManager("c1", "c2");
Cache cache1 = cm.getCache("c1");
assertTrue(cache1 instanceof ConcurrentMapCache);
boolean condition3 = cache1 instanceof ConcurrentMapCache;
assertThat(condition3).isTrue();
Cache cache1again = cm.getCache("c1");
assertSame(cache1again, cache1);
assertThat(cache1).isSameAs(cache1again);
Cache cache2 = cm.getCache("c2");
assertTrue(cache2 instanceof ConcurrentMapCache);
boolean condition2 = cache2 instanceof ConcurrentMapCache;
assertThat(condition2).isTrue();
Cache cache2again = cm.getCache("c2");
assertSame(cache2again, cache2);
assertThat(cache2).isSameAs(cache2again);
Cache cache3 = cm.getCache("c3");
assertNull(cache3);
assertThat(cache3).isNull();
cache1.put("key1", "value1");
assertEquals("value1", cache1.get("key1").get());
assertThat(cache1.get("key1").get()).isEqualTo("value1");
cache1.put("key2", 2);
assertEquals(2, cache1.get("key2").get());
assertThat(cache1.get("key2").get()).isEqualTo(2);
cache1.put("key3", null);
assertNull(cache1.get("key3").get());
assertThat(cache1.get("key3").get()).isNull();
cache1.evict("key3");
assertNull(cache1.get("key3"));
assertThat(cache1.get("key3")).isNull();
cm.setAllowNullValues(false);
Cache cache1x = cm.getCache("c1");
assertTrue(cache1x instanceof ConcurrentMapCache);
assertTrue(cache1x != cache1);
boolean condition1 = cache1x instanceof ConcurrentMapCache;
assertThat(condition1).isTrue();
assertThat(cache1x != cache1).isTrue();
Cache cache2x = cm.getCache("c2");
assertTrue(cache2x instanceof ConcurrentMapCache);
assertTrue(cache2x != cache2);
boolean condition = cache2x instanceof ConcurrentMapCache;
assertThat(condition).isTrue();
assertThat(cache2x != cache2).isTrue();
Cache cache3x = cm.getCache("c3");
assertNull(cache3x);
assertThat(cache3x).isNull();
cache1x.put("key1", "value1");
assertEquals("value1", cache1x.get("key1").get());
assertThat(cache1x.get("key1").get()).isEqualTo("value1");
cache1x.put("key2", 2);
assertEquals(2, cache1x.get("key2").get());
assertThat(cache1x.get("key2").get()).isEqualTo(2);
cm.setAllowNullValues(true);
Cache cache1y = cm.getCache("c1");
cache1y.put("key3", null);
assertNull(cache1y.get("key3").get());
assertThat(cache1y.get("key3").get()).isNull();
cache1y.evict("key3");
assertNull(cache1y.get("key3"));
assertThat(cache1y.get("key3")).isNull();
}
@Test
public void testChangeStoreByValue() {
ConcurrentMapCacheManager cm = new ConcurrentMapCacheManager("c1", "c2");
assertFalse(cm.isStoreByValue());
assertThat(cm.isStoreByValue()).isFalse();
Cache cache1 = cm.getCache("c1");
assertTrue(cache1 instanceof ConcurrentMapCache);
assertFalse(((ConcurrentMapCache)cache1).isStoreByValue());
boolean condition1 = cache1 instanceof ConcurrentMapCache;
assertThat(condition1).isTrue();
assertThat(((ConcurrentMapCache)cache1).isStoreByValue()).isFalse();
cache1.put("key", "value");
cm.setStoreByValue(true);
assertTrue(cm.isStoreByValue());
assertThat(cm.isStoreByValue()).isTrue();
Cache cache1x = cm.getCache("c1");
assertTrue(cache1x instanceof ConcurrentMapCache);
assertTrue(cache1x != cache1);
assertNull(cache1x.get("key"));
boolean condition = cache1x instanceof ConcurrentMapCache;
assertThat(condition).isTrue();
assertThat(cache1x != cache1).isTrue();
assertThat(cache1x.get("key")).isNull();
}
}

View File

@@ -28,10 +28,8 @@ import org.junit.Test;
import org.springframework.cache.AbstractValueAdaptingCacheTests;
import org.springframework.core.serializer.support.SerializationDelegate;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Costin Leau
@@ -77,14 +75,14 @@ public class ConcurrentMapCacheTests
@Test
public void testIsStoreByReferenceByDefault() {
assertFalse(this.cache.isStoreByValue());
assertThat(this.cache.isStoreByValue()).isFalse();
}
@SuppressWarnings("unchecked")
@Test
public void testSerializer() {
ConcurrentMapCache serializeCache = createCacheWithStoreByValue();
assertTrue(serializeCache.isStoreByValue());
assertThat(serializeCache.isStoreByValue()).isTrue();
Object key = createRandomKey();
List<String> content = new ArrayList<>();
@@ -92,8 +90,8 @@ public class ConcurrentMapCacheTests
serializeCache.put(key, content);
content.remove(0);
List<String> entry = (List<String>) serializeCache.get(key).get();
assertEquals(3, entry.size());
assertEquals("one", entry.get(0));
assertThat(entry.size()).isEqualTo(3);
assertThat(entry.get(0)).isEqualTo("one");
}
@Test

View File

@@ -32,12 +32,6 @@ 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.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* Abstract cache annotation tests (containing several reusable methods).
@@ -72,9 +66,9 @@ public abstract class AbstractCacheAnnotationTests {
this.cm = ctx.getBean("cacheManager", CacheManager.class);
Collection<String> cn = this.cm.getCacheNames();
assertTrue(cn.contains("testCache"));
assertTrue(cn.contains("secondary"));
assertTrue(cn.contains("primary"));
assertThat(cn.contains("testCache")).isTrue();
assertThat(cn.contains("secondary")).isTrue();
assertThat(cn.contains("primary")).isTrue();
}
@After
@@ -92,23 +86,23 @@ public abstract class AbstractCacheAnnotationTests {
Object r2 = service.cache(o1);
Object r3 = service.cache(o1);
assertSame(r1, r2);
assertSame(r1, r3);
assertThat(r2).isSameAs(r1);
assertThat(r3).isSameAs(r1);
}
public void testCacheableNull(CacheableService<?> service) throws Exception {
Object o1 = new Object();
assertNull(this.cm.getCache("testCache").get(o1));
assertThat((Object) this.cm.getCache("testCache").get(o1)).isNull();
Object r1 = service.cacheNull(o1);
Object r2 = service.cacheNull(o1);
Object r3 = service.cacheNull(o1);
assertSame(r1, r2);
assertSame(r1, r3);
assertThat(r2).isSameAs(r1);
assertThat(r3).isSameAs(r1);
assertEquals(r3, this.cm.getCache("testCache").get(o1).get());
assertNull("Cached value should be null", r3);
assertThat(this.cm.getCache("testCache").get(o1).get()).isEqualTo(r3);
assertThat(r3).as("Cached value should be null").isNull();
}
public void testCacheableSync(CacheableService<?> service) throws Exception {
@@ -118,23 +112,23 @@ public abstract class AbstractCacheAnnotationTests {
Object r2 = service.cacheSync(o1);
Object r3 = service.cacheSync(o1);
assertSame(r1, r2);
assertSame(r1, r3);
assertThat(r2).isSameAs(r1);
assertThat(r3).isSameAs(r1);
}
public void testCacheableSyncNull(CacheableService<?> service) throws Exception {
Object o1 = new Object();
assertNull(this.cm.getCache("testCache").get(o1));
assertThat((Object) this.cm.getCache("testCache").get(o1)).isNull();
Object r1 = service.cacheSyncNull(o1);
Object r2 = service.cacheSyncNull(o1);
Object r3 = service.cacheSyncNull(o1);
assertSame(r1, r2);
assertSame(r1, r3);
assertThat(r2).isSameAs(r1);
assertThat(r3).isSameAs(r1);
assertEquals(r3, this.cm.getCache("testCache").get(o1).get());
assertNull("Cached value should be null", r3);
assertThat(this.cm.getCache("testCache").get(o1).get()).isEqualTo(r3);
assertThat(r3).as("Cached value should be null").isNull();
}
public void testEvict(CacheableService<?> service) throws Exception {
@@ -143,12 +137,12 @@ public abstract class AbstractCacheAnnotationTests {
Object r1 = service.cache(o1);
Object r2 = service.cache(o1);
assertSame(r1, r2);
assertThat(r2).isSameAs(r1);
service.invalidate(o1);
Object r3 = service.cache(o1);
Object r4 = service.cache(o1);
assertNotSame(r1, r3);
assertSame(r3, r4);
assertThat(r3).isNotSameAs(r1);
assertThat(r4).isSameAs(r3);
}
public void testEvictEarly(CacheableService<?> service) throws Exception {
@@ -157,7 +151,7 @@ public abstract class AbstractCacheAnnotationTests {
Object r1 = service.cache(o1);
Object r2 = service.cache(o1);
assertSame(r1, r2);
assertThat(r2).isSameAs(r1);
try {
service.evictEarly(o1);
}
@@ -167,8 +161,8 @@ public abstract class AbstractCacheAnnotationTests {
Object r3 = service.cache(o1);
Object r4 = service.cache(o1);
assertNotSame(r1, r3);
assertSame(r3, r4);
assertThat(r3).isNotSameAs(r1);
assertThat(r4).isSameAs(r3);
}
public void testEvictException(CacheableService<?> service) throws Exception {
@@ -177,7 +171,7 @@ public abstract class AbstractCacheAnnotationTests {
Object r1 = service.cache(o1);
Object r2 = service.cache(o1);
assertSame(r1, r2);
assertThat(r2).isSameAs(r1);
try {
service.evictWithException(o1);
}
@@ -186,7 +180,7 @@ public abstract class AbstractCacheAnnotationTests {
}
// exception occurred, eviction skipped, data should still be in the cache
Object r3 = service.cache(o1);
assertSame(r1, r3);
assertThat(r3).isSameAs(r1);
}
public void testEvictWKey(CacheableService<?> service) throws Exception {
@@ -195,12 +189,12 @@ public abstract class AbstractCacheAnnotationTests {
Object r1 = service.cache(o1);
Object r2 = service.cache(o1);
assertSame(r1, r2);
assertThat(r2).isSameAs(r1);
service.evict(o1, null);
Object r3 = service.cache(o1);
Object r4 = service.cache(o1);
assertNotSame(r1, r3);
assertSame(r3, r4);
assertThat(r3).isNotSameAs(r1);
assertThat(r4).isSameAs(r3);
}
public void testEvictWKeyEarly(CacheableService<?> service) throws Exception {
@@ -209,7 +203,7 @@ public abstract class AbstractCacheAnnotationTests {
Object r1 = service.cache(o1);
Object r2 = service.cache(o1);
assertSame(r1, r2);
assertThat(r2).isSameAs(r1);
try {
service.invalidateEarly(o1, null);
@@ -219,8 +213,8 @@ public abstract class AbstractCacheAnnotationTests {
}
Object r3 = service.cache(o1);
Object r4 = service.cache(o1);
assertNotSame(r1, r3);
assertSame(r3, r4);
assertThat(r3).isNotSameAs(r1);
assertThat(r4).isSameAs(r3);
}
public void testEvictAll(CacheableService<?> service) throws Exception {
@@ -232,41 +226,41 @@ public abstract class AbstractCacheAnnotationTests {
Object o2 = new Object();
Object r10 = service.cache(o2);
assertSame(r1, r2);
assertNotSame(r1, r10);
assertThat(r2).isSameAs(r1);
assertThat(r10).isNotSameAs(r1);
service.evictAll(new Object());
Cache cache = this.cm.getCache("testCache");
assertNull(cache.get(o1));
assertNull(cache.get(o2));
assertThat((Object) cache.get(o1)).isNull();
assertThat((Object) cache.get(o2)).isNull();
Object r3 = service.cache(o1);
Object r4 = service.cache(o1);
assertNotSame(r1, r3);
assertSame(r3, r4);
assertThat(r3).isNotSameAs(r1);
assertThat(r4).isSameAs(r3);
}
public void testConditionalExpression(CacheableService<?> service) throws Exception {
Object r1 = service.conditional(4);
Object r2 = service.conditional(4);
assertNotSame(r1, r2);
assertThat(r2).isNotSameAs(r1);
Object r3 = service.conditional(3);
Object r4 = service.conditional(3);
assertSame(r3, r4);
assertThat(r4).isSameAs(r3);
}
public void testConditionalExpressionSync(CacheableService<?> service) throws Exception {
Object r1 = service.conditionalSync(4);
Object r2 = service.conditionalSync(4);
assertNotSame(r1, r2);
assertThat(r2).isNotSameAs(r1);
Object r3 = service.conditionalSync(3);
Object r4 = service.conditionalSync(3);
assertSame(r3, r4);
assertThat(r4).isSameAs(r3);
}
public void testUnlessExpression(CacheableService<?> service) throws Exception {
@@ -282,54 +276,54 @@ public abstract class AbstractCacheAnnotationTests {
Object r1 = service.key(5, 1);
Object r2 = service.key(5, 2);
assertSame(r1, r2);
assertThat(r2).isSameAs(r1);
Object r3 = service.key(1, 5);
Object r4 = service.key(2, 5);
assertNotSame(r3, r4);
assertThat(r4).isNotSameAs(r3);
}
public void testVarArgsKey(CacheableService<?> service) throws Exception {
Object r1 = service.varArgsKey(1, 2, 3);
Object r2 = service.varArgsKey(1, 2, 3);
assertSame(r1, r2);
assertThat(r2).isSameAs(r1);
Object r3 = service.varArgsKey(1, 2, 3);
Object r4 = service.varArgsKey(1, 2);
assertNotSame(r3, r4);
assertThat(r4).isNotSameAs(r3);
}
public void testNullValue(CacheableService<?> service) throws Exception {
Object key = new Object();
assertNull(service.nullValue(key));
assertThat(service.nullValue(key)).isNull();
int nr = service.nullInvocations().intValue();
assertNull(service.nullValue(key));
assertEquals(nr, service.nullInvocations().intValue());
assertNull(service.nullValue(new Object()));
assertEquals(nr + 1, service.nullInvocations().intValue());
assertThat(service.nullValue(key)).isNull();
assertThat(service.nullInvocations().intValue()).isEqualTo(nr);
assertThat(service.nullValue(new Object())).isNull();
assertThat(service.nullInvocations().intValue()).isEqualTo(nr + 1);
}
public void testMethodName(CacheableService<?> service, String keyName) throws Exception {
Object key = new Object();
Object r1 = service.name(key);
assertSame(r1, service.name(key));
assertThat(service.name(key)).isSameAs(r1);
Cache cache = this.cm.getCache("testCache");
// assert the method name is used
assertNotNull(cache.get(keyName));
assertThat(cache.get(keyName)).isNotNull();
}
public void testRootVars(CacheableService<?> service) {
Object key = new Object();
Object r1 = service.rootVars(key);
assertSame(r1, service.rootVars(key));
assertThat(service.rootVars(key)).isSameAs(r1);
Cache cache = this.cm.getCache("testCache");
// assert the method name is used
String expectedKey = "rootVarsrootVars" + AopProxyUtils.ultimateTargetClass(service) + service;
assertNotNull(cache.get(expectedKey));
assertThat(cache.get(expectedKey)).isNotNull();
}
public void testCheckedThrowable(CacheableService<?> service) throws Exception {
@@ -360,20 +354,20 @@ public abstract class AbstractCacheAnnotationTests {
public void testNullArg(CacheableService<?> service) {
Object r1 = service.cache(null);
assertSame(r1, service.cache(null));
assertThat(service.cache(null)).isSameAs(r1);
}
public void testCacheUpdate(CacheableService<?> service) {
Object o = new Object();
Cache cache = this.cm.getCache("testCache");
assertNull(cache.get(o));
assertThat((Object) cache.get(o)).isNull();
Object r1 = service.update(o);
assertSame(r1, cache.get(o).get());
assertThat(cache.get(o).get()).isSameAs(r1);
o = new Object();
assertNull(cache.get(o));
assertThat((Object) cache.get(o)).isNull();
Object r2 = service.update(o);
assertSame(r2, cache.get(o).get());
assertThat(cache.get(o).get()).isSameAs(r2);
}
public void testConditionalCacheUpdate(CacheableService<?> service) {
@@ -381,11 +375,11 @@ public abstract class AbstractCacheAnnotationTests {
Integer three = 3;
Cache cache = this.cm.getCache("testCache");
assertEquals(one, Integer.valueOf(service.conditionalUpdate(one).toString()));
assertNull(cache.get(one));
assertThat((int) Integer.valueOf(service.conditionalUpdate(one).toString())).isEqualTo((int) one);
assertThat(cache.get(one)).isNull();
assertEquals(three, Integer.valueOf(service.conditionalUpdate(three).toString()));
assertEquals(three, Integer.valueOf(cache.get(three).get().toString()));
assertThat((int) Integer.valueOf(service.conditionalUpdate(three).toString())).isEqualTo((int) three);
assertThat((int) Integer.valueOf(cache.get(three).get().toString())).isEqualTo((int) three);
}
public void testMultiCache(CacheableService<?> service) {
@@ -395,23 +389,23 @@ public abstract class AbstractCacheAnnotationTests {
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
assertNull(primary.get(o1));
assertNull(secondary.get(o1));
assertThat((Object) primary.get(o1)).isNull();
assertThat((Object) secondary.get(o1)).isNull();
Object r1 = service.multiCache(o1);
assertSame(r1, primary.get(o1).get());
assertSame(r1, secondary.get(o1).get());
assertThat(primary.get(o1).get()).isSameAs(r1);
assertThat(secondary.get(o1).get()).isSameAs(r1);
Object r2 = service.multiCache(o1);
Object r3 = service.multiCache(o1);
assertSame(r1, r2);
assertSame(r1, r3);
assertThat(r2).isSameAs(r1);
assertThat(r3).isSameAs(r1);
assertNull(primary.get(o2));
assertNull(secondary.get(o2));
assertThat((Object) primary.get(o2)).isNull();
assertThat((Object) secondary.get(o2)).isNull();
Object r4 = service.multiCache(o2);
assertSame(r4, primary.get(o2).get());
assertSame(r4, secondary.get(o2).get());
assertThat(primary.get(o2).get()).isSameAs(r4);
assertThat(secondary.get(o2).get()).isSameAs(r4);
}
public void testMultiEvict(CacheableService<?> service) {
@@ -426,22 +420,22 @@ public abstract class AbstractCacheAnnotationTests {
Cache secondary = this.cm.getCache("secondary");
primary.put(o2, o2);
assertSame(r1, r2);
assertSame(r1, primary.get(o1).get());
assertSame(r1, secondary.get(o1).get());
assertThat(r2).isSameAs(r1);
assertThat(primary.get(o1).get()).isSameAs(r1);
assertThat(secondary.get(o1).get()).isSameAs(r1);
service.multiEvict(o1);
assertNull(primary.get(o1));
assertNull(secondary.get(o1));
assertNull(primary.get(o2));
assertThat((Object) primary.get(o1)).isNull();
assertThat((Object) secondary.get(o1)).isNull();
assertThat((Object) primary.get(o2)).isNull();
Object r3 = service.multiCache(o1);
Object r4 = service.multiCache(o1);
assertNotSame(r1, r3);
assertSame(r3, r4);
assertThat(r3).isNotSameAs(r1);
assertThat(r4).isSameAs(r3);
assertSame(r3, primary.get(o1).get());
assertSame(r4, secondary.get(o1).get());
assertThat(primary.get(o1).get()).isSameAs(r3);
assertThat(secondary.get(o1).get()).isSameAs(r4);
}
public void testMultiPut(CacheableService<?> service) {
@@ -450,28 +444,28 @@ public abstract class AbstractCacheAnnotationTests {
Cache primary = this.cm.getCache("primary");
Cache secondary = this.cm.getCache("secondary");
assertNull(primary.get(o));
assertNull(secondary.get(o));
assertThat((Object) primary.get(o)).isNull();
assertThat((Object) secondary.get(o)).isNull();
Object r1 = service.multiUpdate(o);
assertSame(r1, primary.get(o).get());
assertSame(r1, secondary.get(o).get());
assertThat(primary.get(o).get()).isSameAs(r1);
assertThat(secondary.get(o).get()).isSameAs(r1);
o = 2;
assertNull(primary.get(o));
assertNull(secondary.get(o));
assertThat((Object) primary.get(o)).isNull();
assertThat((Object) secondary.get(o)).isNull();
Object r2 = service.multiUpdate(o);
assertSame(r2, primary.get(o).get());
assertSame(r2, secondary.get(o).get());
assertThat(primary.get(o).get()).isSameAs(r2);
assertThat(secondary.get(o).get()).isSameAs(r2);
}
public void testPutRefersToResult(CacheableService<?> service) throws Exception {
Long id = Long.MIN_VALUE;
TestEntity entity = new TestEntity();
Cache primary = this.cm.getCache("primary");
assertNull(primary.get(id));
assertNull(entity.getId());
assertThat((Object) primary.get(id)).isNull();
assertThat((Object) entity.getId()).isNull();
service.putRefersToResult(entity);
assertSame(entity, primary.get(id).get());
assertThat(primary.get(id).get()).isSameAs(entity);
}
public void testMultiCacheAndEvict(CacheableService<?> service) {
@@ -483,16 +477,16 @@ public abstract class AbstractCacheAnnotationTests {
secondary.put(key, key);
assertNull(secondary.get(methodName));
assertSame(key, secondary.get(key).get());
assertThat(secondary.get(methodName)).isNull();
assertThat(secondary.get(key).get()).isSameAs(key);
Object r1 = service.multiCacheAndEvict(key);
assertSame(r1, service.multiCacheAndEvict(key));
assertThat(service.multiCacheAndEvict(key)).isSameAs(r1);
// assert the method name is used
assertSame(r1, primary.get(methodName).get());
assertNull(secondary.get(methodName));
assertNull(secondary.get(key));
assertThat(primary.get(methodName).get()).isSameAs(r1);
assertThat(secondary.get(methodName)).isNull();
assertThat(secondary.get(key)).isNull();
}
public void testMultiConditionalCacheAndEvict(CacheableService<?> service) {
@@ -502,22 +496,22 @@ public abstract class AbstractCacheAnnotationTests {
secondary.put(key, key);
assertNull(primary.get(key));
assertSame(key, secondary.get(key).get());
assertThat(primary.get(key)).isNull();
assertThat(secondary.get(key).get()).isSameAs(key);
Object r1 = service.multiConditionalCacheAndEvict(key);
Object r3 = service.multiConditionalCacheAndEvict(key);
assertTrue(!r1.equals(r3));
assertNull(primary.get(key));
assertThat(!r1.equals(r3)).isTrue();
assertThat((Object) primary.get(key)).isNull();
Object key2 = 3;
Object r2 = service.multiConditionalCacheAndEvict(key2);
assertSame(r2, service.multiConditionalCacheAndEvict(key2));
assertThat(service.multiConditionalCacheAndEvict(key2)).isSameAs(r2);
// assert the method name is used
assertSame(r2, primary.get(key2).get());
assertNull(secondary.get(key2));
assertThat(primary.get(key2).get()).isSameAs(r2);
assertThat(secondary.get(key2)).isNull();
}
@Test
@@ -643,14 +637,14 @@ public abstract class AbstractCacheAnnotationTests {
@Test
public void testClassNullValue() throws Exception {
Object key = new Object();
assertNull(this.ccs.nullValue(key));
assertThat(this.ccs.nullValue(key)).isNull();
int nr = this.ccs.nullInvocations().intValue();
assertNull(this.ccs.nullValue(key));
assertEquals(nr, this.ccs.nullInvocations().intValue());
assertNull(this.ccs.nullValue(new Object()));
assertThat(this.ccs.nullValue(key)).isNull();
assertThat(this.ccs.nullInvocations().intValue()).isEqualTo(nr);
assertThat(this.ccs.nullValue(new Object())).isNull();
// the check method is also cached
assertEquals(nr, this.ccs.nullInvocations().intValue());
assertEquals(nr + 1, AnnotatedClassCacheableService.nullInvocations.intValue());
assertThat(this.ccs.nullInvocations().intValue()).isEqualTo(nr);
assertThat(AnnotatedClassCacheableService.nullInvocations.intValue()).isEqualTo(nr + 1);
}
@Test
@@ -677,11 +671,11 @@ public abstract class AbstractCacheAnnotationTests {
public void testCustomKeyGenerator() {
Object param = new Object();
Object r1 = this.cs.customKeyGenerator(param);
assertSame(r1, this.cs.customKeyGenerator(param));
assertThat(this.cs.customKeyGenerator(param)).isSameAs(r1);
Cache cache = this.cm.getCache("testCache");
// Checks that the custom keyGenerator was used
Object expectedKey = SomeCustomKeyGenerator.generateKey("customKeyGenerator", param);
assertNotNull(cache.get(expectedKey));
assertThat(cache.get(expectedKey)).isNotNull();
}
@Test
@@ -696,10 +690,10 @@ public abstract class AbstractCacheAnnotationTests {
CacheManager customCm = this.ctx.getBean("customCacheManager", CacheManager.class);
Object key = new Object();
Object r1 = this.cs.customCacheManager(key);
assertSame(r1, this.cs.customCacheManager(key));
assertThat(this.cs.customCacheManager(key)).isSameAs(r1);
Cache cache = customCm.getCache("testCache");
assertNotNull(cache.get(key));
assertThat(cache.get(key)).isNotNull();
}
@Test

View File

@@ -23,7 +23,7 @@ import org.springframework.cache.interceptor.CacheInterceptor;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Costin Leau
@@ -42,7 +42,7 @@ public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests
public void testKeyStrategy() {
CacheInterceptor ci = this.ctx.getBean(
"org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class);
assertSame(this.ctx.getBean("keyGenerator"), ci.getKeyGenerator());
assertThat(ci.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator"));
}
@Test
@@ -51,7 +51,7 @@ public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests
"/org/springframework/cache/config/annotationDrivenCacheNamespace-resolver.xml");
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
assertThat(ci.getCacheResolver()).isSameAs(context.getBean("cacheResolver"));
context.close();
}
@@ -61,7 +61,7 @@ public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests
"/org/springframework/cache/config/annotationDrivenCacheNamespace-manager-resolver.xml");
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
assertThat(ci.getCacheResolver()).isSameAs(context.getBean("cacheResolver"));
context.close();
}
@@ -69,7 +69,7 @@ public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests
public void testCacheErrorHandler() {
CacheInterceptor ci = this.ctx.getBean(
"org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class);
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
assertThat(ci.getErrorHandler()).isSameAs(this.ctx.getBean("errorHandler", CacheErrorHandler.class));
}
}

View File

@@ -22,7 +22,7 @@ import org.springframework.cache.interceptor.CacheInterceptor;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Costin Leau
@@ -39,7 +39,7 @@ public class CacheAdviceNamespaceTests extends AbstractCacheAnnotationTests {
@Test
public void testKeyStrategy() throws Exception {
CacheInterceptor bean = this.ctx.getBean("cacheAdviceClass", CacheInterceptor.class);
assertSame(this.ctx.getBean("keyGenerator"), bean.getKeyGenerator());
assertThat(bean.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator"));
}
}

View File

@@ -34,8 +34,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
/**
* @author Stephane Nicoll
@@ -60,15 +60,16 @@ public class CustomInterceptorTests {
@Test
public void onlyOneInterceptorIsAvailable() {
Map<String, CacheInterceptor> interceptors = this.ctx.getBeansOfType(CacheInterceptor.class);
assertEquals("Only one interceptor should be defined", 1, interceptors.size());
assertThat(interceptors.size()).as("Only one interceptor should be defined").isEqualTo(1);
CacheInterceptor interceptor = interceptors.values().iterator().next();
assertEquals("Custom interceptor not defined", TestCacheInterceptor.class, interceptor.getClass());
assertThat(interceptor.getClass()).as("Custom interceptor not defined").isEqualTo(TestCacheInterceptor.class);
}
@Test
public void customInterceptorAppliesWithRuntimeException() {
Object o = this.cs.throwUnchecked(0L);
assertEquals(55L, o); // See TestCacheInterceptor
// See TestCacheInterceptor
assertThat(o).isEqualTo(55L);
}
@Test

View File

@@ -37,7 +37,7 @@ import org.springframework.context.annotation.Import;
import org.springframework.core.env.Environment;
import org.springframework.mock.env.MockEnvironment;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cache.CacheTestUtils.assertCacheHit;
import static org.springframework.cache.CacheTestUtils.assertCacheMiss;
@@ -95,7 +95,7 @@ public class EnableCachingIntegrationTests {
service.getWithCondition(key);
assertCacheMiss(key, cache);
assertEquals(2, this.context.getBean(BeanConditionConfig.Bar.class).count);
assertThat(this.context.getBean(BeanConditionConfig.Bar.class).count).isEqualTo(2);
}
@Test
@@ -115,7 +115,7 @@ public class EnableCachingIntegrationTests {
value = service.getWithCondition(key);
assertCacheHit(key, value, cache);
assertEquals(2, this.context.getBean(BeanConditionConfig.Bar.class).count);
assertThat(this.context.getBean(BeanConditionConfig.Bar.class).count).isEqualTo(2);
}
private Cache getCache() {

View File

@@ -36,10 +36,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@code @EnableCaching} and its related
@@ -59,13 +56,13 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
@Test
public void testKeyStrategy() {
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
assertSame(this.ctx.getBean("keyGenerator", KeyGenerator.class), ci.getKeyGenerator());
assertThat(ci.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator", KeyGenerator.class));
}
@Test
public void testCacheErrorHandler() {
CacheInterceptor ci = this.ctx.getBean(CacheInterceptor.class);
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler());
assertThat(ci.getErrorHandler()).isSameAs(this.ctx.getBean("errorHandler", CacheErrorHandler.class));
}
@Test
@@ -83,7 +80,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
ctx.refresh();
}
catch (IllegalStateException ex) {
assertTrue(ex.getMessage().contains("no unique bean of type CacheManager"));
assertThat(ex.getMessage().contains("no unique bean of type CacheManager")).isTrue();
}
}
@@ -103,8 +100,9 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
}
catch (BeanCreationException ex) {
Throwable root = ex.getRootCause();
assertTrue(root instanceof IllegalStateException);
assertTrue(root.getMessage().contains("implementations of CachingConfigurer"));
boolean condition = root instanceof IllegalStateException;
assertThat(condition).isTrue();
assertThat(root.getMessage().contains("implementations of CachingConfigurer")).isTrue();
}
}
@@ -116,7 +114,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
ctx.refresh();
}
catch (IllegalStateException ex) {
assertTrue(ex.getMessage().contains("no bean of type CacheManager"));
assertThat(ex.getMessage().contains("no bean of type CacheManager")).isTrue();
}
}
@@ -124,9 +122,9 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
public void emptyConfigSupport() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(EmptyConfigSupportConfig.class);
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
assertNotNull(ci.getCacheResolver());
assertEquals(SimpleCacheResolver.class, ci.getCacheResolver().getClass());
assertSame(context.getBean(CacheManager.class), ((SimpleCacheResolver)ci.getCacheResolver()).getCacheManager());
assertThat(ci.getCacheResolver()).isNotNull();
assertThat(ci.getCacheResolver().getClass()).isEqualTo(SimpleCacheResolver.class);
assertThat(((SimpleCacheResolver) ci.getCacheResolver()).getCacheManager()).isSameAs(context.getBean(CacheManager.class));
context.close();
}
@@ -134,8 +132,8 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
public void bothSetOnlyResolverIsUsed() {
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext(FullCachingConfig.class);
CacheInterceptor ci = context.getBean(CacheInterceptor.class);
assertSame(context.getBean("cacheResolver"), ci.getCacheResolver());
assertSame(context.getBean("keyGenerator"), ci.getKeyGenerator());
assertThat(ci.getCacheResolver()).isSameAs(context.getBean("cacheResolver"));
assertThat(ci.getKeyGenerator()).isSameAs(context.getBean("keyGenerator"));
context.close();
}

View File

@@ -36,9 +36,8 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willReturn;
import static org.mockito.BDDMockito.willThrow;
@@ -89,8 +88,8 @@ public class CacheErrorHandlerTests {
willReturn(new SimpleValueWrapper(2L)).given(this.cache).get(0L);
Object counter2 = this.simpleService.get(0L);
Object counter3 = this.simpleService.get(0L);
assertNotSame(counter, counter2);
assertEquals(counter2, counter3);
assertThat(counter2).isNotSameAs(counter);
assertThat(counter3).isEqualTo(counter2);
}
@Test

View File

@@ -27,10 +27,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Integration tests for {@link CacheProxyFactoryBean}.
@@ -45,18 +42,18 @@ public class CacheProxyFactoryBeanTests {
try (AnnotationConfigApplicationContext applicationContext =
new AnnotationConfigApplicationContext(CacheProxyFactoryBeanConfiguration.class)) {
Greeter greeter = applicationContext.getBean("greeter", Greeter.class);
assertNotNull(greeter);
assertFalse(greeter.isCacheMiss());
assertEquals("Hello John!", greeter.greet("John"));
assertTrue(greeter.isCacheMiss());
assertEquals("Hello Jon!", greeter.greet("Jon"));
assertTrue(greeter.isCacheMiss());
assertEquals("Hello John!", greeter.greet("John"));
assertFalse(greeter.isCacheMiss());
assertEquals("Hello World!", greeter.greet());
assertTrue(greeter.isCacheMiss());
assertEquals("Hello World!", greeter.greet());
assertFalse(greeter.isCacheMiss());
assertThat(greeter).isNotNull();
assertThat(greeter.isCacheMiss()).isFalse();
assertThat(greeter.greet("John")).isEqualTo("Hello John!");
assertThat(greeter.isCacheMiss()).isTrue();
assertThat(greeter.greet("Jon")).isEqualTo("Hello Jon!");
assertThat(greeter.isCacheMiss()).isTrue();
assertThat(greeter.greet("John")).isEqualTo("Hello John!");
assertThat(greeter.isCacheMiss()).isFalse();
assertThat(greeter.greet()).isEqualTo("Hello World!");
assertThat(greeter.isCacheMiss()).isTrue();
assertThat(greeter.greet()).isEqualTo("Hello World!");
assertThat(greeter.isCacheMiss()).isFalse();
}
}

View File

@@ -35,9 +35,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests corner case of using {@link Cacheable} and {@link CachePut} on the
@@ -73,15 +71,15 @@ public class CachePutEvaluationTests {
Long first = this.service.getOrPut(key, true);
Long second = this.service.getOrPut(key, true);
assertSame(first, second);
assertThat(second).isSameAs(first);
// This forces the method to be executed again
Long expected = first + 1;
Long third = this.service.getOrPut(key, false);
assertEquals(expected, third);
assertThat(third).isEqualTo(expected);
Long fourth = this.service.getOrPut(key, true);
assertSame(third, fourth);
assertThat(fourth).isSameAs(third);
}
@Test
@@ -91,18 +89,19 @@ public class CachePutEvaluationTests {
long key = 1;
Long value = this.service.getAndPut(key);
assertEquals("Wrong value for @Cacheable key", value, this.cache.get(key).get());
assertEquals("Wrong value for @CachePut key", value, this.cache.get(value + 100).get()); // See @CachePut
assertThat(this.cache.get(key).get()).as("Wrong value for @Cacheable key").isEqualTo(value);
// See @CachePut
assertThat(this.cache.get(value + 100).get()).as("Wrong value for @CachePut key").isEqualTo(value);
// CachePut forced a method call
Long anotherValue = this.service.getAndPut(key);
assertNotSame(value, anotherValue);
assertThat(anotherValue).isNotSameAs(value);
// NOTE: while you might expect the main key to have been updated, it hasn't. @Cacheable operations
// are only processed in case of a cache miss. This is why combining @Cacheable with @CachePut
// is a very bad idea. We could refine the condition now that we can figure out if we are going
// to invoke the method anyway but that brings a whole new set of potential regressions.
//assertEquals("Wrong value for @Cacheable key", anotherValue, cache.get(key).get());
assertEquals("Wrong value for @CachePut key", anotherValue, this.cache.get(anotherValue + 100).get());
assertThat(this.cache.get(anotherValue + 100).get()).as("Wrong value for @CachePut key").isEqualTo(anotherValue);
}
@Configuration

View File

@@ -38,8 +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.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Costin Leau
@@ -63,16 +61,16 @@ public class ExpressionEvaluatorTests {
@Test
public void testMultipleCachingSource() {
Collection<CacheOperation> ops = getOps("multipleCaching");
assertEquals(2, ops.size());
assertThat(ops.size()).isEqualTo(2);
Iterator<CacheOperation> it = ops.iterator();
CacheOperation next = it.next();
assertTrue(next instanceof CacheableOperation);
assertTrue(next.getCacheNames().contains("test"));
assertEquals("#a", next.getKey());
assertThat(next instanceof CacheableOperation).isTrue();
assertThat(next.getCacheNames().contains("test")).isTrue();
assertThat(next.getKey()).isEqualTo("#a");
next = it.next();
assertTrue(next instanceof CacheableOperation);
assertTrue(next.getCacheNames().contains("test"));
assertEquals("#b", next.getKey());
assertThat(next instanceof CacheableOperation).isTrue();
assertThat(next.getCacheNames().contains("test")).isTrue();
assertThat(next.getKey()).isEqualTo("#b");
}
@Test
@@ -93,8 +91,8 @@ public class ExpressionEvaluatorTests {
Object keyA = this.eval.key(it.next().getKey(), key, evalCtx);
Object keyB = this.eval.key(it.next().getKey(), key, evalCtx);
assertEquals(args[0], keyA);
assertEquals(args[1], keyB);
assertThat(keyA).isEqualTo(args[0]);
assertThat(keyB).isEqualTo(args[1]);
}
@Test

View File

@@ -30,9 +30,8 @@ import org.springframework.beans.factory.xml.AbstractListableBeanFactoryTests;
import org.springframework.tests.sample.beans.LifecycleBean;
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.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* @author Rod Johnson
@@ -76,69 +75,71 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
@Test
public void contextAwareSingletonWasCalledBack() throws Exception {
ACATester aca = (ACATester) applicationContext.getBean("aca");
assertTrue("has had context set", aca.getApplicationContext() == applicationContext);
assertThat(aca.getApplicationContext() == applicationContext).as("has had context set").isTrue();
Object aca2 = applicationContext.getBean("aca");
assertTrue("Same instance", aca == aca2);
assertTrue("Says is singleton", applicationContext.isSingleton("aca"));
assertThat(aca == aca2).as("Same instance").isTrue();
assertThat(applicationContext.isSingleton("aca")).as("Says is singleton").isTrue();
}
@Test
public void contextAwarePrototypeWasCalledBack() throws Exception {
ACATester aca = (ACATester) applicationContext.getBean("aca-prototype");
assertTrue("has had context set", aca.getApplicationContext() == applicationContext);
assertThat(aca.getApplicationContext() == applicationContext).as("has had context set").isTrue();
Object aca2 = applicationContext.getBean("aca-prototype");
assertTrue("NOT Same instance", aca != aca2);
assertTrue("Says is prototype", !applicationContext.isSingleton("aca-prototype"));
assertThat(aca != aca2).as("NOT Same instance").isTrue();
boolean condition = !applicationContext.isSingleton("aca-prototype");
assertThat(condition).as("Says is prototype").isTrue();
}
@Test
public void parentNonNull() {
assertTrue("parent isn't null", applicationContext.getParent() != null);
assertThat(applicationContext.getParent() != null).as("parent isn't null").isTrue();
}
@Test
public void grandparentNull() {
assertTrue("grandparent is null", applicationContext.getParent().getParent() == null);
assertThat(applicationContext.getParent().getParent() == null).as("grandparent is null").isTrue();
}
@Test
public void overrideWorked() throws Exception {
TestBean rod = (TestBean) applicationContext.getParent().getBean("rod");
assertTrue("Parent's name differs", rod.getName().equals("Roderick"));
assertThat(rod.getName().equals("Roderick")).as("Parent's name differs").isTrue();
}
@Test
public void grandparentDefinitionFound() throws Exception {
TestBean dad = (TestBean) applicationContext.getBean("father");
assertTrue("Dad has correct name", dad.getName().equals("Albert"));
assertThat(dad.getName().equals("Albert")).as("Dad has correct name").isTrue();
}
@Test
public void grandparentTypedDefinitionFound() throws Exception {
TestBean dad = applicationContext.getBean("father", TestBean.class);
assertTrue("Dad has correct name", dad.getName().equals("Albert"));
assertThat(dad.getName().equals("Albert")).as("Dad has correct name").isTrue();
}
@Test
public void closeTriggersDestroy() {
LifecycleBean lb = (LifecycleBean) applicationContext.getBean("lifecycle");
assertTrue("Not destroyed", !lb.isDestroyed());
boolean condition = !lb.isDestroyed();
assertThat(condition).as("Not destroyed").isTrue();
applicationContext.close();
if (applicationContext.getParent() != null) {
((ConfigurableApplicationContext) applicationContext.getParent()).close();
}
assertTrue("Destroyed", lb.isDestroyed());
assertThat(lb.isDestroyed()).as("Destroyed").isTrue();
applicationContext.close();
if (applicationContext.getParent() != null) {
((ConfigurableApplicationContext) applicationContext.getParent()).close();
}
assertTrue("Destroyed", lb.isDestroyed());
assertThat(lb.isDestroyed()).as("Destroyed").isTrue();
}
@Test
public void messageSource() throws NoSuchMessageException {
assertEquals("message1", applicationContext.getMessage("code1", null, Locale.getDefault()));
assertEquals("message2", applicationContext.getMessage("code2", null, Locale.getDefault()));
assertThat(applicationContext.getMessage("code1", null, Locale.getDefault())).isEqualTo("message1");
assertThat(applicationContext.getMessage("code2", null, Locale.getDefault())).isEqualTo("message2");
assertThatExceptionOfType(NoSuchMessageException.class).isThrownBy(() ->
applicationContext.getMessage("code0", null, Locale.getDefault()));
}
@@ -165,11 +166,11 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
MyEvent event) {
listener.zeroCounter();
parentListener.zeroCounter();
assertTrue("0 events before publication", listener.getEventCount() == 0);
assertTrue("0 parent events before publication", parentListener.getEventCount() == 0);
assertThat(listener.getEventCount() == 0).as("0 events before publication").isTrue();
assertThat(parentListener.getEventCount() == 0).as("0 parent events before publication").isTrue();
this.applicationContext.publishEvent(event);
assertTrue("1 events after publication, not " + listener.getEventCount(), listener.getEventCount() == 1);
assertTrue("1 parent events after publication", parentListener.getEventCount() == 1);
assertThat(listener.getEventCount() == 1).as("1 events after publication, not " + listener.getEventCount()).isTrue();
assertThat(parentListener.getEventCount() == 1).as("1 parent events after publication").isTrue();
}
@Test
@@ -178,9 +179,9 @@ public abstract class AbstractApplicationContextTests extends AbstractListableBe
//assertTrue("listeners include beanThatListens", Arrays.asList(listenerNames).contains("beanThatListens"));
BeanThatListens b = (BeanThatListens) applicationContext.getBean("beanThatListens");
b.zero();
assertTrue("0 events before publication", b.getEventCount() == 0);
assertThat(b.getEventCount() == 0).as("0 events before publication").isTrue();
this.applicationContext.publishEvent(new MyEvent(this));
assertTrue("1 events after publication, not " + b.getEventCount(), b.getEventCount() == 1);
assertThat(b.getEventCount() == 1).as("1 events after publication, not " + b.getEventCount()).isTrue();
}

View File

@@ -21,7 +21,7 @@ import org.junit.Test;
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* TCK-style unit tests for handling circular use of the {@link Import} annotation.
@@ -43,13 +43,12 @@ public abstract class AbstractCircularImportDetectionTests {
newParser().parse(loadAsConfigurationSource(A.class), "A");
}
catch (BeanDefinitionParsingException ex) {
assertTrue("Wrong message. Got: " + ex.getMessage(),
ex.getMessage().contains(
"Illegal attempt by @Configuration class 'AbstractCircularImportDetectionTests.B' " +
"to import class 'AbstractCircularImportDetectionTests.A'"));
assertThat(ex.getMessage().contains(
"Illegal attempt by @Configuration class 'AbstractCircularImportDetectionTests.B' " +
"to import class 'AbstractCircularImportDetectionTests.A'")).as("Wrong message. Got: " + ex.getMessage()).isTrue();
threw = true;
}
assertTrue(threw);
assertThat(threw).isTrue();
}
@Test
@@ -59,13 +58,12 @@ public abstract class AbstractCircularImportDetectionTests {
newParser().parse(loadAsConfigurationSource(X.class), "X");
}
catch (BeanDefinitionParsingException ex) {
assertTrue("Wrong message. Got: " + ex.getMessage(),
ex.getMessage().contains(
"Illegal attempt by @Configuration class 'AbstractCircularImportDetectionTests.Z2' " +
"to import class 'AbstractCircularImportDetectionTests.Z'"));
assertThat(ex.getMessage().contains(
"Illegal attempt by @Configuration class 'AbstractCircularImportDetectionTests.Z2' " +
"to import class 'AbstractCircularImportDetectionTests.Z'")).as("Wrong message. Got: " + ex.getMessage()).isTrue();
threw = true;
}
assertTrue(threw);
assertThat(threw).isTrue();
}

View File

@@ -33,9 +33,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link AnnotationBeanNameGenerator}.
@@ -56,9 +54,9 @@ public class AnnotationBeanNameGeneratorTests {
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentWithName.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
assertNotNull("The generated beanName must *never* be null.", beanName);
assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName));
assertEquals("walden", beanName);
assertThat(beanName).as("The generated beanName must *never* be null.").isNotNull();
assertThat(StringUtils.hasText(beanName)).as("The generated beanName must *never* be blank.").isTrue();
assertThat(beanName).isEqualTo("walden");
}
@Test
@@ -66,9 +64,9 @@ public class AnnotationBeanNameGeneratorTests {
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(DefaultNamedComponent.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
assertNotNull("The generated beanName must *never* be null.", beanName);
assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName));
assertEquals("thoreau", beanName);
assertThat(beanName).as("The generated beanName must *never* be null.").isNotNull();
assertThat(StringUtils.hasText(beanName)).as("The generated beanName must *never* be blank.").isTrue();
assertThat(beanName).isEqualTo("thoreau");
}
@Test
@@ -76,10 +74,10 @@ public class AnnotationBeanNameGeneratorTests {
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentWithBlankName.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
assertNotNull("The generated beanName must *never* be null.", beanName);
assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName));
assertThat(beanName).as("The generated beanName must *never* be null.").isNotNull();
assertThat(StringUtils.hasText(beanName)).as("The generated beanName must *never* be blank.").isTrue();
String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
assertEquals(expectedGeneratedBeanName, beanName);
assertThat(beanName).isEqualTo(expectedGeneratedBeanName);
}
@Test
@@ -87,10 +85,10 @@ public class AnnotationBeanNameGeneratorTests {
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnonymousComponent.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
assertNotNull("The generated beanName must *never* be null.", beanName);
assertTrue("The generated beanName must *never* be blank.", StringUtils.hasText(beanName));
assertThat(beanName).as("The generated beanName must *never* be null.").isNotNull();
assertThat(StringUtils.hasText(beanName)).as("The generated beanName must *never* be blank.").isTrue();
String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
assertEquals(expectedGeneratedBeanName, beanName);
assertThat(beanName).isEqualTo(expectedGeneratedBeanName);
}
@Test
@@ -98,7 +96,7 @@ public class AnnotationBeanNameGeneratorTests {
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromStringMeta.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
assertEquals("henry", beanName);
assertThat(beanName).isEqualTo("henry");
}
@Test
@@ -106,7 +104,7 @@ public class AnnotationBeanNameGeneratorTests {
BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry();
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComponentFromNonStringMeta.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
assertEquals("annotationBeanNameGeneratorTests.ComponentFromNonStringMeta", beanName);
assertThat(beanName).isEqualTo("annotationBeanNameGeneratorTests.ComponentFromNonStringMeta");
}
@Test
@@ -116,7 +114,7 @@ public class AnnotationBeanNameGeneratorTests {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithoutName.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
assertEquals(expectedGeneratedBeanName, beanName);
assertThat(beanName).isEqualTo(expectedGeneratedBeanName);
}
@Test
@@ -126,7 +124,7 @@ public class AnnotationBeanNameGeneratorTests {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(ComposedControllerAnnotationWithBlankName.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
String expectedGeneratedBeanName = this.beanNameGenerator.buildDefaultBeanName(bd);
assertEquals(expectedGeneratedBeanName, beanName);
assertThat(beanName).isEqualTo(expectedGeneratedBeanName);
}
@Test
@@ -136,7 +134,7 @@ public class AnnotationBeanNameGeneratorTests {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(
ComposedControllerAnnotationWithStringValue.class);
String beanName = this.beanNameGenerator.generateBeanName(bd, registry);
assertEquals("restController", beanName);
assertThat(beanName).isEqualTo("restController");
}

View File

@@ -36,13 +36,6 @@ 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.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.springframework.util.StringUtils.uncapitalize;
/**
@@ -62,7 +55,7 @@ public class AnnotationConfigApplicationContextTests {
context.getBean(uncapitalize(ComponentForScanning.class.getSimpleName()));
context.getBean(uncapitalize(Jsr330NamedForScanning.class.getSimpleName()));
Map<String, Object> beans = context.getBeansWithAnnotation(Configuration.class);
assertEquals(1, beans.size());
assertThat(beans.size()).isEqualTo(1);
}
@Test
@@ -74,7 +67,7 @@ public class AnnotationConfigApplicationContextTests {
context.getBean("testBean");
context.getBean("name");
Map<String, Object> beans = context.getBeansWithAnnotation(Configuration.class);
assertEquals(2, beans.size());
assertThat(beans.size()).isEqualTo(2);
}
@Test
@@ -86,14 +79,14 @@ public class AnnotationConfigApplicationContextTests {
context.getBean("testBean");
context.getBean("name");
Map<String, Object> beans = context.getBeansWithAnnotation(Configuration.class);
assertEquals(2, beans.size());
assertThat(beans.size()).isEqualTo(2);
}
@Test
public void getBeanByType() {
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
TestBean testBean = context.getBean(TestBean.class);
assertNotNull(testBean);
assertThat(testBean).isNotNull();
assertThat(testBean.name).isEqualTo("foo");
}
@@ -128,7 +121,7 @@ public class AnnotationConfigApplicationContextTests {
// attempt to retrieve the instance by its generated bean name
Config configObject = (Config) context.getBean("annotationConfigApplicationContextTests.Config");
assertNotNull(configObject);
assertThat(configObject).isNotNull();
}
/**
@@ -141,7 +134,7 @@ public class AnnotationConfigApplicationContextTests {
// attempt to retrieve the instance by its specified name
ConfigWithCustomName configObject = (ConfigWithCustomName) context.getBean("customConfigBeanName");
assertNotNull(configObject);
assertThat(configObject).isNotNull();
}
@Test
@@ -185,9 +178,9 @@ public class AnnotationConfigApplicationContextTests {
context.register(BeanA.class, BeanB.class, BeanC.class);
context.refresh();
assertSame(context.getBean(BeanB.class), context.getBean(BeanA.class).b);
assertSame(context.getBean(BeanC.class), context.getBean(BeanA.class).c);
assertSame(context, context.getBean(BeanB.class).applicationContext);
assertThat(context.getBean(BeanA.class).b).isSameAs(context.getBean(BeanB.class));
assertThat(context.getBean(BeanA.class).c).isSameAs(context.getBean(BeanC.class));
assertThat(context.getBean(BeanB.class).applicationContext).isSameAs(context);
}
@Test
@@ -198,9 +191,9 @@ public class AnnotationConfigApplicationContextTests {
context.registerBean("c", BeanC.class);
context.refresh();
assertSame(context.getBean("b"), context.getBean("a", BeanA.class).b);
assertSame(context.getBean("c"), context.getBean("a", BeanA.class).c);
assertSame(context, context.getBean("b", BeanB.class).applicationContext);
assertThat(context.getBean("a", BeanA.class).b).isSameAs(context.getBean("b"));
assertThat(context.getBean("a", BeanA.class).c).isSameAs(context.getBean("c"));
assertThat(context.getBean("b", BeanB.class).applicationContext).isSameAs(context);
}
@Test
@@ -212,15 +205,13 @@ public class AnnotationConfigApplicationContextTests {
context.registerBean(BeanC.class, BeanC::new);
context.refresh();
assertTrue(context.getBeanFactory().containsSingleton("annotationConfigApplicationContextTests.BeanA"));
assertSame(context.getBean(BeanB.class), context.getBean(BeanA.class).b);
assertSame(context.getBean(BeanC.class), context.getBean(BeanA.class).c);
assertSame(context, context.getBean(BeanB.class).applicationContext);
assertThat(context.getBeanFactory().containsSingleton("annotationConfigApplicationContextTests.BeanA")).isTrue();
assertThat(context.getBean(BeanA.class).b).isSameAs(context.getBean(BeanB.class));
assertThat(context.getBean(BeanA.class).c).isSameAs(context.getBean(BeanC.class));
assertThat(context.getBean(BeanB.class).applicationContext).isSameAs(context);
assertArrayEquals(new String[] {"annotationConfigApplicationContextTests.BeanA"},
context.getDefaultListableBeanFactory().getDependentBeans("annotationConfigApplicationContextTests.BeanB"));
assertArrayEquals(new String[] {"annotationConfigApplicationContextTests.BeanA"},
context.getDefaultListableBeanFactory().getDependentBeans("annotationConfigApplicationContextTests.BeanC"));
assertThat(context.getDefaultListableBeanFactory().getDependentBeans("annotationConfigApplicationContextTests.BeanB")).isEqualTo(new String[] {"annotationConfigApplicationContextTests.BeanA"});
assertThat(context.getDefaultListableBeanFactory().getDependentBeans("annotationConfigApplicationContextTests.BeanC")).isEqualTo(new String[] {"annotationConfigApplicationContextTests.BeanA"});
}
@Test
@@ -233,10 +224,10 @@ public class AnnotationConfigApplicationContextTests {
context.registerBean(BeanC.class, BeanC::new);
context.refresh();
assertFalse(context.getBeanFactory().containsSingleton("annotationConfigApplicationContextTests.BeanA"));
assertSame(context.getBean(BeanB.class), context.getBean(BeanA.class).b);
assertSame(context.getBean(BeanC.class), context.getBean(BeanA.class).c);
assertSame(context, context.getBean(BeanB.class).applicationContext);
assertThat(context.getBeanFactory().containsSingleton("annotationConfigApplicationContextTests.BeanA")).isFalse();
assertThat(context.getBean(BeanA.class).b).isSameAs(context.getBean(BeanB.class));
assertThat(context.getBean(BeanA.class).c).isSameAs(context.getBean(BeanC.class));
assertThat(context.getBean(BeanB.class).applicationContext).isSameAs(context);
}
@Test
@@ -248,10 +239,10 @@ public class AnnotationConfigApplicationContextTests {
context.registerBean("c", BeanC.class, BeanC::new);
context.refresh();
assertTrue(context.getBeanFactory().containsSingleton("a"));
assertSame(context.getBean("b", BeanB.class), context.getBean(BeanA.class).b);
assertSame(context.getBean("c"), context.getBean("a", BeanA.class).c);
assertSame(context, context.getBean("b", BeanB.class).applicationContext);
assertThat(context.getBeanFactory().containsSingleton("a")).isTrue();
assertThat(context.getBean(BeanA.class).b).isSameAs(context.getBean("b", BeanB.class));
assertThat(context.getBean("a", BeanA.class).c).isSameAs(context.getBean("c"));
assertThat(context.getBean("b", BeanB.class).applicationContext).isSameAs(context);
}
@Test
@@ -264,10 +255,10 @@ public class AnnotationConfigApplicationContextTests {
context.registerBean("c", BeanC.class, BeanC::new);
context.refresh();
assertFalse(context.getBeanFactory().containsSingleton("a"));
assertSame(context.getBean("b", BeanB.class), context.getBean(BeanA.class).b);
assertSame(context.getBean("c"), context.getBean("a", BeanA.class).c);
assertSame(context, context.getBean("b", BeanB.class).applicationContext);
assertThat(context.getBeanFactory().containsSingleton("a")).isFalse();
assertThat(context.getBean(BeanA.class).b).isSameAs(context.getBean("b", BeanB.class));
assertThat(context.getBean("a", BeanA.class).c).isSameAs(context.getBean("c"));
assertThat(context.getBean("b", BeanB.class).applicationContext).isSameAs(context);
}
@Test
@@ -278,12 +269,12 @@ public class AnnotationConfigApplicationContextTests {
context.registerBean("c", BeanC.class, BeanC::new);
context.refresh();
assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanA.class), "a"));
assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanB.class), "b"));
assertTrue(ObjectUtils.containsElement(context.getBeanNamesForType(BeanC.class), "c"));
assertTrue(context.getBeansOfType(BeanA.class).isEmpty());
assertSame(context.getBean(BeanB.class), context.getBeansOfType(BeanB.class).values().iterator().next());
assertSame(context.getBean(BeanC.class), context.getBeansOfType(BeanC.class).values().iterator().next());
assertThat(ObjectUtils.containsElement(context.getBeanNamesForType(BeanA.class), "a")).isTrue();
assertThat(ObjectUtils.containsElement(context.getBeanNamesForType(BeanB.class), "b")).isTrue();
assertThat(ObjectUtils.containsElement(context.getBeanNamesForType(BeanC.class), "c")).isTrue();
assertThat(context.getBeansOfType(BeanA.class).isEmpty()).isTrue();
assertThat(context.getBeansOfType(BeanB.class).values().iterator().next()).isSameAs(context.getBean(BeanB.class));
assertThat(context.getBeansOfType(BeanC.class).values().iterator().next()).isSameAs(context.getBean(BeanC.class));
}
@Test
@@ -294,9 +285,9 @@ public class AnnotationConfigApplicationContextTests {
context.registerBean(BeanA.class, b, c);
context.refresh();
assertSame(b, context.getBean(BeanA.class).b);
assertSame(c, context.getBean(BeanA.class).c);
assertNull(b.applicationContext);
assertThat(context.getBean(BeanA.class).b).isSameAs(b);
assertThat(context.getBean(BeanA.class).c).isSameAs(c);
assertThat((Object) b.applicationContext).isNull();
}
@Test
@@ -307,9 +298,9 @@ public class AnnotationConfigApplicationContextTests {
context.registerBean("a", BeanA.class, b, c);
context.refresh();
assertSame(b, context.getBean("a", BeanA.class).b);
assertSame(c, context.getBean("a", BeanA.class).c);
assertNull(b.applicationContext);
assertThat(context.getBean("a", BeanA.class).b).isSameAs(b);
assertThat(context.getBean("a", BeanA.class).c).isSameAs(c);
assertThat((Object) b.applicationContext).isNull();
}
@Test
@@ -320,9 +311,9 @@ public class AnnotationConfigApplicationContextTests {
context.registerBean(BeanB.class);
context.refresh();
assertSame(context.getBean(BeanB.class), context.getBean(BeanA.class).b);
assertSame(c, context.getBean(BeanA.class).c);
assertSame(context, context.getBean(BeanB.class).applicationContext);
assertThat(context.getBean(BeanA.class).b).isSameAs(context.getBean(BeanB.class));
assertThat(context.getBean(BeanA.class).c).isSameAs(c);
assertThat(context.getBean(BeanB.class).applicationContext).isSameAs(context);
}
@Test
@@ -333,9 +324,9 @@ public class AnnotationConfigApplicationContextTests {
context.registerBean("b", BeanB.class);
context.refresh();
assertSame(context.getBean("b", BeanB.class), context.getBean("a", BeanA.class).b);
assertSame(c, context.getBean("a", BeanA.class).c);
assertSame(context, context.getBean("b", BeanB.class).applicationContext);
assertThat(context.getBean("a", BeanA.class).b).isSameAs(context.getBean("b", BeanB.class));
assertThat(context.getBean("a", BeanA.class).c).isSameAs(c);
assertThat(context.getBean("b", BeanB.class).applicationContext).isSameAs(context);
}
@Test
@@ -344,8 +335,8 @@ public class AnnotationConfigApplicationContextTests {
context.registerBean("fb", TypedFactoryBean.class, TypedFactoryBean::new, bd -> bd.setLazyInit(true));
context.refresh();
assertEquals(String.class, context.getType("fb"));
assertEquals(TypedFactoryBean.class, context.getType("&fb"));
assertThat(context.getType("fb")).isEqualTo(String.class);
assertThat(context.getType("&fb")).isEqualTo(TypedFactoryBean.class);
}
@Test
@@ -358,8 +349,8 @@ public class AnnotationConfigApplicationContextTests {
context.registerBeanDefinition("fb", bd);
context.refresh();
assertEquals(String.class, context.getType("fb"));
assertEquals(FactoryBean.class, context.getType("&fb"));
assertThat(context.getType("fb")).isEqualTo(String.class);
assertThat(context.getType("&fb")).isEqualTo(FactoryBean.class);
}

View File

@@ -34,8 +34,7 @@ import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.StopWatch;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
@@ -67,10 +66,10 @@ public class AnnotationProcessorPerformanceTests {
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
TestBean tb = (TestBean) ctx.getBean("test");
assertSame(spouse, tb.getSpouse());
assertThat(tb.getSpouse()).isSameAs(spouse);
}
sw.stop();
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
assertThat(sw.getTotalTimeMillis() < 4000).as("Prototype creation took too long: " + sw.getTotalTimeMillis()).isTrue();
}
@Test
@@ -89,10 +88,10 @@ public class AnnotationProcessorPerformanceTests {
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
TestBean tb = (TestBean) ctx.getBean("test");
assertSame(spouse, tb.getSpouse());
assertThat(tb.getSpouse()).isSameAs(spouse);
}
sw.stop();
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
assertThat(sw.getTotalTimeMillis() < 4000).as("Prototype creation took too long: " + sw.getTotalTimeMillis()).isTrue();
}
@Test
@@ -110,10 +109,10 @@ public class AnnotationProcessorPerformanceTests {
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
TestBean tb = (TestBean) ctx.getBean("test");
assertSame(spouse, tb.getSpouse());
assertThat(tb.getSpouse()).isSameAs(spouse);
}
sw.stop();
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
assertThat(sw.getTotalTimeMillis() < 4000).as("Prototype creation took too long: " + sw.getTotalTimeMillis()).isTrue();
}
@Test
@@ -132,10 +131,10 @@ public class AnnotationProcessorPerformanceTests {
sw.start("prototype");
for (int i = 0; i < 100000; i++) {
TestBean tb = (TestBean) ctx.getBean("test");
assertSame(spouse, tb.getSpouse());
assertThat(tb.getSpouse()).isSameAs(spouse);
}
sw.stop();
assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 6000);
assertThat(sw.getTotalTimeMillis() < 6000).as("Prototype creation took too long: " + sw.getTotalTimeMillis()).isTrue();
}

View File

@@ -29,9 +29,8 @@ import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.springframework.context.annotation.ScopedProxyMode.INTERFACES;
import static org.springframework.context.annotation.ScopedProxyMode.NO;
import static org.springframework.context.annotation.ScopedProxyMode.TARGET_CLASS;
@@ -53,9 +52,9 @@ public class AnnotationScopeMetadataResolverTests {
public void resolveScopeMetadataShouldNotApplyScopedProxyModeToSingleton() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithSingletonScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
assertEquals(BeanDefinition.SCOPE_SINGLETON, scopeMetadata.getScopeName());
assertEquals(NO, scopeMetadata.getScopedProxyMode());
assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
assertThat(scopeMetadata.getScopeName()).isEqualTo(BeanDefinition.SCOPE_SINGLETON);
assertThat(scopeMetadata.getScopedProxyMode()).isEqualTo(NO);
}
@Test
@@ -63,27 +62,27 @@ public class AnnotationScopeMetadataResolverTests {
this.scopeMetadataResolver = new AnnotationScopeMetadataResolver(INTERFACES);
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithPrototypeScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
assertEquals(BeanDefinition.SCOPE_PROTOTYPE, scopeMetadata.getScopeName());
assertEquals(INTERFACES, scopeMetadata.getScopedProxyMode());
assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
assertThat(scopeMetadata.getScopeName()).isEqualTo(BeanDefinition.SCOPE_PROTOTYPE);
assertThat(scopeMetadata.getScopedProxyMode()).isEqualTo(INTERFACES);
}
@Test
public void resolveScopeMetadataShouldReadScopedProxyModeFromAnnotation() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithScopedProxy.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
assertEquals("request", scopeMetadata.getScopeName());
assertEquals(TARGET_CLASS, scopeMetadata.getScopedProxyMode());
assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
assertThat(scopeMetadata.getScopeName()).isEqualTo("request");
assertThat(scopeMetadata.getScopedProxyMode()).isEqualTo(TARGET_CLASS);
}
@Test
public void customRequestScope() {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(AnnotatedWithCustomRequestScope.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
assertEquals("request", scopeMetadata.getScopeName());
assertEquals(NO, scopeMetadata.getScopedProxyMode());
assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
assertThat(scopeMetadata.getScopeName()).isEqualTo("request");
assertThat(scopeMetadata.getScopedProxyMode()).isEqualTo(NO);
}
@Test
@@ -92,9 +91,9 @@ public class AnnotationScopeMetadataResolverTests {
MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScope.class.getName());
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata());
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
assertEquals("request", scopeMetadata.getScopeName());
assertEquals(NO, scopeMetadata.getScopedProxyMode());
assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
assertThat(scopeMetadata.getScopeName()).isEqualTo("request");
assertThat(scopeMetadata.getScopedProxyMode()).isEqualTo(NO);
}
@Test
@@ -102,9 +101,9 @@ public class AnnotationScopeMetadataResolverTests {
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(
AnnotatedWithCustomRequestScopeWithAttributeOverride.class);
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
assertEquals("request", scopeMetadata.getScopeName());
assertEquals(TARGET_CLASS, scopeMetadata.getScopedProxyMode());
assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
assertThat(scopeMetadata.getScopeName()).isEqualTo("request");
assertThat(scopeMetadata.getScopedProxyMode()).isEqualTo(TARGET_CLASS);
}
@Test
@@ -113,9 +112,9 @@ public class AnnotationScopeMetadataResolverTests {
MetadataReader reader = readerFactory.getMetadataReader(AnnotatedWithCustomRequestScopeWithAttributeOverride.class.getName());
AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition(reader.getAnnotationMetadata());
ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(bd);
assertNotNull("resolveScopeMetadata(..) must *never* return null.", scopeMetadata);
assertEquals("request", scopeMetadata.getScopeName());
assertEquals(TARGET_CLASS, scopeMetadata.getScopedProxyMode());
assertThat(scopeMetadata).as("resolveScopeMetadata(..) must *never* return null.").isNotNull();
assertThat(scopeMetadata.getScopeName()).isEqualTo("request");
assertThat(scopeMetadata.getScopedProxyMode()).isEqualTo(TARGET_CLASS);
}
@Test

View File

@@ -27,9 +27,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ApplicationContextEvent;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
@@ -44,9 +42,9 @@ public class AutoProxyLazyInitTests {
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithStatic.class);
MyBean bean = ctx.getBean("myBean", MyBean.class);
assertFalse(MyBeanImpl.initialized);
assertThat(MyBeanImpl.initialized).isFalse();
bean.doIt();
assertTrue(MyBeanImpl.initialized);
assertThat(MyBeanImpl.initialized).isTrue();
}
@Test
@@ -56,9 +54,9 @@ public class AutoProxyLazyInitTests {
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithStaticAndInterface.class);
MyBean bean = ctx.getBean("myBean", MyBean.class);
assertFalse(MyBeanImpl.initialized);
assertThat(MyBeanImpl.initialized).isFalse();
bean.doIt();
assertTrue(MyBeanImpl.initialized);
assertThat(MyBeanImpl.initialized).isTrue();
}
@Test
@@ -68,9 +66,9 @@ public class AutoProxyLazyInitTests {
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNonStatic.class);
MyBean bean = ctx.getBean("myBean", MyBean.class);
assertFalse(MyBeanImpl.initialized);
assertThat(MyBeanImpl.initialized).isFalse();
bean.doIt();
assertTrue(MyBeanImpl.initialized);
assertThat(MyBeanImpl.initialized).isTrue();
}
@Test
@@ -80,9 +78,9 @@ public class AutoProxyLazyInitTests {
ApplicationContext ctx = new AnnotationConfigApplicationContext(ConfigWithNonStaticAndInterface.class);
MyBean bean = ctx.getBean("myBean", MyBean.class);
assertFalse(MyBeanImpl.initialized);
assertThat(MyBeanImpl.initialized).isFalse();
bean.doIt();
assertTrue(MyBeanImpl.initialized);
assertThat(MyBeanImpl.initialized).isTrue();
}
@@ -216,7 +214,7 @@ public class AutoProxyLazyInitTests {
@Override
protected AbstractBeanFactoryBasedTargetSource createBeanFactoryBasedTargetSource(Class<?> beanClass, String beanName) {
if ("myBean".equals(beanName)) {
assertEquals(MyBean.class, beanClass);
assertThat(beanClass).isEqualTo(MyBean.class);
}
return super.createBeanFactoryBasedTargetSource(beanClass, beanName);
}

View File

@@ -26,9 +26,6 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.beans.factory.support.RootBeanDefinition;
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;
/**
* Tests regarding overloading and overriding of bean methods.
@@ -53,9 +50,9 @@ public class BeanMethodPolymorphismTests {
ctx.register(OverridingConfig.class);
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("testBean"));
assertEquals("overridden", ctx.getBean("testBean", TestBean.class).toString());
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("testBean"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isFalse();
assertThat(ctx.getBean("testBean", TestBean.class).toString()).isEqualTo("overridden");
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isTrue();
}
@Test
@@ -64,9 +61,9 @@ public class BeanMethodPolymorphismTests {
ctx.registerBeanDefinition("config", new RootBeanDefinition(OverridingConfig.class.getName()));
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("testBean"));
assertEquals("overridden", ctx.getBean("testBean", TestBean.class).toString());
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("testBean"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isFalse();
assertThat(ctx.getBean("testBean", TestBean.class).toString()).isEqualTo("overridden");
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isTrue();
}
@Test
@@ -75,9 +72,9 @@ public class BeanMethodPolymorphismTests {
ctx.register(NarrowedOverridingConfig.class);
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("testBean"));
assertEquals("overridden", ctx.getBean("testBean", TestBean.class).toString());
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("testBean"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isFalse();
assertThat(ctx.getBean("testBean", TestBean.class).toString()).isEqualTo("overridden");
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isTrue();
}
@Test
@@ -86,9 +83,9 @@ public class BeanMethodPolymorphismTests {
ctx.registerBeanDefinition("config", new RootBeanDefinition(NarrowedOverridingConfig.class.getName()));
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("testBean"));
assertEquals("overridden", ctx.getBean("testBean", TestBean.class).toString());
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("testBean"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isFalse();
assertThat(ctx.getBean("testBean", TestBean.class).toString()).isEqualTo("overridden");
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("testBean")).isTrue();
}
@Test
@@ -116,9 +113,9 @@ public class BeanMethodPolymorphismTests {
ctx.register(ConfigWithOverloadingAndAdditionalMetadata.class);
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isFalse();
assertThat(ctx.getBean(String.class)).isEqualTo("regular");
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isTrue();
}
@Test
@@ -128,9 +125,9 @@ public class BeanMethodPolymorphismTests {
ctx.getDefaultListableBeanFactory().registerSingleton("anInt", 5);
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isFalse();
assertThat(ctx.getBean(String.class)).isEqualTo("overloaded5");
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isTrue();
}
@Test
@@ -139,9 +136,9 @@ public class BeanMethodPolymorphismTests {
ctx.register(SubConfig.class);
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isFalse();
assertThat(ctx.getBean(String.class)).isEqualTo("overloaded5");
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isTrue();
}
// SPR-11025
@@ -151,9 +148,9 @@ public class BeanMethodPolymorphismTests {
ctx.register(SubConfigWithList.class);
ctx.setAllowBeanDefinitionOverriding(false);
ctx.refresh();
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isFalse();
assertThat(ctx.getBean(String.class)).isEqualTo("overloaded5");
assertTrue(ctx.getDefaultListableBeanFactory().containsSingleton("aString"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("aString")).isTrue();
}
/**

View File

@@ -42,10 +42,6 @@ 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.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @author Mark Fisher
@@ -62,25 +58,25 @@ public class ClassPathBeanDefinitionScannerTests {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(12, beanCount);
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertTrue(context.containsBean("thoreau"));
assertTrue(context.containsBean(AnnotationConfigUtils.CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
assertThat(beanCount).isEqualTo(12);
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
assertThat(context.containsBean("thoreau")).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME)).isTrue();
context.refresh();
FooServiceImpl fooService = context.getBean("fooServiceImpl", FooServiceImpl.class);
assertTrue(context.getDefaultListableBeanFactory().containsSingleton("myNamedComponent"));
assertEquals("bar", fooService.foo(123));
assertEquals("bar", fooService.lookupFoo(123));
assertTrue(context.isPrototype("thoreau"));
assertThat(context.getDefaultListableBeanFactory().containsSingleton("myNamedComponent")).isTrue();
assertThat(fooService.foo(123)).isEqualTo("bar");
assertThat(fooService.lookupFoo(123)).isEqualTo("bar");
assertThat(context.isPrototype("thoreau")).isTrue();
}
@Test
@@ -89,20 +85,20 @@ public class ClassPathBeanDefinitionScannerTests {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.scan(BASE_PACKAGE);
scanner.scan("org.springframework.context.annotation5");
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertTrue(context.containsBean("otherFooDao"));
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
assertThat(context.containsBean("otherFooDao")).isTrue();
context.refresh();
assertFalse(context.getBeanFactory().containsSingleton("otherFooDao"));
assertFalse(context.getBeanFactory().containsSingleton("fooServiceImpl"));
assertThat(context.getBeanFactory().containsSingleton("otherFooDao")).isFalse();
assertThat(context.getBeanFactory().containsSingleton("fooServiceImpl")).isFalse();
FooServiceImpl fooService = context.getBean("fooServiceImpl", FooServiceImpl.class);
assertTrue(context.getBeanFactory().containsSingleton("otherFooDao"));
assertEquals("other", fooService.foo(123));
assertEquals("other", fooService.lookupFoo(123));
assertThat(context.getBeanFactory().containsSingleton("otherFooDao")).isTrue();
assertThat(fooService.foo(123)).isEqualTo("other");
assertThat(fooService.lookupFoo(123)).isEqualTo("other");
}
@Test
@@ -110,15 +106,15 @@ public class ClassPathBeanDefinitionScannerTests {
GenericApplicationContext context = new GenericApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(12, beanCount);
assertThat(beanCount).isEqualTo(12);
scanner.scan(BASE_PACKAGE);
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertTrue(context.containsBean("thoreau"));
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
assertThat(context.containsBean("thoreau")).isTrue();
}
@Test
@@ -127,13 +123,13 @@ public class ClassPathBeanDefinitionScannerTests {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(7, beanCount);
assertThat(beanCount).isEqualTo(7);
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
}
@Test
@@ -167,13 +163,13 @@ public class ClassPathBeanDefinitionScannerTests {
scanner.setIncludeAnnotationConfig(false);
int scannedBeanCount = scanner.scan(BASE_PACKAGE);
assertEquals(6, scannedBeanCount);
assertEquals(initialBeanCount + scannedBeanCount, context.getBeanDefinitionCount());
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertThat(scannedBeanCount).isEqualTo(6);
assertThat(context.getBeanDefinitionCount()).isEqualTo((initialBeanCount + scannedBeanCount));
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
}
@Test
@@ -187,13 +183,13 @@ public class ClassPathBeanDefinitionScannerTests {
scanner.setIncludeAnnotationConfig(false);
int scannedBeanCount = scanner.scan(BASE_PACKAGE);
assertEquals(6, scannedBeanCount);
assertEquals(initialBeanCount + scannedBeanCount, context.getBeanDefinitionCount());
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertThat(scannedBeanCount).isEqualTo(6);
assertThat(context.getBeanDefinitionCount()).isEqualTo((initialBeanCount + scannedBeanCount));
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
}
@Test
@@ -226,12 +222,12 @@ public class ClassPathBeanDefinitionScannerTests {
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(6, beanCount);
assertTrue(context.containsBean("messageBean"));
assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
assertThat(beanCount).isEqualTo(6);
assertThat(context.containsBean("messageBean")).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME)).isTrue();
}
@Test
@@ -241,17 +237,17 @@ public class ClassPathBeanDefinitionScannerTests {
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(6, beanCount);
assertTrue(context.containsBean("messageBean"));
assertFalse(context.containsBean("serviceInvocationCounter"));
assertFalse(context.containsBean("fooServiceImpl"));
assertFalse(context.containsBean("stubFooDao"));
assertFalse(context.containsBean("myNamedComponent"));
assertFalse(context.containsBean("myNamedDao"));
assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
assertThat(beanCount).isEqualTo(6);
assertThat(context.containsBean("messageBean")).isTrue();
assertThat(context.containsBean("serviceInvocationCounter")).isFalse();
assertThat(context.containsBean("fooServiceImpl")).isFalse();
assertThat(context.containsBean("stubFooDao")).isFalse();
assertThat(context.containsBean("myNamedComponent")).isFalse();
assertThat(context.containsBean("myNamedDao")).isFalse();
assertThat(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME)).isTrue();
}
@Test
@@ -261,17 +257,17 @@ public class ClassPathBeanDefinitionScannerTests {
scanner.addIncludeFilter(new AnnotationTypeFilter(CustomComponent.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(13, beanCount);
assertTrue(context.containsBean("messageBean"));
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
assertThat(beanCount).isEqualTo(13);
assertThat(context.containsBean("messageBean")).isTrue();
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME)).isTrue();
}
@Test
@@ -281,15 +277,15 @@ public class ClassPathBeanDefinitionScannerTests {
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(11, beanCount);
assertFalse(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
assertThat(beanCount).isEqualTo(11);
assertThat(context.containsBean("serviceInvocationCounter")).isFalse();
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME)).isTrue();
}
@Test
@@ -299,16 +295,16 @@ public class ClassPathBeanDefinitionScannerTests {
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(11, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
assertThat(beanCount).isEqualTo(11);
assertThat(context.containsBean("fooServiceImpl")).isFalse();
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME)).isTrue();
}
@Test
@@ -319,14 +315,14 @@ public class ClassPathBeanDefinitionScannerTests {
scanner.addExcludeFilter(new AssignableTypeFilter(FooService.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(6, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertFalse(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
assertFalse(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
assertThat(beanCount).isEqualTo(6);
assertThat(context.containsBean("fooServiceImpl")).isFalse();
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)).isFalse();
assertThat(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)).isFalse();
}
@Test
@@ -337,16 +333,16 @@ public class ClassPathBeanDefinitionScannerTests {
scanner.addExcludeFilter(new AnnotationTypeFilter(Aspect.class));
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(10, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertFalse(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
assertThat(beanCount).isEqualTo(10);
assertThat(context.containsBean("fooServiceImpl")).isFalse();
assertThat(context.containsBean("serviceInvocationCounter")).isFalse();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME)).isTrue();
}
@Test
@@ -356,17 +352,17 @@ public class ClassPathBeanDefinitionScannerTests {
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(12, beanCount);
assertFalse(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("fooService"));
assertTrue(context.containsBean("serviceInvocationCounter"));
assertTrue(context.containsBean("stubFooDao"));
assertTrue(context.containsBean("myNamedComponent"));
assertTrue(context.containsBean("myNamedDao"));
assertTrue(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME));
assertTrue(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME));
assertThat(beanCount).isEqualTo(12);
assertThat(context.containsBean("fooServiceImpl")).isFalse();
assertThat(context.containsBean("fooService")).isTrue();
assertThat(context.containsBean("serviceInvocationCounter")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("myNamedComponent")).isTrue();
assertThat(context.containsBean("myNamedDao")).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_PROCESSOR_BEAN_NAME)).isTrue();
assertThat(context.containsBean(AnnotationConfigUtils.EVENT_LISTENER_FACTORY_BEAN_NAME)).isTrue();
}
@Test
@@ -376,7 +372,7 @@ public class ClassPathBeanDefinitionScannerTests {
GenericApplicationContext multiPackageContext = new GenericApplicationContext();
ClassPathBeanDefinitionScanner multiPackageScanner = new ClassPathBeanDefinitionScanner(multiPackageContext);
int singlePackageBeanCount = singlePackageScanner.scan(BASE_PACKAGE);
assertEquals(12, singlePackageBeanCount);
assertThat(singlePackageBeanCount).isEqualTo(12);
multiPackageScanner.scan(BASE_PACKAGE, "org.springframework.dao.annotation");
// assertTrue(multiPackageBeanCount > singlePackageBeanCount);
}
@@ -387,10 +383,10 @@ public class ClassPathBeanDefinitionScannerTests {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
int initialBeanCount = context.getBeanDefinitionCount();
int scannedBeanCount = scanner.scan(BASE_PACKAGE);
assertEquals(12, scannedBeanCount);
assertEquals(scannedBeanCount, context.getBeanDefinitionCount() - initialBeanCount);
assertThat(scannedBeanCount).isEqualTo(12);
assertThat((context.getBeanDefinitionCount() - initialBeanCount)).isEqualTo(scannedBeanCount);
int addedBeanCount = scanner.scan("org.springframework.aop.aspectj.annotation");
assertEquals(initialBeanCount + scannedBeanCount + addedBeanCount, context.getBeanDefinitionCount());
assertThat(context.getBeanDefinitionCount()).isEqualTo((initialBeanCount + scannedBeanCount + addedBeanCount));
}
@Test
@@ -400,27 +396,27 @@ public class ClassPathBeanDefinitionScannerTests {
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(12, beanCount);
assertThat(beanCount).isEqualTo(12);
context.refresh();
FooServiceImpl fooService = context.getBean("fooService", FooServiceImpl.class);
StaticListableBeanFactory myBf = (StaticListableBeanFactory) context.getBean("myBf");
MessageSource ms = (MessageSource) context.getBean("messageSource");
assertTrue(fooService.isInitCalled());
assertEquals("bar", fooService.foo(123));
assertEquals("bar", fooService.lookupFoo(123));
assertSame(context.getDefaultListableBeanFactory(), fooService.beanFactory);
assertEquals(2, fooService.listableBeanFactory.size());
assertSame(context.getDefaultListableBeanFactory(), fooService.listableBeanFactory.get(0));
assertSame(myBf, fooService.listableBeanFactory.get(1));
assertSame(context, fooService.resourceLoader);
assertSame(context, fooService.resourcePatternResolver);
assertSame(context, fooService.eventPublisher);
assertSame(ms, fooService.messageSource);
assertSame(context, fooService.context);
assertEquals(1, fooService.configurableContext.length);
assertSame(context, fooService.configurableContext[0]);
assertSame(context, fooService.genericContext);
assertThat(fooService.isInitCalled()).isTrue();
assertThat(fooService.foo(123)).isEqualTo("bar");
assertThat(fooService.lookupFoo(123)).isEqualTo("bar");
assertThat(fooService.beanFactory).isSameAs(context.getDefaultListableBeanFactory());
assertThat(fooService.listableBeanFactory.size()).isEqualTo(2);
assertThat(fooService.listableBeanFactory.get(0)).isSameAs(context.getDefaultListableBeanFactory());
assertThat(fooService.listableBeanFactory.get(1)).isSameAs(myBf);
assertThat(fooService.resourceLoader).isSameAs(context);
assertThat(fooService.resourcePatternResolver).isSameAs(context);
assertThat(fooService.eventPublisher).isSameAs(context);
assertThat(fooService.messageSource).isSameAs(ms);
assertThat(fooService.context).isSameAs(context);
assertThat(fooService.configurableContext.length).isEqualTo(1);
assertThat(fooService.configurableContext[0]).isSameAs(context);
assertThat(fooService.genericContext).isSameAs(context);
}
@Test
@@ -430,14 +426,14 @@ public class ClassPathBeanDefinitionScannerTests {
scanner.setIncludeAnnotationConfig(false);
scanner.setBeanNameGenerator(new TestBeanNameGenerator());
int beanCount = scanner.scan(BASE_PACKAGE);
assertEquals(7, beanCount);
assertThat(beanCount).isEqualTo(7);
context.refresh();
try {
context.getBean("fooService");
}
catch (BeanCreationException expected) {
assertTrue(expected.contains(BeanInstantiationException.class));
assertThat(expected.contains(BeanInstantiationException.class)).isTrue();
// @Lookup method not substituted
}
}
@@ -453,8 +449,8 @@ public class ClassPathBeanDefinitionScannerTests {
context.refresh();
FooServiceImpl fooService = (FooServiceImpl) context.getBean("fooService");
assertEquals("bar", fooService.foo(123));
assertEquals("bar", fooService.lookupFoo(123));
assertThat(fooService.foo(123)).isEqualTo("bar");
assertThat(fooService.lookupFoo(123)).isEqualTo("bar");
}
@Test

View File

@@ -31,11 +31,7 @@ import org.springframework.tests.context.SimpleMapScope;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.ClassUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mark Pollack
@@ -58,37 +54,38 @@ public class ClassPathFactoryBeanDefinitionScannerTests {
context.refresh();
FactoryMethodComponent fmc = context.getBean("factoryMethodComponent", FactoryMethodComponent.class);
assertFalse(fmc.getClass().getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR));
assertThat(fmc.getClass().getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR)).isFalse();
TestBean tb = (TestBean) context.getBean("publicInstance"); //2
assertEquals("publicInstance", tb.getName());
assertThat(tb.getName()).isEqualTo("publicInstance");
TestBean tb2 = (TestBean) context.getBean("publicInstance"); //2
assertEquals("publicInstance", tb2.getName());
assertSame(tb2, tb);
assertThat(tb2.getName()).isEqualTo("publicInstance");
assertThat(tb).isSameAs(tb2);
tb = (TestBean) context.getBean("protectedInstance"); //3
assertEquals("protectedInstance", tb.getName());
assertSame(tb, context.getBean("protectedInstance"));
assertEquals("0", tb.getCountry());
assertThat(tb.getName()).isEqualTo("protectedInstance");
assertThat(context.getBean("protectedInstance")).isSameAs(tb);
assertThat(tb.getCountry()).isEqualTo("0");
tb2 = context.getBean("protectedInstance", TestBean.class); //3
assertEquals("protectedInstance", tb2.getName());
assertSame(tb2, tb);
assertThat(tb2.getName()).isEqualTo("protectedInstance");
assertThat(tb).isSameAs(tb2);
tb = context.getBean("privateInstance", TestBean.class); //4
assertEquals("privateInstance", tb.getName());
assertEquals(1, tb.getAge());
assertThat(tb.getName()).isEqualTo("privateInstance");
assertThat(tb.getAge()).isEqualTo(1);
tb2 = context.getBean("privateInstance", TestBean.class); //4
assertEquals(2, tb2.getAge());
assertNotSame(tb2, tb);
assertThat(tb2.getAge()).isEqualTo(2);
assertThat(tb).isNotSameAs(tb2);
Object bean = context.getBean("requestScopedInstance"); //5
assertTrue(AopUtils.isCglibProxy(bean));
assertTrue(bean instanceof ScopedObject);
assertThat(AopUtils.isCglibProxy(bean)).isTrue();
boolean condition = bean instanceof ScopedObject;
assertThat(condition).isTrue();
QualifiedClientBean clientBean = context.getBean("clientBean", QualifiedClientBean.class);
assertSame(context.getBean("publicInstance"), clientBean.testBean);
assertSame(context.getBean("dependencyBean"), clientBean.dependencyBean);
assertSame(context, clientBean.applicationContext);
assertThat(clientBean.testBean).isSameAs(context.getBean("publicInstance"));
assertThat(clientBean.dependencyBean).isSameAs(context.getBean("dependencyBean"));
assertThat(clientBean.applicationContext).isSameAs(context);
}

View File

@@ -56,9 +56,6 @@ import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
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;
/**
* @author Mark Fisher
@@ -95,14 +92,14 @@ public class ClassPathScanningCandidateComponentProviderTests {
private void testDefault(ClassPathScanningCandidateComponentProvider provider,
Class<? extends BeanDefinition> expectedBeanDefinitionType) {
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertTrue(containsBeanClass(candidates, DefaultNamedComponent.class));
assertTrue(containsBeanClass(candidates, NamedComponent.class));
assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
assertTrue(containsBeanClass(candidates, StubFooDao.class));
assertTrue(containsBeanClass(candidates, NamedStubDao.class));
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
assertTrue(containsBeanClass(candidates, BarComponent.class));
assertEquals(7, candidates.size());
assertThat(containsBeanClass(candidates, DefaultNamedComponent.class)).isTrue();
assertThat(containsBeanClass(candidates, NamedComponent.class)).isTrue();
assertThat(containsBeanClass(candidates, FooServiceImpl.class)).isTrue();
assertThat(containsBeanClass(candidates, StubFooDao.class)).isTrue();
assertThat(containsBeanClass(candidates, NamedStubDao.class)).isTrue();
assertThat(containsBeanClass(candidates, ServiceInvocationCounter.class)).isTrue();
assertThat(containsBeanClass(candidates, BarComponent.class)).isTrue();
assertThat(candidates.size()).isEqualTo(7);
assertBeanDefinitionType(candidates, expectedBeanDefinitionType);
}
@@ -124,8 +121,8 @@ public class ClassPathScanningCandidateComponentProviderTests {
private void testAntStyle(ClassPathScanningCandidateComponentProvider provider,
Class<? extends BeanDefinition> expectedBeanDefinitionType) {
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE + ".**.sub");
assertTrue(containsBeanClass(candidates, BarComponent.class));
assertEquals(1, candidates.size());
assertThat(containsBeanClass(candidates, BarComponent.class)).isTrue();
assertThat(candidates.size()).isEqualTo(1);
assertBeanDefinitionType(candidates, expectedBeanDefinitionType);
}
@@ -135,7 +132,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
provider.setResourceLoader(new DefaultResourceLoader(
CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
Set<BeanDefinition> candidates = provider.findCandidateComponents("bogus");
assertEquals(0, candidates.size());
assertThat(candidates.size()).isEqualTo(0);
}
@Test
@@ -143,7 +140,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(true);
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
Set<BeanDefinition> candidates = provider.findCandidateComponents("bogus");
assertEquals(0, candidates.size());
assertThat(candidates.size()).isEqualTo(0);
}
@Test
@@ -197,10 +194,10 @@ public class ClassPathScanningCandidateComponentProviderTests {
provider.addIncludeFilter(new AssignableTypeFilter(FooService.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
// Interfaces/Abstract class are filtered out automatically.
assertTrue(containsBeanClass(candidates, AutowiredQualifierFooService.class));
assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
assertTrue(containsBeanClass(candidates, ScopedProxyTestBean.class));
assertEquals(3, candidates.size());
assertThat(containsBeanClass(candidates, AutowiredQualifierFooService.class)).isTrue();
assertThat(containsBeanClass(candidates, FooServiceImpl.class)).isTrue();
assertThat(containsBeanClass(candidates, ScopedProxyTestBean.class)).isTrue();
assertThat(candidates.size()).isEqualTo(3);
assertBeanDefinitionType(candidates, expectedBeanDefinitionType);
}
@@ -225,10 +222,10 @@ public class ClassPathScanningCandidateComponentProviderTests {
provider.addExcludeFilter(new AnnotationTypeFilter(Service.class));
provider.addExcludeFilter(new AnnotationTypeFilter(Repository.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertTrue(containsBeanClass(candidates, NamedComponent.class));
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
assertTrue(containsBeanClass(candidates, BarComponent.class));
assertEquals(3, candidates.size());
assertThat(containsBeanClass(candidates, NamedComponent.class)).isTrue();
assertThat(containsBeanClass(candidates, ServiceInvocationCounter.class)).isTrue();
assertThat(containsBeanClass(candidates, BarComponent.class)).isTrue();
assertThat(candidates.size()).isEqualTo(3);
assertBeanDefinitionType(candidates, expectedBeanDefinitionType);
}
@@ -240,8 +237,8 @@ public class ClassPathScanningCandidateComponentProviderTests {
// the index to find candidates
provider.addIncludeFilter(new AnnotationTypeFilter(CustomStereotype.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertTrue(containsBeanClass(candidates, DefaultNamedComponent.class));
assertEquals(1, candidates.size());
assertThat(containsBeanClass(candidates, DefaultNamedComponent.class)).isTrue();
assertThat(candidates.size()).isEqualTo(1);
assertBeanDefinitionType(candidates, ScannedGenericBeanDefinition.class);
}
@@ -251,8 +248,8 @@ public class ClassPathScanningCandidateComponentProviderTests {
provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertTrue(containsBeanClass(candidates, StubFooDao.class));
assertEquals(1, candidates.size());
assertThat(containsBeanClass(candidates, StubFooDao.class)).isTrue();
assertThat(candidates.size()).isEqualTo(1);
assertBeanDefinitionType(candidates, ScannedGenericBeanDefinition.class);
}
@@ -276,11 +273,11 @@ public class ClassPathScanningCandidateComponentProviderTests {
private void testExclude(ClassPathScanningCandidateComponentProvider provider,
Class<? extends BeanDefinition> expectedBeanDefinitionType) {
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
assertTrue(containsBeanClass(candidates, StubFooDao.class));
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
assertTrue(containsBeanClass(candidates, BarComponent.class));
assertEquals(4, candidates.size());
assertThat(containsBeanClass(candidates, FooServiceImpl.class)).isTrue();
assertThat(containsBeanClass(candidates, StubFooDao.class)).isTrue();
assertThat(containsBeanClass(candidates, ServiceInvocationCounter.class)).isTrue();
assertThat(containsBeanClass(candidates, BarComponent.class)).isTrue();
assertThat(candidates.size()).isEqualTo(4);
assertBeanDefinitionType(candidates, expectedBeanDefinitionType);
}
@@ -288,7 +285,7 @@ public class ClassPathScanningCandidateComponentProviderTests {
public void testWithNoFilters() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(0, candidates.size());
assertThat(candidates.size()).isEqualTo(0);
}
@Test
@@ -299,13 +296,13 @@ public class ClassPathScanningCandidateComponentProviderTests {
provider.addExcludeFilter(new AnnotationTypeFilter(Service.class));
provider.addExcludeFilter(new AnnotationTypeFilter(Controller.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(3, candidates.size());
assertTrue(containsBeanClass(candidates, NamedComponent.class));
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
assertTrue(containsBeanClass(candidates, BarComponent.class));
assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
assertFalse(containsBeanClass(candidates, StubFooDao.class));
assertFalse(containsBeanClass(candidates, NamedStubDao.class));
assertThat(candidates.size()).isEqualTo(3);
assertThat(containsBeanClass(candidates, NamedComponent.class)).isTrue();
assertThat(containsBeanClass(candidates, ServiceInvocationCounter.class)).isTrue();
assertThat(containsBeanClass(candidates, BarComponent.class)).isTrue();
assertThat(containsBeanClass(candidates, FooServiceImpl.class)).isFalse();
assertThat(containsBeanClass(candidates, StubFooDao.class)).isFalse();
assertThat(containsBeanClass(candidates, NamedStubDao.class)).isFalse();
}
@Test
@@ -313,8 +310,8 @@ public class ClassPathScanningCandidateComponentProviderTests {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AnnotationTypeFilter(Aspect.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(1, candidates.size());
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
assertThat(candidates.size()).isEqualTo(1);
assertThat(containsBeanClass(candidates, ServiceInvocationCounter.class)).isTrue();
}
@Test
@@ -322,8 +319,8 @@ public class ClassPathScanningCandidateComponentProviderTests {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(1, candidates.size());
assertTrue(containsBeanClass(candidates, StubFooDao.class));
assertThat(candidates.size()).isEqualTo(1);
assertThat(containsBeanClass(candidates, StubFooDao.class)).isTrue();
}
@Test
@@ -331,8 +328,8 @@ public class ClassPathScanningCandidateComponentProviderTests {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AssignableTypeFilter(MessageBean.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(1, candidates.size());
assertTrue(containsBeanClass(candidates, MessageBean.class));
assertThat(candidates.size()).isEqualTo(1);
assertThat(containsBeanClass(candidates, MessageBean.class)).isTrue();
}
@Test
@@ -341,11 +338,11 @@ public class ClassPathScanningCandidateComponentProviderTests {
provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(7, candidates.size());
assertTrue(containsBeanClass(candidates, NamedComponent.class));
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
assertTrue(containsBeanClass(candidates, FooServiceImpl.class));
assertTrue(containsBeanClass(candidates, BarComponent.class));
assertThat(candidates.size()).isEqualTo(7);
assertThat(containsBeanClass(candidates, NamedComponent.class)).isTrue();
assertThat(containsBeanClass(candidates, ServiceInvocationCounter.class)).isTrue();
assertThat(containsBeanClass(candidates, FooServiceImpl.class)).isTrue();
assertThat(containsBeanClass(candidates, BarComponent.class)).isTrue();
}
@Test
@@ -355,11 +352,11 @@ public class ClassPathScanningCandidateComponentProviderTests {
provider.addIncludeFilter(new AssignableTypeFilter(FooServiceImpl.class));
provider.addExcludeFilter(new AssignableTypeFilter(FooService.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertEquals(6, candidates.size());
assertTrue(containsBeanClass(candidates, NamedComponent.class));
assertTrue(containsBeanClass(candidates, ServiceInvocationCounter.class));
assertTrue(containsBeanClass(candidates, BarComponent.class));
assertFalse(containsBeanClass(candidates, FooServiceImpl.class));
assertThat(candidates.size()).isEqualTo(6);
assertThat(containsBeanClass(candidates, NamedComponent.class)).isTrue();
assertThat(containsBeanClass(candidates, ServiceInvocationCounter.class)).isTrue();
assertThat(containsBeanClass(candidates, BarComponent.class)).isTrue();
assertThat(containsBeanClass(candidates, FooServiceImpl.class)).isFalse();
}
@Test

View File

@@ -44,12 +44,7 @@ import org.springframework.tests.sample.beans.NestedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
@@ -64,9 +59,9 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class));
AnnotatedInitDestroyBean bean = (AnnotatedInitDestroyBean) bf.getBean("annotatedBean");
assertTrue(bean.initCalled);
assertThat(bean.initCalled).isTrue();
bf.destroySingletons();
assertTrue(bean.destroyCalled);
assertThat(bean.destroyCalled).isTrue();
}
@Test
@@ -77,9 +72,9 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class));
AnnotatedInitDestroyBean bean = (AnnotatedInitDestroyBean) bf.getBean("annotatedBean");
assertTrue(bean.initCalled);
assertThat(bean.initCalled).isTrue();
bf.destroySingletons();
assertTrue(bean.destroyCalled);
assertThat(bean.destroyCalled).isTrue();
}
@Test
@@ -91,9 +86,9 @@ public class CommonAnnotationBeanPostProcessorTests {
ctx.refresh();
AnnotatedInitDestroyBean bean = (AnnotatedInitDestroyBean) ctx.getBean("annotatedBean");
assertTrue(bean.initCalled);
assertThat(bean.initCalled).isTrue();
ctx.close();
assertTrue(bean.destroyCalled);
assertThat(bean.destroyCalled).isTrue();
}
@Test
@@ -106,9 +101,9 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedInitDestroyBean.class));
AnnotatedInitDestroyBean bean = (AnnotatedInitDestroyBean) bf.getBean("annotatedBean");
assertTrue(bean.initCalled);
assertThat(bean.initCalled).isTrue();
bf.destroySingletons();
assertTrue(bean.destroyCalled);
assertThat(bean.destroyCalled).isTrue();
}
@Test
@@ -119,7 +114,7 @@ public class CommonAnnotationBeanPostProcessorTests {
rbd.setFactoryMethodName("create");
bf.registerBeanDefinition("bean", rbd);
assertEquals("null", bf.getBean("bean").toString());
assertThat(bf.getBean("bean").toString()).isEqualTo("null");
bf.destroySingletons();
}
@@ -131,7 +126,7 @@ public class CommonAnnotationBeanPostProcessorTests {
AnnotatedInitDestroyBean bean = new AnnotatedInitDestroyBean();
bpp2.postProcessBeforeDestruction(bean, "annotatedBean");
assertTrue(bean.destroyCalled);
assertThat(bean.destroyCalled).isTrue();
}
@Test
@@ -144,7 +139,7 @@ public class CommonAnnotationBeanPostProcessorTests {
AnnotatedInitDestroyBean bean = new AnnotatedInitDestroyBean();
bpp2.postProcessBeforeDestruction(bean, "annotatedBean");
assertTrue(bean.destroyCalled);
assertThat(bean.destroyCalled).isTrue();
}
@Test
@@ -160,15 +155,15 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerSingleton("testBean2", tb2);
ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.initCalled);
assertTrue(bean.init2Called);
assertTrue(bean.init3Called);
assertSame(tb, bean.getTestBean());
assertSame(tb2, bean.getTestBean2());
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.init3Called).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb2);
bf.destroySingletons();
assertTrue(bean.destroyCalled);
assertTrue(bean.destroy2Called);
assertTrue(bean.destroy3Called);
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
assertThat(bean.destroy3Called).isTrue();
}
@Test
@@ -188,24 +183,24 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean2", tbd2);
ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.initCalled);
assertTrue(bean.init2Called);
assertTrue(bean.init3Called);
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.init3Called).isTrue();
TestBean tb = bean.getTestBean();
TestBean tb2 = bean.getTestBean2();
assertNotNull(tb);
assertNotNull(tb2);
assertThat(tb).isNotNull();
assertThat(tb2).isNotNull();
ResourceInjectionBean anotherBean = (ResourceInjectionBean) bf.getBean("annotatedBean");
assertNotSame(anotherBean, bean);
assertNotSame(anotherBean.getTestBean(), tb);
assertNotSame(anotherBean.getTestBean2(), tb2);
assertThat(bean).isNotSameAs(anotherBean);
assertThat(tb).isNotSameAs(anotherBean.getTestBean());
assertThat(tb2).isNotSameAs(anotherBean.getTestBean2());
bf.destroyBean("annotatedBean", bean);
assertTrue(bean.destroyCalled);
assertTrue(bean.destroy2Called);
assertTrue(bean.destroy3Called);
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
assertThat(bean.destroy3Called).isTrue();
}
@Test
@@ -237,15 +232,15 @@ public class CommonAnnotationBeanPostProcessorTests {
ExtendedResourceInjectionBean bean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean");
INestedTestBean tb = bean.getTestBean6();
assertNotNull(tb);
assertThat(tb).isNotNull();
ExtendedResourceInjectionBean anotherBean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean");
assertNotSame(anotherBean, bean);
assertNotSame(anotherBean.getTestBean6(), tb);
assertThat(bean).isNotSameAs(anotherBean);
assertThat(tb).isNotSameAs(anotherBean.getTestBean6());
String[] depBeans = bf.getDependenciesForBean("annotatedBean");
assertEquals(1, depBeans.length);
assertEquals("testBean4", depBeans[0]);
assertThat(depBeans.length).isEqualTo(1);
assertThat(depBeans[0]).isEqualTo("testBean4");
}
@Test
@@ -261,11 +256,11 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerSingleton("testBean7", tb7);
DefaultMethodResourceInjectionBean bean = (DefaultMethodResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb2, bean.getTestBean2());
assertSame(2, bean.counter);
assertThat(bean.getTestBean2()).isSameAs(tb2);
assertThat(bean.counter).isSameAs(2);
bf.destroySingletons();
assertSame(3, bean.counter);
assertThat(bean.counter).isSameAs(3);
}
@Test
@@ -284,13 +279,13 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerSingleton("testBean2", tb2);
ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.initCalled);
assertTrue(bean.init2Called);
assertSame(tb, bean.getTestBean());
assertSame(tb2, bean.getTestBean2());
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb2);
bf.destroySingletons();
assertTrue(bean.destroyCalled);
assertTrue(bean.destroy2Called);
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
}
@Test
@@ -309,13 +304,13 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ResourceInjectionBean.class));
ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.initCalled);
assertTrue(bean.init2Called);
assertSame(tb, bean.getTestBean());
assertSame(tb2, bean.getTestBean2());
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb2);
bf.destroySingletons();
assertTrue(bean.destroyCalled);
assertTrue(bean.destroy2Called);
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
}
@Test
@@ -349,25 +344,25 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerAlias("xy", "testBean9");
ExtendedResourceInjectionBean bean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.initCalled);
assertTrue(bean.init2Called);
assertSame(tb, bean.getTestBean());
assertSame(tb2, bean.getTestBean2());
assertSame(tb4, bean.getTestBean3());
assertSame(tb3, bean.getTestBean4());
assertSame(tb6, bean.testBean5);
assertSame(tb6, bean.testBean6);
assertSame(bf, bean.beanFactory);
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb2);
assertThat(bean.getTestBean3()).isSameAs(tb4);
assertThat(bean.getTestBean4()).isSameAs(tb3);
assertThat(bean.testBean5).isSameAs(tb6);
assertThat(bean.testBean6).isSameAs(tb6);
assertThat(bean.beanFactory).isSameAs(bf);
NamedResourceInjectionBean bean2 = (NamedResourceInjectionBean) bf.getBean("annotatedBean2");
assertSame(tb6, bean2.testBean);
assertThat(bean2.testBean).isSameAs(tb6);
ConvertedResourceInjectionBean bean3 = (ConvertedResourceInjectionBean) bf.getBean("annotatedBean3");
assertSame(5, bean3.value);
assertThat(bean3.value).isSameAs(5);
bf.destroySingletons();
assertTrue(bean.destroyCalled);
assertTrue(bean.destroy2Called);
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
}
@Test
@@ -401,28 +396,29 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerSingleton("xy", tb6);
ExtendedResourceInjectionBean bean = (ExtendedResourceInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.initCalled);
assertTrue(bean.init2Called);
assertSame(tb, bean.getTestBean());
assertSame(tb5, bean.getTestBean2());
assertSame(tb4, bean.getTestBean3());
assertSame(tb3, bean.getTestBean4());
assertSame(tb6, bean.testBean5);
assertSame(tb6, bean.testBean6);
assertSame(bf, bean.beanFactory);
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb5);
assertThat(bean.getTestBean3()).isSameAs(tb4);
assertThat(bean.getTestBean4()).isSameAs(tb3);
assertThat(bean.testBean5).isSameAs(tb6);
assertThat(bean.testBean6).isSameAs(tb6);
assertThat(bean.beanFactory).isSameAs(bf);
try {
bf.getBean("annotatedBean2");
}
catch (BeanCreationException ex) {
assertTrue(ex.getRootCause() instanceof NoSuchBeanDefinitionException);
boolean condition = ex.getRootCause() instanceof NoSuchBeanDefinitionException;
assertThat(condition).isTrue();
NoSuchBeanDefinitionException innerEx = (NoSuchBeanDefinitionException) ex.getRootCause();
assertEquals("testBean9", innerEx.getBeanName());
assertThat(innerEx.getBeanName()).isEqualTo("testBean9");
}
bf.destroySingletons();
assertTrue(bean.destroyCalled);
assertTrue(bean.destroy2Called);
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
}
@Test
@@ -447,19 +443,19 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerAlias("xy", "testBean9");
ExtendedEjbInjectionBean bean = (ExtendedEjbInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.initCalled);
assertTrue(bean.init2Called);
assertSame(tb, bean.getTestBean());
assertSame(tb2, bean.getTestBean2());
assertSame(tb4, bean.getTestBean3());
assertSame(tb3, bean.getTestBean4());
assertSame(tb6, bean.testBean5);
assertSame(tb6, bean.testBean6);
assertSame(bf, bean.beanFactory);
assertThat(bean.initCalled).isTrue();
assertThat(bean.init2Called).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb2);
assertThat(bean.getTestBean3()).isSameAs(tb4);
assertThat(bean.getTestBean4()).isSameAs(tb3);
assertThat(bean.testBean5).isSameAs(tb6);
assertThat(bean.testBean6).isSameAs(tb6);
assertThat(bean.beanFactory).isSameAs(bf);
bf.destroySingletons();
assertTrue(bean.destroyCalled);
assertTrue(bean.destroy2Called);
assertThat(bean.destroyCalled).isTrue();
assertThat(bean.destroy2Called).isTrue();
}
@Test
@@ -473,11 +469,11 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
LazyResourceFieldInjectionBean bean = (LazyResourceFieldInjectionBean) bf.getBean("annotatedBean");
assertFalse(bf.containsSingleton("testBean"));
assertThat(bf.containsSingleton("testBean")).isFalse();
bean.testBean.setName("notLazyAnymore");
assertTrue(bf.containsSingleton("testBean"));
assertThat(bf.containsSingleton("testBean")).isTrue();
TestBean tb = (TestBean) bf.getBean("testBean");
assertEquals("notLazyAnymore", tb.getName());
assertThat(tb.getName()).isEqualTo("notLazyAnymore");
}
@Test
@@ -491,11 +487,11 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
LazyResourceMethodInjectionBean bean = (LazyResourceMethodInjectionBean) bf.getBean("annotatedBean");
assertFalse(bf.containsSingleton("testBean"));
assertThat(bf.containsSingleton("testBean")).isFalse();
bean.testBean.setName("notLazyAnymore");
assertTrue(bf.containsSingleton("testBean"));
assertThat(bf.containsSingleton("testBean")).isTrue();
TestBean tb = (TestBean) bf.getBean("testBean");
assertEquals("notLazyAnymore", tb.getName());
assertThat(tb.getName()).isEqualTo("notLazyAnymore");
}
@Test
@@ -509,11 +505,11 @@ public class CommonAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
LazyResourceCglibInjectionBean bean = (LazyResourceCglibInjectionBean) bf.getBean("annotatedBean");
assertFalse(bf.containsSingleton("testBean"));
assertThat(bf.containsSingleton("testBean")).isFalse();
bean.testBean.setName("notLazyAnymore");
assertTrue(bf.containsSingleton("testBean"));
assertThat(bf.containsSingleton("testBean")).isTrue();
TestBean tb = (TestBean) bf.getBean("testBean");
assertEquals("notLazyAnymore", tb.getName());
assertThat(tb.getName()).isEqualTo("notLazyAnymore");
}
@@ -546,7 +542,7 @@ public class CommonAnnotationBeanPostProcessorTests {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof AnnotatedInitDestroyBean) {
assertFalse(((AnnotatedInitDestroyBean) bean).initCalled);
assertThat(((AnnotatedInitDestroyBean) bean).initCalled).isFalse();
}
return bean;
}
@@ -554,7 +550,7 @@ public class CommonAnnotationBeanPostProcessorTests {
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof AnnotatedInitDestroyBean) {
assertTrue(((AnnotatedInitDestroyBean) bean).initCalled);
assertThat(((AnnotatedInitDestroyBean) bean).initCalled).isTrue();
}
return bean;
}
@@ -562,7 +558,7 @@ public class CommonAnnotationBeanPostProcessorTests {
@Override
public void postProcessBeforeDestruction(Object bean, String beanName) throws BeansException {
if (bean instanceof AnnotatedInitDestroyBean) {
assertFalse(((AnnotatedInitDestroyBean) bean).destroyCalled);
assertThat(((AnnotatedInitDestroyBean) bean).destroyCalled).isFalse();
}
}

View File

@@ -62,9 +62,6 @@ import org.springframework.tests.context.SimpleMapScope;
import org.springframework.util.SerializationTestUtils;
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;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;
/**
@@ -192,7 +189,7 @@ public class ComponentScanAnnotationIntegrationTests {
@Test
public void withCustomTypeFilter() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithCustomTypeFilter.class);
assertFalse(ctx.getDefaultListableBeanFactory().containsSingleton("componentScanParserTests.KustomAnnotationAutowiredBean"));
assertThat(ctx.getDefaultListableBeanFactory().containsSingleton("componentScanParserTests.KustomAnnotationAutowiredBean")).isFalse();
KustomAnnotationAutowiredBean testBean = ctx.getBean("componentScanParserTests.KustomAnnotationAutowiredBean", KustomAnnotationAutowiredBean.class);
assertThat(testBean.getDependency()).isNotNull();
}
@@ -200,7 +197,7 @@ public class ComponentScanAnnotationIntegrationTests {
@Test
public void withAwareTypeFilter() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(ComponentScanWithAwareTypeFilter.class);
assertTrue(ctx.getEnvironment().acceptsProfiles(Profiles.of("the-filter-ran")));
assertThat(ctx.getEnvironment().acceptsProfiles(Profiles.of("the-filter-ran"))).isTrue();
}
@Test
@@ -315,10 +312,10 @@ public class ComponentScanAnnotationIntegrationTests {
@Override
public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) {
((ConfigurableEnvironment) this.environment).addActiveProfile("the-filter-ran");
assertNotNull(this.beanFactory);
assertNotNull(this.classLoader);
assertNotNull(this.resourceLoader);
assertNotNull(this.environment);
assertThat(this.beanFactory).isNotNull();
assertThat(this.classLoader).isNotNull();
assertThat(this.resourceLoader).isNotNull();
assertThat(this.environment).isNotNull();
return false;
}

View File

@@ -23,12 +23,8 @@ import org.springframework.beans.factory.UnsatisfiedDependencyException;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.GenericApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* @author Mark Fisher
@@ -51,10 +47,10 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
assertFalse("lazy-init should be false", context.getBeanDefinition(TEST_BEAN_NAME).isLazyInit());
assertEquals("initCount should be 0", 0, DefaultsTestBean.INIT_COUNT);
assertThat(context.getBeanDefinition(TEST_BEAN_NAME).isLazyInit()).as("lazy-init should be false").isFalse();
assertThat(DefaultsTestBean.INIT_COUNT).as("initCount should be 0").isEqualTo(0);
context.refresh();
assertEquals("bean should have been instantiated", 1, DefaultsTestBean.INIT_COUNT);
assertThat(DefaultsTestBean.INIT_COUNT).as("bean should have been instantiated").isEqualTo(1);
}
@Test
@@ -62,12 +58,12 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultLazyInitTrueTests.xml");
assertTrue("lazy-init should be true", context.getBeanDefinition(TEST_BEAN_NAME).isLazyInit());
assertEquals("initCount should be 0", 0, DefaultsTestBean.INIT_COUNT);
assertThat(context.getBeanDefinition(TEST_BEAN_NAME).isLazyInit()).as("lazy-init should be true").isTrue();
assertThat(DefaultsTestBean.INIT_COUNT).as("initCount should be 0").isEqualTo(0);
context.refresh();
assertEquals("bean should not have been instantiated yet", 0, DefaultsTestBean.INIT_COUNT);
assertThat(DefaultsTestBean.INIT_COUNT).as("bean should not have been instantiated yet").isEqualTo(0);
context.getBean(TEST_BEAN_NAME);
assertEquals("bean should have been instantiated", 1, DefaultsTestBean.INIT_COUNT);
assertThat(DefaultsTestBean.INIT_COUNT).as("bean should have been instantiated").isEqualTo(1);
}
@Test
@@ -75,10 +71,10 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
GenericApplicationContext context = new GenericApplicationContext();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(context);
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultLazyInitFalseTests.xml");
assertFalse("lazy-init should be false", context.getBeanDefinition(TEST_BEAN_NAME).isLazyInit());
assertEquals("initCount should be 0", 0, DefaultsTestBean.INIT_COUNT);
assertThat(context.getBeanDefinition(TEST_BEAN_NAME).isLazyInit()).as("lazy-init should be false").isFalse();
assertThat(DefaultsTestBean.INIT_COUNT).as("initCount should be 0").isEqualTo(0);
context.refresh();
assertEquals("bean should have been instantiated", 1, DefaultsTestBean.INIT_COUNT);
assertThat(DefaultsTestBean.INIT_COUNT).as("bean should have been instantiated").isEqualTo(1);
}
@Test
@@ -88,9 +84,9 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertNull("no dependencies should have been autowired", bean.getConstructorDependency());
assertNull("no dependencies should have been autowired", bean.getPropertyDependency1());
assertNull("no dependencies should have been autowired", bean.getPropertyDependency2());
assertThat(bean.getConstructorDependency()).as("no dependencies should have been autowired").isNull();
assertThat(bean.getPropertyDependency1()).as("no dependencies should have been autowired").isNull();
assertThat(bean.getPropertyDependency2()).as("no dependencies should have been autowired").isNull();
}
@Test
@@ -100,9 +96,9 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireNoTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertNull("no dependencies should have been autowired", bean.getConstructorDependency());
assertNull("no dependencies should have been autowired", bean.getPropertyDependency1());
assertNull("no dependencies should have been autowired", bean.getPropertyDependency2());
assertThat(bean.getConstructorDependency()).as("no dependencies should have been autowired").isNull();
assertThat(bean.getPropertyDependency1()).as("no dependencies should have been autowired").isNull();
assertThat(bean.getPropertyDependency2()).as("no dependencies should have been autowired").isNull();
}
@Test
@@ -112,10 +108,10 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireConstructorTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertNotNull("constructor dependency should have been autowired", bean.getConstructorDependency());
assertEquals("cd", bean.getConstructorDependency().getName());
assertNull("property dependencies should not have been autowired", bean.getPropertyDependency1());
assertNull("property dependencies should not have been autowired", bean.getPropertyDependency2());
assertThat(bean.getConstructorDependency()).as("constructor dependency should have been autowired").isNotNull();
assertThat(bean.getConstructorDependency().getName()).isEqualTo("cd");
assertThat(bean.getPropertyDependency1()).as("property dependencies should not have been autowired").isNull();
assertThat(bean.getPropertyDependency2()).as("property dependencies should not have been autowired").isNull();
}
@Test
@@ -134,10 +130,10 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultAutowireByNameTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertNull("constructor dependency should not have been autowired", bean.getConstructorDependency());
assertNull("propertyDependency1 should not have been autowired", bean.getPropertyDependency1());
assertNotNull("propertyDependency2 should have been autowired", bean.getPropertyDependency2());
assertEquals("pd2", bean.getPropertyDependency2().getName());
assertThat(bean.getConstructorDependency()).as("constructor dependency should not have been autowired").isNull();
assertThat(bean.getPropertyDependency1()).as("propertyDependency1 should not have been autowired").isNull();
assertThat(bean.getPropertyDependency2()).as("propertyDependency2 should have been autowired").isNotNull();
assertThat(bean.getPropertyDependency2().getName()).isEqualTo("pd2");
}
@Test
@@ -147,9 +143,9 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertNull("constructor dependency should not have been autowired", bean.getConstructorDependency());
assertNull("property dependencies should not have been autowired", bean.getPropertyDependency1());
assertNull("property dependencies should not have been autowired", bean.getPropertyDependency2());
assertThat(bean.getConstructorDependency()).as("constructor dependency should not have been autowired").isNull();
assertThat(bean.getPropertyDependency1()).as("property dependencies should not have been autowired").isNull();
assertThat(bean.getPropertyDependency2()).as("property dependencies should not have been autowired").isNull();
}
@Test
@@ -159,9 +155,9 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultWithNoOverridesTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertFalse("bean should not have been initialized", bean.isInitialized());
assertThat(bean.isInitialized()).as("bean should not have been initialized").isFalse();
context.close();
assertFalse("bean should not have been destroyed", bean.isDestroyed());
assertThat(bean.isDestroyed()).as("bean should not have been destroyed").isFalse();
}
@Test
@@ -171,9 +167,9 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultInitAndDestroyMethodsTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertTrue("bean should have been initialized", bean.isInitialized());
assertThat(bean.isInitialized()).as("bean should have been initialized").isTrue();
context.close();
assertTrue("bean should have been destroyed", bean.isDestroyed());
assertThat(bean.isDestroyed()).as("bean should have been destroyed").isTrue();
}
@Test
@@ -183,9 +179,9 @@ public class ComponentScanParserBeanDefinitionDefaultsTests {
reader.loadBeanDefinitions(LOCATION_PREFIX + "defaultNonExistingInitAndDestroyMethodsTests.xml");
context.refresh();
DefaultsTestBean bean = (DefaultsTestBean) context.getBean(TEST_BEAN_NAME);
assertFalse("bean should not have been initialized", bean.isInitialized());
assertThat(bean.isInitialized()).as("bean should not have been initialized").isFalse();
context.close();
assertFalse("bean should not have been destroyed", bean.isDestroyed());
assertThat(bean.isDestroyed()).as("bean should not have been destroyed").isFalse();
}

View File

@@ -26,11 +26,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.tests.context.SimpleMapScope;
import org.springframework.util.SerializationTestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* @author Mark Fisher
@@ -47,7 +44,7 @@ public class ComponentScanParserScopedProxyTests {
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertThat(AopUtils.isAopProxy(bean)).isFalse();
context.close();
}
@@ -59,7 +56,7 @@ public class ComponentScanParserScopedProxyTests {
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
// should not be a proxy
assertFalse(AopUtils.isAopProxy(bean));
assertThat(AopUtils.isAopProxy(bean)).isFalse();
context.close();
}
@@ -72,12 +69,12 @@ public class ComponentScanParserScopedProxyTests {
// should cast to the interface
FooService bean = (FooService) context.getBean("scopedProxyTestBean");
// should be dynamic proxy
assertTrue(AopUtils.isJdkDynamicProxy(bean));
assertThat(AopUtils.isJdkDynamicProxy(bean)).isTrue();
// test serializability
assertEquals("bar", bean.foo(1));
assertThat(bean.foo(1)).isEqualTo("bar");
FooService deserialized = (FooService) SerializationTestUtils.serializeAndDeserialize(bean);
assertNotNull(deserialized);
assertEquals("bar", deserialized.foo(1));
assertThat(deserialized).isNotNull();
assertThat(deserialized.foo(1)).isEqualTo("bar");
context.close();
}
@@ -89,12 +86,12 @@ public class ComponentScanParserScopedProxyTests {
ScopedProxyTestBean bean = (ScopedProxyTestBean) context.getBean("scopedProxyTestBean");
// should be a class-based proxy
assertTrue(AopUtils.isCglibProxy(bean));
assertThat(AopUtils.isCglibProxy(bean)).isTrue();
// test serializability
assertEquals("bar", bean.foo(1));
assertThat(bean.foo(1)).isEqualTo("bar");
ScopedProxyTestBean deserialized = (ScopedProxyTestBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertNotNull(deserialized);
assertEquals("bar", deserialized.foo(1));
assertThat(deserialized).isNotNull();
assertThat(deserialized.foo(1)).isEqualTo("bar");
context.close();
}

View File

@@ -34,10 +34,6 @@ import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;
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;
import static org.junit.Assert.assertTrue;
/**
* @author Mark Fisher
@@ -55,9 +51,9 @@ public class ComponentScanParserTests {
@Test
public void aspectjTypeFilter() {
ClassPathXmlApplicationContext context = loadContext("aspectjTypeFilterTests.xml");
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
assertFalse(context.containsBean("scopedProxyTestBean"));
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("scopedProxyTestBean")).isFalse();
context.close();
}
@@ -68,9 +64,9 @@ public class ComponentScanParserTests {
System.setProperty("scanExclude", "example..Scoped*Test*");
try {
ClassPathXmlApplicationContext context = loadContext("aspectjTypeFilterTestsWithPlaceholders.xml");
assertTrue(context.containsBean("fooServiceImpl"));
assertTrue(context.containsBean("stubFooDao"));
assertFalse(context.containsBean("scopedProxyTestBean"));
assertThat(context.containsBean("fooServiceImpl")).isTrue();
assertThat(context.containsBean("stubFooDao")).isTrue();
assertThat(context.containsBean("scopedProxyTestBean")).isFalse();
context.close();
}
finally {
@@ -83,14 +79,14 @@ public class ComponentScanParserTests {
@Test
public void nonMatchingResourcePattern() {
ClassPathXmlApplicationContext context = loadContext("nonMatchingResourcePatternTests.xml");
assertFalse(context.containsBean("fooServiceImpl"));
assertThat(context.containsBean("fooServiceImpl")).isFalse();
context.close();
}
@Test
public void matchingResourcePattern() {
ClassPathXmlApplicationContext context = loadContext("matchingResourcePatternTests.xml");
assertTrue(context.containsBean("fooServiceImpl"));
assertThat(context.containsBean("fooServiceImpl")).isTrue();
context.close();
}
@@ -98,8 +94,8 @@ public class ComponentScanParserTests {
public void componentScanWithAutowiredQualifier() {
ClassPathXmlApplicationContext context = loadContext("componentScanWithAutowiredQualifierTests.xml");
AutowiredQualifierFooService fooService = (AutowiredQualifierFooService) context.getBean("fooService");
assertTrue(fooService.isInitCalled());
assertEquals("bar", fooService.foo(123));
assertThat(fooService.isInitCalled()).isTrue();
assertThat(fooService.foo(123)).isEqualTo("bar");
context.close();
}
@@ -107,7 +103,7 @@ public class ComponentScanParserTests {
public void customAnnotationUsedForBothComponentScanAndQualifier() {
ClassPathXmlApplicationContext context = loadContext("customAnnotationUsedForBothComponentScanAndQualifierTests.xml");
KustomAnnotationAutowiredBean testBean = (KustomAnnotationAutowiredBean) context.getBean("testBean");
assertNotNull(testBean.getDependency());
assertThat(testBean.getDependency()).isNotNull();
context.close();
}
@@ -115,7 +111,7 @@ public class ComponentScanParserTests {
public void customTypeFilter() {
ClassPathXmlApplicationContext context = loadContext("customTypeFilterTests.xml");
KustomAnnotationAutowiredBean testBean = (KustomAnnotationAutowiredBean) context.getBean("testBean");
assertNotNull(testBean.getDependency());
assertThat(testBean.getDependency()).isNotNull();
context.close();
}

View File

@@ -23,10 +23,8 @@ import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Mark Fisher
@@ -37,7 +35,7 @@ public class ComponentScanParserWithUserDefinedStrategiesTests {
public void testCustomBeanNameGenerator() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/customNameGeneratorTests.xml");
assertTrue(context.containsBean("testing.fooServiceImpl"));
assertThat(context.containsBean("testing.fooServiceImpl")).isTrue();
}
@Test
@@ -45,8 +43,8 @@ public class ComponentScanParserWithUserDefinedStrategiesTests {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
"org/springframework/context/annotation/customScopeResolverTests.xml");
BeanDefinition bd = context.getBeanFactory().getBeanDefinition("fooServiceImpl");
assertEquals("myCustomScope", bd.getScope());
assertFalse(bd.isSingleton());
assertThat(bd.getScope()).isEqualTo("myCustomScope");
assertThat(bd.isSingleton()).isFalse();
}
@Test

View File

@@ -64,13 +64,9 @@ import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
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.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @author Chris Beams
@@ -103,11 +99,11 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(SingletonBeanConfig.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
assertTrue(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass());
assertThat(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass()).isTrue();
Foo foo = beanFactory.getBean("foo", Foo.class);
Bar bar = beanFactory.getBean("bar", Bar.class);
assertSame(foo, bar.foo);
assertTrue(Arrays.asList(beanFactory.getDependentBeans("foo")).contains("bar"));
assertThat(bar.foo).isSameAs(foo);
assertThat(Arrays.asList(beanFactory.getDependentBeans("foo")).contains("bar")).isTrue();
}
@Test
@@ -115,11 +111,11 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(SingletonBeanConfig.class.getName()));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
assertTrue(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass());
assertThat(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass()).isTrue();
Foo foo = beanFactory.getBean("foo", Foo.class);
Bar bar = beanFactory.getBean("bar", Bar.class);
assertSame(foo, bar.foo);
assertTrue(Arrays.asList(beanFactory.getDependentBeans("foo")).contains("bar"));
assertThat(bar.foo).isSameAs(foo);
assertThat(Arrays.asList(beanFactory.getDependentBeans("foo")).contains("bar")).isTrue();
}
@Test
@@ -127,10 +123,10 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(NonEnhancedSingletonBeanConfig.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
assertTrue(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass());
assertThat(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass()).isTrue();
Foo foo = beanFactory.getBean("foo", Foo.class);
Bar bar = beanFactory.getBean("bar", Bar.class);
assertNotSame(foo, bar.foo);
assertThat(bar.foo).isNotSameAs(foo);
}
@Test
@@ -138,10 +134,10 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(NonEnhancedSingletonBeanConfig.class.getName()));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
assertTrue(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass());
assertThat(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass()).isTrue();
Foo foo = beanFactory.getBean("foo", Foo.class);
Bar bar = beanFactory.getBean("bar", Bar.class);
assertNotSame(foo, bar.foo);
assertThat(bar.foo).isNotSameAs(foo);
}
@Test
@@ -149,12 +145,12 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(StaticSingletonBeanConfig.class));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
assertTrue(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass());
assertTrue(((RootBeanDefinition) beanFactory.getBeanDefinition("foo")).hasBeanClass());
assertTrue(((RootBeanDefinition) beanFactory.getBeanDefinition("bar")).hasBeanClass());
assertThat(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass()).isTrue();
assertThat(((RootBeanDefinition) beanFactory.getBeanDefinition("foo")).hasBeanClass()).isTrue();
assertThat(((RootBeanDefinition) beanFactory.getBeanDefinition("bar")).hasBeanClass()).isTrue();
Foo foo = beanFactory.getBean("foo", Foo.class);
Bar bar = beanFactory.getBean("bar", Bar.class);
assertNotSame(foo, bar.foo);
assertThat(bar.foo).isNotSameAs(foo);
}
@Test
@@ -162,12 +158,12 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.registerBeanDefinition("config", new RootBeanDefinition(StaticSingletonBeanConfig.class.getName()));
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
assertTrue(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass());
assertTrue(((RootBeanDefinition) beanFactory.getBeanDefinition("foo")).hasBeanClass());
assertTrue(((RootBeanDefinition) beanFactory.getBeanDefinition("bar")).hasBeanClass());
assertThat(((RootBeanDefinition) beanFactory.getBeanDefinition("config")).hasBeanClass()).isTrue();
assertThat(((RootBeanDefinition) beanFactory.getBeanDefinition("foo")).hasBeanClass()).isTrue();
assertThat(((RootBeanDefinition) beanFactory.getBeanDefinition("bar")).hasBeanClass()).isTrue();
Foo foo = beanFactory.getBean("foo", Foo.class);
Bar bar = beanFactory.getBean("bar", Bar.class);
assertNotSame(foo, bar.foo);
assertThat(bar.foo).isNotSameAs(foo);
}
@Test
@@ -177,7 +173,7 @@ public class ConfigurationClassPostProcessorTests {
pp.postProcessBeanFactory(beanFactory);
Foo foo = beanFactory.getBean("foo", Foo.class);
Bar bar = beanFactory.getBean("bar", Bar.class);
assertSame(foo, bar.foo);
assertThat(bar.foo).isSameAs(foo);
}
/**
@@ -206,7 +202,7 @@ public class ConfigurationClassPostProcessorTests {
pp.postProcessBeanFactory(beanFactory);
Foo foo = beanFactory.getBean("foo", Foo.class);
Bar bar = beanFactory.getBean("bar", Bar.class);
assertSame(foo, bar.foo);
assertThat(bar.foo).isSameAs(foo);
}
@Test
@@ -311,7 +307,7 @@ public class ConfigurationClassPostProcessorTests {
pp.setEnvironment(new StandardEnvironment());
pp.postProcessBeanFactory(beanFactory);
SimpleComponent simpleComponent = beanFactory.getBean(SimpleComponent.class);
assertNotNull(simpleComponent);
assertThat(simpleComponent).isNotNull();
}
private void assertSupportForComposedAnnotationWithExclude(RootBeanDefinition beanDefinition) {
@@ -333,7 +329,7 @@ public class ConfigurationClassPostProcessorTests {
pp.postProcessBeanFactory(beanFactory);
Foo foo = beanFactory.getBean("foo", Foo.class);
Bar bar = beanFactory.getBean("bar", Bar.class);
assertSame(foo, bar.foo);
assertThat(bar.foo).isSameAs(foo);
}
@Test
@@ -385,9 +381,10 @@ public class ConfigurationClassPostProcessorTests {
pp.postProcessBeanFactory(beanFactory);
Foo foo = beanFactory.getBean(Foo.class);
assertTrue(foo instanceof ExtendedFoo);
boolean condition = foo instanceof ExtendedFoo;
assertThat(condition).isTrue();
Bar bar = beanFactory.getBean(Bar.class);
assertSame(foo, bar.foo);
assertThat(bar.foo).isSameAs(foo);
}
@Test
@@ -399,9 +396,10 @@ public class ConfigurationClassPostProcessorTests {
pp.postProcessBeanFactory(beanFactory);
Foo foo = beanFactory.getBean(Foo.class);
assertTrue(foo instanceof ExtendedAgainFoo);
boolean condition = foo instanceof ExtendedAgainFoo;
assertThat(condition).isTrue();
Bar bar = beanFactory.getBean(Bar.class);
assertSame(foo, bar.foo);
assertThat(bar.foo).isSameAs(foo);
}
@Test
@@ -427,9 +425,10 @@ public class ConfigurationClassPostProcessorTests {
pp.postProcessBeanFactory(beanFactory);
Foo foo = beanFactory.getBean(Foo.class);
assertTrue(foo instanceof ExtendedFoo);
boolean condition = foo instanceof ExtendedFoo;
assertThat(condition).isTrue();
Bar bar = beanFactory.getBean(Bar.class);
assertSame(foo, bar.foo);
assertThat(bar.foo).isSameAs(foo);
}
@Test // SPR-16734
@@ -440,9 +439,10 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.addBeanPostProcessor(new AutowiredAnnotationBeanPostProcessor());
Foo foo = beanFactory.getBean(Foo.class);
assertTrue(foo instanceof ExtendedFoo);
boolean condition = foo instanceof ExtendedFoo;
assertThat(condition).isTrue();
Bar bar = beanFactory.getBean(Bar.class);
assertSame(foo, bar.foo);
assertThat(bar.foo).isSameAs(foo);
}
@Test
@@ -456,9 +456,10 @@ public class ConfigurationClassPostProcessorTests {
pp.postProcessBeanFactory(beanFactory);
ITestBean injected = beanFactory.getBean("consumer", ScopedProxyConsumer.class).testBean;
assertTrue(injected instanceof ScopedObject);
assertSame(beanFactory.getBean("scopedClass"), injected);
assertSame(beanFactory.getBean(ITestBean.class), injected);
boolean condition = injected instanceof ScopedObject;
assertThat(condition).isTrue();
assertThat(injected).isSameAs(beanFactory.getBean("scopedClass"));
assertThat(injected).isSameAs(beanFactory.getBean(ITestBean.class));
}
@Test
@@ -487,8 +488,8 @@ public class ConfigurationClassPostProcessorTests {
pp.postProcessBeanFactory(beanFactory);
RepositoryInjectionBean bean = (RepositoryInjectionBean) beanFactory.getBean("annotatedBean");
assertEquals("Repository<String>", bean.stringRepository.toString());
assertEquals("Repository<Integer>", bean.integerRepository.toString());
assertThat(bean.stringRepository.toString()).isEqualTo("Repository<String>");
assertThat(bean.integerRepository.toString()).isEqualTo("Repository<Integer>");
}
@Test
@@ -504,8 +505,8 @@ public class ConfigurationClassPostProcessorTests {
pp.postProcessBeanFactory(beanFactory);
RepositoryInjectionBean bean = (RepositoryInjectionBean) beanFactory.getBean("annotatedBean");
assertEquals("Repository<String>", bean.stringRepository.toString());
assertEquals("Repository<Integer>", bean.integerRepository.toString());
assertThat(bean.stringRepository.toString()).isEqualTo("Repository<String>");
assertThat(bean.integerRepository.toString()).isEqualTo("Repository<Integer>");
}
@Test
@@ -522,10 +523,10 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.freezeConfiguration();
RepositoryInjectionBean bean = (RepositoryInjectionBean) beanFactory.getBean("annotatedBean");
assertEquals("Repository<String>", bean.stringRepository.toString());
assertEquals("Repository<Integer>", bean.integerRepository.toString());
assertTrue(AopUtils.isCglibProxy(bean.stringRepository));
assertTrue(AopUtils.isCglibProxy(bean.integerRepository));
assertThat(bean.stringRepository.toString()).isEqualTo("Repository<String>");
assertThat(bean.integerRepository.toString()).isEqualTo("Repository<Integer>");
assertThat(AopUtils.isCglibProxy(bean.stringRepository)).isTrue();
assertThat(AopUtils.isCglibProxy(bean.integerRepository)).isTrue();
}
@Test
@@ -542,10 +543,10 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.freezeConfiguration();
RepositoryInjectionBean bean = (RepositoryInjectionBean) beanFactory.getBean("annotatedBean");
assertEquals("Repository<String>", bean.stringRepository.toString());
assertEquals("Repository<Integer>", bean.integerRepository.toString());
assertTrue(AopUtils.isCglibProxy(bean.stringRepository));
assertTrue(AopUtils.isCglibProxy(bean.integerRepository));
assertThat(bean.stringRepository.toString()).isEqualTo("Repository<String>");
assertThat(bean.integerRepository.toString()).isEqualTo("Repository<Integer>");
assertThat(AopUtils.isCglibProxy(bean.stringRepository)).isTrue();
assertThat(AopUtils.isCglibProxy(bean.integerRepository)).isTrue();
}
@Test
@@ -562,7 +563,7 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.preInstantiateSingletons();
SpecificRepositoryInjectionBean bean = (SpecificRepositoryInjectionBean) beanFactory.getBean("annotatedBean");
assertSame(beanFactory.getBean("genericRepo"), bean.genericRepository);
assertThat(bean.genericRepository).isSameAs(beanFactory.getBean("genericRepo"));
}
@Test
@@ -579,9 +580,9 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.preInstantiateSingletons();
RepositoryFactoryBeanInjectionBean bean = (RepositoryFactoryBeanInjectionBean) beanFactory.getBean("annotatedBean");
assertSame(beanFactory.getBean("&repoFactoryBean"), bean.repositoryFactoryBean);
assertSame(beanFactory.getBean("&repoFactoryBean"), bean.qualifiedRepositoryFactoryBean);
assertSame(beanFactory.getBean("&repoFactoryBean"), bean.prefixQualifiedRepositoryFactoryBean);
assertThat(bean.repositoryFactoryBean).isSameAs(beanFactory.getBean("&repoFactoryBean"));
assertThat(bean.qualifiedRepositoryFactoryBean).isSameAs(beanFactory.getBean("&repoFactoryBean"));
assertThat(bean.prefixQualifiedRepositoryFactoryBean).isSameAs(beanFactory.getBean("&repoFactoryBean"));
}
@Test
@@ -590,7 +591,7 @@ public class ConfigurationClassPostProcessorTests {
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
assertSame(beanFactory.getBean("rawRepo"), beanFactory.getBean("repoConsumer"));
assertThat(beanFactory.getBean("repoConsumer")).isSameAs(beanFactory.getBean("rawRepo"));
}
@Test
@@ -599,7 +600,7 @@ public class ConfigurationClassPostProcessorTests {
ConfigurationClassPostProcessor pp = new ConfigurationClassPostProcessor();
pp.postProcessBeanFactory(beanFactory);
assertSame(beanFactory.getBean("genericRepo"), beanFactory.getBean("repoConsumer"));
assertThat(beanFactory.getBean("repoConsumer")).isSameAs(beanFactory.getBean("genericRepo"));
}
@Test
@@ -607,7 +608,7 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(WildcardWithExtendsConfiguration.class));
new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
assertSame(beanFactory.getBean("stringRepo"), beanFactory.getBean("repoConsumer"));
assertThat(beanFactory.getBean("repoConsumer")).isSameAs(beanFactory.getBean("stringRepo"));
}
@Test
@@ -615,7 +616,7 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.registerBeanDefinition("configClass", new RootBeanDefinition(WildcardWithGenericExtendsConfiguration.class));
new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
assertSame(beanFactory.getBean("genericRepo"), beanFactory.getBean("repoConsumer"));
assertThat(beanFactory.getBean("repoConsumer")).isSameAs(beanFactory.getBean("genericRepo"));
}
@Test
@@ -624,15 +625,15 @@ public class ConfigurationClassPostProcessorTests {
new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
}
@Test
@@ -642,15 +643,15 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.preInstantiateSingletons();
String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
}
@Test
@@ -659,13 +660,13 @@ public class ConfigurationClassPostProcessorTests {
new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(0, beanNames.length);
assertThat(beanNames.length).isEqualTo(0);
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(0, beanNames.length);
assertThat(beanNames.length).isEqualTo(0);
}
@Test
@@ -675,15 +676,15 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.preInstantiateSingletons();
String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
}
@Test
@@ -692,15 +693,15 @@ public class ConfigurationClassPostProcessorTests {
new ConfigurationClassPostProcessor().postProcessBeanFactory(beanFactory);
String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
}
@Test
@@ -710,15 +711,15 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.preInstantiateSingletons();
String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
}
@Test
@@ -732,17 +733,17 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.registerSingleton("traceInterceptor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
assertTrue(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo")));
assertThat(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo"))).isTrue();
}
@Test
@@ -757,17 +758,17 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.preInstantiateSingletons();
String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
assertTrue(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo")));
assertThat(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo"))).isTrue();
}
@Test
@@ -782,17 +783,17 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.preInstantiateSingletons();
String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
assertTrue(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo")));
assertThat(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo"))).isTrue();
}
@Test
@@ -807,17 +808,17 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.preInstantiateSingletons();
String[] beanNames = beanFactory.getBeanNamesForType(Repository.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(Repository.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
assertTrue(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo")));
assertThat(AopUtils.isCglibProxy(beanFactory.getBean("stringRepo"))).isTrue();
}
@Test
@@ -830,17 +831,17 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.registerSingleton("traceInterceptor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
String[] beanNames = beanFactory.getBeanNamesForType(RepositoryInterface.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
assertTrue(AopUtils.isJdkDynamicProxy(beanFactory.getBean("stringRepo")));
assertThat(AopUtils.isJdkDynamicProxy(beanFactory.getBean("stringRepo"))).isTrue();
}
@Test
@@ -854,17 +855,17 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.preInstantiateSingletons();
String[] beanNames = beanFactory.getBeanNamesForType(RepositoryInterface.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
assertTrue(AopUtils.isJdkDynamicProxy(beanFactory.getBean("stringRepo")));
assertThat(AopUtils.isJdkDynamicProxy(beanFactory.getBean("stringRepo"))).isTrue();
}
@Test
@@ -878,17 +879,17 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.preInstantiateSingletons();
String[] beanNames = beanFactory.getBeanNamesForType(RepositoryInterface.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
assertTrue(AopUtils.isJdkDynamicProxy(beanFactory.getBean("stringRepo")));
assertThat(AopUtils.isJdkDynamicProxy(beanFactory.getBean("stringRepo"))).isTrue();
}
@Test
@@ -902,17 +903,17 @@ public class ConfigurationClassPostProcessorTests {
beanFactory.preInstantiateSingletons();
String[] beanNames = beanFactory.getBeanNamesForType(RepositoryInterface.class);
assertTrue(ObjectUtils.containsElement(beanNames, "stringRepo"));
assertThat(ObjectUtils.containsElement(beanNames, "stringRepo")).isTrue();
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
beanNames = beanFactory.getBeanNamesForType(ResolvableType.forClassWithGenerics(RepositoryInterface.class, String.class));
assertEquals(1, beanNames.length);
assertEquals("stringRepo", beanNames[0]);
assertThat(beanNames.length).isEqualTo(1);
assertThat(beanNames[0]).isEqualTo("stringRepo");
assertTrue(AopUtils.isJdkDynamicProxy(beanFactory.getBean("stringRepo")));
assertThat(AopUtils.isJdkDynamicProxy(beanFactory.getBean("stringRepo"))).isTrue();
}
@Test
@@ -998,84 +999,84 @@ public class ConfigurationClassPostProcessorTests {
@Test
public void testInjectionPointMatchForNarrowTargetReturnType() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(FooBarConfiguration.class);
assertSame(ctx.getBean(BarImpl.class), ctx.getBean(FooImpl.class).bar);
assertThat(ctx.getBean(FooImpl.class).bar).isSameAs(ctx.getBean(BarImpl.class));
}
@Test
public void testVarargOnBeanMethod() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class, TestBean.class);
VarargConfiguration bean = ctx.getBean(VarargConfiguration.class);
assertNotNull(bean.testBeans);
assertEquals(1, bean.testBeans.length);
assertSame(ctx.getBean(TestBean.class), bean.testBeans[0]);
assertThat(bean.testBeans).isNotNull();
assertThat(bean.testBeans.length).isEqualTo(1);
assertThat(bean.testBeans[0]).isSameAs(ctx.getBean(TestBean.class));
}
@Test
public void testEmptyVarargOnBeanMethod() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(VarargConfiguration.class);
VarargConfiguration bean = ctx.getBean(VarargConfiguration.class);
assertNotNull(bean.testBeans);
assertEquals(0, bean.testBeans.length);
assertThat(bean.testBeans).isNotNull();
assertThat(bean.testBeans.length).isEqualTo(0);
}
@Test
public void testCollectionArgumentOnBeanMethod() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class, TestBean.class);
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
assertNotNull(bean.testBeans);
assertEquals(1, bean.testBeans.size());
assertSame(ctx.getBean(TestBean.class), bean.testBeans.get(0));
assertThat(bean.testBeans).isNotNull();
assertThat(bean.testBeans.size()).isEqualTo(1);
assertThat(bean.testBeans.get(0)).isSameAs(ctx.getBean(TestBean.class));
}
@Test
public void testEmptyCollectionArgumentOnBeanMethod() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionArgumentConfiguration.class);
CollectionArgumentConfiguration bean = ctx.getBean(CollectionArgumentConfiguration.class);
assertNotNull(bean.testBeans);
assertTrue(bean.testBeans.isEmpty());
assertThat(bean.testBeans).isNotNull();
assertThat(bean.testBeans.isEmpty()).isTrue();
}
@Test
public void testMapArgumentOnBeanMethod() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class, DummyRunnable.class);
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class);
assertNotNull(bean.testBeans);
assertEquals(1, bean.testBeans.size());
assertSame(ctx.getBean(Runnable.class), bean.testBeans.values().iterator().next());
assertThat(bean.testBeans).isNotNull();
assertThat(bean.testBeans.size()).isEqualTo(1);
assertThat(bean.testBeans.values().iterator().next()).isSameAs(ctx.getBean(Runnable.class));
}
@Test
public void testEmptyMapArgumentOnBeanMethod() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(MapArgumentConfiguration.class);
MapArgumentConfiguration bean = ctx.getBean(MapArgumentConfiguration.class);
assertNotNull(bean.testBeans);
assertTrue(bean.testBeans.isEmpty());
assertThat(bean.testBeans).isNotNull();
assertThat(bean.testBeans.isEmpty()).isTrue();
}
@Test
public void testCollectionInjectionFromSameConfigurationClass() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(CollectionInjectionConfiguration.class);
CollectionInjectionConfiguration bean = ctx.getBean(CollectionInjectionConfiguration.class);
assertNotNull(bean.testBeans);
assertEquals(1, bean.testBeans.size());
assertSame(ctx.getBean(TestBean.class), bean.testBeans.get(0));
assertThat(bean.testBeans).isNotNull();
assertThat(bean.testBeans.size()).isEqualTo(1);
assertThat(bean.testBeans.get(0)).isSameAs(ctx.getBean(TestBean.class));
}
@Test
public void testMapInjectionFromSameConfigurationClass() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(MapInjectionConfiguration.class);
MapInjectionConfiguration bean = ctx.getBean(MapInjectionConfiguration.class);
assertNotNull(bean.testBeans);
assertEquals(1, bean.testBeans.size());
assertSame(ctx.getBean(Runnable.class), bean.testBeans.get("testBean"));
assertThat(bean.testBeans).isNotNull();
assertThat(bean.testBeans.size()).isEqualTo(1);
assertThat(bean.testBeans.get("testBean")).isSameAs(ctx.getBean(Runnable.class));
}
@Test
public void testBeanLookupFromSameConfigurationClass() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanLookupConfiguration.class);
BeanLookupConfiguration bean = ctx.getBean(BeanLookupConfiguration.class);
assertNotNull(bean.getTestBean());
assertSame(ctx.getBean(TestBean.class), bean.getTestBean());
assertThat(bean.getTestBean()).isNotNull();
assertThat(bean.getTestBean()).isSameAs(ctx.getBean(TestBean.class));
}
@Test
@@ -1089,7 +1090,8 @@ public class ConfigurationClassPostProcessorTests {
@Test
public void testBeanDefinitionRegistryPostProcessorConfig() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(BeanDefinitionRegistryPostProcessorConfig.class);
assertTrue(ctx.getBean("myTestBean") instanceof TestBean);
boolean condition = ctx.getBean("myTestBean") instanceof TestBean;
assertThat(condition).isTrue();
}
@@ -1910,8 +1912,8 @@ public class ConfigurationClassPostProcessorTests {
@Qualifier("systemProperties") Map<String, String> sysprops,
@Qualifier("systemEnvironment") Map<String, String> sysenv) {
this.testBeans = testBeans;
assertSame(env.getSystemProperties(), sysprops);
assertSame(env.getSystemEnvironment(), sysenv);
assertThat(sysprops).isSameAs(env.getSystemProperties());
assertThat(sysenv).isSameAs(env.getSystemEnvironment());
return () -> {};
}

View File

@@ -32,9 +32,6 @@ import org.springframework.core.type.AnnotationMetadata;
import org.springframework.stereotype.Component;
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;
/**
* Test for {@link Conditional} beans.
@@ -50,9 +47,9 @@ public class ConfigurationClassWithConditionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanOneConfiguration.class, BeanTwoConfiguration.class);
ctx.refresh();
assertTrue(ctx.containsBean("bean1"));
assertFalse(ctx.containsBean("bean2"));
assertFalse(ctx.containsBean("configurationClassWithConditionTests.BeanTwoConfiguration"));
assertThat(ctx.containsBean("bean1")).isTrue();
assertThat(ctx.containsBean("bean2")).isFalse();
assertThat(ctx.containsBean("configurationClassWithConditionTests.BeanTwoConfiguration")).isFalse();
}
@Test
@@ -60,9 +57,9 @@ public class ConfigurationClassWithConditionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanTwoConfiguration.class);
ctx.refresh();
assertFalse(ctx.containsBean("bean1"));
assertTrue(ctx.containsBean("bean2"));
assertTrue(ctx.containsBean("configurationClassWithConditionTests.BeanTwoConfiguration"));
assertThat(ctx.containsBean("bean1")).isFalse();
assertThat(ctx.containsBean("bean2")).isTrue();
assertThat(ctx.containsBean("configurationClassWithConditionTests.BeanTwoConfiguration")).isTrue();
}
@Test
@@ -70,8 +67,8 @@ public class ConfigurationClassWithConditionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanOneConfiguration.class, BeanThreeConfiguration.class);
ctx.refresh();
assertTrue(ctx.containsBean("bean1"));
assertTrue(ctx.containsBean("bean3"));
assertThat(ctx.containsBean("bean1")).isTrue();
assertThat(ctx.containsBean("bean3")).isTrue();
}
@Test
@@ -79,8 +76,8 @@ public class ConfigurationClassWithConditionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(BeanThreeConfiguration.class);
ctx.refresh();
assertFalse(ctx.containsBean("bean1"));
assertFalse(ctx.containsBean("bean3"));
assertThat(ctx.containsBean("bean1")).isFalse();
assertThat(ctx.containsBean("bean3")).isFalse();
}
@Test
@@ -88,7 +85,7 @@ public class ConfigurationClassWithConditionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigurationWithMetaCondition.class);
ctx.refresh();
assertTrue(ctx.containsBean("bean"));
assertThat(ctx.containsBean("bean")).isTrue();
}
@Test
@@ -96,7 +93,7 @@ public class ConfigurationClassWithConditionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.registerBeanDefinition("config", new RootBeanDefinition(ConfigurationWithMetaCondition.class.getName()));
ctx.refresh();
assertTrue(ctx.containsBean("bean"));
assertThat(ctx.containsBean("bean")).isTrue();
}
@Test
@@ -104,7 +101,7 @@ public class ConfigurationClassWithConditionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(NonConfigurationClass.class);
ctx.refresh();
assertFalse(ctx.containsBean("bean1"));
assertThat(ctx.containsBean("bean1")).isFalse();
}
@Test
@@ -112,7 +109,7 @@ public class ConfigurationClassWithConditionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.registerBeanDefinition("config", new RootBeanDefinition(NonConfigurationClass.class.getName()));
ctx.refresh();
assertFalse(ctx.containsBean("bean1"));
assertThat(ctx.containsBean("bean1")).isFalse();
}
@Test
@@ -120,7 +117,7 @@ public class ConfigurationClassWithConditionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConditionOnMethodConfiguration.class);
ctx.refresh();
assertFalse(ctx.containsBean("bean1"));
assertThat(ctx.containsBean("bean1")).isFalse();
}
@Test
@@ -128,7 +125,7 @@ public class ConfigurationClassWithConditionTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.registerBeanDefinition("config", new RootBeanDefinition(ConditionOnMethodConfiguration.class.getName()));
ctx.refresh();
assertFalse(ctx.containsBean("bean1"));
assertThat(ctx.containsBean("bean1")).isFalse();
}
@Test
@@ -141,23 +138,23 @@ public class ConfigurationClassWithConditionTests {
@Test
public void conditionOnOverriddenMethodHonored() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithBeanSkipped.class);
assertEquals(0, context.getBeansOfType(ExampleBean.class).size());
assertThat(context.getBeansOfType(ExampleBean.class).size()).isEqualTo(0);
}
@Test
public void noConditionOnOverriddenMethodHonored() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithBeanReactivated.class);
Map<String, ExampleBean> beans = context.getBeansOfType(ExampleBean.class);
assertEquals(1, beans.size());
assertEquals("baz", beans.keySet().iterator().next());
assertThat(beans.size()).isEqualTo(1);
assertThat(beans.keySet().iterator().next()).isEqualTo("baz");
}
@Test
public void configWithAlternativeBeans() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithAlternativeBeans.class);
Map<String, ExampleBean> beans = context.getBeansOfType(ExampleBean.class);
assertEquals(1, beans.size());
assertEquals("baz", beans.keySet().iterator().next());
assertThat(beans.size()).isEqualTo(1);
assertThat(beans.keySet().iterator().next()).isEqualTo("baz");
}

View File

@@ -23,7 +23,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests cornering bug SPR-8514.
@@ -88,7 +88,7 @@ public class ConfigurationWithFactoryBeanAndAutowiringTests {
ctx.register(AppConfig.class);
ctx.register(FactoryBeanCallingConfig.class);
ctx.refresh();
assertEquals("true", ctx.getBean("myString"));
assertThat(ctx.getBean("myString")).isEqualTo("true");
}

View File

@@ -23,7 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Test case cornering the bug initially raised with SPR-8762, in which a
@@ -38,7 +38,7 @@ public class ConfigurationWithFactoryBeanAndParametersTests {
@Test
public void test() {
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, Bar.class);
assertNotNull(ctx.getBean(Bar.class).foo);
assertThat(ctx.getBean(Bar.class).foo).isNotNull();
}

View File

@@ -21,8 +21,7 @@ import org.junit.Test;
import org.springframework.context.annotation.DeferredImportSelector.Group;
import org.springframework.core.type.AnnotationMetadata;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
/**
@@ -36,27 +35,23 @@ public class DeferredImportSelectorTests {
public void entryEqualsSameInstance() {
AnnotationMetadata metadata = mock(AnnotationMetadata.class);
Group.Entry entry = new Group.Entry(metadata, "com.example.Test");
assertEquals(entry, entry);
assertThat(entry).isEqualTo(entry);
}
@Test
public void entryEqualsSameMetadataAndClassName() {
AnnotationMetadata metadata = mock(AnnotationMetadata.class);
assertEquals(new Group.Entry(metadata, "com.example.Test"),
new Group.Entry(metadata, "com.example.Test"));
assertThat(new Group.Entry(metadata, "com.example.Test")).isEqualTo(new Group.Entry(metadata, "com.example.Test"));
}
@Test
public void entryEqualDifferentMetadataAndSameClassName() {
assertNotEquals(
new Group.Entry(mock(AnnotationMetadata.class), "com.example.Test"),
new Group.Entry(mock(AnnotationMetadata.class), "com.example.Test"));
assertThat(new Group.Entry(mock(AnnotationMetadata.class), "com.example.Test")).isNotEqualTo(new Group.Entry(mock(AnnotationMetadata.class), "com.example.Test"));
}
@Test
public void entryEqualSameMetadataAnDifferentClassName() {
AnnotationMetadata metadata = mock(AnnotationMetadata.class);
assertNotEquals(new Group.Entry(metadata, "com.example.Test"),
new Group.Entry(metadata, "com.example.AnotherTest"));
assertThat(new Group.Entry(metadata, "com.example.AnotherTest")).isNotEqualTo(new Group.Entry(metadata, "com.example.Test"));
}
}

View File

@@ -33,9 +33,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
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;
/**
* @author Juergen Hoeller
@@ -71,17 +68,17 @@ public class EnableAspectJAutoProxyTests {
FooService fooService = ctx.getBean(FooService.class);
ServiceInvocationCounter counter = ctx.getBean(ServiceInvocationCounter.class);
assertEquals(0, counter.getCount());
assertThat(counter.getCount()).isEqualTo(0);
assertTrue(fooService.isInitCalled());
assertEquals(1, counter.getCount());
assertThat(fooService.isInitCalled()).isTrue();
assertThat(counter.getCount()).isEqualTo(1);
String value = fooService.foo(1);
assertEquals("bar", value);
assertEquals(2, counter.getCount());
assertThat(value).isEqualTo("bar");
assertThat(counter.getCount()).isEqualTo(2);
fooService.foo(1);
assertEquals(3, counter.getCount());
assertThat(counter.getCount()).isEqualTo(3);
}
@Test
@@ -130,7 +127,7 @@ public class EnableAspectJAutoProxyTests {
return new FooServiceImpl() {
@Override
public String foo(int id) {
assertNotNull(AopContext.currentProxy());
assertThat(AopContext.currentProxy()).isNotNull();
return super.foo(id);
}
@Override

View File

@@ -37,8 +37,6 @@ import org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcesso
import org.springframework.util.Assert;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* Tests that an ImportAware @Configuration classes gets injected with the
@@ -55,7 +53,7 @@ public class ImportAwareTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImportingConfig.class);
ctx.refresh();
assertNotNull(ctx.getBean("importedConfigBean"));
assertThat(ctx.getBean("importedConfigBean")).isNotNull();
ImportedConfig importAwareConfig = ctx.getBean(ImportedConfig.class);
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
@@ -71,7 +69,7 @@ public class ImportAwareTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(IndirectlyImportingConfig.class);
ctx.refresh();
assertNotNull(ctx.getBean("importedConfigBean"));
assertThat(ctx.getBean("importedConfigBean")).isNotNull();
ImportedConfig importAwareConfig = ctx.getBean(ImportedConfig.class);
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
@@ -87,7 +85,7 @@ public class ImportAwareTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImportingConfigLite.class);
ctx.refresh();
assertNotNull(ctx.getBean("importedConfigBean"));
assertThat(ctx.getBean("importedConfigBean")).isNotNull();
ImportedConfigLite importAwareConfig = ctx.getBean(ImportedConfigLite.class);
AnnotationMetadata importMetadata = importAwareConfig.importMetadata;
@@ -104,8 +102,8 @@ public class ImportAwareTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImportingRegistrarConfig.class);
ctx.refresh();
assertNotNull(ctx.getBean("registrarImportedBean"));
assertNotNull(ctx.getBean("otherImportedConfigBean"));
assertThat(ctx.getBean("registrarImportedBean")).isNotNull();
assertThat(ctx.getBean("otherImportedConfigBean")).isNotNull();
}
@Test
@@ -114,10 +112,10 @@ public class ImportAwareTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ImportingRegistrarConfigWithImport.class);
ctx.refresh();
assertNotNull(ctx.getBean("registrarImportedBean"));
assertNotNull(ctx.getBean("otherImportedConfigBean"));
assertNotNull(ctx.getBean("importedConfigBean"));
assertNotNull(ctx.getBean(ImportedConfig.class));
assertThat(ctx.getBean("registrarImportedBean")).isNotNull();
assertThat(ctx.getBean("otherImportedConfigBean")).isNotNull();
assertThat(ctx.getBean("importedConfigBean")).isNotNull();
assertThat(ctx.getBean(ImportedConfig.class)).isNotNull();
}
@Test
@@ -125,8 +123,7 @@ public class ImportAwareTests {
AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
ConfigurationOne.class, ConfigurationTwo.class)
.getBean(MetadataHolder.class).importMetadata;
assertEquals(ConfigurationOne.class,
((StandardAnnotationMetadata) importMetadata).getIntrospectedClass());
assertThat(((StandardAnnotationMetadata) importMetadata).getIntrospectedClass()).isEqualTo(ConfigurationOne.class);
}
@Test
@@ -134,8 +131,7 @@ public class ImportAwareTests {
AnnotationMetadata importMetadata = new AnnotationConfigApplicationContext(
ConfigurationTwo.class, ConfigurationOne.class)
.getBean(MetadataHolder.class).importMetadata;
assertEquals(ConfigurationOne.class,
((StandardAnnotationMetadata) importMetadata).getIntrospectedClass());
assertThat(((StandardAnnotationMetadata) importMetadata).getIntrospectedClass()).isEqualTo(ConfigurationOne.class);
}
@Test
@@ -398,9 +394,8 @@ public class ImportAwareTests {
public void setImportMetadata(AnnotationMetadata annotationMetadata) {
AnnotationAttributes enableFeatureAttributes =
AnnotationAttributes.fromMap(annotationMetadata.getAnnotationAttributes(EnableFeature.class.getName()));
assertEquals(EnableFeature.class, enableFeatureAttributes.annotationType());
Arrays.stream(enableFeatureAttributes.getAnnotationArray("policies")).forEach(featurePolicyAttributes ->
assertEquals(EnableFeature.FeaturePolicy.class, featurePolicyAttributes.annotationType()));
assertThat(enableFeatureAttributes.annotationType()).isEqualTo(EnableFeature.class);
Arrays.stream(enableFeatureAttributes.getAnnotationArray("policies")).forEach(featurePolicyAttributes -> assertThat(featurePolicyAttributes.annotationType()).isEqualTo(EnableFeature.FeaturePolicy.class));
}
}

View File

@@ -29,12 +29,8 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
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.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @author Juergen Hoeller
@@ -53,13 +49,13 @@ public class LazyAutowiredAnnotationBeanPostProcessorTests {
ac.refresh();
TestBeanHolder bean = ac.getBean("annotatedBean", TestBeanHolder.class);
assertFalse(ac.getBeanFactory().containsSingleton("testBean"));
assertNotNull(bean.getTestBean());
assertNull(bean.getTestBean().getName());
assertTrue(ac.getBeanFactory().containsSingleton("testBean"));
assertThat(ac.getBeanFactory().containsSingleton("testBean")).isFalse();
assertThat(bean.getTestBean()).isNotNull();
assertThat(bean.getTestBean().getName()).isNull();
assertThat(ac.getBeanFactory().containsSingleton("testBean")).isTrue();
TestBean tb = (TestBean) ac.getBean("testBean");
tb.setName("tb");
assertSame("tb", bean.getTestBean().getName());
assertThat(bean.getTestBean().getName()).isSameAs("tb");
}
@Test
@@ -76,13 +72,13 @@ public class LazyAutowiredAnnotationBeanPostProcessorTests {
ac.refresh();
FieldResourceInjectionBean bean = ac.getBean("annotatedBean", FieldResourceInjectionBean.class);
assertFalse(ac.getBeanFactory().containsSingleton("testBean"));
assertFalse(bean.getTestBeans().isEmpty());
assertNull(bean.getTestBeans().get(0).getName());
assertTrue(ac.getBeanFactory().containsSingleton("testBean"));
assertThat(ac.getBeanFactory().containsSingleton("testBean")).isFalse();
assertThat(bean.getTestBeans().isEmpty()).isFalse();
assertThat(bean.getTestBeans().get(0).getName()).isNull();
assertThat(ac.getBeanFactory().containsSingleton("testBean")).isTrue();
TestBean tb = (TestBean) ac.getBean("testBean");
tb.setName("tb");
assertSame("tb", bean.getTestBean().getName());
assertThat(bean.getTestBean().getName()).isSameAs("tb");
}
@Test
@@ -132,7 +128,7 @@ public class LazyAutowiredAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", bd);
FieldResourceInjectionBean bean = (FieldResourceInjectionBean) bf.getBean("annotatedBean");
assertNotNull(bean.getTestBean());
assertThat(bean.getTestBean()).isNotNull();
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
bean.getTestBean().getName());
}
@@ -149,9 +145,9 @@ public class LazyAutowiredAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", bd);
OptionalFieldResourceInjectionBean bean = (OptionalFieldResourceInjectionBean) bf.getBean("annotatedBean");
assertNotNull(bean.getTestBean());
assertNotNull(bean.getTestBeans());
assertTrue(bean.getTestBeans().isEmpty());
assertThat(bean.getTestBean()).isNotNull();
assertThat(bean.getTestBeans()).isNotNull();
assertThat(bean.getTestBeans().isEmpty()).isTrue();
assertThatExceptionOfType(NoSuchBeanDefinitionException.class).isThrownBy(() ->
bean.getTestBean().getName());
}

View File

@@ -22,9 +22,6 @@ import org.springframework.stereotype.Component;
import org.springframework.tests.sample.beans.TestBean;
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;
/**
* Tests ensuring that nested static @Configuration classes are automatically detected
@@ -42,7 +39,7 @@ public class NestedConfigurationClassTests {
ctx.register(L0Config.L1Config.class);
ctx.refresh();
assertFalse(ctx.containsBean("l0Bean"));
assertThat(ctx.containsBean("l0Bean")).isFalse();
ctx.getBean(L0Config.L1Config.class);
ctx.getBean("l1Bean");
@@ -60,15 +57,15 @@ public class NestedConfigurationClassTests {
ctx.register(L0Config.class);
ctx.refresh();
assertFalse(ctx.getBeanFactory().containsSingleton("nestedConfigurationClassTests.L0Config"));
assertThat(ctx.getBeanFactory().containsSingleton("nestedConfigurationClassTests.L0Config")).isFalse();
ctx.getBean(L0Config.class);
ctx.getBean("l0Bean");
assertTrue(ctx.getBeanFactory().containsSingleton(L0Config.L1Config.class.getName()));
assertThat(ctx.getBeanFactory().containsSingleton(L0Config.L1Config.class.getName())).isTrue();
ctx.getBean(L0Config.L1Config.class);
ctx.getBean("l1Bean");
assertFalse(ctx.getBeanFactory().containsSingleton(L0Config.L1Config.L2Config.class.getName()));
assertThat(ctx.getBeanFactory().containsSingleton(L0Config.L1Config.L2Config.class.getName())).isFalse();
ctx.getBean(L0Config.L1Config.L2Config.class);
ctx.getBean("l2Bean");
@@ -82,15 +79,15 @@ public class NestedConfigurationClassTests {
ctx.register(L0ConfigLight.class);
ctx.refresh();
assertFalse(ctx.getBeanFactory().containsSingleton("nestedConfigurationClassTests.L0ConfigLight"));
assertThat(ctx.getBeanFactory().containsSingleton("nestedConfigurationClassTests.L0ConfigLight")).isFalse();
ctx.getBean(L0ConfigLight.class);
ctx.getBean("l0Bean");
assertTrue(ctx.getBeanFactory().containsSingleton(L0ConfigLight.L1ConfigLight.class.getName()));
assertThat(ctx.getBeanFactory().containsSingleton(L0ConfigLight.L1ConfigLight.class.getName())).isTrue();
ctx.getBean(L0ConfigLight.L1ConfigLight.class);
ctx.getBean("l1Bean");
assertFalse(ctx.getBeanFactory().containsSingleton(L0ConfigLight.L1ConfigLight.L2ConfigLight.class.getName()));
assertThat(ctx.getBeanFactory().containsSingleton(L0ConfigLight.L1ConfigLight.L2ConfigLight.class.getName())).isFalse();
ctx.getBean(L0ConfigLight.L1ConfigLight.L2ConfigLight.class);
ctx.getBean("l2Bean");
@@ -105,9 +102,9 @@ public class NestedConfigurationClassTests {
ctx.refresh();
S1Config config = ctx.getBean(S1Config.class);
assertTrue(config != ctx.getBean(S1Config.class));
assertThat(config != ctx.getBean(S1Config.class)).isTrue();
TestBean tb = ctx.getBean("l0Bean", TestBean.class);
assertTrue(tb == ctx.getBean("l0Bean", TestBean.class));
assertThat(tb == ctx.getBean("l0Bean", TestBean.class)).isTrue();
ctx.getBean(L0Config.L1Config.class);
ctx.getBean("l1Bean");
@@ -118,12 +115,12 @@ 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()).isEqualTo("override-s1");
assertTrue(ob == ctx.getBean("overrideBean", TestBean.class));
assertThat(ob == ctx.getBean("overrideBean", TestBean.class)).isTrue();
TestBean pb1 = ctx.getBean("prototypeBean", TestBean.class);
TestBean pb2 = ctx.getBean("prototypeBean", TestBean.class);
assertTrue(pb1 != pb2);
assertTrue(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next());
assertThat(pb1 != pb2).isTrue();
assertThat(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next()).isTrue();
}
@Test
@@ -133,9 +130,9 @@ public class NestedConfigurationClassTests {
ctx.refresh();
S1Config config = ctx.getBean(S1Config.class);
assertTrue(config != ctx.getBean(S1Config.class));
assertThat(config != ctx.getBean(S1Config.class)).isTrue();
TestBean tb = ctx.getBean("l0Bean", TestBean.class);
assertTrue(tb == ctx.getBean("l0Bean", TestBean.class));
assertThat(tb == ctx.getBean("l0Bean", TestBean.class)).isTrue();
ctx.getBean(L0Config.L1Config.class);
ctx.getBean("l1Bean");
@@ -146,12 +143,12 @@ 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()).isEqualTo("override-s1");
assertTrue(ob == ctx.getBean("overrideBean", TestBean.class));
assertThat(ob == ctx.getBean("overrideBean", TestBean.class)).isTrue();
TestBean pb1 = ctx.getBean("prototypeBean", TestBean.class);
TestBean pb2 = ctx.getBean("prototypeBean", TestBean.class);
assertTrue(pb1 != pb2);
assertTrue(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next());
assertThat(pb1 != pb2).isTrue();
assertThat(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next()).isTrue();
}
@Test
@@ -161,9 +158,9 @@ public class NestedConfigurationClassTests {
ctx.refresh();
S1ConfigWithProxy config = ctx.getBean(S1ConfigWithProxy.class);
assertTrue(config == ctx.getBean(S1ConfigWithProxy.class));
assertThat(config == ctx.getBean(S1ConfigWithProxy.class)).isTrue();
TestBean tb = ctx.getBean("l0Bean", TestBean.class);
assertTrue(tb == ctx.getBean("l0Bean", TestBean.class));
assertThat(tb == ctx.getBean("l0Bean", TestBean.class)).isTrue();
ctx.getBean(L0Config.L1Config.class);
ctx.getBean("l1Bean");
@@ -174,12 +171,12 @@ 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()).isEqualTo("override-s1");
assertTrue(ob == ctx.getBean("overrideBean", TestBean.class));
assertThat(ob == ctx.getBean("overrideBean", TestBean.class)).isTrue();
TestBean pb1 = ctx.getBean("prototypeBean", TestBean.class);
TestBean pb2 = ctx.getBean("prototypeBean", TestBean.class);
assertTrue(pb1 != pb2);
assertTrue(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next());
assertThat(pb1 != pb2).isTrue();
assertThat(pb1.getFriends().iterator().next() != pb2.getFriends().iterator().next()).isTrue();
}
@Test
@@ -188,19 +185,19 @@ public class NestedConfigurationClassTests {
ctx.register(L0ConfigEmpty.class);
ctx.refresh();
assertFalse(ctx.getBeanFactory().containsSingleton("l0ConfigEmpty"));
assertThat(ctx.getBeanFactory().containsSingleton("l0ConfigEmpty")).isFalse();
Object l0i1 = ctx.getBean(L0ConfigEmpty.class);
Object l0i2 = ctx.getBean(L0ConfigEmpty.class);
assertTrue(l0i1 == l0i2);
assertThat(l0i1 == l0i2).isTrue();
Object l1i1 = ctx.getBean(L0ConfigEmpty.L1ConfigEmpty.class);
Object l1i2 = ctx.getBean(L0ConfigEmpty.L1ConfigEmpty.class);
assertTrue(l1i1 != l1i2);
assertThat(l1i1 != l1i2).isTrue();
Object l2i1 = ctx.getBean(L0ConfigEmpty.L1ConfigEmpty.L2ConfigEmpty.class);
Object l2i2 = ctx.getBean(L0ConfigEmpty.L1ConfigEmpty.L2ConfigEmpty.class);
assertTrue(l2i1 == l2i2);
assertNotEquals(l2i1.toString(), l2i2.toString());
assertThat(l2i1 == l2i2).isTrue();
assertThat(l2i2.toString()).isNotEqualTo(l2i1.toString());
}
@Test
@@ -209,19 +206,19 @@ public class NestedConfigurationClassTests {
ctx.register(L0ConfigConcrete.class);
ctx.refresh();
assertFalse(ctx.getBeanFactory().containsSingleton("l0ConfigConcrete"));
assertThat(ctx.getBeanFactory().containsSingleton("l0ConfigConcrete")).isFalse();
Object l0i1 = ctx.getBean(L0ConfigConcrete.class);
Object l0i2 = ctx.getBean(L0ConfigConcrete.class);
assertTrue(l0i1 == l0i2);
assertThat(l0i1 == l0i2).isTrue();
Object l1i1 = ctx.getBean(L0ConfigConcrete.L1ConfigEmpty.class);
Object l1i2 = ctx.getBean(L0ConfigConcrete.L1ConfigEmpty.class);
assertTrue(l1i1 != l1i2);
assertThat(l1i1 != l1i2).isTrue();
Object l2i1 = ctx.getBean(L0ConfigConcrete.L1ConfigEmpty.L2ConfigEmpty.class);
Object l2i2 = ctx.getBean(L0ConfigConcrete.L1ConfigEmpty.L2ConfigEmpty.class);
assertTrue(l2i1 == l2i2);
assertNotEquals(l2i1.toString(), l2i2.toString());
assertThat(l2i1 == l2i2).isTrue();
assertThat(l2i2.toString()).isNotEqualTo(l2i1.toString());
}

View File

@@ -40,7 +40,6 @@ 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.junit.Assert.assertTrue;
/**
* Tests the processing of @PropertySource annotations on @Configuration classes.
@@ -57,8 +56,7 @@ public class PropertySourceAnnotationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithExplicitName.class);
ctx.refresh();
assertTrue("property source p1 was not added",
ctx.getEnvironment().getPropertySources().contains("p1"));
assertThat(ctx.getEnvironment().getPropertySources().contains("p1")).as("property source p1 was not added").isTrue();
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
// assert that the property source was added last to the set of sources
@@ -78,8 +76,7 @@ public class PropertySourceAnnotationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithImplicitName.class);
ctx.refresh();
assertTrue("property source p1 was not added",
ctx.getEnvironment().getPropertySources().contains("class path resource [org/springframework/context/annotation/p1.properties]"));
assertThat(ctx.getEnvironment().getPropertySources().contains("class path resource [org/springframework/context/annotation/p1.properties]")).as("property source p1 was not added").isTrue();
assertThat(ctx.getBean(TestBean.class).getName()).isEqualTo("p1TestBean");
}
@@ -88,8 +85,8 @@ public class PropertySourceAnnotationTests {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(ConfigWithTestProfileBeans.class);
ctx.refresh();
assertTrue(ctx.containsBean("testBean"));
assertTrue(ctx.containsBean("testProfileBean"));
assertThat(ctx.containsBean("testBean")).isTrue();
assertThat(ctx.containsBean("testProfileBean")).isTrue();
}
/**
@@ -139,7 +136,7 @@ public class PropertySourceAnnotationTests {
ctx.refresh();
}
catch (BeanDefinitionStoreException ex) {
assertTrue(ex.getCause() instanceof IllegalArgumentException);
assertThat(ex.getCause() instanceof IllegalArgumentException).isTrue();
}
}
@@ -179,7 +176,7 @@ public class PropertySourceAnnotationTests {
ctx.refresh();
}
catch (BeanDefinitionStoreException ex) {
assertTrue(ex.getCause() instanceof IllegalArgumentException);
assertThat(ex.getCause() instanceof IllegalArgumentException).isTrue();
}
}
@@ -398,7 +395,7 @@ public class PropertySourceAnnotationTests {
public static class MyCustomFactory implements PropertySourceFactory {
@Override
public org.springframework.core.env.PropertySource createPropertySource(String name, EncodedResource resource) throws IOException {
public org.springframework.core.env.PropertySource<?> createPropertySource(String name, EncodedResource resource) throws IOException {
Properties props = PropertiesLoaderUtils.loadProperties(resource);
return new org.springframework.core.env.PropertySource<Properties>("my" + name, props) {
@Override

View File

@@ -23,7 +23,6 @@ import org.junit.Test;
import org.springframework.util.ReflectionUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
/**
* Tests ReflectionUtils methods as used against CGLIB-generated classes created
@@ -48,7 +47,7 @@ public class ReflectionUtilsIntegrationTests {
assertThat(m1MethodCount).isEqualTo(1);
for (Method method : methods) {
if (method.getName().contains("m1")) {
assertEquals(method.getReturnType(), Integer.class);
assertThat(Integer.class).isEqualTo(method.getReturnType());
}
}
}

View File

@@ -25,8 +25,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mark Fisher
@@ -42,16 +41,17 @@ public class SimpleConfigTests {
ServiceInvocationCounter serviceInvocationCounter = ctx.getBean("serviceInvocationCounter", ServiceInvocationCounter.class);
String value = fooService.foo(1);
assertEquals("bar", value);
assertThat(value).isEqualTo("bar");
Future<?> future = fooService.asyncFoo(1);
assertTrue(future instanceof FutureTask);
assertEquals("bar", future.get());
boolean condition = future instanceof FutureTask;
assertThat(condition).isTrue();
assertThat(future.get()).isEqualTo("bar");
assertEquals(2, serviceInvocationCounter.getCount());
assertThat(serviceInvocationCounter.getCount()).isEqualTo(2);
fooService.foo(1);
assertEquals(3, serviceInvocationCounter.getCount());
assertThat(serviceInvocationCounter.getCount()).isEqualTo(3);
}
public String[] getConfigLocations() {

View File

@@ -22,8 +22,7 @@ import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Mark Fisher
@@ -43,17 +42,17 @@ public class SimpleScanTests {
FooService fooService = (FooService) ctx.getBean("fooServiceImpl");
ServiceInvocationCounter serviceInvocationCounter = (ServiceInvocationCounter) ctx.getBean("serviceInvocationCounter");
assertEquals(0, serviceInvocationCounter.getCount());
assertThat(serviceInvocationCounter.getCount()).isEqualTo(0);
assertTrue(fooService.isInitCalled());
assertEquals(1, serviceInvocationCounter.getCount());
assertThat(fooService.isInitCalled()).isTrue();
assertThat(serviceInvocationCounter.getCount()).isEqualTo(1);
String value = fooService.foo(1);
assertEquals("bar", value);
assertEquals(2, serviceInvocationCounter.getCount());
assertThat(value).isEqualTo("bar");
assertThat(serviceInvocationCounter.getCount()).isEqualTo(2);
fooService.foo(1);
assertEquals(3, serviceInvocationCounter.getCount());
assertThat(serviceInvocationCounter.getCount()).isEqualTo(3);
}
}

View File

@@ -31,7 +31,7 @@ import org.springframework.core.type.AnnotatedTypeMetadata;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.util.Assert;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Dave Syer
@@ -41,13 +41,13 @@ public class Spr11202Tests {
@Test
public void testWithImporter() {
ApplicationContext context = new AnnotationConfigApplicationContext(Wrapper.class);
assertEquals("foo", context.getBean("value"));
assertThat(context.getBean("value")).isEqualTo("foo");
}
@Test
public void testWithoutImporter() {
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
assertEquals("foo", context.getBean("value"));
assertThat(context.getBean("value")).isEqualTo("foo");
}

View File

@@ -24,7 +24,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.core.annotation.Order;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
@@ -35,18 +35,18 @@ public class Spr11310Tests {
public void orderedList() {
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
StringHolder holder = context.getBean(StringHolder.class);
assertEquals("second", holder.itemsList.get(0));
assertEquals("first", holder.itemsList.get(1));
assertEquals("unknownOrder", holder.itemsList.get(2));
assertThat(holder.itemsList.get(0)).isEqualTo("second");
assertThat(holder.itemsList.get(1)).isEqualTo("first");
assertThat(holder.itemsList.get(2)).isEqualTo("unknownOrder");
}
@Test
public void orderedArray() {
ApplicationContext context = new AnnotationConfigApplicationContext(Config.class);
StringHolder holder = context.getBean(StringHolder.class);
assertEquals("second", holder.itemsArray[0]);
assertEquals("first", holder.itemsArray[1]);
assertEquals("unknownOrder", holder.itemsArray[2]);
assertThat(holder.itemsArray[0]).isEqualTo("second");
assertThat(holder.itemsArray[1]).isEqualTo("first");
assertThat(holder.itemsArray[2]).isEqualTo("unknownOrder");
}

Some files were not shown because too many files have changed in this diff Show More