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

@ -23,9 +23,8 @@ import org.junit.Test;
import org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer.AmbiguousBindingException;
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;
/**
* Unit tests for the {@link AspectJAdviceParameterNameDiscoverer} class.
@ -236,8 +235,7 @@ public class AspectJAdviceParameterNameDiscovererTests {
protected void assertParameterNames(
Method method, String pointcut, String returning, String throwing, String[] parameterNames) {
assertEquals("bad test specification, must have same number of parameter names as method arguments",
method.getParameterCount(), parameterNames.length);
assertThat(parameterNames.length).as("bad test specification, must have same number of parameter names as method arguments").isEqualTo(method.getParameterCount());
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut);
discoverer.setRaiseExceptions(true);
@ -248,16 +246,14 @@ public class AspectJAdviceParameterNameDiscovererTests {
String formattedExpectedNames = format(parameterNames);
String formattedActualNames = format(discoveredNames);
assertEquals("Expecting " + parameterNames.length + " parameter names in return set '" +
assertThat(discoveredNames.length).as("Expecting " + parameterNames.length + " parameter names in return set '" +
formattedExpectedNames + "', but found " + discoveredNames.length +
" '" + formattedActualNames + "'",
parameterNames.length, discoveredNames.length);
" '" + formattedActualNames + "'").isEqualTo(parameterNames.length);
for (int i = 0; i < discoveredNames.length; i++) {
assertNotNull("Parameter names must never be null", discoveredNames[i]);
assertEquals("Expecting parameter " + i + " to be named '" +
parameterNames[i] + "' but was '" + discoveredNames[i] + "'",
parameterNames[i], discoveredNames[i]);
assertThat(discoveredNames[i]).as("Parameter names must never be null").isNotNull();
assertThat(discoveredNames[i]).as("Expecting parameter " + i + " to be named '" +
parameterNames[i] + "' but was '" + discoveredNames[i] + "'").isEqualTo(parameterNames[i]);
}
}

View File

@ -40,9 +40,6 @@ 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.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* @author Rob Harrop
@ -81,9 +78,9 @@ public class AspectJExpressionPointcutTests {
// not currently testable in a reliable fashion
//assertDoesNotMatchStringClass(classFilter);
assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
assertThat(methodMatcher.isRuntime()).as("Should not be a runtime match").isFalse();
assertMatchesGetAge(methodMatcher);
assertFalse("Expression should match setAge() method", methodMatcher.matches(setAge, TestBean.class));
assertThat(methodMatcher.matches(setAge, TestBean.class)).as("Expression should match setAge() method").isFalse();
}
@Test
@ -99,9 +96,9 @@ public class AspectJExpressionPointcutTests {
// not currently testable in a reliable fashion
//assertDoesNotMatchStringClass(classFilter);
assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
assertThat(methodMatcher.isRuntime()).as("Should not be a runtime match").isFalse();
assertMatchesGetAge(methodMatcher);
assertTrue("Expression should match setAge(int) method", methodMatcher.matches(setAge, TestBean.class));
assertThat(methodMatcher.matches(setAge, TestBean.class)).as("Expression should match setAge(int) method").isTrue();
}
@ -128,10 +125,10 @@ public class AspectJExpressionPointcutTests {
AspectJExpressionPointcut iOtherPc = new AspectJExpressionPointcut();
iOtherPc.setExpression(matchesIOther);
assertTrue(testBeanPc.matches(TestBean.class));
assertTrue(testBeanPc.matches(getAge, TestBean.class));
assertTrue(iOtherPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class));
assertFalse(testBeanPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class));
assertThat(testBeanPc.matches(TestBean.class)).isTrue();
assertThat(testBeanPc.matches(getAge, TestBean.class)).isTrue();
assertThat(iOtherPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class)).isTrue();
assertThat(testBeanPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class)).isFalse();
}
@Test
@ -154,13 +151,13 @@ public class AspectJExpressionPointcutTests {
AspectJExpressionPointcut withinBeansPc = new AspectJExpressionPointcut();
withinBeansPc.setExpression(withinBeansPackage);
assertTrue(withinBeansPc.matches(TestBean.class));
assertTrue(withinBeansPc.matches(getAge, TestBean.class));
assertEquals(matchSubpackages, withinBeansPc.matches(DeepBean.class));
assertEquals(matchSubpackages, withinBeansPc.matches(
DeepBean.class.getMethod("aMethod", String.class), DeepBean.class));
assertFalse(withinBeansPc.matches(String.class));
assertFalse(withinBeansPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class));
assertThat(withinBeansPc.matches(TestBean.class)).isTrue();
assertThat(withinBeansPc.matches(getAge, TestBean.class)).isTrue();
assertThat(withinBeansPc.matches(DeepBean.class)).isEqualTo(matchSubpackages);
assertThat(withinBeansPc.matches(
DeepBean.class.getMethod("aMethod", String.class), DeepBean.class)).isEqualTo(matchSubpackages);
assertThat(withinBeansPc.matches(String.class)).isFalse();
assertThat(withinBeansPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class)).isFalse();
}
@Test
@ -201,12 +198,10 @@ public class AspectJExpressionPointcutTests {
// not currently testable in a reliable fashion
//assertDoesNotMatchStringClass(classFilter);
assertTrue("Should match with setSomeNumber with Double input",
methodMatcher.matches(setSomeNumber, TestBean.class, new Double(12)));
assertFalse("Should not match setSomeNumber with Integer input",
methodMatcher.matches(setSomeNumber, TestBean.class, new Integer(11)));
assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class));
assertTrue("Should be a runtime match", methodMatcher.isRuntime());
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, new Double(12))).as("Should match with setSomeNumber with Double input").isTrue();
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, new Integer(11))).as("Should not match setSomeNumber with Integer input").isFalse();
assertThat(methodMatcher.matches(getAge, TestBean.class)).as("Should not match getAge").isFalse();
assertThat(methodMatcher.isRuntime()).as("Should be a runtime match").isTrue();
}
@Test
@ -215,11 +210,11 @@ public class AspectJExpressionPointcutTests {
CallCountingInterceptor interceptor = new CallCountingInterceptor();
TestBean testBean = getAdvisedProxy(expression, interceptor);
assertEquals("Calls should be 0", 0, interceptor.getCount());
assertThat(interceptor.getCount()).as("Calls should be 0").isEqualTo(0);
testBean.getAge();
assertEquals("Calls should be 1", 1, interceptor.getCount());
assertThat(interceptor.getCount()).as("Calls should be 1").isEqualTo(1);
testBean.setAge(90);
assertEquals("Calls should still be 1", 1, interceptor.getCount());
assertThat(interceptor.getCount()).as("Calls should still be 1").isEqualTo(1);
}
@Test
@ -228,12 +223,12 @@ public class AspectJExpressionPointcutTests {
CallCountingInterceptor interceptor = new CallCountingInterceptor();
TestBean testBean = getAdvisedProxy(expression, interceptor);
assertEquals("Calls should be 0", 0, interceptor.getCount());
assertThat(interceptor.getCount()).as("Calls should be 0").isEqualTo(0);
testBean.setSomeNumber(new Double(30));
assertEquals("Calls should be 1", 1, interceptor.getCount());
assertThat(interceptor.getCount()).as("Calls should be 1").isEqualTo(1);
testBean.setSomeNumber(new Integer(90));
assertEquals("Calls should be 1", 1, interceptor.getCount());
assertThat(interceptor.getCount()).as("Calls should be 1").isEqualTo(1);
}
@Test
@ -260,11 +255,11 @@ public class AspectJExpressionPointcutTests {
}
private void assertMatchesGetAge(MethodMatcher methodMatcher) {
assertTrue("Expression should match getAge() method", methodMatcher.matches(getAge, TestBean.class));
assertThat(methodMatcher.matches(getAge, TestBean.class)).as("Expression should match getAge() method").isTrue();
}
private void assertMatchesTestBeanClass(ClassFilter classFilter) {
assertTrue("Expression should match TestBean class", classFilter.matches(TestBean.class));
assertThat(classFilter.matches(TestBean.class)).as("Expression should match TestBean class").isTrue();
}
@Test
@ -279,14 +274,14 @@ public class AspectJExpressionPointcutTests {
public void testAndSubstitution() {
Pointcut pc = getPointcut("execution(* *(..)) and args(String)");
PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
assertEquals("execution(* *(..)) && args(String)",expr.getPointcutExpression());
assertThat(expr.getPointcutExpression()).isEqualTo("execution(* *(..)) && args(String)");
}
@Test
public void testMultipleAndSubstitutions() {
Pointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)");
PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
assertEquals("execution(* *(..)) && args(String) && this(Object)",expr.getPointcutExpression());
assertThat(expr.getPointcutExpression()).isEqualTo("execution(* *(..)) && args(String) && this(Object)");
}
private Pointcut getPointcut(String expression) {

View File

@ -20,8 +20,7 @@ import org.junit.Test;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for matching of bean() pointcut designator.
@ -80,13 +79,11 @@ public class BeanNamePointcutMatchingTests {
private void assertMatch(String beanName, String pcExpression) {
assertTrue("Unexpected mismatch for bean \"" + beanName + "\" for pcExpression \"" + pcExpression + "\"",
matches(beanName, pcExpression));
assertThat(matches(beanName, pcExpression)).as("Unexpected mismatch for bean \"" + beanName + "\" for pcExpression \"" + pcExpression + "\"").isTrue();
}
private void assertMisMatch(String beanName, String pcExpression) {
assertFalse("Unexpected match for bean \"" + beanName + "\" for pcExpression \"" + pcExpression + "\"",
matches(beanName, pcExpression));
assertThat(matches(beanName, pcExpression)).as("Unexpected match for bean \"" + beanName + "\" for pcExpression \"" + pcExpression + "\"").isFalse();
}
private static boolean matches(final String beanName, String pcExpression) {

View File

@ -37,13 +37,9 @@ import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
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;
/**
* @author Rod Johnson
@ -80,21 +76,21 @@ public class MethodInvocationProceedingJoinPointTests {
@Override
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
assertTrue("Method named in toString", jp.toString().contains(method.getName()));
assertThat(jp.toString().contains(method.getName())).as("Method named in toString").isTrue();
// Ensure that these don't cause problems
jp.toShortString();
jp.toLongString();
assertSame(target, AbstractAspectJAdvice.currentJoinPoint().getTarget());
assertFalse(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget()));
assertThat(AbstractAspectJAdvice.currentJoinPoint().getTarget()).isSameAs(target);
assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget())).isFalse();
ITestBean thisProxy = (ITestBean) AbstractAspectJAdvice.currentJoinPoint().getThis();
assertTrue(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis()));
assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis())).isTrue();
assertNotSame(target, thisProxy);
assertThat(thisProxy).isNotSameAs(target);
// Check getting again doesn't cause a problem
assertSame(thisProxy, AbstractAspectJAdvice.currentJoinPoint().getThis());
assertThat(AbstractAspectJAdvice.currentJoinPoint().getThis()).isSameAs(thisProxy);
// Try reentrant call--will go through this advice.
// Be sure to increment depth to avoid infinite recursion
@ -103,29 +99,29 @@ public class MethodInvocationProceedingJoinPointTests {
thisProxy.toString();
// Change age, so this will be returned by invocation
thisProxy.setAge(newAge);
assertEquals(newAge, thisProxy.getAge());
assertThat(thisProxy.getAge()).isEqualTo(newAge);
}
assertSame(AopContext.currentProxy(), thisProxy);
assertSame(target, raw);
assertThat(thisProxy).isSameAs(AopContext.currentProxy());
assertThat(raw).isSameAs(target);
assertSame(method.getName(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getName());
assertEquals(method.getModifiers(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers());
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getName()).isSameAs(method.getName());
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers()).isEqualTo(method.getModifiers());
MethodSignature msig = (MethodSignature) AbstractAspectJAdvice.currentJoinPoint().getSignature();
assertSame("Return same MethodSignature repeatedly", msig, AbstractAspectJAdvice.currentJoinPoint().getSignature());
assertSame("Return same JoinPoint repeatedly", AbstractAspectJAdvice.currentJoinPoint(), AbstractAspectJAdvice.currentJoinPoint());
assertEquals(method.getDeclaringClass(), msig.getDeclaringType());
assertTrue(Arrays.equals(method.getParameterTypes(), msig.getParameterTypes()));
assertEquals(method.getReturnType(), msig.getReturnType());
assertTrue(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes()));
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature()).as("Return same MethodSignature repeatedly").isSameAs(msig);
assertThat(AbstractAspectJAdvice.currentJoinPoint()).as("Return same JoinPoint repeatedly").isSameAs(AbstractAspectJAdvice.currentJoinPoint());
assertThat(msig.getDeclaringType()).isEqualTo(method.getDeclaringClass());
assertThat(Arrays.equals(method.getParameterTypes(), msig.getParameterTypes())).isTrue();
assertThat(msig.getReturnType()).isEqualTo(method.getReturnType());
assertThat(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes())).isTrue();
msig.toLongString();
msig.toShortString();
}
});
ITestBean itb = (ITestBean) pf.getProxy();
// Any call will do
assertEquals("Advice reentrantly set age", newAge, itb.getAge());
assertThat(itb.getAge()).as("Advice reentrantly set age").isEqualTo(newAge);
}
@Test
@ -137,8 +133,8 @@ public class MethodInvocationProceedingJoinPointTests {
@Override
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
SourceLocation sloc = AbstractAspectJAdvice.currentJoinPoint().getSourceLocation();
assertEquals("Same source location must be returned on subsequent requests", sloc, AbstractAspectJAdvice.currentJoinPoint().getSourceLocation());
assertEquals(TestBean.class, sloc.getWithinType());
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation()).as("Same source location must be returned on subsequent requests").isEqualTo(sloc);
assertThat(sloc.getWithinType()).isEqualTo(TestBean.class);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(sloc::getLine);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(sloc::getFileName);
}
@ -157,10 +153,10 @@ public class MethodInvocationProceedingJoinPointTests {
@Override
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart();
assertEquals("Same static part must be returned on subsequent requests", staticPart, AbstractAspectJAdvice.currentJoinPoint().getStaticPart());
assertEquals(ProceedingJoinPoint.METHOD_EXECUTION, staticPart.getKind());
assertSame(AbstractAspectJAdvice.currentJoinPoint().getSignature(), staticPart.getSignature());
assertEquals(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(), staticPart.getSourceLocation());
assertThat(AbstractAspectJAdvice.currentJoinPoint().getStaticPart()).as("Same static part must be returned on subsequent requests").isEqualTo(staticPart);
assertThat(staticPart.getKind()).isEqualTo(ProceedingJoinPoint.METHOD_EXECUTION);
assertThat(staticPart.getSignature()).isSameAs(AbstractAspectJAdvice.currentJoinPoint().getSignature());
assertThat(staticPart.getSourceLocation()).isEqualTo(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation());
}
});
ITestBean itb = (ITestBean) pf.getProxy();
@ -181,13 +177,13 @@ public class MethodInvocationProceedingJoinPointTests {
JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());
assertThat(jp.getSignature().toLongString()).isEqualTo(aspectJVersionJp.getSignature().toLongString());
assertThat(jp.getSignature().toShortString()).isEqualTo(aspectJVersionJp.getSignature().toShortString());
assertThat(jp.getSignature().toString()).isEqualTo(aspectJVersionJp.getSignature().toString());
assertEquals(aspectJVersionJp.toLongString(), jp.toLongString());
assertEquals(aspectJVersionJp.toShortString(), jp.toShortString());
assertEquals(aspectJVersionJp.toString(), jp.toString());
assertThat(jp.toLongString()).isEqualTo(aspectJVersionJp.toLongString());
assertThat(jp.toShortString()).isEqualTo(aspectJVersionJp.toShortString());
assertThat(jp.toString()).isEqualTo(aspectJVersionJp.toString());
}
});
ITestBean itb = (ITestBean) pf.getProxy();

View File

@ -29,8 +29,7 @@ import test.annotation.transaction.Tx;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Java 5 specific {@link AspectJExpressionPointcutTests}.
@ -66,12 +65,12 @@ public class TigerAspectJExpressionPointcutTests {
//assertFalse(ajexp.matches(TestBean.class));
Method takesGenericList = methodsOnHasGeneric.get("setFriends");
assertTrue(ajexp.matches(takesGenericList, HasGeneric.class));
assertTrue(ajexp.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class));
assertFalse(ajexp.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class));
assertFalse(ajexp.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class));
assertThat(ajexp.matches(takesGenericList, HasGeneric.class)).isTrue();
assertThat(ajexp.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class)).isTrue();
assertThat(ajexp.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class)).isFalse();
assertThat(ajexp.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class)).isFalse();
assertFalse(ajexp.matches(getAge, TestBean.class));
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
}
@Test
@ -88,16 +87,16 @@ public class TigerAspectJExpressionPointcutTests {
AspectJExpressionPointcut jdbcVarArgs = new AspectJExpressionPointcut();
jdbcVarArgs.setExpression(expression);
assertTrue(jdbcVarArgs.matches(
assertThat(jdbcVarArgs.matches(
MyTemplate.class.getMethod("queryForInt", String.class, Object[].class),
MyTemplate.class));
MyTemplate.class)).isTrue();
Method takesGenericList = methodsOnHasGeneric.get("setFriends");
assertFalse(jdbcVarArgs.matches(takesGenericList, HasGeneric.class));
assertFalse(jdbcVarArgs.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class));
assertFalse(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class));
assertFalse(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class));
assertFalse(jdbcVarArgs.matches(getAge, TestBean.class));
assertThat(jdbcVarArgs.matches(takesGenericList, HasGeneric.class)).isFalse();
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class)).isFalse();
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class)).isFalse();
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class)).isFalse();
assertThat(jdbcVarArgs.matches(getAge, TestBean.class)).isFalse();
}
@Test
@ -116,12 +115,12 @@ public class TigerAspectJExpressionPointcutTests {
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws Exception {
String expression = "within(@(test.annotation..*) *)";
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression);
assertFalse(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class));
assertTrue(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class));
assertThat(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class)).isFalse();
assertThat(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class)).isTrue();
expression = "within(@(test.annotation.transaction..*) *)";
AspectJExpressionPointcut springTxAnnotatedPc = testMatchAnnotationOnClass(expression);
assertFalse(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class));
assertThat(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class)).isFalse();
}
@Test
@ -134,11 +133,11 @@ public class TigerAspectJExpressionPointcutTests {
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(expression);
assertFalse(ajexp.matches(getAge, TestBean.class));
assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
assertTrue(ajexp.matches(BeanB.class.getMethod("setName", String.class), BeanB.class));
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isTrue();
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isTrue();
assertThat(ajexp.matches(BeanB.class.getMethod("setName", String.class), BeanB.class)).isTrue();
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
return ajexp;
}
@ -148,12 +147,12 @@ public class TigerAspectJExpressionPointcutTests {
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
ajexp.setExpression(expression);
assertFalse(ajexp.matches(getAge, TestBean.class));
assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
assertTrue(ajexp.matches(BeanA.class.getMethod("getAge"), BeanA.class));
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
assertThat(ajexp.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isTrue();
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
}
@Test
@ -165,7 +164,7 @@ public class TigerAspectJExpressionPointcutTests {
ProxyFactory factory = new ProxyFactory(new BeanA());
factory.setProxyTargetClass(true);
BeanA proxy = (BeanA) factory.getProxy();
assertTrue(ajexp.matches(BeanA.class.getMethod("getAge"), proxy.getClass()));
assertThat(ajexp.matches(BeanA.class.getMethod("getAge"), proxy.getClass())).isTrue();
}
@Test
@ -177,7 +176,7 @@ public class TigerAspectJExpressionPointcutTests {
ProxyFactory factory = new ProxyFactory(new BeanA());
factory.setProxyTargetClass(false);
IBeanA proxy = (IBeanA) factory.getProxy();
assertTrue(ajexp.matches(IBeanA.class.getMethod("getAge"), proxy.getClass()));
assertThat(ajexp.matches(IBeanA.class.getMethod("getAge"), proxy.getClass())).isTrue();
}
@Test
@ -186,14 +185,14 @@ public class TigerAspectJExpressionPointcutTests {
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut();
anySpringMethodAnnotation.setExpression(expression);
assertFalse(anySpringMethodAnnotation.matches(getAge, TestBean.class));
assertFalse(anySpringMethodAnnotation.matches(
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
assertFalse(anySpringMethodAnnotation.matches(
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
assertTrue(anySpringMethodAnnotation.matches(BeanA.class.getMethod("getAge"), BeanA.class));
assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
assertThat(anySpringMethodAnnotation.matches(getAge, TestBean.class)).isFalse();
assertThat(anySpringMethodAnnotation.matches(
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
assertThat(anySpringMethodAnnotation.matches(
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isTrue();
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
}
@Test
@ -202,28 +201,27 @@ public class TigerAspectJExpressionPointcutTests {
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
takesSpringAnnotatedArgument2.setExpression(expression);
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
assertFalse(takesSpringAnnotatedArgument2.matches(
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
assertFalse(takesSpringAnnotatedArgument2.matches(
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class));
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
assertThat(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
assertTrue(takesSpringAnnotatedArgument2.matches(
assertThat(takesSpringAnnotatedArgument2.matches(
ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class),
ProcessesSpringAnnotatedParameters.class));
ProcessesSpringAnnotatedParameters.class)).isTrue();
// True because it maybeMatches with potential argument subtypes
assertTrue(takesSpringAnnotatedArgument2.matches(
assertThat(takesSpringAnnotatedArgument2.matches(
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
ProcessesSpringAnnotatedParameters.class));
ProcessesSpringAnnotatedParameters.class)).isTrue();
assertFalse(takesSpringAnnotatedArgument2.matches(
assertThat(takesSpringAnnotatedArgument2.matches(
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
ProcessesSpringAnnotatedParameters.class, new TestBean(), new BeanA())
);
ProcessesSpringAnnotatedParameters.class, new TestBean(), new BeanA())).isFalse();
}
@Test
@ -232,21 +230,21 @@ public class TigerAspectJExpressionPointcutTests {
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
takesSpringAnnotatedArgument2.setExpression(expression);
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
assertFalse(takesSpringAnnotatedArgument2.matches(
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
assertFalse(takesSpringAnnotatedArgument2.matches(
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class));
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
assertThat(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
assertTrue(takesSpringAnnotatedArgument2.matches(
assertThat(takesSpringAnnotatedArgument2.matches(
ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class),
ProcessesSpringAnnotatedParameters.class));
assertFalse(takesSpringAnnotatedArgument2.matches(
ProcessesSpringAnnotatedParameters.class)).isTrue();
assertThat(takesSpringAnnotatedArgument2.matches(
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
ProcessesSpringAnnotatedParameters.class));
ProcessesSpringAnnotatedParameters.class)).isFalse();
}
@ -301,6 +299,7 @@ public class TigerAspectJExpressionPointcutTests {
static class BeanA implements IBeanA {
@SuppressWarnings("unused")
private String name;
private int age;
@ -320,6 +319,7 @@ public class TigerAspectJExpressionPointcutTests {
@Tx
static class BeanB {
@SuppressWarnings("unused")
private String name;
public void setName(String name) {

View File

@ -34,8 +34,8 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.core.OverridingClassLoader;
import org.springframework.lang.Nullable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
/**
* @author Dave Syer
@ -111,10 +111,10 @@ public class TrickyAspectJPointcutExpressionTests {
factory.addAdvisor(advisor);
TestService bean = (TestService) factory.getProxy();
assertEquals(0, logAdvice.getCountThrows());
assertThat(logAdvice.getCountThrows()).isEqualTo(0);
assertThatExceptionOfType(TestException.class).isThrownBy(
bean::sayHello).withMessageContaining(message);
assertEquals(1, logAdvice.getCountThrows());
assertThat(logAdvice.getCountThrows()).isEqualTo(1);
}

View File

@ -26,10 +26,9 @@ import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.tests.sample.beans.subpkg.DeepBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for the {@link TypePatternClassFilter} class.
@ -50,36 +49,36 @@ public class TypePatternClassFilterTests {
@Test
public void testValidPatternMatching() {
TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.*");
assertTrue("Must match: in package", tpcf.matches(TestBean.class));
assertTrue("Must match: in package", tpcf.matches(ITestBean.class));
assertTrue("Must match: in package", tpcf.matches(IOther.class));
assertFalse("Must be excluded: in wrong package", tpcf.matches(DeepBean.class));
assertFalse("Must be excluded: in wrong package", tpcf.matches(BeanFactory.class));
assertFalse("Must be excluded: in wrong package", tpcf.matches(DefaultListableBeanFactory.class));
assertThat(tpcf.matches(TestBean.class)).as("Must match: in package").isTrue();
assertThat(tpcf.matches(ITestBean.class)).as("Must match: in package").isTrue();
assertThat(tpcf.matches(IOther.class)).as("Must match: in package").isTrue();
assertThat(tpcf.matches(DeepBean.class)).as("Must be excluded: in wrong package").isFalse();
assertThat(tpcf.matches(BeanFactory.class)).as("Must be excluded: in wrong package").isFalse();
assertThat(tpcf.matches(DefaultListableBeanFactory.class)).as("Must be excluded: in wrong package").isFalse();
}
@Test
public void testSubclassMatching() {
TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.ITestBean+");
assertTrue("Must match: in package", tpcf.matches(TestBean.class));
assertTrue("Must match: in package", tpcf.matches(ITestBean.class));
assertTrue("Must match: in package", tpcf.matches(CountingTestBean.class));
assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class));
assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class));
assertThat(tpcf.matches(TestBean.class)).as("Must match: in package").isTrue();
assertThat(tpcf.matches(ITestBean.class)).as("Must match: in package").isTrue();
assertThat(tpcf.matches(CountingTestBean.class)).as("Must match: in package").isTrue();
assertThat(tpcf.matches(IOther.class)).as("Must be excluded: not subclass").isFalse();
assertThat(tpcf.matches(DefaultListableBeanFactory.class)).as("Must be excluded: not subclass").isFalse();
}
@Test
public void testAndOrNotReplacement() {
TypePatternClassFilter tpcf = new TypePatternClassFilter("java.lang.Object or java.lang.String");
assertFalse("matches Number",tpcf.matches(Number.class));
assertTrue("matches Object",tpcf.matches(Object.class));
assertTrue("matchesString",tpcf.matches(String.class));
assertThat(tpcf.matches(Number.class)).as("matches Number").isFalse();
assertThat(tpcf.matches(Object.class)).as("matches Object").isTrue();
assertThat(tpcf.matches(String.class)).as("matchesString").isTrue();
tpcf = new TypePatternClassFilter("java.lang.Number+ and java.lang.Float");
assertTrue("matches Float",tpcf.matches(Float.class));
assertFalse("matches Double",tpcf.matches(Double.class));
assertThat(tpcf.matches(Float.class)).as("matches Float").isTrue();
assertThat(tpcf.matches(Double.class)).as("matches Double").isFalse();
tpcf = new TypePatternClassFilter("java.lang.Number+ and not java.lang.Float");
assertFalse("matches Float",tpcf.matches(Float.class));
assertTrue("matches Double",tpcf.matches(Double.class));
assertThat(tpcf.matches(Float.class)).as("matches Float").isFalse();
assertThat(tpcf.matches(Double.class)).as("matches Double").isTrue();
}
@Test

View File

@ -62,10 +62,6 @@ 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.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
/**
* Abstract tests for AspectJAdvisorFactory.
@ -108,28 +104,28 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
TestBean itb = (TestBean) createProxy(target,
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean")),
TestBean.class);
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
assertThat(itb.getAge()).as("Around advice must NOT apply").isEqualTo(realAge);
Advised advised = (Advised) itb;
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
assertThat(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[3];
LazySingletonAspectInstanceFactoryDecorator maaif =
(LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
assertFalse(maaif.isMaterialized());
assertThat(maaif.isMaterialized()).isFalse();
// Check that the perclause pointcut is valid
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
assertThat(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
assertThat(imapa.getPointcut()).isNotSameAs(imapa.getDeclaredPointcut());
// Hit the method in the per clause to instantiate the aspect
itb.getSpouse();
assertTrue(maaif.isMaterialized());
assertThat(maaif.isMaterialized()).isTrue();
assertEquals("Around advice must apply", 0, itb.getAge());
assertEquals("Around advice must apply", 1, itb.getAge());
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(0);
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(1);
}
@Test
@ -151,13 +147,13 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
Collections.sort(advisors, new OrderComparator());
TestBean itb = (TestBean) createProxy(target, advisors, TestBean.class);
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
assertThat(itb.getAge()).as("Around advice must NOT apply").isEqualTo(realAge);
// Hit the method in the per clause to instantiate the aspect
itb.getSpouse();
assertEquals("Around advice must apply", 0, itb.getAge());
assertEquals("Around advice must apply", 1, itb.getAge());
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(0);
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(1);
}
@Test
@ -177,13 +173,13 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
Collections.sort(advisors, new OrderComparator());
TestBean itb = (TestBean) createProxy(target, advisors, TestBean.class);
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
assertThat(itb.getAge()).as("Around advice must NOT apply").isEqualTo(realAge);
// Hit the method in the per clause to instantiate the aspect
itb.getSpouse();
assertEquals("Around advice must apply", 0, itb.getAge());
assertEquals("Around advice must apply", 1, itb.getAge());
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(0);
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(1);
}
@Test
@ -194,32 +190,32 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
TestBean itb = (TestBean) createProxy(target,
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerThisAspect(), "someBean")),
TestBean.class);
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
assertThat(itb.getAge()).as("Around advice must NOT apply").isEqualTo(realAge);
Advised advised = (Advised) itb;
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
assertEquals(4, advised.getAdvisors().length);
assertThat(advised.getAdvisors().length).isEqualTo(4);
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
assertThat(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
LazySingletonAspectInstanceFactoryDecorator maaif =
(LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
assertFalse(maaif.isMaterialized());
assertThat(maaif.isMaterialized()).isFalse();
// Check that the perclause pointcut is valid
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
assertThat(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
assertThat(imapa.getPointcut()).isNotSameAs(imapa.getDeclaredPointcut());
// Hit the method in the per clause to instantiate the aspect
itb.getSpouse();
assertTrue(maaif.isMaterialized());
assertThat(maaif.isMaterialized()).isTrue();
assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null));
assertThat(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null)).isTrue();
assertEquals("Around advice must apply", 0, itb.getAge());
assertEquals("Around advice must apply", 1, itb.getAge());
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(0);
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(1);
}
@Test
@ -229,38 +225,38 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
target.setAge(realAge);
PerTypeWithinAspectInstanceFactory aif = new PerTypeWithinAspectInstanceFactory();
TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.class);
assertEquals("No method calls", 0, aif.getInstantiationCount());
assertEquals("Around advice must now apply", 0, itb.getAge());
assertThat(aif.getInstantiationCount()).as("No method calls").isEqualTo(0);
assertThat(itb.getAge()).as("Around advice must now apply").isEqualTo(0);
Advised advised = (Advised) itb;
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
assertEquals(4, advised.getAdvisors().length);
assertThat(advised.getAdvisors().length).isEqualTo(4);
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
assertThat(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
LazySingletonAspectInstanceFactoryDecorator maaif =
(LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
assertTrue(maaif.isMaterialized());
assertThat(maaif.isMaterialized()).isTrue();
// Check that the perclause pointcut is valid
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
assertThat(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
assertThat(imapa.getPointcut()).isNotSameAs(imapa.getDeclaredPointcut());
// Hit the method in the per clause to instantiate the aspect
itb.getSpouse();
assertTrue(maaif.isMaterialized());
assertThat(maaif.isMaterialized()).isTrue();
assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null));
assertThat(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null)).isTrue();
assertEquals("Around advice must still apply", 1, itb.getAge());
assertEquals("Around advice must still apply", 2, itb.getAge());
assertThat(itb.getAge()).as("Around advice must still apply").isEqualTo(1);
assertThat(itb.getAge()).as("Around advice must still apply").isEqualTo(2);
TestBean itb2 = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.class);
assertEquals(1, aif.getInstantiationCount());
assertEquals("Around advice be independent for second instance", 0, itb2.getAge());
assertEquals(2, aif.getInstantiationCount());
assertThat(aif.getInstantiationCount()).isEqualTo(1);
assertThat(itb2.getAge()).as("Around advice be independent for second instance").isEqualTo(0);
assertThat(aif.getInstantiationCount()).isEqualTo(2);
}
@Test
@ -286,8 +282,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
new NamedPointcutAspectFromLibraryWithBinding(), "someBean")),
ITestBean.class);
itb.setAge(10);
assertEquals("Around advice must apply", 20, itb.getAge());
assertEquals(20,target.getAge());
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(20);
assertThat(target.getAge()).isEqualTo(20);
}
private void testNamedPointcuts(Object aspectInstance) {
@ -297,8 +293,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
ITestBean itb = (ITestBean) createProxy(target,
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspectInstance, "someBean")),
ITestBean.class);
assertEquals("Around advice must apply", -1, itb.getAge());
assertEquals(realAge, target.getAge());
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(-1);
assertThat(target.getAge()).isEqualTo(realAge);
}
@Test
@ -309,8 +305,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
new SingletonMetadataAwareAspectInstanceFactory(new BindingAspectWithSingleArg(), "someBean")),
ITestBean.class);
itb.setAge(10);
assertEquals("Around advice must apply", 20, itb.getAge());
assertEquals(20,target.getAge());
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(20);
assertThat(target.getAge()).isEqualTo(20);
}
@Test
@ -327,7 +323,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
String d = "d";
StringBuffer e = new StringBuffer("stringbuf");
String expectedResult = a + b+ c + d + e;
assertEquals(expectedResult, mva.mungeArgs(a, b, c, d, e));
assertThat(mva.mungeArgs(a, b, c, d, e)).isEqualTo(expectedResult);
}
/**
@ -336,40 +332,40 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
@Test
public void testIntroductionOnTargetNotImplementingInterface() {
NotLockable notLockableTarget = new NotLockable();
assertFalse(notLockableTarget instanceof Lockable);
assertThat(notLockableTarget instanceof Lockable).isFalse();
NotLockable notLockable1 = (NotLockable) createProxy(notLockableTarget,
getFixture().getAdvisors(
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
NotLockable.class);
assertTrue(notLockable1 instanceof Lockable);
assertThat(notLockable1 instanceof Lockable).isTrue();
Lockable lockable = (Lockable) notLockable1;
assertFalse(lockable.locked());
assertThat(lockable.locked()).isFalse();
lockable.lock();
assertTrue(lockable.locked());
assertThat(lockable.locked()).isTrue();
NotLockable notLockable2Target = new NotLockable();
NotLockable notLockable2 = (NotLockable) createProxy(notLockable2Target,
getFixture().getAdvisors(
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
NotLockable.class);
assertTrue(notLockable2 instanceof Lockable);
assertThat(notLockable2 instanceof Lockable).isTrue();
Lockable lockable2 = (Lockable) notLockable2;
assertFalse(lockable2.locked());
assertThat(lockable2.locked()).isFalse();
notLockable2.setIntValue(1);
lockable2.lock();
assertThatIllegalStateException().isThrownBy(() ->
notLockable2.setIntValue(32));
assertTrue(lockable2.locked());
assertThat(lockable2.locked()).isTrue();
}
@Test
public void testIntroductionAdvisorExcludedFromTargetImplementingInterface() {
assertTrue(AopUtils.findAdvisorsThatCanApply(
getFixture().getAdvisors(
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
CannotBeUnlocked.class).isEmpty());
assertEquals(2, AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors(
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size());
assertThat(AopUtils.findAdvisorsThatCanApply(
getFixture().getAdvisors(
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
CannotBeUnlocked.class).isEmpty()).isTrue();
assertThat(AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors(
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size()).isEqualTo(2);
}
@Test
@ -385,9 +381,9 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
CannotBeUnlocked.class);
assertThat(proxy).isInstanceOf(Lockable.class);
Lockable lockable = proxy;
assertTrue("Already locked", lockable.locked());
assertThat(lockable.locked()).as("Already locked").isTrue();
lockable.lock();
assertTrue("Real target ignores locking", lockable.locked());
assertThat(lockable.locked()).as("Real target ignores locking").isTrue();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
lockable.unlock());
}
@ -401,7 +397,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
List.class
),
List.class);
assertFalse("Type pattern must have excluded mixin", proxy instanceof Lockable);
assertThat(proxy instanceof Lockable).as("Type pattern must have excluded mixin").isFalse();
}
@Test
@ -411,7 +407,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
new SingletonMetadataAwareAspectInstanceFactory(new MakeAnnotatedTypeModifiable(), "someBean"));
Object proxy = createProxy(target, advisors, AnnotatedTarget.class);
System.out.println(advisors.get(1));
assertTrue(proxy instanceof Lockable);
assertThat(proxy instanceof Lockable).isTrue();
Lockable lockable = (Lockable)proxy;
lockable.locked();
}
@ -430,22 +426,22 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
Modifiable modifiable = (Modifiable) createProxy(target, advisors, ITestBean.class);
assertThat(modifiable).isInstanceOf(Modifiable.class);
Lockable lockable = (Lockable) modifiable;
assertFalse(lockable.locked());
assertThat(lockable.locked()).isFalse();
ITestBean itb = (ITestBean) modifiable;
assertFalse(modifiable.isModified());
assertThat(modifiable.isModified()).isFalse();
int oldAge = itb.getAge();
itb.setAge(oldAge + 1);
assertTrue(modifiable.isModified());
assertThat(modifiable.isModified()).isTrue();
modifiable.acceptChanges();
assertFalse(modifiable.isModified());
assertThat(modifiable.isModified()).isFalse();
itb.setAge(itb.getAge());
assertFalse("Setting same value does not modify", modifiable.isModified());
assertThat(modifiable.isModified()).as("Setting same value does not modify").isFalse();
itb.setName("And now for something completely different");
assertTrue(modifiable.isModified());
assertThat(modifiable.isModified()).isTrue();
lockable.lock();
assertTrue(lockable.locked());
assertThat(lockable.locked()).isTrue();
assertThatIllegalStateException().as("Should be locked").isThrownBy(() ->
itb.setName("Else"));
lockable.unlock();
@ -458,7 +454,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
UnsupportedOperationException expectedException = new UnsupportedOperationException();
List<Advisor> advisors = getFixture().getAdvisors(
new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException), "someBean"));
assertEquals("One advice method was found", 1, advisors.size());
assertThat(advisors.size()).as("One advice method was found").isEqualTo(1);
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(
itb::getAge);
@ -472,7 +468,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
RemoteException expectedException = new RemoteException();
List<Advisor> advisors = getFixture().getAdvisors(
new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException), "someBean"));
assertEquals("One advice method was found", 1, advisors.size());
assertThat(advisors.size()).as("One advice method was found").isEqualTo(1);
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
assertThatExceptionOfType(UndeclaredThrowableException.class).isThrownBy(
itb::getAge).withCause(expectedException);
@ -501,13 +497,13 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect();
List<Advisor> advisors = getFixture().getAdvisors(
new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect, "someBean"));
assertEquals("Two advice methods found", 2, advisors.size());
assertThat(advisors.size()).as("Two advice methods found").isEqualTo(2);
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
itb.setName("");
assertEquals(0, itb.getAge());
assertThat(itb.getAge()).isEqualTo(0);
int newAge = 32;
itb.setAge(newAge);
assertEquals(1, itb.getAge());
assertThat(itb.getAge()).isEqualTo(1);
}
@Test
@ -517,15 +513,15 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
List<Advisor> advisors = getFixture().getAdvisors(
new SingletonMetadataAwareAspectInstanceFactory(afterReturningAspect, "someBean"));
Echo echo = (Echo) createProxy(target, advisors, Echo.class);
assertEquals(0, afterReturningAspect.successCount);
assertEquals("", echo.echo(""));
assertEquals(1, afterReturningAspect.successCount);
assertEquals(0, afterReturningAspect.failureCount);
assertThat(afterReturningAspect.successCount).isEqualTo(0);
assertThat(echo.echo("")).isEqualTo("");
assertThat(afterReturningAspect.successCount).isEqualTo(1);
assertThat(afterReturningAspect.failureCount).isEqualTo(0);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() ->
echo.echo(new FileNotFoundException()));
assertEquals(1, afterReturningAspect.successCount);
assertEquals(1, afterReturningAspect.failureCount);
assertEquals(afterReturningAspect.failureCount + afterReturningAspect.successCount, afterReturningAspect.afterCount);
assertThat(afterReturningAspect.successCount).isEqualTo(1);
assertThat(afterReturningAspect.failureCount).isEqualTo(1);
assertThat(afterReturningAspect.afterCount).isEqualTo(afterReturningAspect.failureCount + afterReturningAspect.successCount);
}
@Test
@ -651,6 +647,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
@Aspect
public static class NamedPointcutAspectWithFQN {
@SuppressWarnings("unused")
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean();
@Pointcut("execution(* getAge())")
@ -739,7 +736,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
@Around(value="execution(String mungeArgs(..)) && args(a, b, c, d, e)", argNames="b,c,d,e,a")
public String reverseAdvice(ProceedingJoinPoint pjp, int b, int c, String d, StringBuffer e, String a) throws Throwable {
assertEquals(a + b+ c+ d+ e, pjp.proceed());
assertThat(pjp.proceed()).isEqualTo(a + b+ c+ d+ e);
return a + b + c + d + e;
}
}
@ -1053,6 +1050,7 @@ class PerThisAspect {
public int count;
// Just to check that this doesn't cause problems with introduction processing
@SuppressWarnings("unused")
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean();
@Around("execution(int *.getAge())")

View File

@ -30,9 +30,9 @@ import org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer;
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.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.junit.Assert.assertEquals;
/**
* @author Adrian Colyer
@ -71,8 +71,8 @@ public class ArgumentBindingTests {
Method methodUsedForParameterTypeDiscovery =
getClass().getMethod("methodWithOneParam", String.class);
String[] pnames = discoverer.getParameterNames(methodUsedForParameterTypeDiscovery);
assertEquals("one parameter name", 1, pnames.length);
assertEquals("formal", pnames[0]);
assertThat(pnames.length).as("one parameter name").isEqualTo(1);
assertThat(pnames[0]).isEqualTo("formal");
}

View File

@ -25,11 +25,8 @@ import org.springframework.aop.aspectj.AspectJExpressionPointcutTests;
import org.springframework.aop.framework.AopConfigException;
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.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @author Rod Johnson
@ -50,8 +47,8 @@ public class AspectJPointcutAdvisorTests {
new SingletonMetadataAwareAspectInstanceFactory(new AbstractAspectJAdvisorFactoryTests.ExceptionAspect(null), "someBean"),
1, "someBean");
assertSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
assertFalse(ajpa.isPerInstance());
assertThat(ajpa.getAspectMetadata().getPerClausePointcut()).isSameAs(Pointcut.TRUE);
assertThat(ajpa.isPerInstance()).isFalse();
}
@Test
@ -64,16 +61,17 @@ public class AspectJPointcutAdvisorTests {
new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean"),
1, "someBean");
assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut);
assertTrue(ajpa.isPerInstance());
assertThat(ajpa.getAspectMetadata().getPerClausePointcut()).isNotSameAs(Pointcut.TRUE);
boolean condition = ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut;
assertThat(condition).isTrue();
assertThat(ajpa.isPerInstance()).isTrue();
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class));
assertFalse(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
TestBean.class.getMethod("getAge"), TestBean.class));
assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class)).isTrue();
assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
TestBean.class.getMethod("getAge"), TestBean.class)).isFalse();
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
TestBean.class.getMethod("getSpouse"), TestBean.class));
assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
TestBean.class.getMethod("getSpouse"), TestBean.class)).isTrue();
}
@Test

View File

@ -23,12 +23,8 @@ import test.aop.PerTargetAspect;
import org.springframework.aop.Pointcut;
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionAspect;
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.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* @since 2.0
@ -46,24 +42,24 @@ public class AspectMetadataTests {
@Test
public void testSingletonAspect() {
AspectMetadata am = new AspectMetadata(ExceptionAspect.class,"someBean");
assertFalse(am.isPerThisOrPerTarget());
assertSame(Pointcut.TRUE, am.getPerClausePointcut());
assertEquals(PerClauseKind.SINGLETON, am.getAjType().getPerClause().getKind());
assertThat(am.isPerThisOrPerTarget()).isFalse();
assertThat(am.getPerClausePointcut()).isSameAs(Pointcut.TRUE);
assertThat(am.getAjType().getPerClause().getKind()).isEqualTo(PerClauseKind.SINGLETON);
}
@Test
public void testPerTargetAspect() {
AspectMetadata am = new AspectMetadata(PerTargetAspect.class,"someBean");
assertTrue(am.isPerThisOrPerTarget());
assertNotSame(Pointcut.TRUE, am.getPerClausePointcut());
assertEquals(PerClauseKind.PERTARGET, am.getAjType().getPerClause().getKind());
assertThat(am.isPerThisOrPerTarget()).isTrue();
assertThat(am.getPerClausePointcut()).isNotSameAs(Pointcut.TRUE);
assertThat(am.getAjType().getPerClause().getKind()).isEqualTo(PerClauseKind.PERTARGET);
}
@Test
public void testPerThisAspect() {
AspectMetadata am = new AspectMetadata(PerThisAspect.class,"someBean");
assertTrue(am.isPerThisOrPerTarget());
assertNotSame(Pointcut.TRUE, am.getPerClausePointcut());
assertEquals(PerClauseKind.PERTHIS, am.getAjType().getPerClause().getKind());
assertThat(am.isPerThisOrPerTarget()).isTrue();
assertThat(am.getPerClausePointcut()).isNotSameAs(Pointcut.TRUE);
assertThat(am.getAjType().getPerClause().getKind()).isEqualTo(PerClauseKind.PERTHIS);
}
}

View File

@ -28,9 +28,8 @@ import test.aop.PerThisAspect;
import org.springframework.util.SerializationTestUtils;
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.assertTrue;
/**
* @author Rob Harrop
@ -53,7 +52,7 @@ public class AspectProxyFactoryTests {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(bean);
proxyFactory.addAspect(MultiplyReturnValue.class);
ITestBean proxy = proxyFactory.getProxy();
assertEquals("Multiplication did not occur", bean.getAge() * 2, proxy.getAge());
assertThat(proxy.getAge()).as("Multiplication did not occur").isEqualTo((bean.getAge() * 2));
}
@Test
@ -70,10 +69,10 @@ public class AspectProxyFactoryTests {
ITestBean proxy1 = pf1.getProxy();
ITestBean proxy2 = pf2.getProxy();
assertEquals(0, proxy1.getAge());
assertEquals(1, proxy1.getAge());
assertEquals(0, proxy2.getAge());
assertEquals(2, proxy1.getAge());
assertThat(proxy1.getAge()).isEqualTo(0);
assertThat(proxy1.getAge()).isEqualTo(1);
assertThat(proxy2.getAge()).isEqualTo(0);
assertThat(proxy1.getAge()).isEqualTo(2);
}
@Test
@ -84,18 +83,16 @@ public class AspectProxyFactoryTests {
}
@Test
@SuppressWarnings("unchecked")
public void testSerializable() throws Exception {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
proxyFactory.addAspect(LoggingAspectOnVarargs.class);
ITestBean proxy = proxyFactory.getProxy();
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
assertThat(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
ITestBean tb = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
assertTrue(tb.doWithVarargs(MyEnum.A, MyOtherEnum.C));
assertThat(tb.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
}
@Test
@SuppressWarnings("unchecked")
public void testWithInstance() throws Exception {
MultiplyReturnValue aspect = new MultiplyReturnValue();
int multiple = 3;
@ -108,10 +105,10 @@ public class AspectProxyFactoryTests {
proxyFactory.addAspect(aspect);
ITestBean proxy = proxyFactory.getProxy();
assertEquals(target.getAge() * multiple, proxy.getAge());
assertThat(proxy.getAge()).isEqualTo((target.getAge() * multiple));
ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
assertEquals(target.getAge() * multiple, serializedProxy.getAge());
assertThat(serializedProxy.getAge()).isEqualTo((target.getAge() * multiple));
}
@Test
@ -122,21 +119,19 @@ public class AspectProxyFactoryTests {
}
@Test // SPR-13328
@SuppressWarnings("unchecked")
public void testProxiedVarargsWithEnumArray() throws Exception {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
proxyFactory.addAspect(LoggingAspectOnVarargs.class);
ITestBean proxy = proxyFactory.getProxy();
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
assertThat(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
}
@Test // SPR-13328
@SuppressWarnings("unchecked")
public void testUnproxiedVarargsWithEnumArray() throws Exception {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
proxyFactory.addAspect(LoggingAspectOnSetter.class);
ITestBean proxy = proxyFactory.getProxy();
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
assertThat(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
}

View File

@ -31,7 +31,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.beans.factory.xml.XmlReaderContext;
import org.springframework.tests.beans.CollectingReaderEventListener;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Harrop
@ -58,49 +58,46 @@ public class AspectJNamespaceHandlerTests {
@Test
public void testRegisterAutoProxyCreator() throws Exception {
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null);
assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount());
assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1);
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount());
assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1);
}
@Test
public void testRegisterAspectJAutoProxyCreator() throws Exception {
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount());
assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1);
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount());
assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1);
BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
assertEquals("Incorrect APC class",
AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName());
assertThat(definition.getBeanClassName()).as("Incorrect APC class").isEqualTo(AspectJAwareAdvisorAutoProxyCreator.class.getName());
}
@Test
public void testRegisterAspectJAutoProxyCreatorWithExistingAutoProxyCreator() throws Exception {
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null);
assertEquals(1, registry.getBeanDefinitionCount());
assertThat(registry.getBeanDefinitionCount()).isEqualTo(1);
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
assertEquals("Incorrect definition count", 1, registry.getBeanDefinitionCount());
assertThat(registry.getBeanDefinitionCount()).as("Incorrect definition count").isEqualTo(1);
BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
assertEquals("APC class not switched",
AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName());
assertThat(definition.getBeanClassName()).as("APC class not switched").isEqualTo(AspectJAwareAdvisorAutoProxyCreator.class.getName());
}
@Test
public void testRegisterAutoProxyCreatorWhenAspectJAutoProxyCreatorAlreadyExists() throws Exception {
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
assertEquals(1, registry.getBeanDefinitionCount());
assertThat(registry.getBeanDefinitionCount()).isEqualTo(1);
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null);
assertEquals("Incorrect definition count", 1, registry.getBeanDefinitionCount());
assertThat(registry.getBeanDefinitionCount()).as("Incorrect definition count").isEqualTo(1);
BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
assertEquals("Incorrect APC class",
AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName());
assertThat(definition.getBeanClassName()).as("Incorrect APC class").isEqualTo(AspectJAwareAdvisorAutoProxyCreator.class.getName());
}
}

View File

@ -35,7 +35,7 @@ import org.springframework.aop.aspectj.AspectJPointcutAdvisor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.lang.Nullable;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Adrian Colyer
@ -69,95 +69,95 @@ public class AspectJPrecedenceComparatorTests {
public void testSameAspectNoAfterAdvice() {
Advisor advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
assertEquals("advisor2 sorted before advisor1", 1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor2 sorted before advisor1").isEqualTo(1);
}
@Test
public void testSameAspectAfterAdvice() {
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
assertEquals("advisor2 sorted before advisor1", 1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor2 sorted before advisor1").isEqualTo(1);
advisor1 = createAspectJAfterReturningAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
advisor2 = createAspectJAfterThrowingAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
}
@Test
public void testSameAspectOneOfEach() {
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
assertEquals("advisor1 and advisor2 not comparable", 1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 and advisor2 not comparable").isEqualTo(1);
}
@Test
public void testSameAdvisorPrecedenceDifferentAspectNoAfterAdvice() {
Advisor advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0);
advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0);
}
@Test
public void testSameAdvisorPrecedenceDifferentAspectAfterAdvice() {
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0);
advisor1 = createAspectJAfterReturningAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
advisor2 = createAspectJAfterThrowingAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0);
}
@Test
public void testHigherAdvisorPrecedenceNoAfterAdvice() {
Advisor advisor1 = createSpringAOPBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER);
Advisor advisor2 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
advisor2 = createAspectJAroundAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
}
@Test
public void testHigherAdvisorPrecedenceAfterAdvice() {
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJAroundAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
advisor1 = createAspectJAfterReturningAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
advisor2 = createAspectJAfterThrowingAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("advisor2 sorted after advisor1", -1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor2 sorted after advisor1").isEqualTo(-1);
}
@Test
public void testLowerAdvisorPrecedenceNoAfterAdvice() {
Advisor advisor1 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
advisor1 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
}
@Test
public void testLowerAdvisorPrecedenceAfterAdvice() {
Advisor advisor1 = createAspectJAfterAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
advisor1 = createSpringAOPAfterAdvice(LOW_PRECEDENCE_ADVISOR_ORDER);
advisor2 = createAspectJAfterThrowingAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2));
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
}

View File

@ -32,9 +32,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource;
import org.springframework.tests.beans.CollectingReaderEventListener;
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;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -69,14 +67,15 @@ public class AopNamespaceHandlerEventTests {
public void testPointcutEvents() {
this.reader.loadBeanDefinitions(POINTCUT_EVENTS_CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertEquals("Incorrect number of events fired", 1, componentDefinitions.length);
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
assertThat(componentDefinitions.length).as("Incorrect number of events fired").isEqualTo(1);
boolean condition = componentDefinitions[0] instanceof CompositeComponentDefinition;
assertThat(condition).as("No holder with nested components").isTrue();
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
assertEquals("aop:config", compositeDef.getName());
assertThat(compositeDef.getName()).isEqualTo("aop:config");
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
assertThat(nestedComponentDefs.length).as("Incorrect number of inner components").isEqualTo(2);
PointcutComponentDefinition pcd = null;
for (ComponentDefinition componentDefinition : nestedComponentDefs) {
if (componentDefinition instanceof PointcutComponentDefinition) {
@ -84,22 +83,23 @@ public class AopNamespaceHandlerEventTests {
break;
}
}
assertNotNull("PointcutComponentDefinition not found", pcd);
assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
assertThat(pcd).as("PointcutComponentDefinition not found").isNotNull();
assertThat(pcd.getBeanDefinitions().length).as("Incorrect number of BeanDefinitions").isEqualTo(1);
}
@Test
public void testAdvisorEventsWithPointcutRef() {
this.reader.loadBeanDefinitions(POINTCUT_REF_CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
assertThat(componentDefinitions.length).as("Incorrect number of events fired").isEqualTo(2);
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
boolean condition1 = componentDefinitions[0] instanceof CompositeComponentDefinition;
assertThat(condition1).as("No holder with nested components").isTrue();
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
assertEquals("aop:config", compositeDef.getName());
assertThat(compositeDef.getName()).isEqualTo("aop:config");
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
assertEquals("Incorrect number of inner components", 3, nestedComponentDefs.length);
assertThat(nestedComponentDefs.length).as("Incorrect number of inner components").isEqualTo(3);
AdvisorComponentDefinition acd = null;
for (int i = 0; i < nestedComponentDefs.length; i++) {
ComponentDefinition componentDefinition = nestedComponentDefs[i];
@ -108,27 +108,29 @@ public class AopNamespaceHandlerEventTests {
break;
}
}
assertNotNull("AdvisorComponentDefinition not found", acd);
assertEquals(1, acd.getBeanDefinitions().length);
assertEquals(2, acd.getBeanReferences().length);
assertThat(acd).as("AdvisorComponentDefinition not found").isNotNull();
assertThat(acd.getBeanDefinitions().length).isEqualTo(1);
assertThat(acd.getBeanReferences().length).isEqualTo(2);
assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition);
boolean condition = componentDefinitions[1] instanceof BeanComponentDefinition;
assertThat(condition).as("No advice bean found").isTrue();
BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1];
assertEquals("countingAdvice", adviceDef.getBeanName());
assertThat(adviceDef.getBeanName()).isEqualTo("countingAdvice");
}
@Test
public void testAdvisorEventsWithDirectPointcut() {
this.reader.loadBeanDefinitions(DIRECT_POINTCUT_EVENTS_CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
assertThat(componentDefinitions.length).as("Incorrect number of events fired").isEqualTo(2);
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
boolean condition1 = componentDefinitions[0] instanceof CompositeComponentDefinition;
assertThat(condition1).as("No holder with nested components").isTrue();
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
assertEquals("aop:config", compositeDef.getName());
assertThat(compositeDef.getName()).isEqualTo("aop:config");
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
assertThat(nestedComponentDefs.length).as("Incorrect number of inner components").isEqualTo(2);
AdvisorComponentDefinition acd = null;
for (int i = 0; i < nestedComponentDefs.length; i++) {
ComponentDefinition componentDefinition = nestedComponentDefs[i];
@ -137,27 +139,29 @@ public class AopNamespaceHandlerEventTests {
break;
}
}
assertNotNull("AdvisorComponentDefinition not found", acd);
assertEquals(2, acd.getBeanDefinitions().length);
assertEquals(1, acd.getBeanReferences().length);
assertThat(acd).as("AdvisorComponentDefinition not found").isNotNull();
assertThat(acd.getBeanDefinitions().length).isEqualTo(2);
assertThat(acd.getBeanReferences().length).isEqualTo(1);
assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition);
boolean condition = componentDefinitions[1] instanceof BeanComponentDefinition;
assertThat(condition).as("No advice bean found").isTrue();
BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1];
assertEquals("countingAdvice", adviceDef.getBeanName());
assertThat(adviceDef.getBeanName()).isEqualTo("countingAdvice");
}
@Test
public void testAspectEvent() {
this.reader.loadBeanDefinitions(CONTEXT);
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
assertEquals("Incorrect number of events fired", 5, componentDefinitions.length);
assertThat(componentDefinitions.length).as("Incorrect number of events fired").isEqualTo(5);
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
boolean condition = componentDefinitions[0] instanceof CompositeComponentDefinition;
assertThat(condition).as("No holder with nested components").isTrue();
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
assertEquals("aop:config", compositeDef.getName());
assertThat(compositeDef.getName()).isEqualTo("aop:config");
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
assertThat(nestedComponentDefs.length).as("Incorrect number of inner components").isEqualTo(2);
AspectComponentDefinition acd = null;
for (ComponentDefinition componentDefinition : nestedComponentDefs) {
if (componentDefinition instanceof AspectComponentDefinition) {
@ -166,11 +170,11 @@ public class AopNamespaceHandlerEventTests {
}
}
assertNotNull("AspectComponentDefinition not found", acd);
assertThat(acd).as("AspectComponentDefinition not found").isNotNull();
BeanDefinition[] beanDefinitions = acd.getBeanDefinitions();
assertEquals(5, beanDefinitions.length);
assertThat(beanDefinitions.length).isEqualTo(5);
BeanReference[] beanReferences = acd.getBeanReferences();
assertEquals(6, beanReferences.length);
assertThat(beanReferences.length).isEqualTo(6);
Set<String> expectedReferences = new HashSet<>();
expectedReferences.add("pc");
@ -178,17 +182,19 @@ public class AopNamespaceHandlerEventTests {
for (BeanReference beanReference : beanReferences) {
expectedReferences.remove(beanReference.getBeanName());
}
assertEquals("Incorrect references found", 0, expectedReferences.size());
assertThat(expectedReferences.size()).as("Incorrect references found").isEqualTo(0);
for (int i = 1; i < componentDefinitions.length; i++) {
assertTrue(componentDefinitions[i] instanceof BeanComponentDefinition);
boolean condition1 = componentDefinitions[i] instanceof BeanComponentDefinition;
assertThat(condition1).isTrue();
}
ComponentDefinition[] nestedComponentDefs2 = acd.getNestedComponents();
assertEquals("Inner PointcutComponentDefinition not found", 1, nestedComponentDefs2.length);
assertTrue(nestedComponentDefs2[0] instanceof PointcutComponentDefinition);
assertThat(nestedComponentDefs2.length).as("Inner PointcutComponentDefinition not found").isEqualTo(1);
boolean condition1 = nestedComponentDefs2[0] instanceof PointcutComponentDefinition;
assertThat(condition1).isTrue();
PointcutComponentDefinition pcd = (PointcutComponentDefinition) nestedComponentDefs2[0];
assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
assertThat(pcd.getBeanDefinitions().length).as("Incorrect number of BeanDefinitions").isEqualTo(1);
}
}

View File

@ -21,7 +21,7 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -38,7 +38,7 @@ public class TopLevelAopTagTests {
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
qualifiedResource(TopLevelAopTagTests.class, "context.xml"));
assertTrue(beanFactory.containsBeanDefinition("testPointcut"));
assertThat(beanFactory.containsBeanDefinition("testPointcut")).isTrue();
}
}

View File

@ -26,10 +26,8 @@ import org.springframework.aop.SpringProxy;
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.assertTrue;
/**
* @author Rod Johnson
@ -41,10 +39,10 @@ public class AopProxyUtilsTests {
public void testCompleteProxiedInterfacesWorksWithNull() {
AdvisedSupport as = new AdvisedSupport();
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertEquals(2, completedInterfaces.length);
assertThat(completedInterfaces.length).isEqualTo(2);
List<?> ifaces = Arrays.asList(completedInterfaces);
assertTrue(ifaces.contains(Advised.class));
assertTrue(ifaces.contains(SpringProxy.class));
assertThat(ifaces.contains(Advised.class)).isTrue();
assertThat(ifaces.contains(SpringProxy.class)).isTrue();
}
@Test
@ -52,7 +50,7 @@ public class AopProxyUtilsTests {
AdvisedSupport as = new AdvisedSupport();
as.setOpaque(true);
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertEquals(1, completedInterfaces.length);
assertThat(completedInterfaces.length).isEqualTo(1);
}
@Test
@ -61,13 +59,13 @@ public class AopProxyUtilsTests {
as.addInterface(ITestBean.class);
as.addInterface(Comparable.class);
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertEquals(4, completedInterfaces.length);
assertThat(completedInterfaces.length).isEqualTo(4);
// Can't assume ordering for others, so use a list
List<?> l = Arrays.asList(completedInterfaces);
assertTrue(l.contains(Advised.class));
assertTrue(l.contains(ITestBean.class));
assertTrue(l.contains(Comparable.class));
assertThat(l.contains(Advised.class)).isTrue();
assertThat(l.contains(ITestBean.class)).isTrue();
assertThat(l.contains(Comparable.class)).isTrue();
}
@Test
@ -77,13 +75,13 @@ public class AopProxyUtilsTests {
as.addInterface(Comparable.class);
as.addInterface(Advised.class);
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertEquals(4, completedInterfaces.length);
assertThat(completedInterfaces.length).isEqualTo(4);
// Can't assume ordering for others, so use a list
List<?> l = Arrays.asList(completedInterfaces);
assertTrue(l.contains(Advised.class));
assertTrue(l.contains(ITestBean.class));
assertTrue(l.contains(Comparable.class));
assertThat(l.contains(Advised.class)).isTrue();
assertThat(l.contains(ITestBean.class)).isTrue();
assertThat(l.contains(Comparable.class)).isTrue();
}
@Test
@ -93,13 +91,13 @@ public class AopProxyUtilsTests {
as.addInterface(ITestBean.class);
as.addInterface(Comparable.class);
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
assertEquals(3, completedInterfaces.length);
assertThat(completedInterfaces.length).isEqualTo(3);
// Can't assume ordering for others, so use a list
List<?> l = Arrays.asList(completedInterfaces);
assertFalse(l.contains(Advised.class));
assertTrue(l.contains(ITestBean.class));
assertTrue(l.contains(Comparable.class));
assertThat(l.contains(Advised.class)).isFalse();
assertThat(l.contains(ITestBean.class)).isTrue();
assertThat(l.contains(Comparable.class)).isTrue();
}
@Test
@ -109,8 +107,8 @@ public class AopProxyUtilsTests {
pf.addInterface(ITestBean.class);
Object proxy = pf.getProxy();
Class<?>[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy);
assertEquals(1, userInterfaces.length);
assertEquals(ITestBean.class, userInterfaces[0]);
assertThat(userInterfaces.length).isEqualTo(1);
assertThat(userInterfaces[0]).isEqualTo(ITestBean.class);
}
@Test
@ -121,9 +119,9 @@ public class AopProxyUtilsTests {
pf.addInterface(Comparable.class);
Object proxy = pf.getProxy();
Class<?>[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy);
assertEquals(2, userInterfaces.length);
assertEquals(ITestBean.class, userInterfaces[0]);
assertEquals(Comparable.class, userInterfaces[1]);
assertThat(userInterfaces.length).isEqualTo(2);
assertThat(userInterfaces[0]).isEqualTo(ITestBean.class);
assertThat(userInterfaces[1]).isEqualTo(Comparable.class);
}
@Test

View File

@ -26,7 +26,7 @@ import org.junit.Test;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rod Johnson
@ -51,7 +51,7 @@ public class MethodInvocationTests {
m, null, null, is // list
);
Object rv = invocation.proceed();
assertTrue("correct response", rv == returnValue);
assertThat(rv == returnValue).as("correct response").isTrue();
}
/**

View File

@ -24,7 +24,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -47,8 +47,8 @@ public class PrototypeTargetTests {
tb.doSomething();
}
TestInterceptor interceptor = (TestInterceptor) bf.getBean("testInterceptor");
assertEquals(10, TestBeanImpl.constructionCount);
assertEquals(10, interceptor.invocationCount);
assertThat(TestBeanImpl.constructionCount).isEqualTo(10);
assertThat(interceptor.invocationCount).isEqualTo(10);
}
@Test
@ -61,8 +61,8 @@ public class PrototypeTargetTests {
tb.doSomething();
}
TestInterceptor interceptor = (TestInterceptor) bf.getBean("testInterceptor");
assertEquals(1, TestBeanImpl.constructionCount);
assertEquals(10, interceptor.invocationCount);
assertThat(TestBeanImpl.constructionCount).isEqualTo(1);
assertThat(interceptor.invocationCount).isEqualTo(10);
}

View File

@ -44,11 +44,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.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;
/**
* Also tests AdvisedSupport and ProxyCreatorSupport superclasses.
@ -70,10 +65,10 @@ public class ProxyFactoryTests {
// Can use advised and ProxyFactory interchangeably
advised.addAdvice(nop);
pf.addAdvisor(advisor);
assertEquals(-1, pf.indexOf(new NopInterceptor()));
assertEquals(0, pf.indexOf(nop));
assertEquals(1, pf.indexOf(advisor));
assertEquals(-1, advised.indexOf(new DefaultPointcutAdvisor(null)));
assertThat(pf.indexOf(new NopInterceptor())).isEqualTo(-1);
assertThat(pf.indexOf(nop)).isEqualTo(0);
assertThat(pf.indexOf(advisor)).isEqualTo(1);
assertThat(advised.indexOf(new DefaultPointcutAdvisor(null))).isEqualTo(-1);
}
@Test
@ -87,13 +82,13 @@ public class ProxyFactoryTests {
pf.addAdvisor(advisor);
ITestBean proxied = (ITestBean) pf.getProxy();
proxied.setAge(5);
assertEquals(1, cba.getCalls());
assertEquals(1, nop.getCount());
assertTrue(pf.removeAdvisor(advisor));
assertEquals(5, proxied.getAge());
assertEquals(1, cba.getCalls());
assertEquals(2, nop.getCount());
assertFalse(pf.removeAdvisor(new DefaultPointcutAdvisor(null)));
assertThat(cba.getCalls()).isEqualTo(1);
assertThat(nop.getCount()).isEqualTo(1);
assertThat(pf.removeAdvisor(advisor)).isTrue();
assertThat(proxied.getAge()).isEqualTo(5);
assertThat(cba.getCalls()).isEqualTo(1);
assertThat(nop.getCount()).isEqualTo(2);
assertThat(pf.removeAdvisor(new DefaultPointcutAdvisor(null))).isFalse();
}
@Test
@ -109,21 +104,21 @@ public class ProxyFactoryTests {
pf.addAdvice(nop2);
ITestBean proxied = (ITestBean) pf.getProxy();
proxied.setAge(5);
assertEquals(1, cba.getCalls());
assertEquals(1, nop.getCount());
assertEquals(1, nop2.getCount());
assertThat(cba.getCalls()).isEqualTo(1);
assertThat(nop.getCount()).isEqualTo(1);
assertThat(nop2.getCount()).isEqualTo(1);
// Removes counting before advisor
pf.removeAdvisor(1);
assertEquals(5, proxied.getAge());
assertEquals(1, cba.getCalls());
assertEquals(2, nop.getCount());
assertEquals(2, nop2.getCount());
assertThat(proxied.getAge()).isEqualTo(5);
assertThat(cba.getCalls()).isEqualTo(1);
assertThat(nop.getCount()).isEqualTo(2);
assertThat(nop2.getCount()).isEqualTo(2);
// Removes Nop1
pf.removeAdvisor(0);
assertEquals(5, proxied.getAge());
assertEquals(1, cba.getCalls());
assertEquals(2, nop.getCount());
assertEquals(3, nop2.getCount());
assertThat(proxied.getAge()).isEqualTo(5);
assertThat(cba.getCalls()).isEqualTo(1);
assertThat(nop.getCount()).isEqualTo(2);
assertThat(nop2.getCount()).isEqualTo(3);
// Check out of bounds
try {
@ -140,8 +135,8 @@ public class ProxyFactoryTests {
// Ok
}
assertEquals(5, proxied.getAge());
assertEquals(4, nop2.getCount());
assertThat(proxied.getAge()).isEqualTo(5);
assertThat(nop2.getCount()).isEqualTo(4);
}
@Test
@ -160,17 +155,17 @@ public class ProxyFactoryTests {
// Replace etc methods on advised should be same as on ProxyFactory
Advised advised = (Advised) proxied;
proxied.setAge(5);
assertEquals(1, cba1.getCalls());
assertEquals(0, cba2.getCalls());
assertEquals(1, nop.getCount());
assertFalse(advised.replaceAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()), advisor2));
assertTrue(advised.replaceAdvisor(advisor1, advisor2));
assertEquals(advisor2, pf.getAdvisors()[0]);
assertEquals(5, proxied.getAge());
assertEquals(1, cba1.getCalls());
assertEquals(2, nop.getCount());
assertEquals(1, cba2.getCalls());
assertFalse(pf.replaceAdvisor(new DefaultPointcutAdvisor(null), advisor1));
assertThat(cba1.getCalls()).isEqualTo(1);
assertThat(cba2.getCalls()).isEqualTo(0);
assertThat(nop.getCount()).isEqualTo(1);
assertThat(advised.replaceAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()), advisor2)).isFalse();
assertThat(advised.replaceAdvisor(advisor1, advisor2)).isTrue();
assertThat(pf.getAdvisors()[0]).isEqualTo(advisor2);
assertThat(proxied.getAge()).isEqualTo(5);
assertThat(cba1.getCalls()).isEqualTo(1);
assertThat(nop.getCount()).isEqualTo(2);
assertThat(cba2.getCalls()).isEqualTo(1);
assertThat(pf.replaceAdvisor(new DefaultPointcutAdvisor(null), advisor1)).isFalse();
}
@Test
@ -201,11 +196,11 @@ public class ProxyFactoryTests {
TestBeanSubclass raw = new TestBeanSubclass();
ProxyFactory factory = new ProxyFactory(raw);
//System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
assertEquals("Found correct number of interfaces", 5, factory.getProxiedInterfaces().length);
assertThat(factory.getProxiedInterfaces().length).as("Found correct number of interfaces").isEqualTo(5);
ITestBean tb = (ITestBean) factory.getProxy();
assertThat(tb).as("Picked up secondary interface").isInstanceOf(IOther.class);
raw.setAge(25);
assertTrue(tb.getAge() == raw.getAge());
assertThat(tb.getAge() == raw.getAge()).isTrue();
long t = 555555L;
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
@ -215,10 +210,10 @@ public class ProxyFactoryTests {
factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
assertEquals("Advisor proxies one more interface after introduction", oldProxiedInterfaces.length + 1, newProxiedInterfaces.length);
assertThat(newProxiedInterfaces.length).as("Advisor proxies one more interface after introduction").isEqualTo(oldProxiedInterfaces.length + 1);
TimeStamped ts = (TimeStamped) factory.getProxy();
assertTrue(ts.getTimeStamp() == t);
assertThat(ts.getTimeStamp() == t).isTrue();
// Shouldn't fail;
((IOther) ts).absquatulate();
}
@ -237,14 +232,14 @@ public class ProxyFactoryTests {
ProxyFactory factory = new ProxyFactory(new TestBean());
factory.addAdvice(0, di);
assertThat(factory.getProxy()).isInstanceOf(ITestBean.class);
assertTrue(factory.adviceIncluded(di));
assertTrue(!factory.adviceIncluded(diUnused));
assertTrue(factory.countAdvicesOfType(NopInterceptor.class) == 1);
assertTrue(factory.countAdvicesOfType(MyInterceptor.class) == 0);
assertThat(factory.adviceIncluded(di)).isTrue();
assertThat(!factory.adviceIncluded(diUnused)).isTrue();
assertThat(factory.countAdvicesOfType(NopInterceptor.class) == 1).isTrue();
assertThat(factory.countAdvicesOfType(MyInterceptor.class) == 0).isTrue();
factory.addAdvice(0, diUnused);
assertTrue(factory.adviceIncluded(diUnused));
assertTrue(factory.countAdvicesOfType(NopInterceptor.class) == 2);
assertThat(factory.adviceIncluded(diUnused)).isTrue();
assertThat(factory.countAdvicesOfType(NopInterceptor.class) == 2).isTrue();
}
/**
@ -254,8 +249,7 @@ public class ProxyFactoryTests {
public void testCanAddAndRemoveAspectInterfacesOnSingleton() {
ProxyFactory config = new ProxyFactory(new TestBean());
assertFalse("Shouldn't implement TimeStamped before manipulation",
config.getProxy() instanceof TimeStamped);
assertThat(config.getProxy() instanceof TimeStamped).as("Shouldn't implement TimeStamped before manipulation").isFalse();
long time = 666L;
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
@ -265,37 +259,36 @@ public class ProxyFactoryTests {
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) config.getProxy();
assertTrue(ts.getTimeStamp() == time);
assertThat(ts.getTimeStamp() == time).isTrue();
// Can remove
config.removeAdvice(ti);
assertTrue(config.getAdvisors().length == oldCount);
assertThat(config.getAdvisors().length == oldCount).isTrue();
assertThatExceptionOfType(RuntimeException.class)
.as("Existing object won't implement this interface any more")
.isThrownBy(ts::getTimeStamp); // Existing reference will fail
assertFalse("Should no longer implement TimeStamped",
config.getProxy() instanceof TimeStamped);
assertThat(config.getProxy() instanceof TimeStamped).as("Should no longer implement TimeStamped").isFalse();
// 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();
assertEquals(1, debugInterceptor.getCount());
assertThat(debugInterceptor.getCount()).isEqualTo(1);
config.removeAdvice(debugInterceptor);
it.getSpouse();
// not invoked again
assertTrue(debugInterceptor.getCount() == 1);
assertThat(debugInterceptor.getCount() == 1).isTrue();
}
@Test
@ -303,15 +296,15 @@ public class ProxyFactoryTests {
ProxyFactory pf = new ProxyFactory();
pf.setTargetClass(ITestBean.class);
Object proxy = pf.getProxy();
assertTrue("Proxy is a JDK proxy", AopUtils.isJdkDynamicProxy(proxy));
assertTrue(proxy instanceof ITestBean);
assertEquals(ITestBean.class, AopProxyUtils.ultimateTargetClass(proxy));
assertThat(AopUtils.isJdkDynamicProxy(proxy)).as("Proxy is a JDK proxy").isTrue();
assertThat(proxy instanceof ITestBean).isTrue();
assertThat(AopProxyUtils.ultimateTargetClass(proxy)).isEqualTo(ITestBean.class);
ProxyFactory pf2 = new ProxyFactory(proxy);
Object proxy2 = pf2.getProxy();
assertTrue("Proxy is a JDK proxy", AopUtils.isJdkDynamicProxy(proxy2));
assertTrue(proxy2 instanceof ITestBean);
assertEquals(ITestBean.class, AopProxyUtils.ultimateTargetClass(proxy2));
assertThat(AopUtils.isJdkDynamicProxy(proxy2)).as("Proxy is a JDK proxy").isTrue();
assertThat(proxy2 instanceof ITestBean).isTrue();
assertThat(AopProxyUtils.ultimateTargetClass(proxy2)).isEqualTo(ITestBean.class);
}
@Test
@ -319,16 +312,16 @@ public class ProxyFactoryTests {
ProxyFactory pf = new ProxyFactory();
pf.setTargetClass(TestBean.class);
Object proxy = pf.getProxy();
assertTrue("Proxy is a CGLIB proxy", AopUtils.isCglibProxy(proxy));
assertTrue(proxy instanceof TestBean);
assertEquals(TestBean.class, AopProxyUtils.ultimateTargetClass(proxy));
assertThat(AopUtils.isCglibProxy(proxy)).as("Proxy is a CGLIB proxy").isTrue();
assertThat(proxy instanceof TestBean).isTrue();
assertThat(AopProxyUtils.ultimateTargetClass(proxy)).isEqualTo(TestBean.class);
ProxyFactory pf2 = new ProxyFactory(proxy);
pf2.setProxyTargetClass(true);
Object proxy2 = pf2.getProxy();
assertTrue("Proxy is a CGLIB proxy", AopUtils.isCglibProxy(proxy2));
assertTrue(proxy2 instanceof TestBean);
assertEquals(TestBean.class, AopProxyUtils.ultimateTargetClass(proxy2));
assertThat(AopUtils.isCglibProxy(proxy2)).as("Proxy is a CGLIB proxy").isTrue();
assertThat(proxy2 instanceof TestBean).isTrue();
assertThat(AopProxyUtils.ultimateTargetClass(proxy2)).isEqualTo(TestBean.class);
}
@Test
@ -337,8 +330,8 @@ public class ProxyFactoryTests {
JFrame frame = new JFrame();
ProxyFactory proxyFactory = new ProxyFactory(frame);
Object proxy = proxyFactory.getProxy();
assertTrue(proxy instanceof RootPaneContainer);
assertTrue(proxy instanceof Accessible);
assertThat(proxy instanceof RootPaneContainer).isTrue();
assertThat(proxy instanceof Accessible).isTrue();
}
@Test
@ -349,8 +342,8 @@ public class ProxyFactoryTests {
list.add(proxy1);
list.add(proxy2);
AnnotationAwareOrderComparator.sort(list);
assertSame(proxy2, list.get(0));
assertSame(proxy1, list.get(1));
assertThat(list.get(0)).isSameAs(proxy2);
assertThat(list.get(1)).isSameAs(proxy1);
}
@Test
@ -365,18 +358,18 @@ public class ProxyFactoryTests {
list.add(proxy1);
list.add(proxy2);
AnnotationAwareOrderComparator.sort(list);
assertSame(proxy2, list.get(0));
assertSame(proxy1, list.get(1));
assertThat(list.get(0)).isSameAs(proxy2);
assertThat(list.get(1)).isSameAs(proxy1);
}
@Test
public void testInterceptorWithoutJoinpoint() {
final TestBean target = new TestBean("tb");
ITestBean proxy = ProxyFactory.getProxy(ITestBean.class, (MethodInterceptor) invocation -> {
assertNull(invocation.getThis());
assertThat(invocation.getThis()).isNull();
return invocation.getMethod().invoke(target, invocation.getArguments());
});
assertEquals("tb", proxy.getName());
assertThat(proxy.getName()).isEqualTo("tb");
}

View File

@ -28,9 +28,9 @@ import org.junit.Test;
import org.springframework.aop.ThrowsAdvice;
import org.springframework.tests.aop.advice.MethodCounter;
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.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@ -54,22 +54,22 @@ public class ThrowsAdviceInterceptorTests {
Object ret = new Object();
MethodInvocation mi = mock(MethodInvocation.class);
given(mi.proceed()).willReturn(ret);
assertEquals(ret, ti.invoke(mi));
assertEquals(0, th.getCalls());
assertThat(ti.invoke(mi)).isEqualTo(ret);
assertThat(th.getCalls()).isEqualTo(0);
}
@Test
public void testNoHandlerMethodForThrowable() throws Throwable {
MyThrowsHandler th = new MyThrowsHandler();
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
assertEquals(2, ti.getHandlerMethodCount());
assertThat(ti.getHandlerMethodCount()).isEqualTo(2);
Exception ex = new Exception();
MethodInvocation mi = mock(MethodInvocation.class);
given(mi.proceed()).willThrow(ex);
assertThatExceptionOfType(Exception.class).isThrownBy(() ->
ti.invoke(mi))
.isSameAs(ex);
assertEquals(0, th.getCalls());
assertThat(th.getCalls()).isEqualTo(0);
}
@Test
@ -84,8 +84,8 @@ public class ThrowsAdviceInterceptorTests {
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() ->
ti.invoke(mi))
.isSameAs(ex);
assertEquals(1, th.getCalls());
assertEquals(1, th.getCalls("ioException"));
assertThat(th.getCalls()).isEqualTo(1);
assertThat(th.getCalls("ioException")).isEqualTo(1);
}
@Test
@ -99,8 +99,8 @@ public class ThrowsAdviceInterceptorTests {
assertThatExceptionOfType(ConnectException.class).isThrownBy(() ->
ti.invoke(mi))
.isSameAs(ex);
assertEquals(1, th.getCalls());
assertEquals(1, th.getCalls("remoteException"));
assertThat(th.getCalls()).isEqualTo(1);
assertThat(th.getCalls("remoteException")).isEqualTo(1);
}
@Test
@ -124,8 +124,8 @@ public class ThrowsAdviceInterceptorTests {
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
ti.invoke(mi))
.isSameAs(t);
assertEquals(1, th.getCalls());
assertEquals(1, th.getCalls("remoteException"));
assertThat(th.getCalls()).isEqualTo(1);
assertThat(th.getCalls("remoteException")).isEqualTo(1);
}

View File

@ -27,7 +27,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.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
@ -58,7 +58,7 @@ public class ConcurrencyThrottleInterceptorTests {
Advised advised = (Advised) serializedProxy;
ConcurrencyThrottleInterceptor serializedCti =
(ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
assertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit());
assertThat(serializedCti.getConcurrencyLimit()).isEqualTo(cti.getConcurrencyLimit());
serializedProxy.getAge();
}

View File

@ -20,8 +20,8 @@ import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.junit.Test;
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.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
@ -73,7 +73,7 @@ public class DebugInterceptorTests {
}
private void checkCallCountTotal(DebugInterceptor interceptor) {
assertEquals("Intercepted call count not being incremented correctly", 1, interceptor.getCount());
assertThat(interceptor.getCount()).as("Intercepted call count not being incremented correctly").isEqualTo(1);
}

View File

@ -23,9 +23,7 @@ import org.springframework.beans.factory.NamedBean;
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;
/**
* @author Rod Johnson
@ -42,7 +40,7 @@ public class ExposeBeanNameAdvisorsTests {
@Override
public int getAge() {
assertEquals(beanName, ExposeBeanNameAdvisors.getBeanName());
assertThat(ExposeBeanNameAdvisors.getBeanName()).isEqualTo(beanName);
return super.getAge();
}
}
@ -56,7 +54,8 @@ public class ExposeBeanNameAdvisorsTests {
pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorWithoutIntroduction(beanName));
ITestBean proxy = (ITestBean) pf.getProxy();
assertFalse("No introduction", proxy instanceof NamedBean);
boolean condition = proxy instanceof NamedBean;
assertThat(condition).as("No introduction").isFalse();
// Requires binding
proxy.getAge();
}
@ -70,12 +69,13 @@ public class ExposeBeanNameAdvisorsTests {
pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorIntroducingNamedBean(beanName));
ITestBean proxy = (ITestBean) pf.getProxy();
assertTrue("Introduction was made", proxy instanceof NamedBean);
boolean condition = proxy instanceof NamedBean;
assertThat(condition).as("Introduction was made").isTrue();
// Requires binding
proxy.getAge();
NamedBean nb = (NamedBean) proxy;
assertEquals("Name returned correctly", beanName, nb.getBeanName());
assertThat(nb.getBeanName()).as("Name returned correctly").isEqualTo(beanName);
}
}

View File

@ -24,8 +24,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
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;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -45,7 +44,7 @@ public class ExposeInvocationInterceptorTests {
String name = "tony";
tb.setName(name);
// Fires context checks
assertEquals(name, tb.getName());
assertThat(tb.getName()).isEqualTo(name);
}
}
@ -75,8 +74,7 @@ class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean
@Override
protected void assertions(MethodInvocation invocation) {
assertTrue(invocation.getThis() == this);
assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass()));
assertThat(invocation.getThis() == this).isTrue();
assertThat(ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass())).as("Invocation should be on ITestBean: " + invocation.getMethod()).isTrue();
}
}

View File

@ -23,9 +23,8 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
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.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@ -59,9 +58,8 @@ public class JamonPerformanceMonitorInterceptorTests {
interceptor.invokeUnderTrace(mi, log);
assertTrue("jamon must track the method being invoked", MonitorFactory.getNumRows() > 0);
assertTrue("The jamon report must contain the toString method that was invoked",
MonitorFactory.getReport().contains("toString"));
assertThat(MonitorFactory.getNumRows() > 0).as("jamon must track the method being invoked").isTrue();
assertThat(MonitorFactory.getReport().contains("toString")).as("The jamon report must contain the toString method that was invoked").isTrue();
}
@Test
@ -72,14 +70,10 @@ public class JamonPerformanceMonitorInterceptorTests {
assertThatIllegalArgumentException().isThrownBy(() ->
interceptor.invokeUnderTrace(mi, log));
assertEquals("Monitors must exist for the method invocation and 2 exceptions",
3, MonitorFactory.getNumRows());
assertTrue("The jamon report must contain the toString method that was invoked",
MonitorFactory.getReport().contains("toString"));
assertTrue("The jamon report must contain the generic exception: " + MonitorFactory.EXCEPTIONS_LABEL,
MonitorFactory.getReport().contains(MonitorFactory.EXCEPTIONS_LABEL));
assertTrue("The jamon report must contain the specific exception: IllegalArgumentException'",
MonitorFactory.getReport().contains("IllegalArgumentException"));
assertThat(MonitorFactory.getNumRows()).as("Monitors must exist for the method invocation and 2 exceptions").isEqualTo(3);
assertThat(MonitorFactory.getReport().contains("toString")).as("The jamon report must contain the toString method that was invoked").isTrue();
assertThat(MonitorFactory.getReport().contains(MonitorFactory.EXCEPTIONS_LABEL)).as("The jamon report must contain the generic exception: " + MonitorFactory.EXCEPTIONS_LABEL).isTrue();
assertThat(MonitorFactory.getReport().contains("IllegalArgumentException")).as("The jamon report must contain the specific exception: IllegalArgumentException'").isTrue();
}
}

View File

@ -20,8 +20,8 @@ import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.logging.Log;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertNotNull;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@ -38,14 +38,14 @@ public class PerformanceMonitorInterceptorTests {
public void testSuffixAndPrefixAssignment() {
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor();
assertNotNull(interceptor.getPrefix());
assertNotNull(interceptor.getSuffix());
assertThat(interceptor.getPrefix()).isNotNull();
assertThat(interceptor.getSuffix()).isNotNull();
interceptor.setPrefix(null);
interceptor.setSuffix(null);
assertNotNull(interceptor.getPrefix());
assertNotNull(interceptor.getSuffix());
assertThat(interceptor.getPrefix()).isNotNull();
assertThat(interceptor.getSuffix()).isNotNull();
}
@Test

View File

@ -23,9 +23,7 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
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;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -41,12 +39,12 @@ public class ScopedProxyAutowireTests {
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireFalse.xml"));
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped"));
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped"));
assertFalse(bf.containsSingleton("scoped"));
assertThat(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped")).isTrue();
assertThat(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped")).isTrue();
assertThat(bf.containsSingleton("scoped")).isFalse();
TestBean autowired = (TestBean) bf.getBean("autowired");
TestBean unscoped = (TestBean) bf.getBean("unscoped");
assertSame(unscoped, autowired.getChild());
assertThat(autowired.getChild()).isSameAs(unscoped);
}
@Test
@ -55,12 +53,12 @@ public class ScopedProxyAutowireTests {
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireTrue.xml"));
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped"));
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped"));
assertFalse(bf.containsSingleton("scoped"));
assertThat(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped")).isTrue();
assertThat(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped")).isTrue();
assertThat(bf.containsSingleton("scoped")).isFalse();
TestBean autowired = (TestBean) bf.getBean("autowired");
TestBean scoped = (TestBean) bf.getBean("scoped");
assertSame(scoped, autowired.getChild());
assertThat(autowired.getChild()).isSameAs(scoped);
}

View File

@ -24,9 +24,7 @@ import org.junit.Test;
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.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rod Johnson
@ -56,9 +54,9 @@ public abstract class AbstractRegexpMethodPointcutTests {
}
protected void noPatternSuppliedTests(AbstractRegexpMethodPointcut rpc) throws Exception {
assertFalse(rpc.matches(Object.class.getMethod("hashCode"), String.class));
assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class));
assertEquals(0, rpc.getPatterns().length);
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isFalse();
assertThat(rpc.matches(Object.class.getMethod("wait"), Object.class)).isFalse();
assertThat(rpc.getPatterns().length).isEqualTo(0);
}
@Test
@ -71,46 +69,46 @@ public abstract class AbstractRegexpMethodPointcutTests {
protected void exactMatchTests(AbstractRegexpMethodPointcut rpc) throws Exception {
// assumes rpc.setPattern("java.lang.Object.hashCode");
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class));
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), Object.class));
assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class));
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isTrue();
assertThat(rpc.matches(Object.class.getMethod("hashCode"), Object.class)).isTrue();
assertThat(rpc.matches(Object.class.getMethod("wait"), Object.class)).isFalse();
}
@Test
public void testSpecificMatch() throws Exception {
rpc.setPattern("java.lang.String.hashCode");
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class));
assertFalse(rpc.matches(Object.class.getMethod("hashCode"), Object.class));
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isTrue();
assertThat(rpc.matches(Object.class.getMethod("hashCode"), Object.class)).isFalse();
}
@Test
public void testWildcard() throws Exception {
rpc.setPattern(".*Object.hashCode");
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), Object.class));
assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class));
assertThat(rpc.matches(Object.class.getMethod("hashCode"), Object.class)).isTrue();
assertThat(rpc.matches(Object.class.getMethod("wait"), Object.class)).isFalse();
}
@Test
public void testWildcardForOneClass() throws Exception {
rpc.setPattern("java.lang.Object.*");
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class));
assertTrue(rpc.matches(Object.class.getMethod("wait"), String.class));
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isTrue();
assertThat(rpc.matches(Object.class.getMethod("wait"), String.class)).isTrue();
}
@Test
public void testMatchesObjectClass() throws Exception {
rpc.setPattern("java.lang.Object.*");
assertTrue(rpc.matches(Exception.class.getMethod("hashCode"), IOException.class));
assertThat(rpc.matches(Exception.class.getMethod("hashCode"), IOException.class)).isTrue();
// Doesn't match a method from Throwable
assertFalse(rpc.matches(Exception.class.getMethod("getMessage"), Exception.class));
assertThat(rpc.matches(Exception.class.getMethod("getMessage"), Exception.class)).isFalse();
}
@Test
public void testWithExclusion() throws Exception {
this.rpc.setPattern(".*get.*");
this.rpc.setExcludedPattern(".*Age.*");
assertTrue(this.rpc.matches(TestBean.class.getMethod("getName"), TestBean.class));
assertFalse(this.rpc.matches(TestBean.class.getMethod("getAge"), TestBean.class));
assertThat(this.rpc.matches(TestBean.class.getMethod("getName"), TestBean.class)).isTrue();
assertThat(this.rpc.matches(TestBean.class.getMethod("getAge"), TestBean.class)).isFalse();
}
}

View File

@ -30,9 +30,7 @@ import org.springframework.tests.aop.interceptor.NopInterceptor;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
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 Rod Johnson
@ -50,13 +48,13 @@ public class AopUtilsTests {
}
Pointcut no = new TestPointcut();
assertFalse(AopUtils.canApply(no, Object.class));
assertThat(AopUtils.canApply(no, Object.class)).isFalse();
}
@Test
public void testPointcutAlwaysApplies() {
assertTrue(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), Object.class));
assertTrue(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), TestBean.class));
assertThat(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), Object.class)).isTrue();
assertThat(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), TestBean.class)).isTrue();
}
@Test
@ -71,7 +69,7 @@ public class AopUtilsTests {
Pointcut pc = new TestPointcut();
// will return true if we're not proxying interfaces
assertTrue(AopUtils.canApply(pc, Object.class));
assertThat(AopUtils.canApply(pc, Object.class)).isTrue();
}
/**
@ -81,14 +79,13 @@ public class AopUtilsTests {
*/
@Test
public void testCanonicalFrameworkClassesStillCanonicalOnDeserialization() throws Exception {
assertSame(MethodMatcher.TRUE, SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE));
assertSame(ClassFilter.TRUE, SerializationTestUtils.serializeAndDeserialize(ClassFilter.TRUE));
assertSame(Pointcut.TRUE, SerializationTestUtils.serializeAndDeserialize(Pointcut.TRUE));
assertSame(EmptyTargetSource.INSTANCE, SerializationTestUtils.serializeAndDeserialize(EmptyTargetSource.INSTANCE));
assertSame(Pointcuts.SETTERS, SerializationTestUtils.serializeAndDeserialize(Pointcuts.SETTERS));
assertSame(Pointcuts.GETTERS, SerializationTestUtils.serializeAndDeserialize(Pointcuts.GETTERS));
assertSame(ExposeInvocationInterceptor.INSTANCE,
SerializationTestUtils.serializeAndDeserialize(ExposeInvocationInterceptor.INSTANCE));
assertThat(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE)).isSameAs(MethodMatcher.TRUE);
assertThat(SerializationTestUtils.serializeAndDeserialize(ClassFilter.TRUE)).isSameAs(ClassFilter.TRUE);
assertThat(SerializationTestUtils.serializeAndDeserialize(Pointcut.TRUE)).isSameAs(Pointcut.TRUE);
assertThat(SerializationTestUtils.serializeAndDeserialize(EmptyTargetSource.INSTANCE)).isSameAs(EmptyTargetSource.INSTANCE);
assertThat(SerializationTestUtils.serializeAndDeserialize(Pointcuts.SETTERS)).isSameAs(Pointcuts.SETTERS);
assertThat(SerializationTestUtils.serializeAndDeserialize(Pointcuts.GETTERS)).isSameAs(Pointcuts.GETTERS);
assertThat(SerializationTestUtils.serializeAndDeserialize(ExposeInvocationInterceptor.INSTANCE)).isSameAs(ExposeInvocationInterceptor.INSTANCE);
}
}

View File

@ -23,8 +23,7 @@ import org.springframework.core.NestedRuntimeException;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rod Johnson
@ -40,23 +39,23 @@ public class ClassFiltersTests {
@Test
public void testUnion() {
assertTrue(exceptionFilter.matches(RuntimeException.class));
assertFalse(exceptionFilter.matches(TestBean.class));
assertFalse(itbFilter.matches(Exception.class));
assertTrue(itbFilter.matches(TestBean.class));
assertThat(exceptionFilter.matches(RuntimeException.class)).isTrue();
assertThat(exceptionFilter.matches(TestBean.class)).isFalse();
assertThat(itbFilter.matches(Exception.class)).isFalse();
assertThat(itbFilter.matches(TestBean.class)).isTrue();
ClassFilter union = ClassFilters.union(exceptionFilter, itbFilter);
assertTrue(union.matches(RuntimeException.class));
assertTrue(union.matches(TestBean.class));
assertThat(union.matches(RuntimeException.class)).isTrue();
assertThat(union.matches(TestBean.class)).isTrue();
}
@Test
public void testIntersection() {
assertTrue(exceptionFilter.matches(RuntimeException.class));
assertTrue(hasRootCauseFilter.matches(NestedRuntimeException.class));
assertThat(exceptionFilter.matches(RuntimeException.class)).isTrue();
assertThat(hasRootCauseFilter.matches(NestedRuntimeException.class)).isTrue();
ClassFilter intersection = ClassFilters.intersection(exceptionFilter, hasRootCauseFilter);
assertFalse(intersection.matches(RuntimeException.class));
assertFalse(intersection.matches(TestBean.class));
assertTrue(intersection.matches(NestedRuntimeException.class));
assertThat(intersection.matches(RuntimeException.class)).isFalse();
assertThat(intersection.matches(TestBean.class)).isFalse();
assertThat(intersection.matches(NestedRuntimeException.class)).isTrue();
}
}

View File

@ -21,7 +21,7 @@ import org.springframework.aop.framework.ProxyFactory;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.ClassUtils;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Colin Sampaleanu
@ -39,6 +39,6 @@ public class ClassUtilsTests {
pf.setProxyTargetClass(true);
TestBean proxy = (TestBean) pf.getProxy();
String className = ClassUtils.getShortName(proxy.getClass());
assertEquals("Class name did not match", "TestBean", className);
assertThat(className).as("Class name did not match").isEqualTo("TestBean");
}
}

View File

@ -27,9 +27,7 @@ import org.springframework.core.NestedRuntimeException;
import org.springframework.lang.Nullable;
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;
/**
* @author Rod Johnson
@ -69,68 +67,68 @@ public class ComposablePointcutTests {
@Test
public void testMatchAll() throws NoSuchMethodException {
Pointcut pc = new ComposablePointcut();
assertTrue(pc.getClassFilter().matches(Object.class));
assertTrue(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode"), Exception.class));
assertThat(pc.getClassFilter().matches(Object.class)).isTrue();
assertThat(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode"), Exception.class)).isTrue();
}
@Test
public void testFilterByClass() throws NoSuchMethodException {
ComposablePointcut pc = new ComposablePointcut();
assertTrue(pc.getClassFilter().matches(Object.class));
assertThat(pc.getClassFilter().matches(Object.class)).isTrue();
ClassFilter cf = new RootClassFilter(Exception.class);
pc.intersection(cf);
assertFalse(pc.getClassFilter().matches(Object.class));
assertTrue(pc.getClassFilter().matches(Exception.class));
assertThat(pc.getClassFilter().matches(Object.class)).isFalse();
assertThat(pc.getClassFilter().matches(Exception.class)).isTrue();
pc.intersection(new RootClassFilter(NestedRuntimeException.class));
assertFalse(pc.getClassFilter().matches(Exception.class));
assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
assertFalse(pc.getClassFilter().matches(String.class));
assertThat(pc.getClassFilter().matches(Exception.class)).isFalse();
assertThat(pc.getClassFilter().matches(NestedRuntimeException.class)).isTrue();
assertThat(pc.getClassFilter().matches(String.class)).isFalse();
pc.union(new RootClassFilter(String.class));
assertFalse(pc.getClassFilter().matches(Exception.class));
assertTrue(pc.getClassFilter().matches(String.class));
assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
assertThat(pc.getClassFilter().matches(Exception.class)).isFalse();
assertThat(pc.getClassFilter().matches(String.class)).isTrue();
assertThat(pc.getClassFilter().matches(NestedRuntimeException.class)).isTrue();
}
@Test
public void testUnionMethodMatcher() {
// Matches the getAge() method in any class
ComposablePointcut pc = new ComposablePointcut(ClassFilter.TRUE, GET_AGE_METHOD_MATCHER);
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
pc.union(GETTER_METHOD_MATCHER);
// Should now match all getter methods
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
pc.union(ABSQUATULATE_METHOD_MATCHER);
// Should now match absquatulate() as well
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
// But it doesn't match everything
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_SET_AGE, TestBean.class));
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_SET_AGE, TestBean.class)).isFalse();
}
@Test
public void testIntersectionMethodMatcher() {
ComposablePointcut pc = new ComposablePointcut();
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
pc.intersection(GETTER_METHOD_MATCHER);
assertFalse(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
pc.intersection(GET_AGE_METHOD_MATCHER);
// Use the Pointcuts matches method
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
}
@Test
@ -138,24 +136,24 @@ public class ComposablePointcutTests {
ComposablePointcut pc1 = new ComposablePointcut();
ComposablePointcut pc2 = new ComposablePointcut();
assertEquals(pc1, pc2);
assertEquals(pc1.hashCode(), pc2.hashCode());
assertThat(pc2).isEqualTo(pc1);
assertThat(pc2.hashCode()).isEqualTo(pc1.hashCode());
pc1.intersection(GETTER_METHOD_MATCHER);
assertFalse(pc1.equals(pc2));
assertFalse(pc1.hashCode() == pc2.hashCode());
assertThat(pc1.equals(pc2)).isFalse();
assertThat(pc1.hashCode() == pc2.hashCode()).isFalse();
pc2.intersection(GETTER_METHOD_MATCHER);
assertEquals(pc1, pc2);
assertEquals(pc1.hashCode(), pc2.hashCode());
assertThat(pc2).isEqualTo(pc1);
assertThat(pc2.hashCode()).isEqualTo(pc1.hashCode());
pc1.union(GET_AGE_METHOD_MATCHER);
pc2.union(GET_AGE_METHOD_MATCHER);
assertEquals(pc1, pc2);
assertEquals(pc1.hashCode(), pc2.hashCode());
assertThat(pc2).isEqualTo(pc1);
assertThat(pc2.hashCode()).isEqualTo(pc1.hashCode());
}
}

View File

@ -24,8 +24,7 @@ import org.springframework.tests.aop.interceptor.NopInterceptor;
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.assertj.core.api.Assertions.assertThat;
/**
* @author Rod Johnson
@ -44,17 +43,17 @@ public class ControlFlowPointcutTests {
pf.addAdvisor(new DefaultPointcutAdvisor(cflow, nop));
// Not advised, not under One
assertEquals(target.getAge(), proxied.getAge());
assertEquals(0, nop.getCount());
assertThat(proxied.getAge()).isEqualTo(target.getAge());
assertThat(nop.getCount()).isEqualTo(0);
// Will be advised
assertEquals(target.getAge(), new One().getAge(proxied));
assertEquals(1, nop.getCount());
assertThat(new One().getAge(proxied)).isEqualTo(target.getAge());
assertThat(nop.getCount()).isEqualTo(1);
// Won't be advised
assertEquals(target.getAge(), new One().nomatch(proxied));
assertEquals(1, nop.getCount());
assertEquals(3, cflow.getEvaluations());
assertThat(new One().nomatch(proxied)).isEqualTo(target.getAge());
assertThat(nop.getCount()).isEqualTo(1);
assertThat(cflow.getEvaluations()).isEqualTo(3);
}
/**
@ -77,28 +76,28 @@ public class ControlFlowPointcutTests {
// Not advised, not under One
target.setAge(16);
assertEquals(0, nop.getCount());
assertThat(nop.getCount()).isEqualTo(0);
// Not advised; under One but not a setter
assertEquals(16, new One().getAge(proxied));
assertEquals(0, nop.getCount());
assertThat(new One().getAge(proxied)).isEqualTo(16);
assertThat(nop.getCount()).isEqualTo(0);
// Won't be advised
new One().set(proxied);
assertEquals(1, nop.getCount());
assertThat(nop.getCount()).isEqualTo(1);
// We saved most evaluations
assertEquals(1, cflow.getEvaluations());
assertThat(cflow.getEvaluations()).isEqualTo(1);
}
@Test
public void testEqualsAndHashCode() throws Exception {
assertEquals(new ControlFlowPointcut(One.class), new ControlFlowPointcut(One.class));
assertEquals(new ControlFlowPointcut(One.class, "getAge"), new ControlFlowPointcut(One.class, "getAge"));
assertFalse(new ControlFlowPointcut(One.class, "getAge").equals(new ControlFlowPointcut(One.class)));
assertEquals(new ControlFlowPointcut(One.class).hashCode(), new ControlFlowPointcut(One.class).hashCode());
assertEquals(new ControlFlowPointcut(One.class, "getAge").hashCode(), new ControlFlowPointcut(One.class, "getAge").hashCode());
assertFalse(new ControlFlowPointcut(One.class, "getAge").hashCode() == new ControlFlowPointcut(One.class).hashCode());
assertThat(new ControlFlowPointcut(One.class)).isEqualTo(new ControlFlowPointcut(One.class));
assertThat(new ControlFlowPointcut(One.class, "getAge")).isEqualTo(new ControlFlowPointcut(One.class, "getAge"));
assertThat(new ControlFlowPointcut(One.class, "getAge").equals(new ControlFlowPointcut(One.class))).isFalse();
assertThat(new ControlFlowPointcut(One.class).hashCode()).isEqualTo(new ControlFlowPointcut(One.class).hashCode());
assertThat(new ControlFlowPointcut(One.class, "getAge").hashCode()).isEqualTo(new ControlFlowPointcut(One.class, "getAge").hashCode());
assertThat(new ControlFlowPointcut(One.class, "getAge").hashCode() == new ControlFlowPointcut(One.class).hashCode()).isFalse();
}
public class One {

View File

@ -36,9 +36,6 @@ import org.springframework.util.SerializationTestUtils;
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.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@ -59,7 +56,7 @@ public class DelegatingIntroductionInterceptorTests {
@Test
public void testIntroductionInterceptorWithDelegation() throws Exception {
TestBean raw = new TestBean();
assertTrue(! (raw instanceof TimeStamped));
assertThat(! (raw instanceof TimeStamped)).isTrue();
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = mock(TimeStamped.class);
@ -69,13 +66,13 @@ public class DelegatingIntroductionInterceptorTests {
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
TimeStamped tsp = (TimeStamped) factory.getProxy();
assertTrue(tsp.getTimeStamp() == timestamp);
assertThat(tsp.getTimeStamp() == timestamp).isTrue();
}
@Test
public void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
TestBean raw = new TestBean();
assertTrue(! (raw instanceof SubTimeStamped));
assertThat(! (raw instanceof SubTimeStamped)).isTrue();
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = mock(SubTimeStamped.class);
@ -85,13 +82,13 @@ public class DelegatingIntroductionInterceptorTests {
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), SubTimeStamped.class));
SubTimeStamped tsp = (SubTimeStamped) factory.getProxy();
assertTrue(tsp.getTimeStamp() == timestamp);
assertThat(tsp.getTimeStamp() == timestamp).isTrue();
}
@Test
public void testIntroductionInterceptorWithSuperInterface() throws Exception {
TestBean raw = new TestBean();
assertTrue(! (raw instanceof TimeStamped));
assertThat(! (raw instanceof TimeStamped)).isTrue();
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = mock(SubTimeStamped.class);
@ -101,8 +98,8 @@ public class DelegatingIntroductionInterceptorTests {
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), TimeStamped.class));
TimeStamped tsp = (TimeStamped) factory.getProxy();
assertTrue(!(tsp instanceof SubTimeStamped));
assertTrue(tsp.getTimeStamp() == timestamp);
assertThat(!(tsp instanceof SubTimeStamped)).isTrue();
assertThat(tsp.getTimeStamp() == timestamp).isTrue();
}
@Test
@ -128,7 +125,7 @@ public class DelegatingIntroductionInterceptorTests {
//assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
TimeStamped ts = (TimeStamped) pf.getProxy();
assertTrue(ts.getTimeStamp() == t);
assertThat(ts.getTimeStamp() == t).isTrue();
((ITester) ts).foo();
((ITestBean) ts).getAge();
@ -155,7 +152,7 @@ public class DelegatingIntroductionInterceptorTests {
ProxyFactory pf = new ProxyFactory(target);
IntroductionAdvisor ia = new DefaultIntroductionAdvisor(ii);
assertTrue(ia.isPerInstance());
assertThat(ia.isPerInstance()).isTrue();
pf.addAdvisor(0, ia);
//assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
@ -163,10 +160,10 @@ public class DelegatingIntroductionInterceptorTests {
assertThat(ts).isInstanceOf(TimeStamped.class);
// Shouldn't proxy framework interfaces
assertTrue(!(ts instanceof MethodInterceptor));
assertTrue(!(ts instanceof IntroductionInterceptor));
assertThat(!(ts instanceof MethodInterceptor)).isTrue();
assertThat(!(ts instanceof IntroductionInterceptor)).isTrue();
assertTrue(ts.getTimeStamp() == t);
assertThat(ts.getTimeStamp() == t).isTrue();
((ITester) ts).foo();
((ITestBean) ts).getAge();
@ -177,14 +174,14 @@ public class DelegatingIntroductionInterceptorTests {
pf = new ProxyFactory(target);
pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii));
Object o = pf.getProxy();
assertTrue(!(o instanceof TimeStamped));
assertThat(!(o instanceof TimeStamped)).isTrue();
}
@SuppressWarnings("serial")
@Test
public void testIntroductionInterceptorDoesntReplaceToString() throws Exception {
TestBean raw = new TestBean();
assertTrue(! (raw instanceof TimeStamped));
assertThat(! (raw instanceof TimeStamped)).isTrue();
ProxyFactory factory = new ProxyFactory(raw);
TimeStamped ts = new SerializableTimeStamped(0);
@ -197,9 +194,9 @@ public class DelegatingIntroductionInterceptorTests {
}));
TimeStamped tsp = (TimeStamped) factory.getProxy();
assertEquals(0, tsp.getTimeStamp());
assertThat(tsp.getTimeStamp()).isEqualTo(0);
assertEquals(raw.toString(), tsp.toString());
assertThat(tsp.toString()).isEqualTo(raw.toString());
}
@Test
@ -217,10 +214,10 @@ public class DelegatingIntroductionInterceptorTests {
pf.addAdvice(new DelegatingIntroductionInterceptor(delegate));
INestedTestBean proxy = (INestedTestBean) pf.getProxy();
assertEquals(company, proxy.getCompany());
assertThat(proxy.getCompany()).isEqualTo(company);
ITestBean introduction = (ITestBean) proxy;
assertSame("Introduced method returning delegate returns proxy", introduction, introduction.getSpouse());
assertTrue("Introduced method returning delegate returns proxy", AopUtils.isAopProxy(introduction.getSpouse()));
assertThat(introduction.getSpouse()).as("Introduced method returning delegate returns proxy").isSameAs(introduction);
assertThat(AopUtils.isAopProxy(introduction.getSpouse())).as("Introduced method returning delegate returns proxy").isTrue();
}
@Test
@ -239,12 +236,12 @@ public class DelegatingIntroductionInterceptorTests {
Person p = (Person) factory.getProxy();
assertEquals(name, p.getName());
assertEquals(time, ((TimeStamped) p).getTimeStamp());
assertThat(p.getName()).isEqualTo(name);
assertThat(((TimeStamped) p).getTimeStamp()).isEqualTo(time);
Person p1 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
assertEquals(name, p1.getName());
assertEquals(time, ((TimeStamped) p1).getTimeStamp());
assertThat(p1.getName()).isEqualTo(name);
assertThat(((TimeStamped) p1).getTimeStamp()).isEqualTo(time);
}
// Test when target implements the interface: should get interceptor by preference.
@ -269,7 +266,7 @@ public class DelegatingIntroductionInterceptorTests {
TimeStamped ts = (TimeStamped) pf.getProxy();
// From introduction interceptor, not target
assertTrue(ts.getTimeStamp() == t);
assertThat(ts.getTimeStamp() == t).isTrue();
}

View File

@ -27,9 +27,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.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
@ -57,24 +55,24 @@ public class MethodMatchersTests {
@Test
public void testDefaultMatchesAll() throws Exception {
MethodMatcher defaultMm = MethodMatcher.TRUE;
assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue();
assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isTrue();
}
@Test
public void testMethodMatcherTrueSerializable() throws Exception {
assertSame(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE), MethodMatcher.TRUE);
assertThat(MethodMatcher.TRUE).isSameAs(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE));
}
@Test
public void testSingle() throws Exception {
MethodMatcher defaultMm = MethodMatcher.TRUE;
assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue();
assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isTrue();
defaultMm = MethodMatchers.intersection(defaultMm, new StartsWithMatcher("get"));
assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
assertFalse(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue();
assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isFalse();
}
@ -83,14 +81,14 @@ public class MethodMatchersTests {
MethodMatcher mm1 = MethodMatcher.TRUE;
MethodMatcher mm2 = new TestDynamicMethodMatcherWhichMatches();
MethodMatcher intersection = MethodMatchers.intersection(mm1, mm2);
assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
assertTrue("3Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5)));
assertThat(intersection.isRuntime()).as("Intersection is a dynamic matcher").isTrue();
assertThat(intersection.matches(ITESTBEAN_SETAGE, TestBean.class)).as("2Matched setAge method").isTrue();
assertThat(intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5))).as("3Matched setAge method").isTrue();
// Knock out dynamic part
intersection = MethodMatchers.intersection(intersection, new TestDynamicMethodMatcherWhichDoesNotMatch());
assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5)));
assertThat(intersection.isRuntime()).as("Intersection is a dynamic matcher").isTrue();
assertThat(intersection.matches(ITESTBEAN_SETAGE, TestBean.class)).as("2Matched setAge method").isTrue();
assertThat(intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5))).as("3 - not Matched setAge method").isFalse();
}
@Test
@ -99,18 +97,18 @@ public class MethodMatchersTests {
MethodMatcher setterMatcher = new StartsWithMatcher("set");
MethodMatcher union = MethodMatchers.union(getterMatcher, setterMatcher);
assertFalse("Union is a static matcher", union.isRuntime());
assertTrue("Matched setAge method", union.matches(ITESTBEAN_SETAGE, TestBean.class));
assertTrue("Matched getAge method", union.matches(ITESTBEAN_GETAGE, TestBean.class));
assertFalse("Didn't matched absquatulate method", union.matches(IOTHER_ABSQUATULATE, TestBean.class));
assertThat(union.isRuntime()).as("Union is a static matcher").isFalse();
assertThat(union.matches(ITESTBEAN_SETAGE, TestBean.class)).as("Matched setAge method").isTrue();
assertThat(union.matches(ITESTBEAN_GETAGE, TestBean.class)).as("Matched getAge method").isTrue();
assertThat(union.matches(IOTHER_ABSQUATULATE, TestBean.class)).as("Didn't matched absquatulate method").isFalse();
}
@Test
public void testUnionEquals() {
MethodMatcher first = MethodMatchers.union(MethodMatcher.TRUE, MethodMatcher.TRUE);
MethodMatcher second = new ComposablePointcut(MethodMatcher.TRUE).union(new ComposablePointcut(MethodMatcher.TRUE)).getMethodMatcher();
assertTrue(first.equals(second));
assertTrue(second.equals(first));
assertThat(first.equals(second)).isTrue();
assertThat(second.equals(first)).isTrue();
}

View File

@ -27,9 +27,7 @@ import org.springframework.tests.sample.beans.Person;
import org.springframework.tests.sample.beans.SerializablePerson;
import org.springframework.util.SerializationTestUtils;
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 Rod Johnson
@ -60,21 +58,21 @@ public class NameMatchMethodPointcutTests {
@Test
public void testMatchingOnly() {
// Can't do exact matching through isMatch
assertTrue(pc.isMatch("echo", "ech*"));
assertTrue(pc.isMatch("setName", "setN*"));
assertTrue(pc.isMatch("setName", "set*"));
assertFalse(pc.isMatch("getName", "set*"));
assertFalse(pc.isMatch("setName", "set"));
assertTrue(pc.isMatch("testing", "*ing"));
assertThat(pc.isMatch("echo", "ech*")).isTrue();
assertThat(pc.isMatch("setName", "setN*")).isTrue();
assertThat(pc.isMatch("setName", "set*")).isTrue();
assertThat(pc.isMatch("getName", "set*")).isFalse();
assertThat(pc.isMatch("setName", "set")).isFalse();
assertThat(pc.isMatch("testing", "*ing")).isTrue();
}
@Test
public void testEmpty() throws Throwable {
assertEquals(0, nop.getCount());
assertThat(nop.getCount()).isEqualTo(0);
proxied.getName();
proxied.setName("");
proxied.echo(null);
assertEquals(0, nop.getCount());
assertThat(nop.getCount()).isEqualTo(0);
}
@ -82,29 +80,29 @@ public class NameMatchMethodPointcutTests {
public void testMatchOneMethod() throws Throwable {
pc.addMethodName("echo");
pc.addMethodName("set*");
assertEquals(0, nop.getCount());
assertThat(nop.getCount()).isEqualTo(0);
proxied.getName();
proxied.getName();
assertEquals(0, nop.getCount());
assertThat(nop.getCount()).isEqualTo(0);
proxied.echo(null);
assertEquals(1, nop.getCount());
assertThat(nop.getCount()).isEqualTo(1);
proxied.setName("");
assertEquals(2, nop.getCount());
assertThat(nop.getCount()).isEqualTo(2);
proxied.setAge(25);
assertEquals(25, proxied.getAge());
assertEquals(3, nop.getCount());
assertThat(proxied.getAge()).isEqualTo(25);
assertThat(nop.getCount()).isEqualTo(3);
}
@Test
public void testSets() throws Throwable {
pc.setMappedNames("set*", "echo");
assertEquals(0, nop.getCount());
assertThat(nop.getCount()).isEqualTo(0);
proxied.getName();
proxied.setName("");
assertEquals(1, nop.getCount());
assertThat(nop.getCount()).isEqualTo(1);
proxied.echo(null);
assertEquals(2, nop.getCount());
assertThat(nop.getCount()).isEqualTo(2);
}
@Test
@ -114,9 +112,9 @@ public class NameMatchMethodPointcutTests {
Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(proxied);
NopInterceptor nop2 = (NopInterceptor) ((Advised) p2).getAdvisors()[0].getAdvice();
p2.getName();
assertEquals(2, nop2.getCount());
assertThat(nop2.getCount()).isEqualTo(2);
p2.echo(null);
assertEquals(3, nop2.getCount());
assertThat(nop2.getCount()).isEqualTo(3);
}
@Test
@ -126,16 +124,16 @@ public class NameMatchMethodPointcutTests {
String foo = "foo";
assertEquals(pc1, pc2);
assertEquals(pc1.hashCode(), pc2.hashCode());
assertThat(pc2).isEqualTo(pc1);
assertThat(pc2.hashCode()).isEqualTo(pc1.hashCode());
pc1.setMappedName(foo);
assertFalse(pc1.equals(pc2));
assertTrue(pc1.hashCode() != pc2.hashCode());
assertThat(pc1.equals(pc2)).isFalse();
assertThat(pc1.hashCode() != pc2.hashCode()).isTrue();
pc2.setMappedName(foo);
assertEquals(pc1, pc2);
assertEquals(pc1.hashCode(), pc2.hashCode());
assertThat(pc2).isEqualTo(pc1);
assertThat(pc2.hashCode()).isEqualTo(pc1.hashCode());
}
}

View File

@ -25,8 +25,7 @@ import org.springframework.aop.Pointcut;
import org.springframework.lang.Nullable;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rod Johnson
@ -127,22 +126,22 @@ public class PointcutsTests {
@Test
public void testTrue() {
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class));
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class));
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class));
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class));
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
}
@Test
public void testMatches() {
assertTrue(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class));
assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertTrue(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class));
assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isFalse();
assertThat(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
}
/**
@ -151,29 +150,29 @@ public class PointcutsTests {
@Test
public void testUnionOfSettersAndGetters() {
Pointcut union = Pointcuts.union(allClassGetterPointcut, allClassSetterPointcut);
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
}
@Test
public void testUnionOfSpecificGetters() {
Pointcut union = Pointcuts.union(allClassGetAgePointcut, allClassGetNamePointcut);
assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class));
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isFalse();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
// Union with all setters
union = Pointcuts.union(union, allClassSetterPointcut);
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class));
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
}
/**
@ -182,16 +181,16 @@ public class PointcutsTests {
*/
@Test
public void testUnionOfAllSettersAndSubclassSetters() {
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertTrue(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6)));
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isFalse();
assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6))).isTrue();
assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
Pointcut union = Pointcuts.union(myTestBeanSetterPointcut, allClassGetterPointcut);
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class));
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class)).isTrue();
// Still doesn't match superclass setter
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6)));
assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6))).isTrue();
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isFalse();
}
/**
@ -200,44 +199,44 @@ public class PointcutsTests {
*/
@Test
public void testIntersectionOfSpecificGettersAndSubclassGetters() {
assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, TestBean.class));
assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, MyTestBean.class));
assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, TestBean.class));
assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, MyTestBean.class));
assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, MyTestBean.class));
assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, MyTestBean.class)).isTrue();
assertThat(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, MyTestBean.class)).isTrue();
assertThat(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, MyTestBean.class)).isTrue();
Pointcut intersection = Pointcuts.intersection(allClassGetAgePointcut, myTestBeanGetterPointcut);
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class));
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class));
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class));
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class)).isFalse();
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class)).isTrue();
// Matches subclass of MyTestBean
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class));
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class));
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class)).isFalse();
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class)).isTrue();
// Now intersection with MyTestBeanSubclass getters should eliminate MyTestBean target
intersection = Pointcuts.intersection(intersection, myTestBeanSubclassGetterPointcut);
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class));
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class));
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class));
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class)).isFalse();
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class)).isFalse();
// Still matches subclass of MyTestBean
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class));
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class));
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class)).isFalse();
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class)).isTrue();
// Now union with all TestBean methods
Pointcut union = Pointcuts.union(intersection, allTestBeanMethodsPointcut);
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBean.class));
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class));
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBean.class)).isFalse();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class)).isFalse();
// Still matches subclass of MyTestBean
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class));
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class));
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class)).isFalse();
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class)).isTrue();
assertTrue(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, MyTestBean.class));
assertThat(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
assertThat(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, MyTestBean.class)).isFalse();
}
@ -247,9 +246,9 @@ public class PointcutsTests {
@Test
public void testSimpleIntersection() {
Pointcut intersection = Pointcuts.intersection(allClassGetterPointcut, allClassSetterPointcut);
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class));
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_ABSQUATULATE, TestBean.class));
assertThat(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isFalse();
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
assertThat(Pointcuts.matches(intersection, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
}
}

View File

@ -29,7 +29,7 @@ import org.springframework.tests.sample.beans.Person;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -49,16 +49,16 @@ public class RegexpMethodPointcutAdvisorIntegrationTests {
ITestBean advised = (ITestBean) bf.getBean("settersAdvised");
// Interceptor behind regexp advisor
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
assertEquals(0, nop.getCount());
assertThat(nop.getCount()).isEqualTo(0);
int newAge = 12;
// Not advised
advised.exceptional(null);
assertEquals(0, nop.getCount());
assertThat(nop.getCount()).isEqualTo(0);
advised.setAge(newAge);
assertEquals(newAge, advised.getAge());
assertThat(advised.getAge()).isEqualTo(newAge);
// Only setter fired
assertEquals(1, nop.getCount());
assertThat(nop.getCount()).isEqualTo(1);
}
@Test
@ -69,20 +69,20 @@ public class RegexpMethodPointcutAdvisorIntegrationTests {
TestBean advised = (TestBean) bf.getBean("settersAndAbsquatulateAdvised");
// Interceptor behind regexp advisor
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
assertEquals(0, nop.getCount());
assertThat(nop.getCount()).isEqualTo(0);
int newAge = 12;
// Not advised
advised.exceptional(null);
assertEquals(0, nop.getCount());
assertThat(nop.getCount()).isEqualTo(0);
// This is proxied
advised.absquatulate();
assertEquals(1, nop.getCount());
assertThat(nop.getCount()).isEqualTo(1);
advised.setAge(newAge);
assertEquals(newAge, advised.getAge());
assertThat(advised.getAge()).isEqualTo(newAge);
// Only setter fired
assertEquals(2, nop.getCount());
assertThat(nop.getCount()).isEqualTo(2);
}
@Test
@ -93,31 +93,31 @@ public class RegexpMethodPointcutAdvisorIntegrationTests {
Person p = (Person) bf.getBean("serializableSettersAdvised");
// Interceptor behind regexp advisor
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
assertEquals(0, nop.getCount());
assertThat(nop.getCount()).isEqualTo(0);
int newAge = 12;
// Not advised
assertEquals(0, p.getAge());
assertEquals(0, nop.getCount());
assertThat(p.getAge()).isEqualTo(0);
assertThat(nop.getCount()).isEqualTo(0);
// This is proxied
p.setAge(newAge);
assertEquals(1, nop.getCount());
assertThat(nop.getCount()).isEqualTo(1);
p.setAge(newAge);
assertEquals(newAge, p.getAge());
assertThat(p.getAge()).isEqualTo(newAge);
// Only setter fired
assertEquals(2, nop.getCount());
assertThat(nop.getCount()).isEqualTo(2);
// Serialize and continue...
p = (Person) SerializationTestUtils.serializeAndDeserialize(p);
assertEquals(newAge, p.getAge());
assertThat(p.getAge()).isEqualTo(newAge);
// Remembers count, but we need to get a new reference to nop...
nop = (SerializableNopInterceptor) ((Advised) p).getAdvisors()[0].getAdvice();
assertEquals(2, nop.getCount());
assertEquals("serializableSettersAdvised", p.getName());
assertThat(nop.getCount()).isEqualTo(2);
assertThat(p.getName()).isEqualTo("serializableSettersAdvised");
p.setAge(newAge + 1);
assertEquals(3, nop.getCount());
assertEquals(newAge + 1, p.getAge());
assertThat(nop.getCount()).isEqualTo(3);
assertThat(p.getAge()).isEqualTo((newAge + 1));
}
}

View File

@ -24,7 +24,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource;
import org.springframework.tests.sample.beans.ITestBean;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -42,6 +42,6 @@ public class CommonsPool2TargetSourceProxyTests {
reader.loadBeanDefinitions(CONTEXT);
beanFactory.preInstantiateSingletons();
ITestBean bean = (ITestBean)beanFactory.getBean("testBean");
assertTrue(AopUtils.isAopProxy(bean));
assertThat(AopUtils.isAopProxy(bean)).isTrue();
}
}

View File

@ -31,8 +31,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.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -70,13 +70,13 @@ public class HotSwappableTargetSourceTests {
@Test
public void testBasicFunctionality() {
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
assertEquals(INITIAL_COUNT, proxied.getCount());
assertThat(proxied.getCount()).isEqualTo(INITIAL_COUNT);
proxied.doWork();
assertEquals(INITIAL_COUNT + 1, proxied.getCount());
assertThat(proxied.getCount()).isEqualTo((INITIAL_COUNT + 1));
proxied = (SideEffectBean) beanFactory.getBean("swappable");
proxied.doWork();
assertEquals(INITIAL_COUNT + 2, proxied.getCount());
assertThat(proxied.getCount()).isEqualTo((INITIAL_COUNT + 2));
}
@Test
@ -85,25 +85,25 @@ public class HotSwappableTargetSourceTests {
SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2");
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
assertEquals(target1.getCount(), proxied.getCount());
assertThat(proxied.getCount()).isEqualTo(target1.getCount());
proxied.doWork();
assertEquals(INITIAL_COUNT + 1, proxied.getCount());
assertThat(proxied.getCount()).isEqualTo((INITIAL_COUNT + 1));
HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper");
Object old = swapper.swap(target2);
assertEquals("Correct old target was returned", target1, old);
assertThat(old).as("Correct old target was returned").isEqualTo(target1);
// TODO should be able to make this assertion: need to fix target handling
// in AdvisedSupport
//assertEquals(target2, ((Advised) proxied).getTarget());
assertEquals(20, proxied.getCount());
assertThat(proxied.getCount()).isEqualTo(20);
proxied.doWork();
assertEquals(21, target2.getCount());
assertThat(target2.getCount()).isEqualTo(21);
// Swap it back
swapper.swap(target1);
assertEquals(target1.getCount(), proxied.getCount());
assertThat(proxied.getCount()).isEqualTo(target1.getCount());
}
@Test
@ -130,16 +130,16 @@ public class HotSwappableTargetSourceTests {
pf.addAdvisor(new DefaultPointcutAdvisor(new SerializableNopInterceptor()));
Person p = (Person) pf.getProxy();
assertEquals(sp1.getName(), p.getName());
assertThat(p.getName()).isEqualTo(sp1.getName());
hts.swap(sp2);
assertEquals(sp2.getName(), p.getName());
assertThat(p.getName()).isEqualTo(sp2.getName());
p = (Person) SerializationTestUtils.serializeAndDeserialize(p);
// We need to get a reference to the client-side targetsource
hts = (HotSwappableTargetSource) ((Advised) p).getTargetSource();
assertEquals(sp2.getName(), p.getName());
assertThat(p.getName()).isEqualTo(sp2.getName());
hts.swap(sp1);
assertEquals(sp1.getName(), p.getName());
assertThat(p.getName()).isEqualTo(sp1.getName());
}

View File

@ -21,7 +21,7 @@ import org.junit.Test;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.ProxyFactory;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Harrop
@ -44,15 +44,15 @@ public class LazyCreationTargetSourceTests {
};
InitCountingBean proxy = (InitCountingBean) ProxyFactory.getProxy(targetSource);
assertEquals("Init count should be 0", 0, InitCountingBean.initCount);
assertEquals("Target class incorrect", InitCountingBean.class, targetSource.getTargetClass());
assertEquals("Init count should still be 0 after getTargetClass()", 0, InitCountingBean.initCount);
assertThat(InitCountingBean.initCount).as("Init count should be 0").isEqualTo(0);
assertThat(targetSource.getTargetClass()).as("Target class incorrect").isEqualTo(InitCountingBean.class);
assertThat(InitCountingBean.initCount).as("Init count should still be 0 after getTargetClass()").isEqualTo(0);
proxy.doSomething();
assertEquals("Init count should now be 1", 1, InitCountingBean.initCount);
assertThat(InitCountingBean.initCount).as("Init count should now be 1").isEqualTo(1);
proxy.doSomething();
assertEquals("Init count should still be 1", 1, InitCountingBean.initCount);
assertThat(InitCountingBean.initCount).as("Init count should still be 1").isEqualTo(1);
}

View File

@ -25,9 +25,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource;
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;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -51,9 +49,9 @@ public class LazyInitTargetSourceTests {
bf.preInstantiateSingletons();
ITestBean tb = (ITestBean) bf.getBean("proxy");
assertFalse(bf.containsSingleton("target"));
assertEquals(10, tb.getAge());
assertTrue(bf.containsSingleton("target"));
assertThat(bf.containsSingleton("target")).isFalse();
assertThat(tb.getAge()).isEqualTo(10);
assertThat(bf.containsSingleton("target")).isTrue();
}
@Test
@ -63,9 +61,9 @@ public class LazyInitTargetSourceTests {
bf.preInstantiateSingletons();
ITestBean tb = (ITestBean) bf.getBean("proxy");
assertFalse(bf.containsSingleton("target"));
assertEquals("Rob Harrop", tb.getName());
assertTrue(bf.containsSingleton("target"));
assertThat(bf.containsSingleton("target")).isFalse();
assertThat(tb.getName()).isEqualTo("Rob Harrop");
assertThat(bf.containsSingleton("target")).isTrue();
}
@Test
@ -75,14 +73,14 @@ public class LazyInitTargetSourceTests {
bf.preInstantiateSingletons();
Set<?> set1 = (Set<?>) bf.getBean("proxy1");
assertFalse(bf.containsSingleton("target1"));
assertTrue(set1.contains("10"));
assertTrue(bf.containsSingleton("target1"));
assertThat(bf.containsSingleton("target1")).isFalse();
assertThat(set1.contains("10")).isTrue();
assertThat(bf.containsSingleton("target1")).isTrue();
Set<?> set2 = (Set<?>) bf.getBean("proxy2");
assertFalse(bf.containsSingleton("target2"));
assertTrue(set2.contains("20"));
assertTrue(bf.containsSingleton("target2"));
assertThat(bf.containsSingleton("target2")).isFalse();
assertThat(set2.contains("20")).isTrue();
assertThat(bf.containsSingleton("target2")).isTrue();
}

View File

@ -26,8 +26,7 @@ import org.springframework.tests.sample.beans.SerializablePerson;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.SerializationTestUtils;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests relating to the abstract {@link AbstractPrototypeBasedTargetSource}
@ -56,10 +55,10 @@ public class PrototypeBasedTargetSourceTests {
TestTargetSource cpts = (TestTargetSource) bf.getBean("ts");
TargetSource serialized = (TargetSource) SerializationTestUtils.serializeAndDeserialize(cpts);
assertTrue("Changed to SingletonTargetSource on deserialization",
serialized instanceof SingletonTargetSource);
boolean condition = serialized instanceof SingletonTargetSource;
assertThat(condition).as("Changed to SingletonTargetSource on deserialization").isTrue();
SingletonTargetSource sts = (SingletonTargetSource) serialized;
assertNotNull(sts.getTarget());
assertThat(sts.getTarget()).isNotNull();
}
@ -71,6 +70,7 @@ public class PrototypeBasedTargetSourceTests {
* Nonserializable test field to check that subclass
* state can't prevent serialization from working
*/
@SuppressWarnings("unused")
private TestBean thisFieldIsNotSerializable = new TestBean();
@Override

View File

@ -23,7 +23,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.tests.sample.beans.SideEffectBean;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -54,14 +54,14 @@ public class PrototypeTargetSourceTests {
@Test
public void testPrototypeAndSingletonBehaveDifferently() {
SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton");
assertEquals(INITIAL_COUNT, singleton.getCount());
assertThat(singleton.getCount()).isEqualTo(INITIAL_COUNT);
singleton.doWork();
assertEquals(INITIAL_COUNT + 1, singleton.getCount());
assertThat(singleton.getCount()).isEqualTo((INITIAL_COUNT + 1));
SideEffectBean prototype = (SideEffectBean) beanFactory.getBean("prototype");
assertEquals(INITIAL_COUNT, prototype.getCount());
assertThat(prototype.getCount()).isEqualTo(INITIAL_COUNT);
prototype.doWork();
assertEquals(INITIAL_COUNT, prototype.getCount());
assertThat(prototype.getCount()).isEqualTo(INITIAL_COUNT);
}
}

View File

@ -24,8 +24,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.SideEffectBean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -63,24 +62,24 @@ public class ThreadLocalTargetSourceTests {
@Test
public void testUseDifferentManagedInstancesInSameThread() {
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertEquals(INITIAL_COUNT, apartment.getCount());
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
apartment.doWork();
assertEquals(INITIAL_COUNT + 1, apartment.getCount());
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
ITestBean test = (ITestBean) beanFactory.getBean("threadLocal2");
assertEquals("Rod", test.getName());
assertEquals("Kerry", test.getSpouse().getName());
assertThat(test.getName()).isEqualTo("Rod");
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
}
@Test
public void testReuseInSameThread() {
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertEquals(INITIAL_COUNT, apartment.getCount());
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
apartment.doWork();
assertEquals(INITIAL_COUNT + 1, apartment.getCount());
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertEquals(INITIAL_COUNT + 1, apartment.getCount());
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
}
/**
@ -90,37 +89,37 @@ public class ThreadLocalTargetSourceTests {
public void testCanGetStatsViaMixin() {
ThreadLocalTargetSourceStats stats = (ThreadLocalTargetSourceStats) beanFactory.getBean("apartment");
// +1 because creating target for stats call counts
assertEquals(1, stats.getInvocationCount());
assertThat(stats.getInvocationCount()).isEqualTo(1);
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
apartment.doWork();
// +1 again
assertEquals(3, stats.getInvocationCount());
assertThat(stats.getInvocationCount()).isEqualTo(3);
// + 1 for states call!
assertEquals(3, stats.getHitCount());
assertThat(stats.getHitCount()).isEqualTo(3);
apartment.doWork();
assertEquals(6, stats.getInvocationCount());
assertEquals(6, stats.getHitCount());
assertThat(stats.getInvocationCount()).isEqualTo(6);
assertThat(stats.getHitCount()).isEqualTo(6);
// Only one thread so only one object can have been bound
assertEquals(1, stats.getObjectCount());
assertThat(stats.getObjectCount()).isEqualTo(1);
}
@Test
public void testNewThreadHasOwnInstance() throws InterruptedException {
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertEquals(INITIAL_COUNT, apartment.getCount());
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
apartment.doWork();
apartment.doWork();
apartment.doWork();
assertEquals(INITIAL_COUNT + 3, apartment.getCount());
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 3));
class Runner implements Runnable {
public SideEffectBean mine;
@Override
public void run() {
this.mine = (SideEffectBean) beanFactory.getBean("apartment");
assertEquals(INITIAL_COUNT, mine.getCount());
assertThat(mine.getCount()).isEqualTo(INITIAL_COUNT);
mine.doWork();
assertEquals(INITIAL_COUNT + 1, mine.getCount());
assertThat(mine.getCount()).isEqualTo((INITIAL_COUNT + 1));
}
}
Runner r = new Runner();
@ -128,17 +127,17 @@ public class ThreadLocalTargetSourceTests {
t.start();
t.join();
assertNotNull(r);
assertThat(r).isNotNull();
// Check it didn't affect the other thread's copy
assertEquals(INITIAL_COUNT + 3, apartment.getCount());
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 3));
// When we use other thread's copy in this thread
// it should behave like ours
assertEquals(INITIAL_COUNT + 3, r.mine.getCount());
assertThat(r.mine.getCount()).isEqualTo((INITIAL_COUNT + 3));
// Bound to two threads
assertEquals(2, ((ThreadLocalTargetSourceStats) apartment).getObjectCount());
assertThat(((ThreadLocalTargetSourceStats) apartment).getObjectCount()).isEqualTo(2);
}
/**

View File

@ -21,11 +21,7 @@ import org.junit.Test;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
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.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Harrop
@ -45,8 +41,8 @@ public class RefreshableTargetSourceTests {
Thread.sleep(1);
Object b = ts.getTarget();
assertEquals("Should be one call to freshTarget to get initial target", 1, ts.getCallCount());
assertSame("Returned objects should be the same - no refresh should occur", a, b);
assertThat(ts.getCallCount()).as("Should be one call to freshTarget to get initial target").isEqualTo(1);
assertThat(b).as("Returned objects should be the same - no refresh should occur").isSameAs(a);
}
/**
@ -61,8 +57,8 @@ public class RefreshableTargetSourceTests {
Thread.sleep(100);
Object b = ts.getTarget();
assertEquals("Should have called freshTarget twice", 2, ts.getCallCount());
assertNotSame("Should be different objects", a, b);
assertThat(ts.getCallCount()).as("Should have called freshTarget twice").isEqualTo(2);
assertThat(b).as("Should be different objects").isNotSameAs(a);
}
/**
@ -76,8 +72,8 @@ public class RefreshableTargetSourceTests {
Object a = ts.getTarget();
Object b = ts.getTarget();
assertEquals("Refresh target should only be called once", 1, ts.getCallCount());
assertSame("Objects should be the same - refresh check delay not elapsed", a, b);
assertThat(ts.getCallCount()).as("Refresh target should only be called once").isEqualTo(1);
assertThat(b).as("Objects should be the same - refresh check delay not elapsed").isSameAs(a);
}
@Test
@ -89,26 +85,26 @@ public class RefreshableTargetSourceTests {
Object a = ts.getTarget();
Object b = ts.getTarget();
assertEquals("Objects should be same", a, b);
assertThat(b).as("Objects should be same").isEqualTo(a);
Thread.sleep(50);
Object c = ts.getTarget();
assertEquals("A and C should be same", a, c);
assertThat(c).as("A and C should be same").isEqualTo(a);
Thread.sleep(60);
Object d = ts.getTarget();
assertNotNull("D should not be null", d);
assertFalse("A and D should not be equal", a.equals(d));
assertThat(d).as("D should not be null").isNotNull();
assertThat(a.equals(d)).as("A and D should not be equal").isFalse();
Object e = ts.getTarget();
assertEquals("D and E should be equal", d, e);
assertThat(e).as("D and E should be equal").isEqualTo(d);
Thread.sleep(110);
Object f = ts.getTarget();
assertFalse("E and F should be different", e.equals(f));
assertThat(e.equals(f)).as("E and F should be different").isFalse();
}

View File

@ -20,7 +20,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 Chris Beams
@ -33,7 +33,7 @@ public class XmlBeanConfigurerTests {
"org/springframework/beans/factory/aspectj/beanConfigurerTests.xml")) {
ShouldBeConfiguredBySpring myObject = new ShouldBeConfiguredBySpring();
assertEquals("Rod", myObject.getName());
assertThat(myObject.getName()).isEqualTo("Rod");
}
}

View File

@ -24,9 +24,7 @@ import org.springframework.cache.config.CacheableService;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Costin Leau
@ -43,7 +41,7 @@ public class AspectJCacheAnnotationTests extends AbstractCacheAnnotationTests {
public void testKeyStrategy() throws Exception {
AnnotationCacheAspect aspect = ctx.getBean(
"org.springframework.cache.config.internalCacheAspect", AnnotationCacheAspect.class);
assertSame(ctx.getBean("keyGenerator"), aspect.getKeyGenerator());
assertThat(aspect.getKeyGenerator()).isSameAs(ctx.getBean("keyGenerator"));
}
@Override
@ -56,21 +54,21 @@ public class AspectJCacheAnnotationTests extends AbstractCacheAnnotationTests {
Cache primary = cm.getCache("primary");
Cache secondary = cm.getCache("secondary");
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));
assertThat(primary.get(o1)).isNull();
assertThat(secondary.get(o1)).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);
}
}

View File

@ -43,10 +43,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;
/**
* @author Stephane Nicoll
@ -72,14 +69,14 @@ public class AspectJEnableCachingIsolatedTests {
public void testKeyStrategy() {
load(EnableCachingConfig.class);
AnnotationCacheAspect aspect = this.ctx.getBean(AnnotationCacheAspect.class);
assertSame(this.ctx.getBean("keyGenerator", KeyGenerator.class), aspect.getKeyGenerator());
assertThat(aspect.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator", KeyGenerator.class));
}
@Test
public void testCacheErrorHandler() {
load(EnableCachingConfig.class);
AnnotationCacheAspect aspect = this.ctx.getBean(AnnotationCacheAspect.class);
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), aspect.getErrorHandler());
assertThat(aspect.getErrorHandler()).isSameAs(this.ctx.getBean("errorHandler", CacheErrorHandler.class));
}
@ -96,7 +93,7 @@ public class AspectJEnableCachingIsolatedTests {
load(MultiCacheManagerConfig.class);
}
catch (IllegalStateException ex) {
assertTrue(ex.getMessage().contains("bean of type CacheManager"));
assertThat(ex.getMessage().contains("bean of type CacheManager")).isTrue();
}
}
@ -112,8 +109,9 @@ public class AspectJEnableCachingIsolatedTests {
}
catch (BeanCreationException ex) {
Throwable root = ex.getRootCause();
assertTrue(root instanceof IllegalStateException);
assertTrue(ex.getMessage().contains("implementations of CachingConfigurer"));
boolean condition = root instanceof IllegalStateException;
assertThat(condition).isTrue();
assertThat(ex.getMessage().contains("implementations of CachingConfigurer")).isTrue();
}
}
@ -123,7 +121,7 @@ public class AspectJEnableCachingIsolatedTests {
load(EmptyConfig.class);
}
catch (IllegalStateException ex) {
assertTrue(ex.getMessage().contains("no bean of type CacheManager"));
assertThat(ex.getMessage().contains("no bean of type CacheManager")).isTrue();
}
}
@ -132,10 +130,9 @@ public class AspectJEnableCachingIsolatedTests {
public void emptyConfigSupport() {
load(EmptyConfigSupportConfig.class);
AnnotationCacheAspect aspect = this.ctx.getBean(AnnotationCacheAspect.class);
assertNotNull(aspect.getCacheResolver());
assertEquals(SimpleCacheResolver.class, aspect.getCacheResolver().getClass());
assertSame(this.ctx.getBean(CacheManager.class),
((SimpleCacheResolver) aspect.getCacheResolver()).getCacheManager());
assertThat(aspect.getCacheResolver()).isNotNull();
assertThat(aspect.getCacheResolver().getClass()).isEqualTo(SimpleCacheResolver.class);
assertThat(((SimpleCacheResolver) aspect.getCacheResolver()).getCacheManager()).isSameAs(this.ctx.getBean(CacheManager.class));
}
@Test
@ -143,8 +140,8 @@ public class AspectJEnableCachingIsolatedTests {
load(FullCachingConfig.class);
AnnotationCacheAspect aspect = this.ctx.getBean(AnnotationCacheAspect.class);
assertSame(this.ctx.getBean("cacheResolver"), aspect.getCacheResolver());
assertSame(this.ctx.getBean("keyGenerator"), aspect.getKeyGenerator());
assertThat(aspect.getCacheResolver()).isSameAs(this.ctx.getBean("cacheResolver"));
assertThat(aspect.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator"));
}

View File

@ -23,7 +23,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests that @EnableSpringConfigured properly registers an
@ -39,7 +39,7 @@ public class AnnotationBeanConfigurerTests {
public void injection() {
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class)) {
ShouldBeConfiguredBySpring myObject = new ShouldBeConfiguredBySpring();
assertEquals("Rod", myObject.getName());
assertThat(myObject.getName()).isEqualTo("Rod");
}
}

View File

@ -39,8 +39,6 @@ import org.springframework.util.ReflectionUtils;
import org.springframework.util.concurrent.ListenableFuture;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
/**
* Unit tests for {@link AnnotationAsyncExecutionAspect}.
@ -71,9 +69,9 @@ public class AnnotationAsyncExecutionAspectTests {
ClassWithoutAsyncAnnotation obj = new ClassWithoutAsyncAnnotation();
obj.incrementAsync();
executor.waitForCompletion();
assertEquals(1, obj.counter);
assertEquals(1, executor.submitStartCounter);
assertEquals(1, executor.submitCompleteCounter);
assertThat(obj.counter).isEqualTo(1);
assertThat(executor.submitStartCounter).isEqualTo(1);
assertThat(executor.submitCompleteCounter).isEqualTo(1);
}
@Test
@ -81,19 +79,19 @@ public class AnnotationAsyncExecutionAspectTests {
ClassWithoutAsyncAnnotation obj = new ClassWithoutAsyncAnnotation();
Future<Integer> future = obj.incrementReturningAFuture();
// No need to executor.waitForCompletion() as future.get() will have the same effect
assertEquals(5, future.get().intValue());
assertEquals(1, obj.counter);
assertEquals(1, executor.submitStartCounter);
assertEquals(1, executor.submitCompleteCounter);
assertThat(future.get().intValue()).isEqualTo(5);
assertThat(obj.counter).isEqualTo(1);
assertThat(executor.submitStartCounter).isEqualTo(1);
assertThat(executor.submitCompleteCounter).isEqualTo(1);
}
@Test
public void syncMethodGetsRoutedSynchronously() {
ClassWithoutAsyncAnnotation obj = new ClassWithoutAsyncAnnotation();
obj.increment();
assertEquals(1, obj.counter);
assertEquals(0, executor.submitStartCounter);
assertEquals(0, executor.submitCompleteCounter);
assertThat(obj.counter).isEqualTo(1);
assertThat(executor.submitStartCounter).isEqualTo(0);
assertThat(executor.submitCompleteCounter).isEqualTo(0);
}
@Test
@ -103,19 +101,19 @@ public class AnnotationAsyncExecutionAspectTests {
ClassWithAsyncAnnotation obj = new ClassWithAsyncAnnotation();
obj.increment();
executor.waitForCompletion();
assertEquals(1, obj.counter);
assertEquals(1, executor.submitStartCounter);
assertEquals(1, executor.submitCompleteCounter);
assertThat(obj.counter).isEqualTo(1);
assertThat(executor.submitStartCounter).isEqualTo(1);
assertThat(executor.submitCompleteCounter).isEqualTo(1);
}
@Test
public void methodReturningFutureInAsyncClassGetsRoutedAsynchronouslyAndReturnsAFuture() throws InterruptedException, ExecutionException {
ClassWithAsyncAnnotation obj = new ClassWithAsyncAnnotation();
Future<Integer> future = obj.incrementReturningAFuture();
assertEquals(5, future.get().intValue());
assertEquals(1, obj.counter);
assertEquals(1, executor.submitStartCounter);
assertEquals(1, executor.submitCompleteCounter);
assertThat(future.get().intValue()).isEqualTo(5);
assertThat(obj.counter).isEqualTo(1);
assertThat(executor.submitStartCounter).isEqualTo(1);
assertThat(executor.submitCompleteCounter).isEqualTo(1);
}
/*
@ -154,7 +152,7 @@ public class AnnotationAsyncExecutionAspectTests {
TestableAsyncUncaughtExceptionHandler exceptionHandler = new TestableAsyncUncaughtExceptionHandler();
AnnotationAsyncExecutionAspect.aspectOf().setExceptionHandler(exceptionHandler);
try {
assertFalse("Handler should not have been called", exceptionHandler.isCalled());
assertThat(exceptionHandler.isCalled()).as("Handler should not have been called").isFalse();
ClassWithException obj = new ClassWithException();
obj.failWithVoid();
exceptionHandler.await(3000);
@ -171,7 +169,7 @@ public class AnnotationAsyncExecutionAspectTests {
TestableAsyncUncaughtExceptionHandler exceptionHandler = new TestableAsyncUncaughtExceptionHandler(true);
AnnotationAsyncExecutionAspect.aspectOf().setExceptionHandler(exceptionHandler);
try {
assertFalse("Handler should not have been called", exceptionHandler.isCalled());
assertThat(exceptionHandler.isCalled()).as("Handler should not have been called").isFalse();
ClassWithException obj = new ClassWithException();
obj.failWithVoid();
exceptionHandler.await(3000);

View File

@ -27,8 +27,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.config.TaskManagementConfigUtils;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Stephane Nicoll
@ -52,7 +51,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
@Test
public void asyncAspectRegistered() {
assertTrue(context.containsBean(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME));
assertThat(context.containsBean(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME)).isTrue();
}
@Test
@ -60,7 +59,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
public void asyncPostProcessorExecutorReference() {
Object executor = context.getBean("testExecutor");
Object aspect = context.getBean(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME);
assertSame(executor, ((Supplier) new DirectFieldAccessor(aspect).getPropertyValue("defaultExecutor")).get());
assertThat(((Supplier) new DirectFieldAccessor(aspect).getPropertyValue("defaultExecutor")).get()).isSameAs(executor);
}
@Test
@ -68,7 +67,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
public void asyncPostProcessorExceptionHandlerReference() {
Object exceptionHandler = context.getBean("testExceptionHandler");
Object aspect = context.getBean(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME);
assertSame(exceptionHandler, ((Supplier) new DirectFieldAccessor(aspect).getPropertyValue("exceptionHandler")).get());
assertThat(((Supplier) new DirectFieldAccessor(aspect).getPropertyValue("exceptionHandler")).get()).isSameAs(exceptionHandler);
}
}

View File

@ -22,8 +22,7 @@ import java.util.concurrent.TimeUnit;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* A {@link AsyncUncaughtExceptionHandler} implementation used for testing purposes.
@ -61,9 +60,9 @@ class TestableAsyncUncaughtExceptionHandler
}
public void assertCalledWith(Method expectedMethod, Class<? extends Throwable> expectedExceptionType) {
assertNotNull("Handler not called", descriptor);
assertEquals("Wrong exception type", expectedExceptionType, descriptor.ex.getClass());
assertEquals("Wrong method", expectedMethod, descriptor.method);
assertThat(descriptor).as("Handler not called").isNotNull();
assertThat(descriptor.ex.getClass()).as("Wrong exception type").isEqualTo(expectedExceptionType);
assertThat(descriptor.method).as("Wrong method").isEqualTo(expectedMethod);
}
public void await(long timeout) {

View File

@ -30,9 +30,9 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.tests.transaction.CallCountingTransactionManager;
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;
/**
* @author Stephane Nicoll
@ -51,66 +51,66 @@ public class JtaTransactionAspectsTests {
@Test
public void commitOnAnnotatedPublicMethod() throws Throwable {
assertEquals(0, this.txManager.begun);
assertThat(this.txManager.begun).isEqualTo(0);
new JtaAnnotationPublicAnnotatedMember().echo(null);
assertEquals(1, this.txManager.commits);
assertThat(this.txManager.commits).isEqualTo(1);
}
@Test
public void matchingRollbackOnApplied() throws Throwable {
assertEquals(0, this.txManager.begun);
assertThat(this.txManager.begun).isEqualTo(0);
InterruptedException test = new InterruptedException();
assertThatExceptionOfType(InterruptedException.class).isThrownBy(() ->
new JtaAnnotationPublicAnnotatedMember().echo(test))
.isSameAs(test);
assertEquals(1, this.txManager.rollbacks);
assertEquals(0, this.txManager.commits);
assertThat(this.txManager.rollbacks).isEqualTo(1);
assertThat(this.txManager.commits).isEqualTo(0);
}
@Test
public void nonMatchingRollbackOnApplied() throws Throwable {
assertEquals(0, this.txManager.begun);
assertThat(this.txManager.begun).isEqualTo(0);
IOException test = new IOException();
assertThatIOException().isThrownBy(() ->
new JtaAnnotationPublicAnnotatedMember().echo(test))
.isSameAs(test);
assertEquals(1, this.txManager.commits);
assertEquals(0, this.txManager.rollbacks);
assertThat(this.txManager.commits).isEqualTo(1);
assertThat(this.txManager.rollbacks).isEqualTo(0);
}
@Test
public void commitOnAnnotatedProtectedMethod() {
assertEquals(0, this.txManager.begun);
assertThat(this.txManager.begun).isEqualTo(0);
new JtaAnnotationProtectedAnnotatedMember().doInTransaction();
assertEquals(1, this.txManager.commits);
assertThat(this.txManager.commits).isEqualTo(1);
}
@Test
public void nonAnnotatedMethodCallingProtectedMethod() {
assertEquals(0, this.txManager.begun);
assertThat(this.txManager.begun).isEqualTo(0);
new JtaAnnotationProtectedAnnotatedMember().doSomething();
assertEquals(1, this.txManager.commits);
assertThat(this.txManager.commits).isEqualTo(1);
}
@Test
public void commitOnAnnotatedPrivateMethod() {
assertEquals(0, this.txManager.begun);
assertThat(this.txManager.begun).isEqualTo(0);
new JtaAnnotationPrivateAnnotatedMember().doInTransaction();
assertEquals(1, this.txManager.commits);
assertThat(this.txManager.commits).isEqualTo(1);
}
@Test
public void nonAnnotatedMethodCallingPrivateMethod() {
assertEquals(0, this.txManager.begun);
assertThat(this.txManager.begun).isEqualTo(0);
new JtaAnnotationPrivateAnnotatedMember().doSomething();
assertEquals(1, this.txManager.commits);
assertThat(this.txManager.commits).isEqualTo(1);
}
@Test
public void notTransactional() {
assertEquals(0, this.txManager.begun);
assertThat(this.txManager.begun).isEqualTo(0);
new TransactionAspectTests.NotTransactional().noop();
assertEquals(0, this.txManager.begun);
assertThat(this.txManager.begun).isEqualTo(0);
}

View File

@ -21,8 +21,8 @@ import org.junit.Test;
import org.springframework.tests.transaction.CallCountingTransactionManager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
/**
* @author Rod Johnson
@ -56,49 +56,49 @@ public class TransactionAspectTests {
@Test
public void testCommitOnAnnotatedClass() throws Throwable {
txManager.clear();
assertEquals(0, txManager.begun);
assertThat(txManager.begun).isEqualTo(0);
annotationOnlyOnClassWithNoInterface.echo(null);
assertEquals(1, txManager.commits);
assertThat(txManager.commits).isEqualTo(1);
}
@Test
public void commitOnAnnotatedProtectedMethod() throws Throwable {
txManager.clear();
assertEquals(0, txManager.begun);
assertThat(txManager.begun).isEqualTo(0);
beanWithAnnotatedProtectedMethod.doInTransaction();
assertEquals(1, txManager.commits);
assertThat(txManager.commits).isEqualTo(1);
}
@Test
public void commitOnAnnotatedPrivateMethod() throws Throwable {
txManager.clear();
assertEquals(0, txManager.begun);
assertThat(txManager.begun).isEqualTo(0);
beanWithAnnotatedPrivateMethod.doSomething();
assertEquals(1, txManager.commits);
assertThat(txManager.commits).isEqualTo(1);
}
@Test
public void commitOnNonAnnotatedNonPublicMethodInTransactionalType() throws Throwable {
txManager.clear();
assertEquals(0, txManager.begun);
assertThat(txManager.begun).isEqualTo(0);
annotationOnlyOnClassWithNoInterface.nonTransactionalMethod();
assertEquals(0, txManager.begun);
assertThat(txManager.begun).isEqualTo(0);
}
@Test
public void commitOnAnnotatedMethod() throws Throwable {
txManager.clear();
assertEquals(0, txManager.begun);
assertThat(txManager.begun).isEqualTo(0);
methodAnnotationOnly.echo(null);
assertEquals(1, txManager.commits);
assertThat(txManager.commits).isEqualTo(1);
}
@Test
public void notTransactional() throws Throwable {
txManager.clear();
assertEquals(0, txManager.begun);
assertThat(txManager.begun).isEqualTo(0);
new NotTransactional().noop();
assertEquals(0, txManager.begun);
assertThat(txManager.begun).isEqualTo(0);
}
@Test
@ -149,23 +149,25 @@ public class TransactionAspectTests {
protected void testRollback(TransactionOperationCallback toc, boolean rollback) throws Throwable {
txManager.clear();
assertEquals(0, txManager.begun);
assertThat(txManager.begun).isEqualTo(0);
try {
toc.performTransactionalOperation();
}
finally {
assertEquals(1, txManager.begun);
assertEquals(rollback ? 0 : 1, txManager.commits);
assertEquals(rollback ? 1 : 0, txManager.rollbacks);
assertThat(txManager.begun).isEqualTo(1);
long expected1 = rollback ? 0 : 1;
assertThat(txManager.commits).isEqualTo(expected1);
long expected = rollback ? 1 : 0;
assertThat(txManager.rollbacks).isEqualTo(expected);
}
}
protected void testNotTransactional(TransactionOperationCallback toc, Throwable expected) throws Throwable {
txManager.clear();
assertEquals(0, txManager.begun);
assertThat(txManager.begun).isEqualTo(0);
assertThatExceptionOfType(Throwable.class).isThrownBy(
toc::performTransactionalOperation).isSameAs(expected);
assertEquals(0, txManager.begun);
assertThat(txManager.begun).isEqualTo(0);
}

View File

@ -19,7 +19,7 @@ package org.springframework.beans;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rod Johnson
@ -31,11 +31,12 @@ public abstract class AbstractPropertyValuesTests {
* Must contain: forname=Tony surname=Blair age=50
*/
protected void doTestTony(PropertyValues pvs) {
assertTrue("Contains 3", pvs.getPropertyValues().length == 3);
assertTrue("Contains forname", pvs.contains("forname"));
assertTrue("Contains surname", pvs.contains("surname"));
assertTrue("Contains age", pvs.contains("age"));
assertTrue("Doesn't contain tory", !pvs.contains("tory"));
assertThat(pvs.getPropertyValues().length == 3).as("Contains 3").isTrue();
assertThat(pvs.contains("forname")).as("Contains forname").isTrue();
assertThat(pvs.contains("surname")).as("Contains surname").isTrue();
assertThat(pvs.contains("age")).as("Contains age").isTrue();
boolean condition1 = !pvs.contains("tory");
assertThat(condition1).as("Doesn't contain tory").isTrue();
PropertyValue[] ps = pvs.getPropertyValues();
Map<String, String> m = new HashMap<>();
@ -44,12 +45,13 @@ public abstract class AbstractPropertyValuesTests {
m.put("age", "50");
for (int i = 0; i < ps.length; i++) {
Object val = m.get(ps[i].getName());
assertTrue("Can't have unexpected value", val != null);
assertTrue("Val i string", val instanceof String);
assertTrue("val matches expected", val.equals(ps[i].getValue()));
assertThat(val != null).as("Can't have unexpected value").isTrue();
boolean condition = val instanceof String;
assertThat(condition).as("Val i string").isTrue();
assertThat(val.equals(ps[i].getValue())).as("val matches expected").isTrue();
m.remove(ps[i].getName());
}
assertTrue("Map size is 0", m.size() == 0);
assertThat(m.size() == 0).as("Map size is 0").isTrue();
}
}

View File

@ -33,12 +33,9 @@ import org.springframework.tests.sample.beans.DerivedTestBean;
import org.springframework.tests.sample.beans.ITestBean;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link BeanUtils}.
@ -68,18 +65,18 @@ public class BeanUtilsTests {
Constructor<BeanWithNullableTypes> ctor = BeanWithNullableTypes.class.getDeclaredConstructor(
Integer.class, Boolean.class, String.class);
BeanWithNullableTypes bean = BeanUtils.instantiateClass(ctor, null, null, "foo");
assertNull(bean.getCounter());
assertNull(bean.isFlag());
assertEquals("foo", bean.getValue());
assertThat(bean.getCounter()).isNull();
assertThat(bean.isFlag()).isNull();
assertThat(bean.getValue()).isEqualTo("foo");
}
@Test // gh-22531
public void testInstantiateClassWithOptionalPrimitiveType() throws NoSuchMethodException {
Constructor<BeanWithPrimitiveTypes> ctor = BeanWithPrimitiveTypes.class.getDeclaredConstructor(int.class, boolean.class, String.class);
BeanWithPrimitiveTypes bean = BeanUtils.instantiateClass(ctor, null, null, "foo");
assertEquals(0, bean.getCounter());
assertEquals(false, bean.isFlag());
assertEquals("foo", bean.getValue());
assertThat(bean.getCounter()).isEqualTo(0);
assertThat(bean.isFlag()).isEqualTo(false);
assertThat(bean.getValue()).isEqualTo("foo");
}
@Test // gh-22531
@ -93,8 +90,8 @@ public class BeanUtilsTests {
public void testGetPropertyDescriptors() throws Exception {
PropertyDescriptor[] actual = Introspector.getBeanInfo(TestBean.class).getPropertyDescriptors();
PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(TestBean.class);
assertNotNull("Descriptors should not be null", descriptors);
assertEquals("Invalid number of descriptors returned", actual.length, descriptors.length);
assertThat(descriptors).as("Descriptors should not be null").isNotNull();
assertThat(descriptors.length).as("Invalid number of descriptors returned").isEqualTo(actual.length);
}
@Test
@ -102,15 +99,15 @@ public class BeanUtilsTests {
PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(ContainerBean.class);
for (PropertyDescriptor descriptor : descriptors) {
if ("containedBeans".equals(descriptor.getName())) {
assertTrue("Property should be an array", descriptor.getPropertyType().isArray());
assertEquals(descriptor.getPropertyType().getComponentType(), ContainedBean.class);
assertThat(descriptor.getPropertyType().isArray()).as("Property should be an array").isTrue();
assertThat(ContainedBean.class).isEqualTo(descriptor.getPropertyType().getComponentType());
}
}
}
@Test
public void testFindEditorByConvention() {
assertEquals(ResourceEditor.class, BeanUtils.findEditorByConvention(Resource.class).getClass());
assertThat(BeanUtils.findEditorByConvention(Resource.class).getClass()).isEqualTo(ResourceEditor.class);
}
@Test
@ -120,13 +117,13 @@ public class BeanUtilsTests {
tb.setAge(32);
tb.setTouchy("touchy");
TestBean tb2 = new TestBean();
assertTrue("Name empty", tb2.getName() == null);
assertTrue("Age empty", tb2.getAge() == 0);
assertTrue("Touchy empty", tb2.getTouchy() == null);
assertThat(tb2.getName() == null).as("Name empty").isTrue();
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
BeanUtils.copyProperties(tb, tb2);
assertTrue("Name copied", tb2.getName().equals(tb.getName()));
assertTrue("Age copied", tb2.getAge() == tb.getAge());
assertTrue("Touchy copied", tb2.getTouchy().equals(tb.getTouchy()));
assertThat(tb2.getName().equals(tb.getName())).as("Name copied").isTrue();
assertThat(tb2.getAge() == tb.getAge()).as("Age copied").isTrue();
assertThat(tb2.getTouchy().equals(tb.getTouchy())).as("Touchy copied").isTrue();
}
@Test
@ -136,13 +133,13 @@ public class BeanUtilsTests {
tb.setAge(32);
tb.setTouchy("touchy");
TestBean tb2 = new TestBean();
assertTrue("Name empty", tb2.getName() == null);
assertTrue("Age empty", tb2.getAge() == 0);
assertTrue("Touchy empty", tb2.getTouchy() == null);
assertThat(tb2.getName() == null).as("Name empty").isTrue();
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
BeanUtils.copyProperties(tb, tb2);
assertTrue("Name copied", tb2.getName().equals(tb.getName()));
assertTrue("Age copied", tb2.getAge() == tb.getAge());
assertTrue("Touchy copied", tb2.getTouchy().equals(tb.getTouchy()));
assertThat(tb2.getName().equals(tb.getName())).as("Name copied").isTrue();
assertThat(tb2.getAge() == tb.getAge()).as("Age copied").isTrue();
assertThat(tb2.getTouchy().equals(tb.getTouchy())).as("Touchy copied").isTrue();
}
@Test
@ -152,49 +149,49 @@ public class BeanUtilsTests {
tb.setAge(32);
tb.setTouchy("touchy");
DerivedTestBean tb2 = new DerivedTestBean();
assertTrue("Name empty", tb2.getName() == null);
assertTrue("Age empty", tb2.getAge() == 0);
assertTrue("Touchy empty", tb2.getTouchy() == null);
assertThat(tb2.getName() == null).as("Name empty").isTrue();
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
BeanUtils.copyProperties(tb, tb2);
assertTrue("Name copied", tb2.getName().equals(tb.getName()));
assertTrue("Age copied", tb2.getAge() == tb.getAge());
assertTrue("Touchy copied", tb2.getTouchy().equals(tb.getTouchy()));
assertThat(tb2.getName().equals(tb.getName())).as("Name copied").isTrue();
assertThat(tb2.getAge() == tb.getAge()).as("Age copied").isTrue();
assertThat(tb2.getTouchy().equals(tb.getTouchy())).as("Touchy copied").isTrue();
}
@Test
public void testCopyPropertiesWithEditable() throws Exception {
TestBean tb = new TestBean();
assertTrue("Name empty", tb.getName() == null);
assertThat(tb.getName() == null).as("Name empty").isTrue();
tb.setAge(32);
tb.setTouchy("bla");
TestBean tb2 = new TestBean();
tb2.setName("rod");
assertTrue("Age empty", tb2.getAge() == 0);
assertTrue("Touchy empty", tb2.getTouchy() == null);
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
// "touchy" should not be copied: it's not defined in ITestBean
BeanUtils.copyProperties(tb, tb2, ITestBean.class);
assertTrue("Name copied", tb2.getName() == null);
assertTrue("Age copied", tb2.getAge() == 32);
assertTrue("Touchy still empty", tb2.getTouchy() == null);
assertThat(tb2.getName() == null).as("Name copied").isTrue();
assertThat(tb2.getAge() == 32).as("Age copied").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy still empty").isTrue();
}
@Test
public void testCopyPropertiesWithIgnore() throws Exception {
TestBean tb = new TestBean();
assertTrue("Name empty", tb.getName() == null);
assertThat(tb.getName() == null).as("Name empty").isTrue();
tb.setAge(32);
tb.setTouchy("bla");
TestBean tb2 = new TestBean();
tb2.setName("rod");
assertTrue("Age empty", tb2.getAge() == 0);
assertTrue("Touchy empty", tb2.getTouchy() == null);
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
// "spouse", "touchy", "age" should not be copied
BeanUtils.copyProperties(tb, tb2, "spouse", "touchy", "age");
assertTrue("Name copied", tb2.getName() == null);
assertTrue("Age still empty", tb2.getAge() == 0);
assertTrue("Touchy still empty", tb2.getTouchy() == null);
assertThat(tb2.getName() == null).as("Name copied").isTrue();
assertThat(tb2.getAge() == 0).as("Age still empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy still empty").isTrue();
}
@Test
@ -203,7 +200,7 @@ public class BeanUtilsTests {
source.setName("name");
TestBean target = new TestBean();
BeanUtils.copyProperties(source, target, "specialProperty");
assertEquals(target.getName(), "name");
assertThat("name").isEqualTo(target.getName());
}
@Test
@ -214,9 +211,9 @@ public class BeanUtilsTests {
source.setFlag2(true);
InvalidProperty target = new InvalidProperty();
BeanUtils.copyProperties(source, target);
assertEquals("name", target.getName());
assertTrue(target.getFlag1());
assertTrue(target.getFlag2());
assertThat(target.getName()).isEqualTo("name");
assertThat((boolean) target.getFlag1()).isTrue();
assertThat(target.getFlag2()).isTrue();
}
@Test
@ -242,7 +239,7 @@ public class BeanUtilsTests {
public void testResolveWithAndWithoutArgList() throws Exception {
Method desiredMethod = MethodSignatureBean.class.getMethod("doSomethingElse", String.class, int.class);
assertSignatureEquals(desiredMethod, "doSomethingElse");
assertNull(BeanUtils.resolveSignature("doSomethingElse()", MethodSignatureBean.class));
assertThat(BeanUtils.resolveSignature("doSomethingElse()", MethodSignatureBean.class)).isNull();
}
@Test
@ -280,17 +277,16 @@ public class BeanUtilsTests {
PropertyDescriptor[] descrs = BeanUtils.getPropertyDescriptors(Bean.class);
PropertyDescriptor keyDescr = BeanUtils.getPropertyDescriptor(Bean.class, "value");
assertEquals(String.class, keyDescr.getPropertyType());
assertThat(keyDescr.getPropertyType()).isEqualTo(String.class);
for (PropertyDescriptor propertyDescriptor : descrs) {
if (propertyDescriptor.getName().equals(keyDescr.getName())) {
assertEquals(propertyDescriptor.getName() + " has unexpected type",
keyDescr.getPropertyType(), propertyDescriptor.getPropertyType());
assertThat(propertyDescriptor.getPropertyType()).as(propertyDescriptor.getName() + " has unexpected type").isEqualTo(keyDescr.getPropertyType());
}
}
}
private void assertSignatureEquals(Method desiredMethod, String signature) {
assertEquals(desiredMethod, BeanUtils.resolveSignature(signature, MethodSignatureBean.class));
assertThat(BeanUtils.resolveSignature(signature, MethodSignatureBean.class)).isEqualTo(desiredMethod);
}

View File

@ -24,9 +24,6 @@ import org.junit.Test;
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.assertNull;
/**
* @author Keith Donald
@ -47,13 +44,13 @@ public class BeanWrapperAutoGrowingTests {
@Test
public void getPropertyValueNullValueInNestedPath() {
assertNull(wrapper.getPropertyValue("nested.prop"));
assertThat(wrapper.getPropertyValue("nested.prop")).isNull();
}
@Test
public void setPropertyValueNullValueInNestedPath() {
wrapper.setPropertyValue("nested.prop", "test");
assertEquals("test", bean.getNested().getProp());
assertThat(bean.getNested().getProp()).isEqualTo("test");
}
@Test
@ -65,20 +62,25 @@ public class BeanWrapperAutoGrowingTests {
@Test
public void getPropertyValueAutoGrowArray() {
assertNotNull(wrapper.getPropertyValue("array[0]"));
assertEquals(1, bean.getArray().length);
assertThat(bean.getArray().length).isEqualTo(1);
assertThat(bean.getArray()[0]).isInstanceOf(Bean.class);
}
private void assertNotNull(Object propertyValue) {
assertThat(propertyValue).isNotNull();
}
@Test
public void setPropertyValueAutoGrowArray() {
wrapper.setPropertyValue("array[0].prop", "test");
assertEquals("test", bean.getArray()[0].getProp());
assertThat(bean.getArray()[0].getProp()).isEqualTo("test");
}
@Test
public void getPropertyValueAutoGrowArrayBySeveralElements() {
assertNotNull(wrapper.getPropertyValue("array[4]"));
assertEquals(5, bean.getArray().length);
assertThat(bean.getArray().length).isEqualTo(5);
assertThat(bean.getArray()[0]).isInstanceOf(Bean.class);
assertThat(bean.getArray()[1]).isInstanceOf(Bean.class);
assertThat(bean.getArray()[2]).isInstanceOf(Bean.class);
@ -93,27 +95,27 @@ public class BeanWrapperAutoGrowingTests {
@Test
public void getPropertyValueAutoGrowMultiDimensionalArray() {
assertNotNull(wrapper.getPropertyValue("multiArray[0][0]"));
assertEquals(1, bean.getMultiArray()[0].length);
assertThat(bean.getMultiArray()[0].length).isEqualTo(1);
assertThat(bean.getMultiArray()[0][0]).isInstanceOf(Bean.class);
}
@Test
public void getPropertyValueAutoGrowList() {
assertNotNull(wrapper.getPropertyValue("list[0]"));
assertEquals(1, bean.getList().size());
assertThat(bean.getList().size()).isEqualTo(1);
assertThat(bean.getList().get(0)).isInstanceOf(Bean.class);
}
@Test
public void setPropertyValueAutoGrowList() {
wrapper.setPropertyValue("list[0].prop", "test");
assertEquals("test", bean.getList().get(0).getProp());
assertThat(bean.getList().get(0).getProp()).isEqualTo("test");
}
@Test
public void getPropertyValueAutoGrowListBySeveralElements() {
assertNotNull(wrapper.getPropertyValue("list[4]"));
assertEquals(5, bean.getList().size());
assertThat(bean.getList().size()).isEqualTo(5);
assertThat(bean.getList().get(0)).isInstanceOf(Bean.class);
assertThat(bean.getList().get(1)).isInstanceOf(Bean.class);
assertThat(bean.getList().get(2)).isInstanceOf(Bean.class);
@ -136,7 +138,7 @@ public class BeanWrapperAutoGrowingTests {
@Test
public void getPropertyValueAutoGrowMultiDimensionalList() {
assertNotNull(wrapper.getPropertyValue("multiList[0][0]"));
assertEquals(1, bean.getMultiList().get(0).size());
assertThat(bean.getMultiList().get(0).size()).isEqualTo(1);
assertThat(bean.getMultiList().get(0).get(0)).isInstanceOf(Bean.class);
}

View File

@ -25,9 +25,7 @@ import org.springframework.core.convert.support.DefaultConversionService;
import org.springframework.tests.sample.beans.CustomEnum;
import org.springframework.tests.sample.beans.GenericBean;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
@ -40,7 +38,7 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnum", "VALUE_1");
assertEquals(CustomEnum.VALUE_1, gb.getCustomEnum());
assertThat(gb.getCustomEnum()).isEqualTo(CustomEnum.VALUE_1);
}
@Test
@ -48,7 +46,7 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnum", null);
assertEquals(null, gb.getCustomEnum());
assertThat(gb.getCustomEnum()).isEqualTo(null);
}
@Test
@ -56,7 +54,7 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnum", "");
assertEquals(null, gb.getCustomEnum());
assertThat(gb.getCustomEnum()).isEqualTo(null);
}
@Test
@ -64,8 +62,8 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnumArray", "VALUE_1");
assertEquals(1, gb.getCustomEnumArray().length);
assertEquals(CustomEnum.VALUE_1, gb.getCustomEnumArray()[0]);
assertThat(gb.getCustomEnumArray().length).isEqualTo(1);
assertThat(gb.getCustomEnumArray()[0]).isEqualTo(CustomEnum.VALUE_1);
}
@Test
@ -73,9 +71,9 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnumArray", new String[] {"VALUE_1", "VALUE_2"});
assertEquals(2, gb.getCustomEnumArray().length);
assertEquals(CustomEnum.VALUE_1, gb.getCustomEnumArray()[0]);
assertEquals(CustomEnum.VALUE_2, gb.getCustomEnumArray()[1]);
assertThat(gb.getCustomEnumArray().length).isEqualTo(2);
assertThat(gb.getCustomEnumArray()[0]).isEqualTo(CustomEnum.VALUE_1);
assertThat(gb.getCustomEnumArray()[1]).isEqualTo(CustomEnum.VALUE_2);
}
@Test
@ -83,9 +81,9 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnumArray", "VALUE_1,VALUE_2");
assertEquals(2, gb.getCustomEnumArray().length);
assertEquals(CustomEnum.VALUE_1, gb.getCustomEnumArray()[0]);
assertEquals(CustomEnum.VALUE_2, gb.getCustomEnumArray()[1]);
assertThat(gb.getCustomEnumArray().length).isEqualTo(2);
assertThat(gb.getCustomEnumArray()[0]).isEqualTo(CustomEnum.VALUE_1);
assertThat(gb.getCustomEnumArray()[1]).isEqualTo(CustomEnum.VALUE_2);
}
@Test
@ -93,8 +91,8 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnumSet", "VALUE_1");
assertEquals(1, gb.getCustomEnumSet().size());
assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1));
assertThat(gb.getCustomEnumSet().size()).isEqualTo(1);
assertThat(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1)).isTrue();
}
@Test
@ -102,9 +100,9 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnumSet", new String[] {"VALUE_1", "VALUE_2"});
assertEquals(2, gb.getCustomEnumSet().size());
assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1));
assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_2));
assertThat(gb.getCustomEnumSet().size()).isEqualTo(2);
assertThat(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1)).isTrue();
assertThat(gb.getCustomEnumSet().contains(CustomEnum.VALUE_2)).isTrue();
}
@Test
@ -112,9 +110,9 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnumSet", "VALUE_1,VALUE_2");
assertEquals(2, gb.getCustomEnumSet().size());
assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1));
assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_2));
assertThat(gb.getCustomEnumSet().size()).isEqualTo(2);
assertThat(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1)).isTrue();
assertThat(gb.getCustomEnumSet().contains(CustomEnum.VALUE_2)).isTrue();
}
@Test
@ -122,9 +120,9 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("customEnumSetMismatch", new String[] {"VALUE_1", "VALUE_2"});
assertEquals(2, gb.getCustomEnumSet().size());
assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1));
assertTrue(gb.getCustomEnumSet().contains(CustomEnum.VALUE_2));
assertThat(gb.getCustomEnumSet().size()).isEqualTo(2);
assertThat(gb.getCustomEnumSet().contains(CustomEnum.VALUE_1)).isTrue();
assertThat(gb.getCustomEnumSet().contains(CustomEnum.VALUE_2)).isTrue();
}
@Test
@ -132,11 +130,11 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setConversionService(new DefaultConversionService());
assertNull(gb.getStandardEnumSet());
assertThat(gb.getStandardEnumSet()).isNull();
bw.setPropertyValue("standardEnumSet", new String[] {"VALUE_1", "VALUE_2"});
assertEquals(2, gb.getStandardEnumSet().size());
assertTrue(gb.getStandardEnumSet().contains(CustomEnum.VALUE_1));
assertTrue(gb.getStandardEnumSet().contains(CustomEnum.VALUE_2));
assertThat(gb.getStandardEnumSet().size()).isEqualTo(2);
assertThat(gb.getStandardEnumSet().contains(CustomEnum.VALUE_1)).isTrue();
assertThat(gb.getStandardEnumSet().contains(CustomEnum.VALUE_2)).isTrue();
}
@Test
@ -144,9 +142,9 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setAutoGrowNestedPaths(true);
assertNull(gb.getStandardEnumSet());
assertThat(gb.getStandardEnumSet()).isNull();
bw.getPropertyValue("standardEnumSet.class");
assertEquals(0, gb.getStandardEnumSet().size());
assertThat(gb.getStandardEnumSet().size()).isEqualTo(0);
}
@Test
@ -154,14 +152,14 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setConversionService(new DefaultConversionService());
assertNull(gb.getStandardEnumMap());
assertThat(gb.getStandardEnumMap()).isNull();
Map<String, Integer> map = new LinkedHashMap<>();
map.put("VALUE_1", 1);
map.put("VALUE_2", 2);
bw.setPropertyValue("standardEnumMap", map);
assertEquals(2, gb.getStandardEnumMap().size());
assertEquals(new Integer(1), gb.getStandardEnumMap().get(CustomEnum.VALUE_1));
assertEquals(new Integer(2), gb.getStandardEnumMap().get(CustomEnum.VALUE_2));
assertThat(gb.getStandardEnumMap().size()).isEqualTo(2);
assertThat(gb.getStandardEnumMap().get(CustomEnum.VALUE_1)).isEqualTo(new Integer(1));
assertThat(gb.getStandardEnumMap().get(CustomEnum.VALUE_2)).isEqualTo(new Integer(2));
}
@Test
@ -169,10 +167,10 @@ public class BeanWrapperEnumTests {
GenericBean<?> gb = new GenericBean<>();
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setAutoGrowNestedPaths(true);
assertNull(gb.getStandardEnumMap());
assertThat(gb.getStandardEnumMap()).isNull();
bw.setPropertyValue("standardEnumMap[VALUE_1]", 1);
assertEquals(1, gb.getStandardEnumMap().size());
assertEquals(new Integer(1), gb.getStandardEnumMap().get(CustomEnum.VALUE_1));
assertThat(gb.getStandardEnumMap().size()).isEqualTo(1);
assertThat(gb.getStandardEnumMap().get(CustomEnum.VALUE_1)).isEqualTo(new Integer(1));
}
@Test
@ -180,7 +178,7 @@ public class BeanWrapperEnumTests {
NonPublicEnumHolder holder = new NonPublicEnumHolder();
BeanWrapper bw = new BeanWrapperImpl(holder);
bw.setPropertyValue("nonPublicEnum", "VALUE_1");
assertEquals(NonPublicEnum.VALUE_1, holder.getNonPublicEnum());
assertThat(holder.getNonPublicEnum()).isEqualTo(NonPublicEnum.VALUE_1);
}

View File

@ -39,9 +39,8 @@ import org.springframework.tests.sample.beans.GenericIntegerBean;
import org.springframework.tests.sample.beans.GenericSetOfIntegerBean;
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 Juergen Hoeller
@ -58,8 +57,8 @@ public class BeanWrapperGenericsTests {
input.add("4");
input.add("5");
bw.setPropertyValue("integerSet", input);
assertTrue(gb.getIntegerSet().contains(new Integer(4)));
assertTrue(gb.getIntegerSet().contains(new Integer(5)));
assertThat(gb.getIntegerSet().contains(new Integer(4))).isTrue();
assertThat(gb.getIntegerSet().contains(new Integer(5))).isTrue();
}
@Test
@ -71,8 +70,8 @@ public class BeanWrapperGenericsTests {
input.add("4");
input.add("5");
bw.setPropertyValue("numberSet", input);
assertTrue(gb.getNumberSet().contains(new Integer(4)));
assertTrue(gb.getNumberSet().contains(new Integer(5)));
assertThat(gb.getNumberSet().contains(new Integer(4))).isTrue();
assertThat(gb.getNumberSet().contains(new Integer(5))).isTrue();
}
@Test
@ -94,8 +93,8 @@ public class BeanWrapperGenericsTests {
input.add("http://localhost:8080");
input.add("http://localhost:9090");
bw.setPropertyValue("resourceList", input);
assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
assertEquals(new UrlResource("http://localhost:9090"), gb.getResourceList().get(1));
assertThat(gb.getResourceList().get(0)).isEqualTo(new UrlResource("http://localhost:8080"));
assertThat(gb.getResourceList().get(1)).isEqualTo(new UrlResource("http://localhost:9090"));
}
@Test
@ -104,7 +103,7 @@ public class BeanWrapperGenericsTests {
gb.setResourceList(new ArrayList<>());
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("resourceList[0]", "http://localhost:8080");
assertEquals(new UrlResource("http://localhost:8080"), gb.getResourceList().get(0));
assertThat(gb.getResourceList().get(0)).isEqualTo(new UrlResource("http://localhost:8080"));
}
@Test
@ -115,8 +114,8 @@ public class BeanWrapperGenericsTests {
input.put("4", "5");
input.put("6", "7");
bw.setPropertyValue("shortMap", input);
assertEquals(new Integer(5), gb.getShortMap().get(new Short("4")));
assertEquals(new Integer(7), gb.getShortMap().get(new Short("6")));
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(new Integer(5));
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(new Integer(7));
}
@Test
@ -125,8 +124,8 @@ public class BeanWrapperGenericsTests {
gb.setShortMap(new HashMap<>());
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("shortMap[4]", "5");
assertEquals(new Integer(5), bw.getPropertyValue("shortMap[4]"));
assertEquals(new Integer(5), gb.getShortMap().get(new Short("4")));
assertThat(bw.getPropertyValue("shortMap[4]")).isEqualTo(new Integer(5));
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(new Integer(5));
}
@Test
@ -137,8 +136,8 @@ public class BeanWrapperGenericsTests {
input.put("4", "5");
input.put("6", "7");
bw.setPropertyValue("longMap", input);
assertEquals("5", gb.getLongMap().get(new Long("4")));
assertEquals("7", gb.getLongMap().get(new Long("6")));
assertThat(gb.getLongMap().get(new Long("4"))).isEqualTo("5");
assertThat(gb.getLongMap().get(new Long("6"))).isEqualTo("7");
}
@Test
@ -147,8 +146,8 @@ public class BeanWrapperGenericsTests {
gb.setLongMap(new HashMap<Long, Integer>());
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("longMap[4]", "5");
assertEquals("5", gb.getLongMap().get(new Long("4")));
assertEquals("5", bw.getPropertyValue("longMap[4]"));
assertThat(gb.getLongMap().get(new Long("4"))).isEqualTo("5");
assertThat(bw.getPropertyValue("longMap[4]")).isEqualTo("5");
}
@Test
@ -164,8 +163,10 @@ public class BeanWrapperGenericsTests {
value2.add(Boolean.TRUE);
input.put("2", value2);
bw.setPropertyValue("collectionMap", input);
assertTrue(gb.getCollectionMap().get(new Integer(1)) instanceof HashSet);
assertTrue(gb.getCollectionMap().get(new Integer(2)) instanceof ArrayList);
boolean condition1 = gb.getCollectionMap().get(new Integer(1)) instanceof HashSet;
assertThat(condition1).isTrue();
boolean condition = gb.getCollectionMap().get(new Integer(2)) instanceof ArrayList;
assertThat(condition).isTrue();
}
@Test
@ -177,7 +178,8 @@ public class BeanWrapperGenericsTests {
HashSet<Integer> value1 = new HashSet<>();
value1.add(new Integer(1));
bw.setPropertyValue("collectionMap[1]", value1);
assertTrue(gb.getCollectionMap().get(new Integer(1)) instanceof HashSet);
boolean condition = gb.getCollectionMap().get(new Integer(1)) instanceof HashSet;
assertThat(condition).isTrue();
}
@Test
@ -188,8 +190,8 @@ public class BeanWrapperGenericsTests {
input.setProperty("4", "5");
input.setProperty("6", "7");
bw.setPropertyValue("shortMap", input);
assertEquals(new Integer(5), gb.getShortMap().get(new Short("4")));
assertEquals(new Integer(7), gb.getShortMap().get(new Short("6")));
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(new Integer(5));
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(new Integer(7));
}
@Test
@ -200,8 +202,8 @@ public class BeanWrapperGenericsTests {
gb.setListOfLists(list);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("listOfLists[0][0]", new Integer(5));
assertEquals(new Integer(5), bw.getPropertyValue("listOfLists[0][0]"));
assertEquals(new Integer(5), gb.getListOfLists().get(0).get(0));
assertThat(bw.getPropertyValue("listOfLists[0][0]")).isEqualTo(new Integer(5));
assertThat(gb.getListOfLists().get(0).get(0)).isEqualTo(new Integer(5));
}
@Test
@ -212,8 +214,8 @@ public class BeanWrapperGenericsTests {
gb.setListOfLists(list);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("listOfLists[0][0]", "5");
assertEquals(new Integer(5), bw.getPropertyValue("listOfLists[0][0]"));
assertEquals(new Integer(5), gb.getListOfLists().get(0).get(0));
assertThat(bw.getPropertyValue("listOfLists[0][0]")).isEqualTo(new Integer(5));
assertThat(gb.getListOfLists().get(0).get(0)).isEqualTo(new Integer(5));
}
@Test
@ -224,8 +226,8 @@ public class BeanWrapperGenericsTests {
gb.setListOfArrays(list);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("listOfArrays[0][1]", "str3 ");
assertEquals("str3 ", bw.getPropertyValue("listOfArrays[0][1]"));
assertEquals("str3 ", gb.getListOfArrays().get(0)[1]);
assertThat(bw.getPropertyValue("listOfArrays[0][1]")).isEqualTo("str3 ");
assertThat(gb.getListOfArrays().get(0)[1]).isEqualTo("str3 ");
}
@Test
@ -237,8 +239,8 @@ public class BeanWrapperGenericsTests {
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.registerCustomEditor(String.class, new StringTrimmerEditor(false));
bw.setPropertyValue("listOfArrays[0][1]", "str3 ");
assertEquals("str3", bw.getPropertyValue("listOfArrays[0][1]"));
assertEquals("str3", gb.getListOfArrays().get(0)[1]);
assertThat(bw.getPropertyValue("listOfArrays[0][1]")).isEqualTo("str3");
assertThat(gb.getListOfArrays().get(0)[1]).isEqualTo("str3");
}
@Test
@ -249,8 +251,8 @@ public class BeanWrapperGenericsTests {
gb.setListOfMaps(list);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("listOfMaps[0][10]", new Long(5));
assertEquals(new Long(5), bw.getPropertyValue("listOfMaps[0][10]"));
assertEquals(new Long(5), gb.getListOfMaps().get(0).get(10));
assertThat(bw.getPropertyValue("listOfMaps[0][10]")).isEqualTo(new Long(5));
assertThat(gb.getListOfMaps().get(0).get(10)).isEqualTo(new Long(5));
}
@Test
@ -261,8 +263,8 @@ public class BeanWrapperGenericsTests {
gb.setListOfMaps(list);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("listOfMaps[0][10]", "5");
assertEquals(new Long(5), bw.getPropertyValue("listOfMaps[0][10]"));
assertEquals(new Long(5), gb.getListOfMaps().get(0).get(10));
assertThat(bw.getPropertyValue("listOfMaps[0][10]")).isEqualTo(new Long(5));
assertThat(gb.getListOfMaps().get(0).get(10)).isEqualTo(new Long(5));
}
@Test
@ -273,8 +275,8 @@ public class BeanWrapperGenericsTests {
gb.setMapOfMaps(map);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("mapOfMaps[mykey][10]", new Long(5));
assertEquals(new Long(5), bw.getPropertyValue("mapOfMaps[mykey][10]"));
assertEquals(new Long(5), gb.getMapOfMaps().get("mykey").get(10));
assertThat(bw.getPropertyValue("mapOfMaps[mykey][10]")).isEqualTo(new Long(5));
assertThat(gb.getMapOfMaps().get("mykey").get(10)).isEqualTo(new Long(5));
}
@Test
@ -285,8 +287,8 @@ public class BeanWrapperGenericsTests {
gb.setMapOfMaps(map);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("mapOfMaps[mykey][10]", "5");
assertEquals(new Long(5), bw.getPropertyValue("mapOfMaps[mykey][10]"));
assertEquals(new Long(5), gb.getMapOfMaps().get("mykey").get(10));
assertThat(bw.getPropertyValue("mapOfMaps[mykey][10]")).isEqualTo(new Long(5));
assertThat(gb.getMapOfMaps().get("mykey").get(10)).isEqualTo(new Long(5));
}
@Test
@ -297,8 +299,8 @@ public class BeanWrapperGenericsTests {
gb.setMapOfLists(map);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("mapOfLists[1][0]", new Integer(5));
assertEquals(new Integer(5), bw.getPropertyValue("mapOfLists[1][0]"));
assertEquals(new Integer(5), gb.getMapOfLists().get(new Integer(1)).get(0));
assertThat(bw.getPropertyValue("mapOfLists[1][0]")).isEqualTo(new Integer(5));
assertThat(gb.getMapOfLists().get(new Integer(1)).get(0)).isEqualTo(new Integer(5));
}
@Test
@ -309,8 +311,8 @@ public class BeanWrapperGenericsTests {
gb.setMapOfLists(map);
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("mapOfLists[1][0]", "5");
assertEquals(new Integer(5), bw.getPropertyValue("mapOfLists[1][0]"));
assertEquals(new Integer(5), gb.getMapOfLists().get(new Integer(1)).get(0));
assertThat(bw.getPropertyValue("mapOfLists[1][0]")).isEqualTo(new Integer(5));
assertThat(gb.getMapOfLists().get(new Integer(1)).get(0)).isEqualTo(new Integer(5));
}
@Test
@ -323,7 +325,8 @@ public class BeanWrapperGenericsTests {
bw.setPropertyValue("mapOfInteger", map);
Object obj = gb.getMapOfInteger().get("testKey");
assertTrue(obj instanceof Integer);
boolean condition = obj instanceof Integer;
assertThat(condition).isTrue();
}
@Test
@ -337,8 +340,9 @@ public class BeanWrapperGenericsTests {
bw.setPropertyValue("mapOfListOfInteger", map);
Object obj = gb.getMapOfListOfInteger().get("testKey").get(0);
assertTrue(obj instanceof Integer);
assertEquals(1, ((Integer) obj).intValue());
boolean condition = obj instanceof Integer;
assertThat(condition).isTrue();
assertThat(((Integer) obj).intValue()).isEqualTo(1);
}
@Test
@ -353,8 +357,9 @@ public class BeanWrapperGenericsTests {
bw.setPropertyValue("listOfMapOfInteger", list);
Object obj = gb.getListOfMapOfInteger().get(0).get("testKey");
assertTrue(obj instanceof Integer);
assertEquals(5, ((Integer) obj).intValue());
boolean condition = obj instanceof Integer;
assertThat(condition).isTrue();
assertThat(((Integer) obj).intValue()).isEqualTo(5);
}
@Test
@ -368,8 +373,9 @@ public class BeanWrapperGenericsTests {
bw.setPropertyValue("mapOfListOfListOfInteger", map);
Object obj = gb.getMapOfListOfListOfInteger().get("testKey").get(0).get(0);
assertTrue(obj instanceof Integer);
assertEquals(1, ((Integer) obj).intValue());
boolean condition = obj instanceof Integer;
assertThat(condition).isTrue();
assertThat(((Integer) obj).intValue()).isEqualTo(1);
}
@Test
@ -385,8 +391,8 @@ public class BeanWrapperGenericsTests {
BeanWrapper bw = new BeanWrapperImpl(holder);
bw.setPropertyValue("genericMap", inputMap);
assertEquals(new Integer(1), holder.getGenericMap().keySet().iterator().next().get(0));
assertEquals(new Long(10), holder.getGenericMap().values().iterator().next().get(0));
assertThat(holder.getGenericMap().keySet().iterator().next().get(0)).isEqualTo(new Integer(1));
assertThat(holder.getGenericMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
}
@Test
@ -402,8 +408,8 @@ public class BeanWrapperGenericsTests {
BeanWrapper bw = new BeanWrapperImpl(holder);
bw.setPropertyValue("genericMap", inputMap);
assertEquals(new Integer(1), holder.getGenericMap().keySet().iterator().next().get(0));
assertEquals(new Long(10), holder.getGenericMap().values().iterator().next().get(0));
assertThat(holder.getGenericMap().keySet().iterator().next().get(0)).isEqualTo(new Integer(1));
assertThat(holder.getGenericMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
}
@Test
@ -415,8 +421,8 @@ public class BeanWrapperGenericsTests {
BeanWrapper bw = new BeanWrapperImpl(holder);
bw.setPropertyValue("genericIndexedMap[1]", inputValue);
assertEquals(new Integer(1), holder.getGenericIndexedMap().keySet().iterator().next());
assertEquals(new Long(10), holder.getGenericIndexedMap().values().iterator().next().get(0));
assertThat(holder.getGenericIndexedMap().keySet().iterator().next()).isEqualTo(new Integer(1));
assertThat(holder.getGenericIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
}
@Test
@ -428,8 +434,8 @@ public class BeanWrapperGenericsTests {
BeanWrapper bw = new BeanWrapperImpl(holder);
bw.setPropertyValue("genericIndexedMap[1]", inputValue);
assertEquals(new Integer(1), holder.getGenericIndexedMap().keySet().iterator().next());
assertEquals(new Long(10), holder.getGenericIndexedMap().values().iterator().next().get(0));
assertThat(holder.getGenericIndexedMap().keySet().iterator().next()).isEqualTo(new Integer(1));
assertThat(holder.getGenericIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
}
@Test
@ -441,8 +447,8 @@ public class BeanWrapperGenericsTests {
BeanWrapper bw = new BeanWrapperImpl(holder);
bw.setPropertyValue("derivedIndexedMap[1]", inputValue);
assertEquals(new Integer(1), holder.getDerivedIndexedMap().keySet().iterator().next());
assertEquals(new Long(10), holder.getDerivedIndexedMap().values().iterator().next().get(0));
assertThat(holder.getDerivedIndexedMap().keySet().iterator().next()).isEqualTo(new Integer(1));
assertThat(holder.getDerivedIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
}
@Test
@ -454,8 +460,8 @@ public class BeanWrapperGenericsTests {
BeanWrapper bw = new BeanWrapperImpl(holder);
bw.setPropertyValue("derivedIndexedMap[1]", inputValue);
assertEquals(new Integer(1), holder.getDerivedIndexedMap().keySet().iterator().next());
assertEquals(new Long(10), holder.getDerivedIndexedMap().values().iterator().next().get(0));
assertThat(holder.getDerivedIndexedMap().keySet().iterator().next()).isEqualTo(new Integer(1));
assertThat(holder.getDerivedIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
}
@Test
@ -464,9 +470,9 @@ public class BeanWrapperGenericsTests {
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("genericProperty", "10");
bw.setPropertyValue("genericListProperty", new String[] {"20", "30"});
assertEquals(new Integer(10), gb.getGenericProperty());
assertEquals(new Integer(20), gb.getGenericListProperty().get(0));
assertEquals(new Integer(30), gb.getGenericListProperty().get(1));
assertThat(gb.getGenericProperty()).isEqualTo(new Integer(10));
assertThat(gb.getGenericListProperty().get(0)).isEqualTo(new Integer(20));
assertThat(gb.getGenericListProperty().get(1)).isEqualTo(new Integer(30));
}
@Test
@ -475,9 +481,9 @@ public class BeanWrapperGenericsTests {
BeanWrapper bw = new BeanWrapperImpl(gb);
bw.setPropertyValue("genericProperty", "10");
bw.setPropertyValue("genericListProperty", new String[] {"20", "30"});
assertEquals(new Integer(10), gb.getGenericProperty().iterator().next());
assertEquals(new Integer(20), gb.getGenericListProperty().get(0).iterator().next());
assertEquals(new Integer(30), gb.getGenericListProperty().get(1).iterator().next());
assertThat(gb.getGenericProperty().iterator().next()).isEqualTo(new Integer(10));
assertThat(gb.getGenericListProperty().get(0).iterator().next()).isEqualTo(new Integer(20));
assertThat(gb.getGenericListProperty().get(1).iterator().next()).isEqualTo(new Integer(30));
}
@Test
@ -485,7 +491,7 @@ public class BeanWrapperGenericsTests {
Bar bar = new Bar();
BeanWrapper bw = new BeanWrapperImpl(bar);
bw.setPropertyValue("version", "10");
assertEquals(new Double(10.0), bar.getVersion());
assertThat(bar.getVersion()).isEqualTo(new Double(10.0));
}
@Test
@ -493,7 +499,7 @@ public class BeanWrapperGenericsTests {
Promotion bean = new Promotion();
BeanWrapper bw = new BeanWrapperImpl(bean);
bw.setPropertyValue("id", "10");
assertEquals(new Long(10), bean.getId());
assertThat(bean.getId()).isEqualTo(new Long(10));
}
@Test
@ -514,10 +520,10 @@ public class BeanWrapperGenericsTests {
Holder<Map<String, Object>> context = new Holder<>(data);
BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(context);
assertEquals("y", bw.getPropertyValue("data['x']"));
assertThat(bw.getPropertyValue("data['x']")).isEqualTo("y");
bw.setPropertyValue("data['message']", "it works!");
assertEquals("it works!", data.get("message"));
assertThat(data.get("message")).isEqualTo("it works!");
}

View File

@ -26,10 +26,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.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* Specific {@link BeanWrapperImpl} tests.
@ -54,8 +50,8 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
GetterBean target = new GetterBean();
BeanWrapper accessor = createAccessor(target);
accessor.setPropertyValue("name", "tom");
assertEquals("tom", target.getAliasedName());
assertEquals("tom", accessor.getPropertyValue("aliasedName"));
assertThat(target.getAliasedName()).isEqualTo("tom");
assertThat(accessor.getPropertyValue("aliasedName")).isEqualTo("tom");
}
@Test
@ -64,8 +60,8 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
BeanWrapper accessor = createAccessor(target);
accessor.setExtractOldValueForEditor(true); // This will call the getter
accessor.setPropertyValue("name", "tom");
assertEquals("tom", target.getAliasedName());
assertEquals("tom", accessor.getPropertyValue("aliasedName"));
assertThat(target.getAliasedName()).isEqualTo("tom");
assertThat(accessor.getPropertyValue("aliasedName")).isEqualTo("tom");
}
@Test
@ -73,8 +69,8 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
GetterBean target = new GetterBean();
BeanWrapper accessor = createAccessor(target);
accessor.setPropertyValue("aliasedName", "tom");
assertEquals("tom", target.getAliasedName());
assertEquals("tom", accessor.getPropertyValue("aliasedName"));
assertThat(target.getAliasedName()).isEqualTo("tom");
assertThat(accessor.getPropertyValue("aliasedName")).isEqualTo("tom");
}
@Test
@ -95,8 +91,8 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
.getNewValue()).isEqualTo(invalidTouchy);
});
// Test validly set property matches
assertTrue("Valid set property must stick", target.getName().equals(newName));
assertTrue("Invalid set property must retain old value", target.getAge() == 0);
assertThat(target.getName().equals(newName)).as("Valid set property must stick").isTrue();
assertThat(target.getAge() == 0).as("Invalid set property must retain old value").isTrue();
}
@Test
@ -124,8 +120,8 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
bw.setPropertyValue("names", "Alef");
}
catch (NotWritablePropertyException ex) {
assertNotNull("Possible matches not determined", ex.getPossibleMatches());
assertEquals("Invalid amount of alternatives", 1, ex.getPossibleMatches().length);
assertThat(ex.getPossibleMatches()).as("Possible matches not determined").isNotNull();
assertThat(ex.getPossibleMatches().length).as("Invalid amount of alternatives").isEqualTo(1);
}
}
@ -137,8 +133,8 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
bw.setPropertyValue("mystring", "Arjen");
}
catch (NotWritablePropertyException ex) {
assertNotNull("Possible matches not determined", ex.getPossibleMatches());
assertEquals("Invalid amount of alternatives", 3, ex.getPossibleMatches().length);
assertThat(ex.getPossibleMatches()).as("Possible matches not determined").isNotNull();
assertThat(ex.getPossibleMatches().length).as("Invalid amount of alternatives").isEqualTo(3);
}
}
@ -147,9 +143,9 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
PropertyTypeMismatch target = new PropertyTypeMismatch();
BeanWrapper accessor = createAccessor(target);
accessor.setPropertyValue("object", "a String");
assertEquals("a String", target.value);
assertTrue(target.getObject() == 8);
assertEquals(8, accessor.getPropertyValue("object"));
assertThat(target.value).isEqualTo("a String");
assertThat(target.getObject() == 8).isTrue();
assertThat(accessor.getPropertyValue("object")).isEqualTo(8);
}
@Test
@ -159,12 +155,12 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
BeanWrapper accessor = createAccessor(target);
accessor.setPropertyValue("name", "a");
accessor.setPropertyValue("spouse.name", "b");
assertEquals("a", target.getName());
assertEquals("b", target.getSpouse().getName());
assertEquals("a", accessor.getPropertyValue("name"));
assertEquals("b", accessor.getPropertyValue("spouse.name"));
assertEquals(String.class, accessor.getPropertyDescriptor("name").getPropertyType());
assertEquals(String.class, accessor.getPropertyDescriptor("spouse.name").getPropertyType());
assertThat(target.getName()).isEqualTo("a");
assertThat(target.getSpouse().getName()).isEqualTo("b");
assertThat(accessor.getPropertyValue("name")).isEqualTo("a");
assertThat(accessor.getPropertyValue("spouse.name")).isEqualTo("b");
assertThat(accessor.getPropertyDescriptor("name").getPropertyType()).isEqualTo(String.class);
assertThat(accessor.getPropertyDescriptor("spouse.name").getPropertyType()).isEqualTo(String.class);
}
@Test
@ -175,20 +171,20 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
BeanWrapper accessor = createAccessor(target);
accessor.setPropertyValue("object", tb);
assertSame(tb, target.value);
assertSame(tb, target.getObject().get());
assertSame(tb, ((Optional<String>) accessor.getPropertyValue("object")).get());
assertEquals("x", target.value.getName());
assertEquals("x", target.getObject().get().getName());
assertEquals("x", accessor.getPropertyValue("object.name"));
assertThat(target.value).isSameAs(tb);
assertThat(target.getObject().get()).isSameAs(tb);
assertThat(((Optional<TestBean>) accessor.getPropertyValue("object")).get()).isSameAs(tb);
assertThat(target.value.getName()).isEqualTo("x");
assertThat(target.getObject().get().getName()).isEqualTo("x");
assertThat(accessor.getPropertyValue("object.name")).isEqualTo("x");
accessor.setPropertyValue("object.name", "y");
assertSame(tb, target.value);
assertSame(tb, target.getObject().get());
assertSame(tb, ((Optional<String>) accessor.getPropertyValue("object")).get());
assertEquals("y", target.value.getName());
assertEquals("y", target.getObject().get().getName());
assertEquals("y", accessor.getPropertyValue("object.name"));
assertThat(target.value).isSameAs(tb);
assertThat(target.getObject().get()).isSameAs(tb);
assertThat(((Optional<TestBean>) accessor.getPropertyValue("object")).get()).isSameAs(tb);
assertThat(target.value.getName()).isEqualTo("y");
assertThat(target.getObject().get().getName()).isEqualTo("y");
assertThat(accessor.getPropertyValue("object.name")).isEqualTo("y");
}
@Test
@ -198,9 +194,9 @@ public class BeanWrapperTests extends AbstractPropertyAccessorTests {
accessor.setAutoGrowNestedPaths(true);
accessor.setPropertyValue("object.name", "x");
assertEquals("x", target.value.getName());
assertEquals("x", target.getObject().get().getName());
assertEquals("x", accessor.getPropertyValue("object.name"));
assertThat(target.value.getName()).isEqualTo("x");
assertThat(target.getObject().get().getName()).isEqualTo("x");
assertThat(accessor.getPropertyValue("object.name")).isEqualTo("x");
}
@Test

View File

@ -26,8 +26,6 @@ import org.springframework.core.OverridingClassLoader;
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.assertTrue;
/**
* @author Juergen Hoeller
@ -39,30 +37,30 @@ public class CachedIntrospectionResultsTests {
@Test
public void acceptAndClearClassLoader() throws Exception {
BeanWrapper bw = new BeanWrapperImpl(TestBean.class);
assertTrue(bw.isWritableProperty("name"));
assertTrue(bw.isWritableProperty("age"));
assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));
assertThat(bw.isWritableProperty("name")).isTrue();
assertThat(bw.isWritableProperty("age")).isTrue();
assertThat(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class)).isTrue();
ClassLoader child = new OverridingClassLoader(getClass().getClassLoader());
Class<?> tbClass = child.loadClass("org.springframework.tests.sample.beans.TestBean");
assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
assertThat(CachedIntrospectionResults.strongClassCache.containsKey(tbClass)).isFalse();
CachedIntrospectionResults.acceptClassLoader(child);
bw = new BeanWrapperImpl(tbClass);
assertTrue(bw.isWritableProperty("name"));
assertTrue(bw.isWritableProperty("age"));
assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
assertThat(bw.isWritableProperty("name")).isTrue();
assertThat(bw.isWritableProperty("age")).isTrue();
assertThat(CachedIntrospectionResults.strongClassCache.containsKey(tbClass)).isTrue();
CachedIntrospectionResults.clearClassLoader(child);
assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(tbClass));
assertThat(CachedIntrospectionResults.strongClassCache.containsKey(tbClass)).isFalse();
assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class));
assertThat(CachedIntrospectionResults.strongClassCache.containsKey(TestBean.class)).isTrue();
}
@Test
public void clearClassLoaderForSystemClassLoader() throws Exception {
BeanUtils.getPropertyDescriptors(ArrayList.class);
assertTrue(CachedIntrospectionResults.strongClassCache.containsKey(ArrayList.class));
assertThat(CachedIntrospectionResults.strongClassCache.containsKey(ArrayList.class)).isTrue();
CachedIntrospectionResults.clearClassLoader(ArrayList.class.getClassLoader());
assertFalse(CachedIntrospectionResults.strongClassCache.containsKey(ArrayList.class));
assertThat(CachedIntrospectionResults.strongClassCache.containsKey(ArrayList.class)).isFalse();
}
@Test

View File

@ -28,8 +28,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Guillaume Poirier
@ -83,7 +82,7 @@ public class ConcurrentBeanWrapperTests {
Properties p = (Properties) System.getProperties().clone();
assertTrue("The System properties must not be empty", p.size() != 0);
assertThat(p.size() != 0).as("The System properties must not be empty").isTrue();
for (Iterator<?> i = p.entrySet().iterator(); i.hasNext();) {
i.next();
@ -104,7 +103,7 @@ public class ConcurrentBeanWrapperTests {
BeanWrapperImpl wrapper = new BeanWrapperImpl(bean);
wrapper.setPropertyValue("properties", value);
assertEquals(p, bean.getProperties());
assertThat(bean.getProperties()).isEqualTo(p);
}

View File

@ -20,7 +20,7 @@ import org.junit.Test;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Specific {@link DirectFieldAccessor} tests.
@ -48,8 +48,8 @@ public class DirectFieldAccessorTests extends AbstractPropertyAccessorTests {
};
DirectFieldAccessor dfa = createAccessor(target);
assertEquals(StringBuilder.class, dfa.getPropertyType("name"));
assertEquals(sb, dfa.getPropertyValue("name"));
assertThat(dfa.getPropertyType("name")).isEqualTo(StringBuilder.class);
assertThat(dfa.getPropertyValue("name")).isEqualTo(sb);
}
}

View File

@ -28,7 +28,6 @@ import org.junit.Test;
import org.springframework.tests.sample.beans.TestBean;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
/**
* @author Chris Beams
@ -323,7 +322,7 @@ public class ExtendedBeanInfoTests {
assertThat(hasReadMethodForProperty(bi, "foo")).isTrue();
assertThat(hasReadMethodForProperty(ebi, "foo")).isTrue();
assertEquals(hasWriteMethodForProperty(bi, "foo"), hasWriteMethodForProperty(ebi, "foo"));
assertThat(hasWriteMethodForProperty(ebi, "foo")).isEqualTo(hasWriteMethodForProperty(bi, "foo"));
}
@Test
@ -338,7 +337,7 @@ public class ExtendedBeanInfoTests {
assertThat(hasIndexedReadMethodForProperty(bi, "foos")).isTrue();
assertThat(hasIndexedReadMethodForProperty(ebi, "foos")).isTrue();
assertEquals(hasIndexedWriteMethodForProperty(bi, "foos"), hasIndexedWriteMethodForProperty(ebi, "foos"));
assertThat(hasIndexedWriteMethodForProperty(ebi, "foos")).isEqualTo(hasIndexedWriteMethodForProperty(bi, "foos"));
}
/**
@ -849,10 +848,10 @@ public class ExtendedBeanInfoTests {
// ExtendedBeanInfo needs to behave exactly like BeanInfo...
BeanInfo ebi = new ExtendedBeanInfo(bi);
assertEquals(hasReadMethod, hasReadMethodForProperty(ebi, "address"));
assertEquals(hasWriteMethod, hasWriteMethodForProperty(ebi, "address"));
assertEquals(hasIndexedReadMethod, hasIndexedReadMethodForProperty(ebi, "address"));
assertEquals(hasIndexedWriteMethod, hasIndexedWriteMethodForProperty(ebi, "address"));
assertThat(hasReadMethodForProperty(ebi, "address")).isEqualTo(hasReadMethod);
assertThat(hasWriteMethodForProperty(ebi, "address")).isEqualTo(hasWriteMethod);
assertThat(hasIndexedReadMethodForProperty(ebi, "address")).isEqualTo(hasIndexedReadMethod);
assertThat(hasIndexedWriteMethodForProperty(ebi, "address")).isEqualTo(hasIndexedWriteMethod);
}
@Test

View File

@ -22,9 +22,6 @@ import org.junit.Test;
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;
/**
* Tests for {@link MutablePropertyValues}.
@ -47,7 +44,7 @@ public class MutablePropertyValuesTests extends AbstractPropertyValuesTests {
doTestTony(deepCopy);
deepCopy.setPropertyValueAt(new PropertyValue("name", "Gordon"), 0);
doTestTony(pvs);
assertEquals("Gordon", deepCopy.getPropertyValue("name").getValue());
assertThat(deepCopy.getPropertyValue("name").getValue()).isEqualTo("Gordon");
}
@Test
@ -59,10 +56,10 @@ public class MutablePropertyValuesTests extends AbstractPropertyValuesTests {
doTestTony(pvs);
PropertyValue addedPv = new PropertyValue("rod", "Rod");
pvs.addPropertyValue(addedPv);
assertTrue(pvs.getPropertyValue("rod").equals(addedPv));
assertThat(pvs.getPropertyValue("rod").equals(addedPv)).isTrue();
PropertyValue changedPv = new PropertyValue("forname", "Greg");
pvs.addPropertyValue(changedPv);
assertTrue(pvs.getPropertyValue("forname").equals(changedPv));
assertThat(pvs.getPropertyValue("forname").equals(changedPv)).isTrue();
}
@Test
@ -73,7 +70,7 @@ public class MutablePropertyValuesTests extends AbstractPropertyValuesTests {
pvs.addPropertyValue(new PropertyValue("age", "50"));
MutablePropertyValues pvs2 = pvs;
PropertyValues changes = pvs2.changesSince(pvs);
assertTrue("changes are empty", changes.getPropertyValues().length == 0);
assertThat(changes.getPropertyValues().length == 0).as("changes are empty").isTrue();
}
@Test
@ -85,29 +82,27 @@ public class MutablePropertyValuesTests extends AbstractPropertyValuesTests {
MutablePropertyValues pvs2 = new MutablePropertyValues(pvs);
PropertyValues changes = pvs2.changesSince(pvs);
assertTrue("changes are empty, not of length " + changes.getPropertyValues().length,
changes.getPropertyValues().length == 0);
assertThat(changes.getPropertyValues().length == 0).as("changes are empty, not of length " + changes.getPropertyValues().length).isTrue();
pvs2.addPropertyValue(new PropertyValue("forname", "Gordon"));
changes = pvs2.changesSince(pvs);
assertEquals("1 change", 1, changes.getPropertyValues().length);
assertThat(changes.getPropertyValues().length).as("1 change").isEqualTo(1);
PropertyValue fn = changes.getPropertyValue("forname");
assertTrue("change is forname", fn != null);
assertTrue("new value is gordon", fn.getValue().equals("Gordon"));
assertThat(fn != null).as("change is forname").isTrue();
assertThat(fn.getValue().equals("Gordon")).as("new value is gordon").isTrue();
MutablePropertyValues pvs3 = new MutablePropertyValues(pvs);
changes = pvs3.changesSince(pvs);
assertTrue("changes are empty, not of length " + changes.getPropertyValues().length,
changes.getPropertyValues().length == 0);
assertThat(changes.getPropertyValues().length == 0).as("changes are empty, not of length " + changes.getPropertyValues().length).isTrue();
// add new
pvs3.addPropertyValue(new PropertyValue("foo", "bar"));
pvs3.addPropertyValue(new PropertyValue("fi", "fum"));
changes = pvs3.changesSince(pvs);
assertTrue("2 change", changes.getPropertyValues().length == 2);
assertThat(changes.getPropertyValues().length == 2).as("2 change").isTrue();
fn = changes.getPropertyValue("foo");
assertTrue("change in foo", fn != null);
assertTrue("new value is bar", fn.getValue().equals("bar"));
assertThat(fn != null).as("change in foo").isTrue();
assertThat(fn.getValue().equals("bar")).as("new value is bar").isTrue();
}
@Test
@ -116,19 +111,19 @@ public class MutablePropertyValuesTests extends AbstractPropertyValuesTests {
pvs.add("foo", "bar");
Iterator<PropertyValue> it = pvs.iterator();
assertTrue(it.hasNext());
assertThat(it.hasNext()).isTrue();
PropertyValue pv = it.next();
assertEquals("foo", pv.getName());
assertEquals("bar", pv.getValue());
assertThat(pv.getName()).isEqualTo("foo");
assertThat(pv.getValue()).isEqualTo("bar");
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(it::remove);
assertFalse(it.hasNext());
assertThat(it.hasNext()).isFalse();
}
@Test
public void iteratorIsEmptyForEmptyValues() {
MutablePropertyValues pvs = new MutablePropertyValues();
Iterator<PropertyValue> it = pvs.iterator();
assertFalse(it.hasNext());
assertThat(it.hasNext()).isFalse();
}
@Test

View File

@ -20,8 +20,7 @@ import java.util.Arrays;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
@ -31,15 +30,15 @@ public class PropertyAccessorUtilsTests {
@Test
public void testCanonicalPropertyName() {
assertEquals("map", PropertyAccessorUtils.canonicalPropertyName("map"));
assertEquals("map[key1]", PropertyAccessorUtils.canonicalPropertyName("map[key1]"));
assertEquals("map[key1]", PropertyAccessorUtils.canonicalPropertyName("map['key1']"));
assertEquals("map[key1]", PropertyAccessorUtils.canonicalPropertyName("map[\"key1\"]"));
assertEquals("map[key1][key2]", PropertyAccessorUtils.canonicalPropertyName("map[key1][key2]"));
assertEquals("map[key1][key2]", PropertyAccessorUtils.canonicalPropertyName("map['key1'][\"key2\"]"));
assertEquals("map[key1].name", PropertyAccessorUtils.canonicalPropertyName("map[key1].name"));
assertEquals("map[key1].name", PropertyAccessorUtils.canonicalPropertyName("map['key1'].name"));
assertEquals("map[key1].name", PropertyAccessorUtils.canonicalPropertyName("map[\"key1\"].name"));
assertThat(PropertyAccessorUtils.canonicalPropertyName("map")).isEqualTo("map");
assertThat(PropertyAccessorUtils.canonicalPropertyName("map[key1]")).isEqualTo("map[key1]");
assertThat(PropertyAccessorUtils.canonicalPropertyName("map['key1']")).isEqualTo("map[key1]");
assertThat(PropertyAccessorUtils.canonicalPropertyName("map[\"key1\"]")).isEqualTo("map[key1]");
assertThat(PropertyAccessorUtils.canonicalPropertyName("map[key1][key2]")).isEqualTo("map[key1][key2]");
assertThat(PropertyAccessorUtils.canonicalPropertyName("map['key1'][\"key2\"]")).isEqualTo("map[key1][key2]");
assertThat(PropertyAccessorUtils.canonicalPropertyName("map[key1].name")).isEqualTo("map[key1].name");
assertThat(PropertyAccessorUtils.canonicalPropertyName("map['key1'].name")).isEqualTo("map[key1].name");
assertThat(PropertyAccessorUtils.canonicalPropertyName("map[\"key1\"].name")).isEqualTo("map[key1].name");
}
@Test
@ -51,7 +50,7 @@ public class PropertyAccessorUtilsTests {
new String[] {"map", "map[key1]", "map[key1]", "map[key1]", "map[key1][key2]",
"map[key1][key2]", "map[key1].name", "map[key1].name", "map[key1].name"};
assertTrue(Arrays.equals(canonical, PropertyAccessorUtils.canonicalPropertyNames(original)));
assertThat(Arrays.equals(canonical, PropertyAccessorUtils.canonicalPropertyNames(original))).isTrue();
}
}

View File

@ -36,8 +36,7 @@ import org.springframework.tests.sample.beans.TestBean;
import org.springframework.tests.sample.beans.factory.DummyFactory;
import org.springframework.util.ObjectUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -83,7 +82,7 @@ public class BeanFactoryUtilsTests {
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
lbf.addBean("t1", new TestBean());
lbf.addBean("t2", new TestBean());
assertTrue(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2);
assertThat(BeanFactoryUtils.countBeansIncludingAncestors(lbf) == 2).isTrue();
}
/**
@ -92,27 +91,26 @@ public class BeanFactoryUtilsTests {
@Test
public void testHierarchicalCountBeansWithOverride() throws Exception {
// Leaf count
assertTrue(this.listableBeanFactory.getBeanDefinitionCount() == 1);
assertThat(this.listableBeanFactory.getBeanDefinitionCount() == 1).isTrue();
// Count minus duplicate
assertTrue("Should count 8 beans, not " + BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory),
BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory) == 8);
assertThat(BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory) == 8).as("Should count 8 beans, not " + BeanFactoryUtils.countBeansIncludingAncestors(this.listableBeanFactory)).isTrue();
}
@Test
public void testHierarchicalNamesWithNoMatch() throws Exception {
List<String> names = Arrays.asList(
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory, NoOp.class));
assertEquals(0, names.size());
assertThat(names.size()).isEqualTo(0);
}
@Test
public void testHierarchicalNamesWithMatchOnlyInRoot() throws Exception {
List<String> names = Arrays.asList(
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory, IndexedTestBean.class));
assertEquals(1, names.size());
assertTrue(names.contains("indexedBean"));
assertThat(names.size()).isEqualTo(1);
assertThat(names.contains("indexedBean")).isTrue();
// Distinguish from default ListableBeanFactory behavior
assertTrue(listableBeanFactory.getBeanNamesForType(IndexedTestBean.class).length == 0);
assertThat(listableBeanFactory.getBeanNamesForType(IndexedTestBean.class).length == 0).isTrue();
}
@Test
@ -120,11 +118,11 @@ public class BeanFactoryUtilsTests {
List<String> names = Arrays.asList(
BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class));
// includes 2 TestBeans from FactoryBeans (DummyFactory definitions)
assertEquals(4, names.size());
assertTrue(names.contains("test"));
assertTrue(names.contains("test3"));
assertTrue(names.contains("testFactory1"));
assertTrue(names.contains("testFactory2"));
assertThat(names.size()).isEqualTo(4);
assertThat(names.contains("test")).isTrue();
assertThat(names.contains("test3")).isTrue();
assertThat(names.contains("testFactory1")).isTrue();
assertThat(names.contains("testFactory2")).isTrue();
}
@Test
@ -132,7 +130,7 @@ public class BeanFactoryUtilsTests {
StaticListableBeanFactory lbf = new StaticListableBeanFactory();
lbf.addBean("foo", new Object());
Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, false);
assertTrue(beans.isEmpty());
assertThat(beans.isEmpty()).isTrue();
}
@Test
@ -149,21 +147,22 @@ public class BeanFactoryUtilsTests {
lbf.addBean("t4", t4);
Map<String, ?> beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, ITestBean.class, true, true);
assertEquals(4, beans.size());
assertEquals(t1, beans.get("t1"));
assertEquals(t2, beans.get("t2"));
assertEquals(t3.getObject(), beans.get("t3"));
assertTrue(beans.get("t4") instanceof TestBean);
assertThat(beans.size()).isEqualTo(4);
assertThat(beans.get("t1")).isEqualTo(t1);
assertThat(beans.get("t2")).isEqualTo(t2);
assertThat(beans.get("t3")).isEqualTo(t3.getObject());
boolean condition = beans.get("t4") instanceof TestBean;
assertThat(condition).isTrue();
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, DummyFactory.class, true, true);
assertEquals(2, beans.size());
assertEquals(t3, beans.get("&t3"));
assertEquals(t4, beans.get("&t4"));
assertThat(beans.size()).isEqualTo(2);
assertThat(beans.get("&t3")).isEqualTo(t3);
assertThat(beans.get("&t4")).isEqualTo(t4);
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(lbf, FactoryBean.class, true, true);
assertEquals(2, beans.size());
assertEquals(t3, beans.get("&t3"));
assertEquals(t4, beans.get("&t4"));
assertThat(beans.size()).isEqualTo(2);
assertThat(beans.get("&t3")).isEqualTo(t3);
assertThat(beans.get("&t4")).isEqualTo(t4);
}
@Test
@ -183,50 +182,53 @@ public class BeanFactoryUtilsTests {
Map<String, ?> beans =
BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true, false);
assertEquals(6, beans.size());
assertEquals(test3, beans.get("test3"));
assertEquals(test, beans.get("test"));
assertEquals(t1, beans.get("t1"));
assertEquals(t2, beans.get("t2"));
assertEquals(t3.getObject(), beans.get("t3"));
assertTrue(beans.get("t4") instanceof TestBean);
assertThat(beans.size()).isEqualTo(6);
assertThat(beans.get("test3")).isEqualTo(test3);
assertThat(beans.get("test")).isEqualTo(test);
assertThat(beans.get("t1")).isEqualTo(t1);
assertThat(beans.get("t2")).isEqualTo(t2);
assertThat(beans.get("t3")).isEqualTo(t3.getObject());
boolean condition2 = beans.get("t4") instanceof TestBean;
assertThat(condition2).isTrue();
// t3 and t4 are found here as of Spring 2.0, since they are pre-registered
// singleton instances, while testFactory1 and testFactory are *not* found
// because they are FactoryBean definitions that haven't been initialized yet.
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, false, true);
Object testFactory1 = this.listableBeanFactory.getBean("testFactory1");
assertEquals(5, beans.size());
assertEquals(test, beans.get("test"));
assertEquals(testFactory1, beans.get("testFactory1"));
assertEquals(t1, beans.get("t1"));
assertEquals(t2, beans.get("t2"));
assertEquals(t3.getObject(), beans.get("t3"));
assertThat(beans.size()).isEqualTo(5);
assertThat(beans.get("test")).isEqualTo(test);
assertThat(beans.get("testFactory1")).isEqualTo(testFactory1);
assertThat(beans.get("t1")).isEqualTo(t1);
assertThat(beans.get("t2")).isEqualTo(t2);
assertThat(beans.get("t3")).isEqualTo(t3.getObject());
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true, true);
assertEquals(8, beans.size());
assertEquals(test3, beans.get("test3"));
assertEquals(test, beans.get("test"));
assertEquals(testFactory1, beans.get("testFactory1"));
assertTrue(beans.get("testFactory2") instanceof TestBean);
assertEquals(t1, beans.get("t1"));
assertEquals(t2, beans.get("t2"));
assertEquals(t3.getObject(), beans.get("t3"));
assertTrue(beans.get("t4") instanceof TestBean);
assertThat(beans.size()).isEqualTo(8);
assertThat(beans.get("test3")).isEqualTo(test3);
assertThat(beans.get("test")).isEqualTo(test);
assertThat(beans.get("testFactory1")).isEqualTo(testFactory1);
boolean condition1 = beans.get("testFactory2") instanceof TestBean;
assertThat(condition1).isTrue();
assertThat(beans.get("t1")).isEqualTo(t1);
assertThat(beans.get("t2")).isEqualTo(t2);
assertThat(beans.get("t3")).isEqualTo(t3.getObject());
boolean condition = beans.get("t4") instanceof TestBean;
assertThat(condition).isTrue();
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, DummyFactory.class, true, true);
assertEquals(4, beans.size());
assertEquals(this.listableBeanFactory.getBean("&testFactory1"), beans.get("&testFactory1"));
assertEquals(this.listableBeanFactory.getBean("&testFactory2"), beans.get("&testFactory2"));
assertEquals(t3, beans.get("&t3"));
assertEquals(t4, beans.get("&t4"));
assertThat(beans.size()).isEqualTo(4);
assertThat(beans.get("&testFactory1")).isEqualTo(this.listableBeanFactory.getBean("&testFactory1"));
assertThat(beans.get("&testFactory2")).isEqualTo(this.listableBeanFactory.getBean("&testFactory2"));
assertThat(beans.get("&t3")).isEqualTo(t3);
assertThat(beans.get("&t4")).isEqualTo(t4);
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, FactoryBean.class, true, true);
assertEquals(4, beans.size());
assertEquals(this.listableBeanFactory.getBean("&testFactory1"), beans.get("&testFactory1"));
assertEquals(this.listableBeanFactory.getBean("&testFactory2"), beans.get("&testFactory2"));
assertEquals(t3, beans.get("&t3"));
assertEquals(t4, beans.get("&t4"));
assertThat(beans.size()).isEqualTo(4);
assertThat(beans.get("&testFactory1")).isEqualTo(this.listableBeanFactory.getBean("&testFactory1"));
assertThat(beans.get("&testFactory2")).isEqualTo(this.listableBeanFactory.getBean("&testFactory2"));
assertThat(beans.get("&t3")).isEqualTo(t3);
assertThat(beans.get("&t4")).isEqualTo(t4);
}
@Test
@ -236,53 +238,54 @@ public class BeanFactoryUtilsTests {
Map<String, ?> beans =
BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true, false);
assertEquals(2, beans.size());
assertEquals(test3, beans.get("test3"));
assertEquals(test, beans.get("test"));
assertThat(beans.size()).isEqualTo(2);
assertThat(beans.get("test3")).isEqualTo(test3);
assertThat(beans.get("test")).isEqualTo(test);
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, false, false);
assertEquals(1, beans.size());
assertEquals(test, beans.get("test"));
assertThat(beans.size()).isEqualTo(1);
assertThat(beans.get("test")).isEqualTo(test);
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, false, true);
Object testFactory1 = this.listableBeanFactory.getBean("testFactory1");
assertEquals(2, beans.size());
assertEquals(test, beans.get("test"));
assertEquals(testFactory1, beans.get("testFactory1"));
assertThat(beans.size()).isEqualTo(2);
assertThat(beans.get("test")).isEqualTo(test);
assertThat(beans.get("testFactory1")).isEqualTo(testFactory1);
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, ITestBean.class, true, true);
assertEquals(4, beans.size());
assertEquals(test3, beans.get("test3"));
assertEquals(test, beans.get("test"));
assertEquals(testFactory1, beans.get("testFactory1"));
assertTrue(beans.get("testFactory2") instanceof TestBean);
assertThat(beans.size()).isEqualTo(4);
assertThat(beans.get("test3")).isEqualTo(test3);
assertThat(beans.get("test")).isEqualTo(test);
assertThat(beans.get("testFactory1")).isEqualTo(testFactory1);
boolean condition = beans.get("testFactory2") instanceof TestBean;
assertThat(condition).isTrue();
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, DummyFactory.class, true, true);
assertEquals(2, beans.size());
assertEquals(this.listableBeanFactory.getBean("&testFactory1"), beans.get("&testFactory1"));
assertEquals(this.listableBeanFactory.getBean("&testFactory2"), beans.get("&testFactory2"));
assertThat(beans.size()).isEqualTo(2);
assertThat(beans.get("&testFactory1")).isEqualTo(this.listableBeanFactory.getBean("&testFactory1"));
assertThat(beans.get("&testFactory2")).isEqualTo(this.listableBeanFactory.getBean("&testFactory2"));
beans = BeanFactoryUtils.beansOfTypeIncludingAncestors(this.listableBeanFactory, FactoryBean.class, true, true);
assertEquals(2, beans.size());
assertEquals(this.listableBeanFactory.getBean("&testFactory1"), beans.get("&testFactory1"));
assertEquals(this.listableBeanFactory.getBean("&testFactory2"), beans.get("&testFactory2"));
assertThat(beans.size()).isEqualTo(2);
assertThat(beans.get("&testFactory1")).isEqualTo(this.listableBeanFactory.getBean("&testFactory1"));
assertThat(beans.get("&testFactory2")).isEqualTo(this.listableBeanFactory.getBean("&testFactory2"));
}
@Test
public void testHierarchicalNamesForAnnotationWithNoMatch() throws Exception {
List<String> names = Arrays.asList(
BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors(this.listableBeanFactory, Override.class));
assertEquals(0, names.size());
assertThat(names.size()).isEqualTo(0);
}
@Test
public void testHierarchicalNamesForAnnotationWithMatchOnlyInRoot() throws Exception {
List<String> names = Arrays.asList(
BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors(this.listableBeanFactory, TestAnnotation.class));
assertEquals(1, names.size());
assertTrue(names.contains("annotatedBean"));
assertThat(names.size()).isEqualTo(1);
assertThat(names.contains("annotatedBean")).isTrue();
// Distinguish from default ListableBeanFactory behavior
assertTrue(listableBeanFactory.getBeanNamesForAnnotation(TestAnnotation.class).length == 0);
assertThat(listableBeanFactory.getBeanNamesForAnnotation(TestAnnotation.class).length == 0).isTrue();
}
@Test
@ -291,33 +294,33 @@ public class BeanFactoryUtilsTests {
this.listableBeanFactory.registerSingleton("anotherAnnotatedBean", annotatedBean);
List<String> names = Arrays.asList(
BeanFactoryUtils.beanNamesForAnnotationIncludingAncestors(this.listableBeanFactory, TestAnnotation.class));
assertEquals(2, names.size());
assertTrue(names.contains("annotatedBean"));
assertTrue(names.contains("anotherAnnotatedBean"));
assertThat(names.size()).isEqualTo(2);
assertThat(names.contains("annotatedBean")).isTrue();
assertThat(names.contains("anotherAnnotatedBean")).isTrue();
}
@Test
public void testADependencies() {
String[] deps = this.dependentBeansFactory.getDependentBeans("a");
assertTrue(ObjectUtils.isEmpty(deps));
assertThat(ObjectUtils.isEmpty(deps)).isTrue();
}
@Test
public void testBDependencies() {
String[] deps = this.dependentBeansFactory.getDependentBeans("b");
assertTrue(Arrays.equals(new String[] { "c" }, deps));
assertThat(Arrays.equals(new String[] { "c" }, deps)).isTrue();
}
@Test
public void testCDependencies() {
String[] deps = this.dependentBeansFactory.getDependentBeans("c");
assertTrue(Arrays.equals(new String[] { "int", "long" }, deps));
assertThat(Arrays.equals(new String[] { "int", "long" }, deps)).isTrue();
}
@Test
public void testIntDependencies() {
String[] deps = this.dependentBeansFactory.getDependentBeans("int");
assertTrue(Arrays.equals(new String[] { "buffer" }, deps));
assertThat(Arrays.equals(new String[] { "buffer" }, deps)).isTrue();
}
}

View File

@ -36,7 +36,7 @@ import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -126,8 +126,8 @@ public class ConcurrentBeanFactoryTests {
ConcurrentBean b1 = (ConcurrentBean) factory.getBean("bean1");
ConcurrentBean b2 = (ConcurrentBean) factory.getBean("bean2");
assertEquals(DATE_1, b1.getDate());
assertEquals(DATE_2, b2.getDate());
assertThat(b1.getDate()).isEqualTo(DATE_1);
assertThat(b2.getDate()).isEqualTo(DATE_2);
}

View File

@ -26,7 +26,6 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
/**
* Written with the intention of reproducing SPR-7318.
@ -52,13 +51,13 @@ public class FactoryBeanLookupTests {
@Test
public void factoryBeanLookupByType() {
FooFactoryBean fooFactory = beanFactory.getBean(FooFactoryBean.class);
assertNotNull(fooFactory);
assertThat(fooFactory).isNotNull();
}
@Test
public void factoryBeanLookupByTypeAndNameDereference() {
FooFactoryBean fooFactory = beanFactory.getBean("&fooFactory", FooFactoryBean.class);
assertNotNull(fooFactory);
assertThat(fooFactory).isNotNull();
}
@Test
@ -70,7 +69,7 @@ public class FactoryBeanLookupTests {
@Test
public void factoryBeanObjectLookupByNameAndType() {
Foo foo = beanFactory.getBean("fooFactory", Foo.class);
assertNotNull(foo);
assertThat(foo).isNotNull();
}
}

View File

@ -30,10 +30,7 @@ import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -55,7 +52,7 @@ public class FactoryBeanTests {
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(factory).loadBeanDefinitions(RETURNS_NULL_CONTEXT);
assertEquals("null", factory.getBean("factoryBean").toString());
assertThat(factory.getBean("factoryBean").toString()).isEqualTo("null");
}
@Test
@ -66,17 +63,17 @@ public class FactoryBeanTests {
BeanFactoryPostProcessor ppc = (BeanFactoryPostProcessor) factory.getBean("propertyPlaceholderConfigurer");
ppc.postProcessBeanFactory(factory);
assertNull(factory.getType("betaFactory"));
assertThat(factory.getType("betaFactory")).isNull();
Alpha alpha = (Alpha) factory.getBean("alpha");
Beta beta = (Beta) factory.getBean("beta");
Gamma gamma = (Gamma) factory.getBean("gamma");
Gamma gamma2 = (Gamma) factory.getBean("gammaFactory");
assertSame(beta, alpha.getBeta());
assertSame(gamma, beta.getGamma());
assertSame(gamma2, beta.getGamma());
assertEquals("yourName", beta.getName());
assertThat(alpha.getBeta()).isSameAs(beta);
assertThat(beta.getGamma()).isSameAs(gamma);
assertThat(beta.getGamma()).isSameAs(gamma2);
assertThat(beta.getName()).isEqualTo("yourName");
}
@Test
@ -90,8 +87,8 @@ public class FactoryBeanTests {
Beta beta = (Beta) factory.getBean("beta");
Alpha alpha = (Alpha) factory.getBean("alpha");
Gamma gamma = (Gamma) factory.getBean("gamma");
assertSame(beta, alpha.getBeta());
assertSame(gamma, beta.getGamma());
assertThat(alpha.getBeta()).isSameAs(beta);
assertThat(beta.getGamma()).isSameAs(gamma);
}
@Test
@ -117,12 +114,12 @@ public class FactoryBeanTests {
factory.addBeanPostProcessor(counter);
BeanImpl1 impl1 = factory.getBean(BeanImpl1.class);
assertNotNull(impl1);
assertNotNull(impl1.getImpl2());
assertNotNull(impl1.getImpl2());
assertSame(impl1, impl1.getImpl2().getImpl1());
assertEquals(1, counter.getCount("bean1"));
assertEquals(1, counter.getCount("bean2"));
assertThat(impl1).isNotNull();
assertThat(impl1.getImpl2()).isNotNull();
assertThat(impl1.getImpl2()).isNotNull();
assertThat(impl1.getImpl2().getImpl1()).isSameAs(impl1);
assertThat(counter.getCount("bean1")).isEqualTo(1);
assertThat(counter.getCount("bean2")).isEqualTo(1);
}

View File

@ -20,11 +20,8 @@ import org.junit.Test;
import org.springframework.beans.factory.wiring.BeanWiringInfo;
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.assertNotNull;
import static org.junit.Assert.assertNull;
/**
* @author Rick Evans
@ -42,32 +39,32 @@ public class AnnotationBeanWiringInfoResolverTests {
public void testResolveWiringInfoWithAnInstanceOfANonAnnotatedClass() {
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
BeanWiringInfo info = resolver.resolveWiringInfo("java.lang.String is not @Configurable");
assertNull("Must be returning null for a non-@Configurable class instance", info);
assertThat(info).as("Must be returning null for a non-@Configurable class instance").isNull();
}
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClass() {
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
BeanWiringInfo info = resolver.resolveWiringInfo(new Soap());
assertNotNull("Must *not* be returning null for a non-@Configurable class instance", info);
assertThat(info).as("Must *not* be returning null for a non-@Configurable class instance").isNotNull();
}
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitly() {
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
BeanWiringInfo info = resolver.resolveWiringInfo(new WirelessSoap());
assertNotNull("Must *not* be returning null for an @Configurable class instance even when autowiring is NO", info);
assertFalse(info.indicatesAutowiring());
assertEquals(WirelessSoap.class.getName(), info.getBeanName());
assertThat(info).as("Must *not* be returning null for an @Configurable class instance even when autowiring is NO").isNotNull();
assertThat(info.indicatesAutowiring()).isFalse();
assertThat(info.getBeanName()).isEqualTo(WirelessSoap.class.getName());
}
@Test
public void testResolveWiringInfoWithAnInstanceOfAnAnnotatedClassWithAutowiringTurnedOffExplicitlyAndCustomBeanName() {
AnnotationBeanWiringInfoResolver resolver = new AnnotationBeanWiringInfoResolver();
BeanWiringInfo info = resolver.resolveWiringInfo(new NamedWirelessSoap());
assertNotNull("Must *not* be returning null for an @Configurable class instance even when autowiring is NO", info);
assertFalse(info.indicatesAutowiring());
assertEquals("DerBigStick", info.getBeanName());
assertThat(info).as("Must *not* be returning null for an @Configurable class instance even when autowiring is NO").isNotNull();
assertThat(info.indicatesAutowiring()).isFalse();
assertThat(info.getBeanName()).isEqualTo("DerBigStick");
}

View File

@ -24,7 +24,7 @@ import org.springframework.beans.factory.support.AutowireCandidateResolver;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -47,7 +47,7 @@ public class CustomAutowireConfigurerTests {
bf.setAutowireCandidateResolver(customResolver);
cac.postProcessBeanFactory(bf);
TestBean testBean = (TestBean) bf.getBean("testBean");
assertEquals("#1!", testBean.getName());
assertThat(testBean.getName()).isEqualTo("#1!");
}

View File

@ -45,14 +45,8 @@ import org.springframework.tests.sample.beans.NestedTestBean;
import org.springframework.tests.sample.beans.TestBean;
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.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor}
@ -91,7 +85,8 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.getBean("testBean");
}
catch (BeanCreationException ex) {
assertTrue(ex.getRootCause() instanceof IllegalStateException);
boolean condition = ex.getRootCause() instanceof IllegalStateException;
assertThat(condition).isTrue();
}
}
@ -104,12 +99,12 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerSingleton("testBean", tb);
ResourceInjectionBean bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean());
assertSame(tb, bean.getTestBean2());
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb);
bean = (ResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean());
assertSame(tb, bean.getTestBean2());
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb);
}
@Test
@ -123,20 +118,20 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerSingleton("nestedTestBean", ntb);
TypedExtendedResourceInjectionBean bean = (TypedExtendedResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean());
assertSame(tb, bean.getTestBean2());
assertSame(tb, bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertSame(ntb, bean.getNestedTestBean());
assertSame(bf, bean.getBeanFactory());
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb);
assertThat(bean.getTestBean3()).isSameAs(tb);
assertThat(bean.getTestBean4()).isSameAs(tb);
assertThat(bean.getNestedTestBean()).isSameAs(ntb);
assertThat(bean.getBeanFactory()).isSameAs(bf);
bean = (TypedExtendedResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean());
assertSame(tb, bean.getTestBean2());
assertSame(tb, bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertSame(ntb, bean.getNestedTestBean());
assertSame(bf, bean.getBeanFactory());
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb);
assertThat(bean.getTestBean3()).isSameAs(tb);
assertThat(bean.getTestBean4()).isSameAs(tb);
assertThat(bean.getNestedTestBean()).isSameAs(ntb);
assertThat(bean.getBeanFactory()).isSameAs(bf);
}
@Test
@ -151,12 +146,12 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerSingleton("nestedTestBean", ntb);
TypedExtendedResourceInjectionBean bean = (TypedExtendedResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean());
assertSame(tb2, bean.getTestBean2());
assertSame(tb, bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertSame(ntb, bean.getNestedTestBean());
assertSame(bf, bean.getBeanFactory());
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb2);
assertThat(bean.getTestBean3()).isSameAs(tb);
assertThat(bean.getTestBean4()).isSameAs(tb);
assertThat(bean.getNestedTestBean()).isSameAs(ntb);
assertThat(bean.getBeanFactory()).isSameAs(bf);
}
@Test
@ -172,12 +167,12 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerSingleton("nestedTestBean", ntb);
TypedExtendedResourceInjectionBean bean = (TypedExtendedResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean());
assertSame(tb, bean.getTestBean2());
assertSame(tb, bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertSame(ntb, bean.getNestedTestBean());
assertSame(bf, bean.getBeanFactory());
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb);
assertThat(bean.getTestBean3()).isSameAs(tb);
assertThat(bean.getTestBean4()).isSameAs(tb);
assertThat(bean.getNestedTestBean()).isSameAs(ntb);
assertThat(bean.getBeanFactory()).isSameAs(bf);
}
@Test
@ -191,20 +186,20 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerSingleton("nestedTestBean", ntb);
ConstructorResourceInjectionBean bean = (ConstructorResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean());
assertSame(tb, bean.getTestBean2());
assertSame(tb, bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertSame(ntb, bean.getNestedTestBean());
assertSame(bf, bean.getBeanFactory());
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb);
assertThat(bean.getTestBean3()).isSameAs(tb);
assertThat(bean.getTestBean4()).isSameAs(tb);
assertThat(bean.getNestedTestBean()).isSameAs(ntb);
assertThat(bean.getBeanFactory()).isSameAs(bf);
bean = (ConstructorResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean());
assertSame(tb, bean.getTestBean2());
assertSame(tb, bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertSame(ntb, bean.getNestedTestBean());
assertSame(bf, bean.getBeanFactory());
assertThat(bean.getTestBean()).isSameAs(tb);
assertThat(bean.getTestBean2()).isSameAs(tb);
assertThat(bean.getTestBean3()).isSameAs(tb);
assertThat(bean.getTestBean4()).isSameAs(tb);
assertThat(bean.getNestedTestBean()).isSameAs(ntb);
assertThat(bean.getBeanFactory()).isSameAs(bf);
}
@Test
@ -219,11 +214,11 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerSingleton("nestedTestBean2", ntb2);
ConstructorsCollectionResourceInjectionBean bean = (ConstructorsCollectionResourceInjectionBean) bf.getBean("annotatedBean");
assertNull(bean.getTestBean3());
assertSame(tb, bean.getTestBean4());
assertEquals(2, bean.getNestedTestBeans().size());
assertSame(ntb1, bean.getNestedTestBeans().get(0));
assertSame(ntb2, bean.getNestedTestBeans().get(1));
assertThat(bean.getTestBean3()).isNull();
assertThat(bean.getTestBean4()).isSameAs(tb);
assertThat(bean.getNestedTestBeans().size()).isEqualTo(2);
assertThat(bean.getNestedTestBeans().get(0)).isSameAs(ntb1);
assertThat(bean.getNestedTestBeans().get(1)).isSameAs(ntb2);
}
@Test
@ -233,8 +228,8 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerSingleton("testBean", tb);
ConstructorsResourceInjectionBean bean = (ConstructorsResourceInjectionBean) bf.getBean("annotatedBean");
assertSame(tb, bean.getTestBean3());
assertNull(bean.getTestBean4());
assertThat(bean.getTestBean3()).isSameAs(tb);
assertThat(bean.getTestBean4()).isNull();
}
@Test
@ -248,18 +243,18 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerSingleton("testBean2", tb1);
MapConstructorInjectionBean bean = (MapConstructorInjectionBean) bf.getBean("annotatedBean");
assertEquals(2, bean.getTestBeanMap().size());
assertTrue(bean.getTestBeanMap().keySet().contains("testBean1"));
assertTrue(bean.getTestBeanMap().keySet().contains("testBean2"));
assertTrue(bean.getTestBeanMap().values().contains(tb1));
assertTrue(bean.getTestBeanMap().values().contains(tb2));
assertThat(bean.getTestBeanMap().size()).isEqualTo(2);
assertThat(bean.getTestBeanMap().keySet().contains("testBean1")).isTrue();
assertThat(bean.getTestBeanMap().keySet().contains("testBean2")).isTrue();
assertThat(bean.getTestBeanMap().values().contains(tb1)).isTrue();
assertThat(bean.getTestBeanMap().values().contains(tb2)).isTrue();
bean = (MapConstructorInjectionBean) bf.getBean("annotatedBean");
assertEquals(2, bean.getTestBeanMap().size());
assertTrue(bean.getTestBeanMap().keySet().contains("testBean1"));
assertTrue(bean.getTestBeanMap().keySet().contains("testBean2"));
assertTrue(bean.getTestBeanMap().values().contains(tb1));
assertTrue(bean.getTestBeanMap().values().contains(tb2));
assertThat(bean.getTestBeanMap().size()).isEqualTo(2);
assertThat(bean.getTestBeanMap().keySet().contains("testBean1")).isTrue();
assertThat(bean.getTestBeanMap().keySet().contains("testBean2")).isTrue();
assertThat(bean.getTestBeanMap().values().contains(tb1)).isTrue();
assertThat(bean.getTestBeanMap().values().contains(tb2)).isTrue();
}
@Test
@ -273,18 +268,18 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerSingleton("testBean2", tb1);
MapFieldInjectionBean bean = (MapFieldInjectionBean) bf.getBean("annotatedBean");
assertEquals(2, bean.getTestBeanMap().size());
assertTrue(bean.getTestBeanMap().keySet().contains("testBean1"));
assertTrue(bean.getTestBeanMap().keySet().contains("testBean2"));
assertTrue(bean.getTestBeanMap().values().contains(tb1));
assertTrue(bean.getTestBeanMap().values().contains(tb2));
assertThat(bean.getTestBeanMap().size()).isEqualTo(2);
assertThat(bean.getTestBeanMap().keySet().contains("testBean1")).isTrue();
assertThat(bean.getTestBeanMap().keySet().contains("testBean2")).isTrue();
assertThat(bean.getTestBeanMap().values().contains(tb1)).isTrue();
assertThat(bean.getTestBeanMap().values().contains(tb2)).isTrue();
bean = (MapFieldInjectionBean) bf.getBean("annotatedBean");
assertEquals(2, bean.getTestBeanMap().size());
assertTrue(bean.getTestBeanMap().keySet().contains("testBean1"));
assertTrue(bean.getTestBeanMap().keySet().contains("testBean2"));
assertTrue(bean.getTestBeanMap().values().contains(tb1));
assertTrue(bean.getTestBeanMap().values().contains(tb2));
assertThat(bean.getTestBeanMap().size()).isEqualTo(2);
assertThat(bean.getTestBeanMap().keySet().contains("testBean1")).isTrue();
assertThat(bean.getTestBeanMap().keySet().contains("testBean2")).isTrue();
assertThat(bean.getTestBeanMap().values().contains(tb1)).isTrue();
assertThat(bean.getTestBeanMap().values().contains(tb2)).isTrue();
}
@Test
@ -296,16 +291,16 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerSingleton("testBean", tb);
MapMethodInjectionBean bean = (MapMethodInjectionBean) bf.getBean("annotatedBean");
assertEquals(1, bean.getTestBeanMap().size());
assertTrue(bean.getTestBeanMap().keySet().contains("testBean"));
assertTrue(bean.getTestBeanMap().values().contains(tb));
assertSame(tb, bean.getTestBean());
assertThat(bean.getTestBeanMap().size()).isEqualTo(1);
assertThat(bean.getTestBeanMap().keySet().contains("testBean")).isTrue();
assertThat(bean.getTestBeanMap().values().contains(tb)).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
bean = (MapMethodInjectionBean) bf.getBean("annotatedBean");
assertEquals(1, bean.getTestBeanMap().size());
assertTrue(bean.getTestBeanMap().keySet().contains("testBean"));
assertTrue(bean.getTestBeanMap().values().contains(tb));
assertSame(tb, bean.getTestBean());
assertThat(bean.getTestBeanMap().size()).isEqualTo(1);
assertThat(bean.getTestBeanMap().keySet().contains("testBean")).isTrue();
assertThat(bean.getTestBeanMap().values().contains(tb)).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
}
@Test
@ -327,10 +322,10 @@ public class InjectAnnotationBeanPostProcessorTests {
MapMethodInjectionBean bean = (MapMethodInjectionBean) bf.getBean("annotatedBean");
TestBean tb = (TestBean) bf.getBean("testBean1");
assertEquals(1, bean.getTestBeanMap().size());
assertTrue(bean.getTestBeanMap().keySet().contains("testBean1"));
assertTrue(bean.getTestBeanMap().values().contains(tb));
assertSame(tb, bean.getTestBean());
assertThat(bean.getTestBeanMap().size()).isEqualTo(1);
assertThat(bean.getTestBeanMap().keySet().contains("testBean1")).isTrue();
assertThat(bean.getTestBeanMap().values().contains(tb)).isTrue();
assertThat(bean.getTestBean()).isSameAs(tb);
}
@Test
@ -342,7 +337,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean2", new RootBeanDefinition(TestBean.class));
ObjectFactoryQualifierFieldInjectionBean bean = (ObjectFactoryQualifierFieldInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -353,7 +348,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", bd);
ObjectFactoryQualifierFieldInjectionBean bean = (ObjectFactoryQualifierFieldInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -367,10 +362,10 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean2", new RootBeanDefinition(TestBean.class));
ObjectFactoryQualifierFieldInjectionBean bean = (ObjectFactoryQualifierFieldInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
ObjectFactoryQualifierFieldInjectionBean anotherBean = (ObjectFactoryQualifierFieldInjectionBean) bf.getBean("annotatedBean");
assertNotSame(anotherBean, bean);
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean).isNotSameAs(anotherBean);
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -384,10 +379,10 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean2", new RootBeanDefinition(TestBean.class));
ObjectFactoryQualifierMethodInjectionBean bean = (ObjectFactoryQualifierMethodInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
ObjectFactoryQualifierMethodInjectionBean anotherBean = (ObjectFactoryQualifierMethodInjectionBean) bf.getBean("annotatedBean");
assertNotSame(anotherBean, bean);
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean).isNotSameAs(anotherBean);
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -397,9 +392,9 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.setSerializationId("test");
ObjectFactoryFieldInjectionBean bean = (ObjectFactoryFieldInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
bean = (ObjectFactoryFieldInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -409,9 +404,9 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.setSerializationId("test");
ObjectFactoryMethodInjectionBean bean = (ObjectFactoryMethodInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
bean = (ObjectFactoryMethodInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -421,9 +416,9 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.setSerializationId("test");
ObjectFactoryListFieldInjectionBean bean = (ObjectFactoryListFieldInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
bean = (ObjectFactoryListFieldInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -433,9 +428,9 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.setSerializationId("test");
ObjectFactoryListMethodInjectionBean bean = (ObjectFactoryListMethodInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
bean = (ObjectFactoryListMethodInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -445,9 +440,9 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.setSerializationId("test");
ObjectFactoryMapFieldInjectionBean bean = (ObjectFactoryMapFieldInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
bean = (ObjectFactoryMapFieldInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -457,9 +452,9 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.setSerializationId("test");
ObjectFactoryMapMethodInjectionBean bean = (ObjectFactoryMapMethodInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
bean = (ObjectFactoryMapMethodInjectionBean) SerializationTestUtils.serializeAndDeserialize(bean);
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
/**
@ -475,10 +470,9 @@ public class InjectAnnotationBeanPostProcessorTests {
final StringFactoryBean factoryBean = (StringFactoryBean) bf.getBean("&stringFactoryBean");
final FactoryBeanDependentBean bean = (FactoryBeanDependentBean) bf.getBean("factoryBeanDependentBean");
assertNotNull("The singleton StringFactoryBean should have been registered.", factoryBean);
assertNotNull("The factoryBeanDependentBean should have been registered.", bean);
assertEquals("The FactoryBeanDependentBean should have been autowired 'by type' with the StringFactoryBean.",
factoryBean, bean.getFactoryBean());
assertThat(factoryBean).as("The singleton StringFactoryBean should have been registered.").isNotNull();
assertThat(bean).as("The factoryBeanDependentBean should have been registered.").isNotNull();
assertThat(bean.getFactoryBean()).as("The FactoryBeanDependentBean should have been autowired 'by type' with the StringFactoryBean.").isEqualTo(factoryBean);
}
@Test
@ -487,7 +481,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
NullableFieldInjectionBean bean = (NullableFieldInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -495,7 +489,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(NullableFieldInjectionBean.class));
NullableFieldInjectionBean bean = (NullableFieldInjectionBean) bf.getBean("annotatedBean");
assertNull(bean.getTestBean());
assertThat(bean.getTestBean()).isNull();
}
@Test
@ -504,7 +498,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
NullableMethodInjectionBean bean = (NullableMethodInjectionBean) bf.getBean("annotatedBean");
assertSame(bf.getBean("testBean"), bean.getTestBean());
assertThat(bean.getTestBean()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -512,7 +506,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(NullableMethodInjectionBean.class));
NullableMethodInjectionBean bean = (NullableMethodInjectionBean) bf.getBean("annotatedBean");
assertNull(bean.getTestBean());
assertThat(bean.getTestBean()).isNull();
}
@Test
@ -521,8 +515,8 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
OptionalFieldInjectionBean bean = (OptionalFieldInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.getTestBean().isPresent());
assertSame(bf.getBean("testBean"), bean.getTestBean().get());
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean().get()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -530,7 +524,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalFieldInjectionBean.class));
OptionalFieldInjectionBean bean = (OptionalFieldInjectionBean) bf.getBean("annotatedBean");
assertFalse(bean.getTestBean().isPresent());
assertThat(bean.getTestBean().isPresent()).isFalse();
}
@Test
@ -539,8 +533,8 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
OptionalMethodInjectionBean bean = (OptionalMethodInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.getTestBean().isPresent());
assertSame(bf.getBean("testBean"), bean.getTestBean().get());
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean().get()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -548,7 +542,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalMethodInjectionBean.class));
OptionalMethodInjectionBean bean = (OptionalMethodInjectionBean) bf.getBean("annotatedBean");
assertFalse(bean.getTestBean().isPresent());
assertThat(bean.getTestBean().isPresent()).isFalse();
}
@Test
@ -557,8 +551,8 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
OptionalListFieldInjectionBean bean = (OptionalListFieldInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.getTestBean().isPresent());
assertSame(bf.getBean("testBean"), bean.getTestBean().get().get(0));
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean().get().get(0)).isSameAs(bf.getBean("testBean"));
}
@Test
@ -566,7 +560,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListFieldInjectionBean.class));
OptionalListFieldInjectionBean bean = (OptionalListFieldInjectionBean) bf.getBean("annotatedBean");
assertFalse(bean.getTestBean().isPresent());
assertThat(bean.getTestBean().isPresent()).isFalse();
}
@Test
@ -575,8 +569,8 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
OptionalListMethodInjectionBean bean = (OptionalListMethodInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.getTestBean().isPresent());
assertSame(bf.getBean("testBean"), bean.getTestBean().get().get(0));
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean().get().get(0)).isSameAs(bf.getBean("testBean"));
}
@Test
@ -584,7 +578,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(OptionalListMethodInjectionBean.class));
OptionalListMethodInjectionBean bean = (OptionalListMethodInjectionBean) bf.getBean("annotatedBean");
assertFalse(bean.getTestBean().isPresent());
assertThat(bean.getTestBean().isPresent()).isFalse();
}
@Test
@ -593,8 +587,8 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
ProviderOfOptionalFieldInjectionBean bean = (ProviderOfOptionalFieldInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.getTestBean().isPresent());
assertSame(bf.getBean("testBean"), bean.getTestBean().get());
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean().get()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -602,7 +596,7 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ProviderOfOptionalFieldInjectionBean.class));
ProviderOfOptionalFieldInjectionBean bean = (ProviderOfOptionalFieldInjectionBean) bf.getBean("annotatedBean");
assertFalse(bean.getTestBean().isPresent());
assertThat(bean.getTestBean().isPresent()).isFalse();
}
@Test
@ -611,8 +605,8 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("testBean", new RootBeanDefinition(TestBean.class));
ProviderOfOptionalMethodInjectionBean bean = (ProviderOfOptionalMethodInjectionBean) bf.getBean("annotatedBean");
assertTrue(bean.getTestBean().isPresent());
assertSame(bf.getBean("testBean"), bean.getTestBean().get());
assertThat(bean.getTestBean().isPresent()).isTrue();
assertThat(bean.getTestBean().get()).isSameAs(bf.getBean("testBean"));
}
@Test
@ -620,14 +614,14 @@ public class InjectAnnotationBeanPostProcessorTests {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(ProviderOfOptionalMethodInjectionBean.class));
ProviderOfOptionalMethodInjectionBean bean = (ProviderOfOptionalMethodInjectionBean) bf.getBean("annotatedBean");
assertFalse(bean.getTestBean().isPresent());
assertThat(bean.getTestBean().isPresent()).isFalse();
}
@Test
public void testAnnotatedDefaultConstructor() {
bf.registerBeanDefinition("annotatedBean", new RootBeanDefinition(AnnotatedDefaultConstructorBean.class));
assertNotNull(bf.getBean("annotatedBean"));
assertThat(bf.getBean("annotatedBean")).isNotNull();
}

View File

@ -23,10 +23,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.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
/**
* @author Karl Pietrzak
@ -54,59 +52,59 @@ public class LookupAnnotationTests {
@Test
public void testWithoutConstructorArg() {
AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
assertNotNull(bean);
assertThat(bean).isNotNull();
Object expected = bean.get();
assertEquals(TestBean.class, expected.getClass());
assertSame(bean, beanFactory.getBean(BeanConsumer.class).abstractBean);
assertThat(expected.getClass()).isEqualTo(TestBean.class);
assertThat(beanFactory.getBean(BeanConsumer.class).abstractBean).isSameAs(bean);
}
@Test
public void testWithOverloadedArg() {
AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
assertNotNull(bean);
assertThat(bean).isNotNull();
TestBean expected = bean.get("haha");
assertEquals(TestBean.class, expected.getClass());
assertEquals("haha", expected.getName());
assertSame(bean, beanFactory.getBean(BeanConsumer.class).abstractBean);
assertThat(expected.getClass()).isEqualTo(TestBean.class);
assertThat(expected.getName()).isEqualTo("haha");
assertThat(beanFactory.getBean(BeanConsumer.class).abstractBean).isSameAs(bean);
}
@Test
public void testWithOneConstructorArg() {
AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
assertNotNull(bean);
assertThat(bean).isNotNull();
TestBean expected = bean.getOneArgument("haha");
assertEquals(TestBean.class, expected.getClass());
assertEquals("haha", expected.getName());
assertSame(bean, beanFactory.getBean(BeanConsumer.class).abstractBean);
assertThat(expected.getClass()).isEqualTo(TestBean.class);
assertThat(expected.getName()).isEqualTo("haha");
assertThat(beanFactory.getBean(BeanConsumer.class).abstractBean).isSameAs(bean);
}
@Test
public void testWithTwoConstructorArg() {
AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
assertNotNull(bean);
assertThat(bean).isNotNull();
TestBean expected = bean.getTwoArguments("haha", 72);
assertEquals(TestBean.class, expected.getClass());
assertEquals("haha", expected.getName());
assertEquals(72, expected.getAge());
assertSame(bean, beanFactory.getBean(BeanConsumer.class).abstractBean);
assertThat(expected.getClass()).isEqualTo(TestBean.class);
assertThat(expected.getName()).isEqualTo("haha");
assertThat(expected.getAge()).isEqualTo(72);
assertThat(beanFactory.getBean(BeanConsumer.class).abstractBean).isSameAs(bean);
}
@Test
public void testWithThreeArgsShouldFail() {
AbstractBean bean = (AbstractBean) beanFactory.getBean("abstractBean");
assertNotNull(bean);
assertThat(bean).isNotNull();
assertThatExceptionOfType(AbstractMethodError.class).as("TestBean has no three arg constructor").isThrownBy(() ->
bean.getThreeArguments("name", 1, 2));
assertSame(bean, beanFactory.getBean(BeanConsumer.class).abstractBean);
assertThat(beanFactory.getBean(BeanConsumer.class).abstractBean).isSameAs(bean);
}
@Test
public void testWithEarlyInjection() {
AbstractBean bean = beanFactory.getBean("beanConsumer", BeanConsumer.class).abstractBean;
assertNotNull(bean);
assertThat(bean).isNotNull();
Object expected = bean.get();
assertEquals(TestBean.class, expected.getClass());
assertSame(bean, beanFactory.getBean(BeanConsumer.class).abstractBean);
assertThat(expected.getClass()).isEqualTo(TestBean.class);
assertThat(beanFactory.getBean(BeanConsumer.class).abstractBean).isSameAs(bean);
}

View File

@ -27,10 +27,8 @@ import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.beans.factory.config.DependencyDescriptor;
import org.springframework.util.ClassUtils;
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;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.given;
@ -67,7 +65,7 @@ public class ParameterResolutionTests {
@Test
public void annotatedParametersInInnerClassConstructorAreCandidatesForAutowiring() throws Exception {
Class<?> innerClass = AutowirableClass.InnerAutowirableClass.class;
assertTrue(ClassUtils.isInnerClass(innerClass));
assertThat(ClassUtils.isInnerClass(innerClass)).isTrue();
Constructor<?> constructor = innerClass.getConstructor(AutowirableClass.class, String.class, String.class);
assertAutowirableParameters(constructor);
}
@ -78,8 +76,7 @@ public class ParameterResolutionTests {
Parameter[] parameters = executable.getParameters();
for (int parameterIndex = startIndex; parameterIndex < parameters.length; parameterIndex++) {
Parameter parameter = parameters[parameterIndex];
assertTrue("Parameter " + parameter + " must be autowirable",
ParameterResolutionDelegate.isAutowirable(parameter, parameterIndex));
assertThat(ParameterResolutionDelegate.isAutowirable(parameter, parameterIndex)).as("Parameter " + parameter + " must be autowirable").isTrue();
}
}
@ -90,8 +87,7 @@ public class ParameterResolutionTests {
Parameter[] parameters = notAutowirableConstructor.getParameters();
for (int parameterIndex = 0; parameterIndex < parameters.length; parameterIndex++) {
Parameter parameter = parameters[parameterIndex];
assertFalse("Parameter " + parameter + " must not be autowirable",
ParameterResolutionDelegate.isAutowirable(parameter, parameterIndex));
assertThat(ParameterResolutionDelegate.isAutowirable(parameter, parameterIndex)).as("Parameter " + parameter + " must not be autowirable").isFalse();
}
}
@ -135,8 +131,8 @@ public class ParameterResolutionTests {
Parameter parameter = parameters[parameterIndex];
DependencyDescriptor intermediateDependencyDescriptor = (DependencyDescriptor) ParameterResolutionDelegate.resolveDependency(
parameter, parameterIndex, AutowirableClass.class, beanFactory);
assertEquals(constructor, intermediateDependencyDescriptor.getAnnotatedElement());
assertEquals(parameter, intermediateDependencyDescriptor.getMethodParameter().getParameter());
assertThat(intermediateDependencyDescriptor.getAnnotatedElement()).isEqualTo(constructor);
assertThat(intermediateDependencyDescriptor.getMethodParameter().getParameter()).isEqualTo(parameter);
}
}

View File

@ -32,8 +32,8 @@ import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assert.assertEquals;
/**
* @author Rob Harrop
@ -92,8 +92,8 @@ public class RequiredAnnotationBeanPostProcessorTests {
factory.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());
factory.preInstantiateSingletons();
RequiredTestBean bean = (RequiredTestBean) factory.getBean("testBean");
assertEquals(24, bean.getAge());
assertEquals("Blue", bean.getFavouriteColour());
assertThat(bean.getAge()).isEqualTo(24);
assertThat(bean.getFavouriteColour()).isEqualTo("Blue");
}
@Test
@ -146,8 +146,8 @@ public class RequiredAnnotationBeanPostProcessorTests {
factory.addBeanPostProcessor(new RequiredAnnotationBeanPostProcessor());
factory.preInstantiateSingletons();
RequiredTestBean bean = (RequiredTestBean) factory.getBean("testBean");
assertEquals(24, bean.getAge());
assertEquals("Blue", bean.getFavouriteColour());
assertThat(bean.getAge()).isEqualTo(24);
assertThat(bean.getFavouriteColour()).isEqualTo("Blue");
}
@Test

View File

@ -35,8 +35,7 @@ import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.propertyeditors.CustomDateEditor;
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;
/**
* @author Juergen Hoeller
@ -71,9 +70,9 @@ public class CustomEditorConfigurerTests {
bf.registerBeanDefinition("tb2", bd2);
TestBean tb1 = (TestBean) bf.getBean("tb1");
assertEquals(df.parse("2.12.1975"), tb1.getDate());
assertThat(tb1.getDate()).isEqualTo(df.parse("2.12.1975"));
TestBean tb2 = (TestBean) bf.getBean("tb2");
assertEquals(df.parse("2.12.1975"), tb2.getSomeMap().get("myKey"));
assertThat(tb2.getSomeMap().get("myKey")).isEqualTo(df.parse("2.12.1975"));
}
@Test
@ -93,7 +92,7 @@ public class CustomEditorConfigurerTests {
TestBean tb = (TestBean) bf.getBean("tb");
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.GERMAN);
assertEquals(df.parse("2.12.1975"), tb.getDate());
assertThat(tb.getDate()).isEqualTo(df.parse("2.12.1975"));
}
@Test
@ -112,8 +111,8 @@ public class CustomEditorConfigurerTests {
bf.registerBeanDefinition("tb", bd);
TestBean tb = (TestBean) bf.getBean("tb");
assertTrue(tb.getStringArray() != null && tb.getStringArray().length == 1);
assertEquals("test", tb.getStringArray()[0]);
assertThat(tb.getStringArray() != null && tb.getStringArray().length == 1).isTrue();
assertThat(tb.getStringArray()[0]).isEqualTo("test");
}

View File

@ -23,9 +23,9 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
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.assertTrue;
import static org.mockito.Mockito.mock;
/**
@ -66,7 +66,8 @@ public class CustomScopeConfigurerTests {
CustomScopeConfigurer figurer = new CustomScopeConfigurer();
figurer.setScopes(scopes);
figurer.postProcessBeanFactory(factory);
assertTrue(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope);
boolean condition = factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope;
assertThat(condition).isTrue();
}
@Test
@ -76,7 +77,8 @@ public class CustomScopeConfigurerTests {
CustomScopeConfigurer figurer = new CustomScopeConfigurer();
figurer.setScopes(scopes);
figurer.postProcessBeanFactory(factory);
assertTrue(factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope);
boolean condition = factory.getRegisteredScope(FOO_SCOPE) instanceof NoOpScope;
assertThat(condition).isTrue();
}
@Test

View File

@ -21,7 +21,7 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Arjen Poutsma
@ -43,8 +43,8 @@ public class DeprecatedBeanWarnerTests {
DeprecatedBeanWarner warner = new MyDeprecatedBeanWarner();
warner.postProcessBeanFactory(beanFactory);
assertEquals(beanName, this.beanName);
assertEquals(def, this.beanDefinition);
assertThat(this.beanName).isEqualTo(beanName);
assertThat(this.beanDefinition).isEqualTo(def);
}

View File

@ -24,7 +24,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.tests.sample.beans.TestBean;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -41,7 +41,7 @@ public class FieldRetrievingFactoryBeanTests {
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
fr.setStaticField("java.sql.Connection.TRANSACTION_SERIALIZABLE");
fr.afterPropertiesSet();
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), fr.getObject());
assertThat(fr.getObject()).isEqualTo(new Integer(Connection.TRANSACTION_SERIALIZABLE));
}
@Test
@ -49,7 +49,7 @@ public class FieldRetrievingFactoryBeanTests {
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
fr.setStaticField(" java.sql.Connection.TRANSACTION_SERIALIZABLE ");
fr.afterPropertiesSet();
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), fr.getObject());
assertThat(fr.getObject()).isEqualTo(new Integer(Connection.TRANSACTION_SERIALIZABLE));
}
@Test
@ -58,7 +58,7 @@ public class FieldRetrievingFactoryBeanTests {
fr.setTargetClass(Connection.class);
fr.setTargetField("TRANSACTION_SERIALIZABLE");
fr.afterPropertiesSet();
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), fr.getObject());
assertThat(fr.getObject()).isEqualTo(new Integer(Connection.TRANSACTION_SERIALIZABLE));
}
@Test
@ -68,7 +68,7 @@ public class FieldRetrievingFactoryBeanTests {
fr.setTargetObject(target);
fr.setTargetField("publicField");
fr.afterPropertiesSet();
assertEquals(target.publicField, fr.getObject());
assertThat(fr.getObject()).isEqualTo(target.publicField);
}
@Test
@ -76,7 +76,7 @@ public class FieldRetrievingFactoryBeanTests {
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
fr.setBeanName("java.sql.Connection.TRANSACTION_SERIALIZABLE");
fr.afterPropertiesSet();
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), fr.getObject());
assertThat(fr.getObject()).isEqualTo(new Integer(Connection.TRANSACTION_SERIALIZABLE));
}
@Test
@ -117,7 +117,7 @@ public class FieldRetrievingFactoryBeanTests {
FieldRetrievingFactoryBean fr = new FieldRetrievingFactoryBean();
fr.setBeanName("org.springframework.tests.sample.beans.PackageLevelVisibleBean.CONSTANT");
fr.afterPropertiesSet();
assertEquals("Wuby", fr.getObject());
assertThat(fr.getObject()).isEqualTo("Wuby");
}
@Test
@ -127,8 +127,8 @@ public class FieldRetrievingFactoryBeanTests {
qualifiedResource(FieldRetrievingFactoryBeanTests.class, "context.xml"));
TestBean testBean = (TestBean) bf.getBean("testBean");
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[0]);
assertEquals(new Integer(Connection.TRANSACTION_SERIALIZABLE), testBean.getSomeIntegerArray()[1]);
assertThat(testBean.getSomeIntegerArray()[0]).isEqualTo(new Integer(Connection.TRANSACTION_SERIALIZABLE));
assertThat(testBean.getSomeIntegerArray()[1]).isEqualTo(new Integer(Connection.TRANSACTION_SERIALIZABLE));
}

View File

@ -26,12 +26,9 @@ import org.springframework.beans.propertyeditors.StringTrimmerEditor;
import org.springframework.beans.support.ArgumentConvertingMethodInvoker;
import org.springframework.util.MethodInvoker;
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.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
/**
* Unit tests for {@link MethodInvokingFactoryBean} and {@link MethodInvokingBean}.
@ -45,7 +42,6 @@ public class MethodInvokingFactoryBeanTests {
@Test
public void testParameterValidation() throws Exception {
String validationError = "improper validation of input properties";
// assert that only static OR non static are set, but not both or none
MethodInvokingFactoryBean mcfb = new MethodInvokingFactoryBean();
@ -102,14 +98,14 @@ public class MethodInvokingFactoryBeanTests {
mcfb.setTargetObject(tc1);
mcfb.setTargetMethod("method1");
mcfb.afterPropertiesSet();
assertTrue(int.class.equals(mcfb.getObjectType()));
assertThat(int.class.equals(mcfb.getObjectType())).isTrue();
mcfb = new MethodInvokingFactoryBean();
mcfb.setTargetClass(TestClass1.class);
mcfb.setTargetMethod("voidRetvalMethod");
mcfb.afterPropertiesSet();
Class<?> objType = mcfb.getObjectType();
assertSame(objType, void.class);
assertThat(void.class).isSameAs(objType);
// verify that we can call a method with args that are subtypes of the
// target method arg types
@ -139,9 +135,9 @@ public class MethodInvokingFactoryBeanTests {
mcfb.setTargetMethod("method1");
mcfb.afterPropertiesSet();
Integer i = (Integer) mcfb.getObject();
assertEquals(1, i.intValue());
assertThat(i.intValue()).isEqualTo(1);
i = (Integer) mcfb.getObject();
assertEquals(1, i.intValue());
assertThat(i.intValue()).isEqualTo(1);
// non-singleton, non-static
tc1 = new TestClass1();
@ -151,9 +147,9 @@ public class MethodInvokingFactoryBeanTests {
mcfb.setSingleton(false);
mcfb.afterPropertiesSet();
i = (Integer) mcfb.getObject();
assertEquals(1, i.intValue());
assertThat(i.intValue()).isEqualTo(1);
i = (Integer) mcfb.getObject();
assertEquals(2, i.intValue());
assertThat(i.intValue()).isEqualTo(2);
// singleton, static
TestClass1._staticField1 = 0;
@ -162,9 +158,9 @@ public class MethodInvokingFactoryBeanTests {
mcfb.setTargetMethod("staticMethod1");
mcfb.afterPropertiesSet();
i = (Integer) mcfb.getObject();
assertEquals(1, i.intValue());
assertThat(i.intValue()).isEqualTo(1);
i = (Integer) mcfb.getObject();
assertEquals(1, i.intValue());
assertThat(i.intValue()).isEqualTo(1);
// non-singleton, static
TestClass1._staticField1 = 0;
@ -173,16 +169,16 @@ public class MethodInvokingFactoryBeanTests {
mcfb.setSingleton(false);
mcfb.afterPropertiesSet();
i = (Integer) mcfb.getObject();
assertEquals(1, i.intValue());
assertThat(i.intValue()).isEqualTo(1);
i = (Integer) mcfb.getObject();
assertEquals(2, i.intValue());
assertThat(i.intValue()).isEqualTo(2);
// void return value
mcfb = new MethodInvokingFactoryBean();
mcfb.setTargetClass(TestClass1.class);
mcfb.setTargetMethod("voidRetvalMethod");
mcfb.afterPropertiesSet();
assertNull(mcfb.getObject());
assertThat(mcfb.getObject()).isNull();
// now see if we can match methods with arguments that have supertype arguments
mcfb = new MethodInvokingFactoryBean();
@ -216,7 +212,7 @@ public class MethodInvokingFactoryBeanTests {
mcfb.setTargetMethod("supertypes2");
mcfb.setArguments(new ArrayList<>(), new ArrayList<Object>(), "hello", "bogus");
mcfb.afterPropertiesSet();
assertEquals("hello", mcfb.getObject());
assertThat(mcfb.getObject()).isEqualTo("hello");
mcfb = new MethodInvokingFactoryBean();
mcfb.setTargetClass(TestClass1.class);

View File

@ -29,10 +29,8 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.util.SerializationTestUtils;
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.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
@ -69,7 +67,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
Date date1 = (Date) objectFactory.getObject();
Date date2 = (Date) objectFactory.getObject();
assertTrue(date1 != date2);
assertThat(date1 != date2).isTrue();
}
@Test
@ -82,7 +80,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
Date date1 = (Date) objectFactory.getObject();
Date date2 = (Date) objectFactory.getObject();
assertTrue(date1 != date2);
assertThat(date1 != date2).isTrue();
}
@Test
@ -92,7 +90,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
Date date1 = (Date) provider.get();
Date date2 = (Date) provider.get();
assertTrue(date1 != date2);
assertThat(date1 != date2).isTrue();
}
@Test
@ -105,7 +103,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
Date date1 = (Date) provider.get();
Date date2 = (Date) provider.get();
assertTrue(date1 != date2);
assertThat(date1 != date2).isTrue();
}
@Test
@ -122,7 +120,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
factory.afterPropertiesSet();
ObjectFactory<?> objectFactory = factory.getObject();
Object actualSingleton = objectFactory.getObject();
assertSame(expectedSingleton, actualSingleton);
assertThat(actualSingleton).isSameAs(expectedSingleton);
}
@Test
@ -152,8 +150,7 @@ public class ObjectFactoryCreatingFactoryBeanTests {
@Test
public void testEnsureOFBFBReportsThatItActuallyCreatesObjectFactoryInstances() {
assertEquals("Must be reporting that it creates ObjectFactory instances (as per class contract).",
ObjectFactory.class, new ObjectFactoryCreatingFactoryBean().getObjectType());
assertThat(new ObjectFactoryCreatingFactoryBean().getObjectType()).as("Must be reporting that it creates ObjectFactory instances (as per class contract).").isEqualTo(ObjectFactory.class);
}

View File

@ -22,8 +22,7 @@ import org.junit.Test;
import org.springframework.core.io.Resource;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -45,7 +44,7 @@ public class PropertiesFactoryBeanTests {
pfb.setLocation(TEST_PROPS);
pfb.afterPropertiesSet();
Properties props = pfb.getObject();
assertEquals("99", props.getProperty("tb.array[0].age"));
assertThat(props.getProperty("tb.array[0].age")).isEqualTo("99");
}
@Test
@ -54,7 +53,7 @@ public class PropertiesFactoryBeanTests {
pfb.setLocation(TEST_PROPS_XML);
pfb.afterPropertiesSet();
Properties props = pfb.getObject();
assertEquals("99", props.getProperty("tb.array[0].age"));
assertThat(props.getProperty("tb.array[0].age")).isEqualTo("99");
}
@Test
@ -65,7 +64,7 @@ public class PropertiesFactoryBeanTests {
pfb.setProperties(localProps);
pfb.afterPropertiesSet();
Properties props = pfb.getObject();
assertEquals("value2", props.getProperty("key2"));
assertThat(props.getProperty("key2")).isEqualTo("value2");
}
@Test
@ -78,8 +77,8 @@ public class PropertiesFactoryBeanTests {
pfb.setProperties(localProps);
pfb.afterPropertiesSet();
Properties props = pfb.getObject();
assertEquals("99", props.getProperty("tb.array[0].age"));
assertEquals("value2", props.getProperty("key2"));
assertThat(props.getProperty("tb.array[0].age")).isEqualTo("99");
assertThat(props.getProperty("key2")).isEqualTo("value2");
}
@Test
@ -103,12 +102,12 @@ public class PropertiesFactoryBeanTests {
pfb.afterPropertiesSet();
Properties props = pfb.getObject();
assertEquals("99", props.getProperty("tb.array[0].age"));
assertEquals("value2", props.getProperty("key2"));
assertEquals("framework", props.getProperty("spring"));
assertEquals("Mattingly", props.getProperty("Don"));
assertEquals("man", props.getProperty("spider"));
assertEquals("man", props.getProperty("bat"));
assertThat(props.getProperty("tb.array[0].age")).isEqualTo("99");
assertThat(props.getProperty("key2")).isEqualTo("value2");
assertThat(props.getProperty("spring")).isEqualTo("framework");
assertThat(props.getProperty("Don")).isEqualTo("Mattingly");
assertThat(props.getProperty("spider")).isEqualTo("man");
assertThat(props.getProperty("bat")).isEqualTo("man");
}
@Test
@ -122,8 +121,8 @@ public class PropertiesFactoryBeanTests {
pfb.setLocalOverride(true);
pfb.afterPropertiesSet();
Properties props = pfb.getObject();
assertEquals("0", props.getProperty("tb.array[0].age"));
assertEquals("value2", props.getProperty("key2"));
assertThat(props.getProperty("tb.array[0].age")).isEqualTo("0");
assertThat(props.getProperty("key2")).isEqualTo("value2");
}
@Test
@ -136,12 +135,12 @@ public class PropertiesFactoryBeanTests {
pfb.setProperties(localProps);
pfb.afterPropertiesSet();
Properties props = pfb.getObject();
assertEquals("99", props.getProperty("tb.array[0].age"));
assertEquals("value2", props.getProperty("key2"));
assertThat(props.getProperty("tb.array[0].age")).isEqualTo("99");
assertThat(props.getProperty("key2")).isEqualTo("value2");
Properties newProps = pfb.getObject();
assertTrue(props != newProps);
assertEquals("99", newProps.getProperty("tb.array[0].age"));
assertEquals("value2", newProps.getProperty("key2"));
assertThat(props != newProps).isTrue();
assertThat(newProps.getProperty("tb.array[0].age")).isEqualTo("99");
assertThat(newProps.getProperty("key2")).isEqualTo("value2");
}
}

View File

@ -24,10 +24,7 @@ import org.springframework.core.io.Resource;
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.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -46,43 +43,47 @@ public class PropertyPathFactoryBeanTests {
public void testPropertyPathFactoryBeanWithSingletonResult() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertEquals(new Integer(12), xbf.getBean("propertyPath1"));
assertEquals(new Integer(11), xbf.getBean("propertyPath2"));
assertEquals(new Integer(10), xbf.getBean("tb.age"));
assertEquals(ITestBean.class, xbf.getType("otb.spouse"));
assertThat(xbf.getBean("propertyPath1")).isEqualTo(new Integer(12));
assertThat(xbf.getBean("propertyPath2")).isEqualTo(new Integer(11));
assertThat(xbf.getBean("tb.age")).isEqualTo(new Integer(10));
assertThat(xbf.getType("otb.spouse")).isEqualTo(ITestBean.class);
Object result1 = xbf.getBean("otb.spouse");
Object result2 = xbf.getBean("otb.spouse");
assertTrue(result1 instanceof TestBean);
assertTrue(result1 == result2);
assertEquals(99, ((TestBean) result1).getAge());
boolean condition = result1 instanceof TestBean;
assertThat(condition).isTrue();
assertThat(result1 == result2).isTrue();
assertThat(((TestBean) result1).getAge()).isEqualTo(99);
}
@Test
public void testPropertyPathFactoryBeanWithPrototypeResult() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertNull(xbf.getType("tb.spouse"));
assertEquals(TestBean.class, xbf.getType("propertyPath3"));
assertThat(xbf.getType("tb.spouse")).isNull();
assertThat(xbf.getType("propertyPath3")).isEqualTo(TestBean.class);
Object result1 = xbf.getBean("tb.spouse");
Object result2 = xbf.getBean("propertyPath3");
Object result3 = xbf.getBean("propertyPath3");
assertTrue(result1 instanceof TestBean);
assertTrue(result2 instanceof TestBean);
assertTrue(result3 instanceof TestBean);
assertEquals(11, ((TestBean) result1).getAge());
assertEquals(11, ((TestBean) result2).getAge());
assertEquals(11, ((TestBean) result3).getAge());
assertTrue(result1 != result2);
assertTrue(result1 != result3);
assertTrue(result2 != result3);
boolean condition2 = result1 instanceof TestBean;
assertThat(condition2).isTrue();
boolean condition1 = result2 instanceof TestBean;
assertThat(condition1).isTrue();
boolean condition = result3 instanceof TestBean;
assertThat(condition).isTrue();
assertThat(((TestBean) result1).getAge()).isEqualTo(11);
assertThat(((TestBean) result2).getAge()).isEqualTo(11);
assertThat(((TestBean) result3).getAge()).isEqualTo(11);
assertThat(result1 != result2).isTrue();
assertThat(result1 != result3).isTrue();
assertThat(result2 != result3).isTrue();
}
@Test
public void testPropertyPathFactoryBeanWithNullResult() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertNull(xbf.getType("tb.spouse.spouse"));
assertEquals("null", xbf.getBean("tb.spouse.spouse").toString());
assertThat(xbf.getType("tb.spouse.spouse")).isNull();
assertThat(xbf.getBean("tb.spouse.spouse").toString()).isEqualTo("null");
}
@Test
@ -91,23 +92,24 @@ public class PropertyPathFactoryBeanTests {
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
TestBean spouse = (TestBean) xbf.getBean("otb.spouse");
TestBean tbWithInner = (TestBean) xbf.getBean("tbWithInner");
assertSame(spouse, tbWithInner.getSpouse());
assertTrue(!tbWithInner.getFriends().isEmpty());
assertSame(spouse, tbWithInner.getFriends().iterator().next());
assertThat(tbWithInner.getSpouse()).isSameAs(spouse);
boolean condition = !tbWithInner.getFriends().isEmpty();
assertThat(condition).isTrue();
assertThat(tbWithInner.getFriends().iterator().next()).isSameAs(spouse);
}
@Test
public void testPropertyPathFactoryBeanAsNullReference() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertNull(xbf.getBean("tbWithNullReference", TestBean.class).getSpouse());
assertThat(xbf.getBean("tbWithNullReference", TestBean.class).getSpouse()).isNull();
}
@Test
public void testPropertyPathFactoryBeanAsInnerNull() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertNull(xbf.getBean("tbWithInnerNull", TestBean.class).getSpouse());
assertThat(xbf.getBean("tbWithInnerNull", TestBean.class).getSpouse()).isNull();
}
}

View File

@ -44,12 +44,8 @@ import org.springframework.tests.sample.beans.IndexedTestBean;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.StringUtils;
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.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
@ -113,10 +109,10 @@ public class PropertyResourceConfigurerTests {
TestBean tb1 = (TestBean) factory.getBean("tb1");
TestBean tb2 = (TestBean) factory.getBean("tb2");
assertEquals(99, tb1.getAge());
assertEquals(99, tb2.getAge());
assertEquals(null, tb1.getName());
assertEquals("test", tb2.getName());
assertThat(tb1.getAge()).isEqualTo(99);
assertThat(tb2.getAge()).isEqualTo(99);
assertThat(tb1.getName()).isEqualTo(null);
assertThat(tb2.getName()).isEqualTo("test");
}
@Test
@ -133,8 +129,8 @@ public class PropertyResourceConfigurerTests {
poc.postProcessBeanFactory(factory);
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
assertEquals(99, tb.getArray()[0].getAge());
assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
assertThat(tb.getArray()[0].getAge()).isEqualTo(99);
assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("test");
}
@Test
@ -152,8 +148,8 @@ public class PropertyResourceConfigurerTests {
poc.postProcessBeanFactory(factory);
IndexedTestBean tb = (IndexedTestBean) factory.getBean("my.tb");
assertEquals(99, tb.getArray()[0].getAge());
assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
assertThat(tb.getArray()[0].getAge()).isEqualTo(99);
assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("test");
}
@Test
@ -170,8 +166,8 @@ public class PropertyResourceConfigurerTests {
poc.postProcessBeanFactory(factory);
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
assertEquals("99", tb.getMap().get("key1"));
assertEquals("test", tb.getMap().get("key2.ext"));
assertThat(tb.getMap().get("key1")).isEqualTo("99");
assertThat(tb.getMap().get("key2.ext")).isEqualTo("test");
}
@Test
@ -187,7 +183,7 @@ public class PropertyResourceConfigurerTests {
poc.postProcessBeanFactory(factory);
PropertiesHolder tb = (PropertiesHolder) factory.getBean("tb");
assertEquals("true", tb.getHeldProperties().getProperty("mail.smtp.auth"));
assertThat(tb.getHeldProperties().getProperty("mail.smtp.auth")).isEqualTo("true");
}
@Test
@ -200,8 +196,8 @@ public class PropertyResourceConfigurerTests {
poc.postProcessBeanFactory(factory);
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
assertEquals(99, tb.getArray()[0].getAge());
assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
assertThat(tb.getArray()[0].getAge()).isEqualTo(99);
assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("test");
}
@Test
@ -215,8 +211,8 @@ public class PropertyResourceConfigurerTests {
poc.postProcessBeanFactory(factory);
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
assertEquals(99, tb.getArray()[0].getAge());
assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
assertThat(tb.getArray()[0].getAge()).isEqualTo(99);
assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("test");
}
@Test
@ -229,8 +225,8 @@ public class PropertyResourceConfigurerTests {
poc.postProcessBeanFactory(factory);
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
assertEquals(99, tb.getArray()[0].getAge());
assertEquals("test", ((TestBean) tb.getList().get(1)).getName());
assertThat(tb.getArray()[0].getAge()).isEqualTo(99);
assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("test");
}
@Test
@ -246,8 +242,8 @@ public class PropertyResourceConfigurerTests {
bfpp.postProcessBeanFactory(factory);
IndexedTestBean tb = (IndexedTestBean) factory.getBean("tb");
assertEquals("X99", tb.getArray()[0].getName());
assertEquals("Xtest", ((TestBean) tb.getList().get(1)).getName());
assertThat(tb.getArray()[0].getName()).isEqualTo("X99");
assertThat(((TestBean) tb.getList().get(1)).getName()).isEqualTo("Xtest");
}
@Test
@ -265,7 +261,7 @@ public class PropertyResourceConfigurerTests {
props.setProperty("tb3.name", "test");
poc.setProperties(props);
poc.postProcessBeanFactory(factory);
assertEquals("test", factory.getBean("tb2", TestBean.class).getName());
assertThat(factory.getBean("tb2", TestBean.class).getName()).isEqualTo("test");
}
{
PropertyOverrideConfigurer poc = new PropertyOverrideConfigurer();
@ -280,7 +276,7 @@ public class PropertyResourceConfigurerTests {
}
catch (BeanInitializationException ex) {
// prove that the processor chokes on the invalid key
assertTrue(ex.getMessage().toLowerCase().contains("argh"));
assertThat(ex.getMessage().toLowerCase().contains("argh")).isTrue();
}
}
}
@ -312,10 +308,10 @@ public class PropertyResourceConfigurerTests {
TestBean tb1 = (TestBean) factory.getBean("tb1");
TestBean tb2 = (TestBean) factory.getBean("tb2");
assertEquals(99, tb1.getAge());
assertEquals(99, tb2.getAge());
assertEquals(null, tb1.getName());
assertEquals("test", tb2.getName());
assertThat(tb1.getAge()).isEqualTo(99);
assertThat(tb2.getAge()).isEqualTo(99);
assertThat(tb1.getName()).isEqualTo(null);
assertThat(tb2.getName()).isEqualTo("test");
}
@Test
@ -402,36 +398,36 @@ public class PropertyResourceConfigurerTests {
TestBean tb1 = (TestBean) factory.getBean("tb1");
TestBean tb2 = (TestBean) factory.getBean("tb2");
assertEquals(98, tb1.getAge());
assertEquals(98, tb2.getAge());
assertEquals("namemyvarmyvar${", tb1.getName());
assertEquals("myvarname98", tb2.getName());
assertEquals(tb2, tb1.getSpouse());
assertEquals(1, tb1.getSomeMap().size());
assertEquals("myValue", tb1.getSomeMap().get("myKey"));
assertEquals(2, tb2.getStringArray().length);
assertEquals(System.getProperty("os.name"), tb2.getStringArray()[0]);
assertEquals("98", tb2.getStringArray()[1]);
assertEquals(2, tb2.getFriends().size());
assertEquals("na98me", tb2.getFriends().iterator().next());
assertEquals(tb2, tb2.getFriends().toArray()[1]);
assertEquals(3, tb2.getSomeSet().size());
assertTrue(tb2.getSomeSet().contains("na98me"));
assertTrue(tb2.getSomeSet().contains(tb2));
assertTrue(tb2.getSomeSet().contains(new Integer(98)));
assertEquals(6, tb2.getSomeMap().size());
assertEquals("98", tb2.getSomeMap().get("key98"));
assertEquals(tb2, tb2.getSomeMap().get("key98ref"));
assertEquals(tb2, tb2.getSomeMap().get("key1"));
assertEquals("98name", tb2.getSomeMap().get("key2"));
assertThat(tb1.getAge()).isEqualTo(98);
assertThat(tb2.getAge()).isEqualTo(98);
assertThat(tb1.getName()).isEqualTo("namemyvarmyvar${");
assertThat(tb2.getName()).isEqualTo("myvarname98");
assertThat(tb1.getSpouse()).isEqualTo(tb2);
assertThat(tb1.getSomeMap().size()).isEqualTo(1);
assertThat(tb1.getSomeMap().get("myKey")).isEqualTo("myValue");
assertThat(tb2.getStringArray().length).isEqualTo(2);
assertThat(tb2.getStringArray()[0]).isEqualTo(System.getProperty("os.name"));
assertThat(tb2.getStringArray()[1]).isEqualTo("98");
assertThat(tb2.getFriends().size()).isEqualTo(2);
assertThat(tb2.getFriends().iterator().next()).isEqualTo("na98me");
assertThat(tb2.getFriends().toArray()[1]).isEqualTo(tb2);
assertThat(tb2.getSomeSet().size()).isEqualTo(3);
assertThat(tb2.getSomeSet().contains("na98me")).isTrue();
assertThat(tb2.getSomeSet().contains(tb2)).isTrue();
assertThat(tb2.getSomeSet().contains(new Integer(98))).isTrue();
assertThat(tb2.getSomeMap().size()).isEqualTo(6);
assertThat(tb2.getSomeMap().get("key98")).isEqualTo("98");
assertThat(tb2.getSomeMap().get("key98ref")).isEqualTo(tb2);
assertThat(tb2.getSomeMap().get("key1")).isEqualTo(tb2);
assertThat(tb2.getSomeMap().get("key2")).isEqualTo("98name");
TestBean inner1 = (TestBean) tb2.getSomeMap().get("key3");
TestBean inner2 = (TestBean) tb2.getSomeMap().get("mykey4");
assertEquals(0, inner1.getAge());
assertEquals(null, inner1.getName());
assertEquals(System.getProperty("os.name"), inner1.getCountry());
assertEquals(98, inner2.getAge());
assertEquals("namemyvarmyvar${", inner2.getName());
assertEquals(System.getProperty("os.name"), inner2.getCountry());
assertThat(inner1.getAge()).isEqualTo(0);
assertThat(inner1.getName()).isEqualTo(null);
assertThat(inner1.getCountry()).isEqualTo(System.getProperty("os.name"));
assertThat(inner2.getAge()).isEqualTo(98);
assertThat(inner2.getName()).isEqualTo("namemyvarmyvar${");
assertThat(inner2.getCountry()).isEqualTo(System.getProperty("os.name"));
}
@Test
@ -443,7 +439,7 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals(System.getProperty("os.name"), tb.getCountry());
assertThat(tb.getCountry()).isEqualTo(System.getProperty("os.name"));
}
@Test
@ -458,7 +454,7 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals("myos", tb.getCountry());
assertThat(tb.getCountry()).isEqualTo("myos");
}
@Test
@ -474,7 +470,7 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals(System.getProperty("os.name"), tb.getCountry());
assertThat(tb.getCountry()).isEqualTo(System.getProperty("os.name"));
}
@Test
@ -508,7 +504,7 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals("${ref}", tb.getName());
assertThat(tb.getName()).isEqualTo("${ref}");
}
@Test
@ -521,7 +517,7 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertNull(tb.getName());
assertThat(tb.getName()).isNull();
}
@Test
@ -537,7 +533,7 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertNull(tb.getName());
assertThat(tb.getName()).isNull();
}
@Test
@ -553,7 +549,7 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals("myname", tb.getName());
assertThat(tb.getName()).isEqualTo("myname");
}
@Test
@ -569,7 +565,7 @@ public class PropertyResourceConfigurerTests {
TestBean tb = (TestBean) factory.getBean("tb");
TestBean tb2 = (TestBean) factory.getBean("tb2");
assertSame(tb, tb2);
assertThat(tb2).isSameAs(tb);
}
@Test
@ -584,8 +580,8 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertNotNull(tb);
assertEquals(0, factory.getAliases("tb").length);
assertThat(tb).isNotNull();
assertThat(factory.getAliases("tb").length).isEqualTo(0);
}
@Test
@ -617,7 +613,7 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals("mytest", tb.getTouchy());
assertThat(tb.getTouchy()).isEqualTo("mytest");
}
@Test
@ -629,7 +625,7 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals("mytest", tb.getTouchy());
assertThat(tb.getTouchy()).isEqualTo("mytest");
}
@Test
@ -649,11 +645,11 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals("mytest", tb.getTouchy());
assertThat(tb.getTouchy()).isEqualTo("mytest");
tb = (TestBean) factory.getBean("alias");
assertEquals("mytest", tb.getTouchy());
assertThat(tb.getTouchy()).isEqualTo("mytest");
tb = (TestBean) factory.getBean("alias2");
assertEquals("mytest", tb.getTouchy());
assertThat(tb.getTouchy()).isEqualTo("mytest");
}
@Test
@ -675,9 +671,9 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals("myNameValue", tb.getName());
assertEquals(99, tb.getAge());
assertEquals("myOtherTouchyValue", tb.getTouchy());
assertThat(tb.getName()).isEqualTo("myNameValue");
assertThat(tb.getAge()).isEqualTo(99);
assertThat(tb.getTouchy()).isEqualTo("myOtherTouchyValue");
Preferences.userRoot().remove("myTouchy");
Preferences.systemRoot().remove("myTouchy");
Preferences.systemRoot().remove("myName");
@ -704,9 +700,9 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals("myNameValue", tb.getName());
assertEquals(99, tb.getAge());
assertEquals("myOtherTouchyValue", tb.getTouchy());
assertThat(tb.getName()).isEqualTo("myNameValue");
assertThat(tb.getAge()).isEqualTo(99);
assertThat(tb.getTouchy()).isEqualTo("myOtherTouchyValue");
Preferences.userRoot().node("myUserPath").remove("myTouchy");
Preferences.systemRoot().node("mySystemPath").remove("myTouchy");
Preferences.systemRoot().node("mySystemPath").remove("myName");
@ -733,9 +729,9 @@ public class PropertyResourceConfigurerTests {
ppc.postProcessBeanFactory(factory);
TestBean tb = (TestBean) factory.getBean("tb");
assertEquals("myNameValue", tb.getName());
assertEquals(99, tb.getAge());
assertEquals("myOtherTouchyValue", tb.getTouchy());
assertThat(tb.getName()).isEqualTo("myNameValue");
assertThat(tb.getAge()).isEqualTo(99);
assertThat(tb.getTouchy()).isEqualTo("myOtherTouchyValue");
Preferences.userRoot().node("myUserPath/myotherpath").remove("myTouchy");
Preferences.systemRoot().node("mySystemPath/myotherpath").remove("myTouchy");
Preferences.systemRoot().node("mySystemPath/mypath").remove("myName");

View File

@ -27,12 +27,9 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.core.NestedCheckedException;
import org.springframework.core.NestedRuntimeException;
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.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;
@ -62,7 +59,7 @@ public class ServiceLocatorFactoryBeanTests {
TestServiceLocator factory = (TestServiceLocator) bf.getBean("factory");
TestService testService = factory.getTestService();
assertNotNull(testService);
assertThat(testService).isNotNull();
}
@Test
@ -161,14 +158,14 @@ public class ServiceLocatorFactoryBeanTests {
TestService testBean2 = factory.getTestService("testService");
TestService testBean3 = factory.getTestService(1);
TestService testBean4 = factory.someFactoryMethod();
assertNotSame(testBean1, testBean2);
assertNotSame(testBean1, testBean3);
assertNotSame(testBean1, testBean4);
assertNotSame(testBean2, testBean3);
assertNotSame(testBean2, testBean4);
assertNotSame(testBean3, testBean4);
assertThat(testBean2).isNotSameAs(testBean1);
assertThat(testBean3).isNotSameAs(testBean1);
assertThat(testBean4).isNotSameAs(testBean1);
assertThat(testBean3).isNotSameAs(testBean2);
assertThat(testBean4).isNotSameAs(testBean2);
assertThat(testBean4).isNotSameAs(testBean3);
assertTrue(factory.toString().contains("TestServiceLocator3"));
assertThat(factory.toString().contains("TestServiceLocator3")).isTrue();
}
@Ignore @Test // worked when using an ApplicationContext (see commented), fails when using BeanFactory
@ -195,16 +192,20 @@ public class ServiceLocatorFactoryBeanTests {
TestService testBean2 = factory.getTestService("testService1");
TestService testBean3 = factory.getTestService(1);
TestService testBean4 = factory.getTestService(2);
assertNotSame(testBean1, testBean2);
assertNotSame(testBean1, testBean3);
assertNotSame(testBean1, testBean4);
assertNotSame(testBean2, testBean3);
assertNotSame(testBean2, testBean4);
assertNotSame(testBean3, testBean4);
assertFalse(testBean1 instanceof ExtendedTestService);
assertFalse(testBean2 instanceof ExtendedTestService);
assertFalse(testBean3 instanceof ExtendedTestService);
assertTrue(testBean4 instanceof ExtendedTestService);
assertThat(testBean2).isNotSameAs(testBean1);
assertThat(testBean3).isNotSameAs(testBean1);
assertThat(testBean4).isNotSameAs(testBean1);
assertThat(testBean3).isNotSameAs(testBean2);
assertThat(testBean4).isNotSameAs(testBean2);
assertThat(testBean4).isNotSameAs(testBean3);
boolean condition3 = testBean1 instanceof ExtendedTestService;
assertThat(condition3).isFalse();
boolean condition2 = testBean2 instanceof ExtendedTestService;
assertThat(condition2).isFalse();
boolean condition1 = testBean3 instanceof ExtendedTestService;
assertThat(condition1).isFalse();
boolean condition = testBean4 instanceof ExtendedTestService;
assertThat(condition).isTrue();
}
@Test

View File

@ -27,9 +27,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.tests.sample.beans.TestBean;
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;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -65,9 +63,9 @@ public class SimpleScopeTests {
beanFactory.registerScope("myScope", scope);
String[] scopeNames = beanFactory.getRegisteredScopeNames();
assertEquals(1, scopeNames.length);
assertEquals("myScope", scopeNames[0]);
assertSame(scope, beanFactory.getRegisteredScope("myScope"));
assertThat(scopeNames.length).isEqualTo(1);
assertThat(scopeNames[0]).isEqualTo("myScope");
assertThat(beanFactory.getRegisteredScope("myScope")).isSameAs(scope);
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
qualifiedResource(SimpleScopeTests.class, "context.xml"));
@ -78,9 +76,9 @@ public class SimpleScopeTests {
public void testCanGetScopedObject() {
TestBean tb1 = (TestBean) beanFactory.getBean("usesScope");
TestBean tb2 = (TestBean) beanFactory.getBean("usesScope");
assertNotSame(tb1, tb2);
assertThat(tb2).isNotSameAs(tb1);
TestBean tb3 = (TestBean) beanFactory.getBean("usesScope");
assertSame(tb3, tb1);
assertThat(tb1).isSameAs(tb3);
}
}

View File

@ -28,10 +28,9 @@ import org.springframework.core.io.AbstractResource;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.FileSystemResource;
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.assertTrue;
/**
* Tests for {@link YamlMapFactoryBean}.
@ -48,7 +47,7 @@ public class YamlMapFactoryBeanTests {
public void testSetIgnoreResourceNotFound() {
this.factory.setResolutionMethod(YamlMapFactoryBean.ResolutionMethod.OVERRIDE_AND_IGNORE);
this.factory.setResources(new FileSystemResource("non-exsitent-file.yml"));
assertEquals(0, this.factory.getObject().size());
assertThat(this.factory.getObject().size()).isEqualTo(0);
}
@Test
@ -62,7 +61,7 @@ public class YamlMapFactoryBeanTests {
@Test
public void testGetObject() {
this.factory.setResources(new ByteArrayResource("foo: bar".getBytes()));
assertEquals(1, this.factory.getObject().size());
assertThat(this.factory.getObject().size()).isEqualTo(1);
}
@SuppressWarnings("unchecked")
@ -71,8 +70,8 @@ public class YamlMapFactoryBeanTests {
this.factory.setResources(new ByteArrayResource("foo:\n bar: spam".getBytes()),
new ByteArrayResource("foo:\n spam: bar".getBytes()));
assertEquals(1, this.factory.getObject().size());
assertEquals(2, ((Map<String, Object>) this.factory.getObject().get("foo")).size());
assertThat(this.factory.getObject().size()).isEqualTo(1);
assertThat(((Map<String, Object>) this.factory.getObject().get("foo")).size()).isEqualTo(2);
}
@Test
@ -89,7 +88,7 @@ public class YamlMapFactoryBeanTests {
}
}, new ByteArrayResource("foo:\n spam: bar".getBytes()));
assertEquals(1, this.factory.getObject().size());
assertThat(this.factory.getObject().size()).isEqualTo(1);
}
@Test
@ -97,14 +96,15 @@ public class YamlMapFactoryBeanTests {
this.factory.setResources(new ByteArrayResource("foo:\n ? key1.key2\n : value".getBytes()));
Map<String, Object> map = this.factory.getObject();
assertEquals(1, map.size());
assertTrue(map.containsKey("foo"));
assertThat(map.size()).isEqualTo(1);
assertThat(map.containsKey("foo")).isTrue();
Object object = map.get("foo");
assertTrue(object instanceof LinkedHashMap);
boolean condition = object instanceof LinkedHashMap;
assertThat(condition).isTrue();
@SuppressWarnings("unchecked")
Map<String, Object> sub = (Map<String, Object>) object;
assertTrue(sub.containsKey("key1.key2"));
assertEquals("value", sub.get("key1.key2"));
assertThat(sub.containsKey("key1.key2")).isTrue();
assertThat(sub.get("key1.key2")).isEqualTo("value");
}
@Test
@ -112,14 +112,15 @@ public class YamlMapFactoryBeanTests {
this.factory.setResources(new ByteArrayResource("foo:\n ? key1.key2\n : 3".getBytes()));
Map<String, Object> map = this.factory.getObject();
assertEquals(1, map.size());
assertTrue(map.containsKey("foo"));
assertThat(map.size()).isEqualTo(1);
assertThat(map.containsKey("foo")).isTrue();
Object object = map.get("foo");
assertTrue(object instanceof LinkedHashMap);
boolean condition = object instanceof LinkedHashMap;
assertThat(condition).isTrue();
@SuppressWarnings("unchecked")
Map<String, Object> sub = (Map<String, Object>) object;
assertEquals(1, sub.size());
assertEquals(Integer.valueOf(3), sub.get("key1.key2"));
assertThat(sub.size()).isEqualTo(1);
assertThat(sub.get("key1.key2")).isEqualTo(Integer.valueOf(3));
}
@Test

View File

@ -25,9 +25,8 @@ import org.yaml.snakeyaml.scanner.ScannerException;
import org.springframework.core.io.ByteArrayResource;
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;
/**
* Tests for {@link YamlProcessor}.
@ -44,22 +43,22 @@ public class YamlProcessorTests {
public void arrayConvertedToIndexedBeanReference() {
this.processor.setResources(new ByteArrayResource("foo: bar\nbar: [1,2,3]".getBytes()));
this.processor.process((properties, map) -> {
assertEquals(4, properties.size());
assertEquals("bar", properties.get("foo"));
assertEquals("bar", properties.getProperty("foo"));
assertEquals(1, properties.get("bar[0]"));
assertEquals("1", properties.getProperty("bar[0]"));
assertEquals(2, properties.get("bar[1]"));
assertEquals("2", properties.getProperty("bar[1]"));
assertEquals(3, properties.get("bar[2]"));
assertEquals("3", properties.getProperty("bar[2]"));
assertThat(properties.size()).isEqualTo(4);
assertThat(properties.get("foo")).isEqualTo("bar");
assertThat(properties.getProperty("foo")).isEqualTo("bar");
assertThat(properties.get("bar[0]")).isEqualTo(1);
assertThat(properties.getProperty("bar[0]")).isEqualTo("1");
assertThat(properties.get("bar[1]")).isEqualTo(2);
assertThat(properties.getProperty("bar[1]")).isEqualTo("2");
assertThat(properties.get("bar[2]")).isEqualTo(3);
assertThat(properties.getProperty("bar[2]")).isEqualTo("3");
});
}
@Test
public void testStringResource() {
this.processor.setResources(new ByteArrayResource("foo # a document that is a literal".getBytes()));
this.processor.process((properties, map) -> assertEquals("foo", map.get("document")));
this.processor.process((properties, map) -> assertThat(map.get("document")).isEqualTo("foo"));
}
@Test
@ -82,8 +81,8 @@ public class YamlProcessorTests {
public void mapConvertedToIndexedBeanReference() {
this.processor.setResources(new ByteArrayResource("foo: bar\nbar:\n spam: bucket".getBytes()));
this.processor.process((properties, map) -> {
assertEquals("bucket", properties.get("bar.spam"));
assertEquals(2, properties.size());
assertThat(properties.get("bar.spam")).isEqualTo("bucket");
assertThat(properties.size()).isEqualTo(2);
});
}
@ -91,8 +90,8 @@ public class YamlProcessorTests {
public void integerKeyBehaves() {
this.processor.setResources(new ByteArrayResource("foo: bar\n1: bar".getBytes()));
this.processor.process((properties, map) -> {
assertEquals("bar", properties.get("[1]"));
assertEquals(2, properties.size());
assertThat(properties.get("[1]")).isEqualTo("bar");
assertThat(properties.size()).isEqualTo(2);
});
}
@ -100,8 +99,8 @@ public class YamlProcessorTests {
public void integerDeepKeyBehaves() {
this.processor.setResources(new ByteArrayResource("foo:\n 1: bar".getBytes()));
this.processor.process((properties, map) -> {
assertEquals("bar", properties.get("foo[1]"));
assertEquals(1, properties.size());
assertThat(properties.get("foo[1]")).isEqualTo("bar");
assertThat(properties.size()).isEqualTo(1);
});
}
@ -110,14 +109,15 @@ public class YamlProcessorTests {
public void flattenedMapIsSameAsPropertiesButOrdered() {
this.processor.setResources(new ByteArrayResource("foo: bar\nbar:\n spam: bucket".getBytes()));
this.processor.process((properties, map) -> {
assertEquals("bucket", properties.get("bar.spam"));
assertEquals(2, properties.size());
assertThat(properties.get("bar.spam")).isEqualTo("bucket");
assertThat(properties.size()).isEqualTo(2);
Map<String, Object> flattenedMap = processor.getFlattenedMap(map);
assertEquals("bucket", flattenedMap.get("bar.spam"));
assertEquals(2, flattenedMap.size());
assertTrue(flattenedMap instanceof LinkedHashMap);
assertThat(flattenedMap.get("bar.spam")).isEqualTo("bucket");
assertThat(flattenedMap.size()).isEqualTo(2);
boolean condition = flattenedMap instanceof LinkedHashMap;
assertThat(condition).isTrue();
Map<String, Object> bar = (Map<String, Object>) map.get("bar");
assertEquals("bucket", bar.get("spam"));
assertThat(bar.get("spam")).isEqualTo("bucket");
});
}

View File

@ -26,8 +26,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
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;
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
/**
@ -56,10 +55,10 @@ public class CustomProblemReporterTests {
@Test
public void testErrorsAreCollated() {
this.reader.loadBeanDefinitions(qualifiedResource(CustomProblemReporterTests.class, "context.xml"));
assertEquals("Incorrect number of errors collated", 4, this.problemReporter.getErrors().length);
assertThat(this.problemReporter.getErrors().length).as("Incorrect number of errors collated").isEqualTo(4);
TestBean bean = (TestBean) this.beanFactory.getBean("validBean");
assertNotNull(bean);
assertThat(bean).isNotNull();
}

View File

@ -18,7 +18,7 @@ package org.springframework.beans.factory.parsing;
import org.junit.Test;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rick Evans
@ -30,13 +30,13 @@ public class NullSourceExtractorTests {
public void testPassThroughContract() throws Exception {
Object source = new Object();
Object extractedSource = new NullSourceExtractor().extractSource(source, null);
assertNull("The contract of NullSourceExtractor states that the extraction *always* return null", extractedSource);
assertThat(extractedSource).as("The contract of NullSourceExtractor states that the extraction *always* return null").isNull();
}
@Test
public void testPassThroughContractEvenWithNull() throws Exception {
Object extractedSource = new NullSourceExtractor().extractSource(null, null);
assertNull("The contract of NullSourceExtractor states that the extraction *always* return null", extractedSource);
assertThat(extractedSource).as("The contract of NullSourceExtractor states that the extraction *always* return null").isNull();
}
}

View File

@ -18,8 +18,7 @@ package org.springframework.beans.factory.parsing;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Rob Harrop
@ -34,9 +33,9 @@ public class ParseStateTests {
ParseState parseState = new ParseState();
parseState.push(entry);
assertEquals("Incorrect peek value.", entry, parseState.peek());
assertThat(parseState.peek()).as("Incorrect peek value.").isEqualTo(entry);
parseState.pop();
assertNull("Should get null on peek()", parseState.peek());
assertThat(parseState.peek()).as("Should get null on peek()").isNull();
}
@Test
@ -47,16 +46,16 @@ public class ParseStateTests {
ParseState parseState = new ParseState();
parseState.push(one);
assertEquals(one, parseState.peek());
assertThat(parseState.peek()).isEqualTo(one);
parseState.push(two);
assertEquals(two, parseState.peek());
assertThat(parseState.peek()).isEqualTo(two);
parseState.push(three);
assertEquals(three, parseState.peek());
assertThat(parseState.peek()).isEqualTo(three);
parseState.pop();
assertEquals(two, parseState.peek());
assertThat(parseState.peek()).isEqualTo(two);
parseState.pop();
assertEquals(one, parseState.peek());
assertThat(parseState.peek()).isEqualTo(one);
}
@Test
@ -68,7 +67,7 @@ public class ParseStateTests {
ParseState snapshot = original.snapshot();
original.push(new MockEntry());
assertEquals("Snapshot should not have been modified.", entry, snapshot.peek());
assertThat(snapshot.peek()).as("Snapshot should not have been modified.").isEqualTo(entry);
}

View File

@ -18,8 +18,7 @@ package org.springframework.beans.factory.parsing;
import org.junit.Test;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link PassThroughSourceExtractor}.
@ -33,15 +32,15 @@ public class PassThroughSourceExtractorTests {
public void testPassThroughContract() throws Exception {
Object source = new Object();
Object extractedSource = new PassThroughSourceExtractor().extractSource(source, null);
assertSame("The contract of PassThroughSourceExtractor states that the supplied " +
"source object *must* be returned as-is", source, extractedSource);
assertThat(extractedSource).as("The contract of PassThroughSourceExtractor states that the supplied " +
"source object *must* be returned as-is").isSameAs(source);
}
@Test
public void testPassThroughContractEvenWithNull() throws Exception {
Object extractedSource = new PassThroughSourceExtractor().extractSource(null, null);
assertNull("The contract of PassThroughSourceExtractor states that the supplied " +
"source object *must* be returned as-is (even if null)", extractedSource);
assertThat(extractedSource).as("The contract of PassThroughSourceExtractor states that the supplied " +
"source object *must* be returned as-is (even if null)").isNull();
}
}

View File

@ -25,7 +25,7 @@ import org.junit.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import static org.junit.Assert.assertTrue;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
/**
@ -43,7 +43,8 @@ public class ServiceLoaderTests {
bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());
bf.registerBeanDefinition("service", bd);
ServiceLoader<?> serviceLoader = (ServiceLoader<?>) bf.getBean("service");
assertTrue(serviceLoader.iterator().next() instanceof DocumentBuilderFactory);
boolean condition = serviceLoader.iterator().next() instanceof DocumentBuilderFactory;
assertThat(condition).isTrue();
}
@Test
@ -54,7 +55,8 @@ public class ServiceLoaderTests {
RootBeanDefinition bd = new RootBeanDefinition(ServiceFactoryBean.class);
bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());
bf.registerBeanDefinition("service", bd);
assertTrue(bf.getBean("service") instanceof DocumentBuilderFactory);
boolean condition = bf.getBean("service") instanceof DocumentBuilderFactory;
assertThat(condition).isTrue();
}
@Test
@ -66,7 +68,8 @@ public class ServiceLoaderTests {
bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());
bf.registerBeanDefinition("service", bd);
List<?> serviceList = (List<?>) bf.getBean("service");
assertTrue(serviceList.get(0) instanceof DocumentBuilderFactory);
boolean condition = serviceList.get(0) instanceof DocumentBuilderFactory;
assertThat(condition).isTrue();
}
}

View File

@ -24,7 +24,7 @@ import org.junit.Test;
import org.springframework.util.ReflectionUtils;
import static org.junit.Assert.assertEquals;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link AutowireUtils}.
@ -38,45 +38,36 @@ public class AutowireUtilsTests {
@Test
public void genericMethodReturnTypes() {
Method notParameterized = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterized");
assertEquals(String.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterized, new Object[0], getClass().getClassLoader()));
Object actual = AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterized, new Object[0], getClass().getClassLoader());
assertThat(actual).isEqualTo(String.class);
Method notParameterizedWithArguments = ReflectionUtils.findMethod(MyTypeWithMethods.class, "notParameterizedWithArguments", Integer.class, Boolean.class);
assertEquals(String.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterizedWithArguments, new Object[] {99, true}, getClass().getClassLoader()));
assertThat(AutowireUtils.resolveReturnTypeForFactoryMethod(notParameterizedWithArguments, new Object[]{99, true}, getClass().getClassLoader())).isEqualTo(String.class);
Method createProxy = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createProxy", Object.class);
assertEquals(String.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createProxy, new Object[] {"foo"}, getClass().getClassLoader()));
assertThat(AutowireUtils.resolveReturnTypeForFactoryMethod(createProxy, new Object[]{"foo"}, getClass().getClassLoader())).isEqualTo(String.class);
Method createNamedProxyWithDifferentTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy", String.class, Object.class);
assertEquals(Long.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDifferentTypes, new Object[] {"enigma", 99L}, getClass().getClassLoader()));
assertThat(AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDifferentTypes, new Object[]{"enigma", 99L}, getClass().getClassLoader())).isEqualTo(Long.class);
Method createNamedProxyWithDuplicateTypes = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedProxy", String.class, Object.class);
assertEquals(String.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDuplicateTypes, new Object[] {"enigma", "foo"}, getClass().getClassLoader()));
assertThat(AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedProxyWithDuplicateTypes, new Object[]{"enigma", "foo"}, getClass().getClassLoader())).isEqualTo(String.class);
Method createMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createMock", Class.class);
assertEquals(Runnable.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] {Runnable.class}, getClass().getClassLoader()));
assertEquals(Runnable.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[] {Runnable.class.getName()}, getClass().getClassLoader()));
assertThat(AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[]{Runnable.class}, getClass().getClassLoader())).isEqualTo(Runnable.class);
assertThat(AutowireUtils.resolveReturnTypeForFactoryMethod(createMock, new Object[]{Runnable.class.getName()}, getClass().getClassLoader())).isEqualTo(Runnable.class);
Method createNamedMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createNamedMock", String.class, Class.class);
assertEquals(Runnable.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedMock, new Object[] {"foo", Runnable.class}, getClass().getClassLoader()));
assertThat(AutowireUtils.resolveReturnTypeForFactoryMethod(createNamedMock, new Object[]{"foo", Runnable.class}, getClass().getClassLoader())).isEqualTo(Runnable.class);
Method createVMock = ReflectionUtils.findMethod(MyTypeWithMethods.class, "createVMock", Object.class, Class.class);
assertEquals(Runnable.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(createVMock, new Object[] {"foo", Runnable.class}, getClass().getClassLoader()));
assertThat(AutowireUtils.resolveReturnTypeForFactoryMethod(createVMock, new Object[]{"foo", Runnable.class}, getClass().getClassLoader())).isEqualTo(Runnable.class);
// Ideally we would expect String.class instead of Object.class, but
// resolveReturnTypeForFactoryMethod() does not currently support this form of
// look-up.
Method extractValueFrom = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractValueFrom", MyInterfaceType.class);
assertEquals(Object.class,
AutowireUtils.resolveReturnTypeForFactoryMethod(extractValueFrom, new Object[] {new MySimpleInterfaceType()}, getClass().getClassLoader()));
assertThat(AutowireUtils.resolveReturnTypeForFactoryMethod(extractValueFrom, new Object[]{new MySimpleInterfaceType()}, getClass().getClassLoader())).isEqualTo(Object.class);
// Ideally we would expect Boolean.class instead of Object.class, but this
// information is not available at run-time due to type erasure.
@ -84,7 +75,7 @@ public class AutowireUtilsTests {
map.put(0, false);
map.put(1, true);
Method extractMagicValue = ReflectionUtils.findMethod(MyTypeWithMethods.class, "extractMagicValue", Map.class);
assertEquals(Object.class, AutowireUtils.resolveReturnTypeForFactoryMethod(extractMagicValue, new Object[] {map}, getClass().getClassLoader()));
assertThat(AutowireUtils.resolveReturnTypeForFactoryMethod(extractMagicValue, new Object[]{map}, getClass().getClassLoader())).isEqualTo(Object.class);
}

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