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();
}