Browse Source

moving unit tests from .testsuite -> .aop

pull/23217/head
Chris Beams 17 years ago
parent
commit
4b2a5a2383
  1. 20
      org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectMetadataTests.java
  2. 41
      org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java
  3. 48
      org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/MultiplyReturnValue.java
  4. 0
      org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/PerThisAspect.java

20
org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/annotation/AspectMetadataTests.java → org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectMetadataTests.java

@ -16,8 +16,9 @@ @@ -16,8 +16,9 @@
package org.springframework.aop.aspectj.annotation;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.aspectj.lang.reflect.PerClauseKind;
import org.junit.Test;
import org.springframework.aop.Pointcut;
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionAspect;
@ -25,23 +26,18 @@ import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryT @@ -25,23 +26,18 @@ import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryT
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.PerThisAspect;
/**
*
* @since 2.0
* @author Rod Johnson
*
* @author Chris Beams
*/
public class AspectMetadataTests extends TestCase {
public class AspectMetadataTests {
@Test(expected=IllegalArgumentException.class)
public void testNotAnAspect() {
try {
new AspectMetadata(String.class,"someBean");
fail();
}
catch (IllegalArgumentException ex) {
// Ok
}
new AspectMetadata(String.class,"someBean");
}
@Test
public void testSingletonAspect() {
AspectMetadata am = new AspectMetadata(ExceptionAspect.class,"someBean");
assertFalse(am.isPerThisOrPerTarget());
@ -49,6 +45,7 @@ public class AspectMetadataTests extends TestCase { @@ -49,6 +45,7 @@ public class AspectMetadataTests extends TestCase {
assertEquals(PerClauseKind.SINGLETON, am.getAjType().getPerClause().getKind());
}
@Test
public void testPerTargetAspect() {
AspectMetadata am = new AspectMetadata(PerTargetAspect.class,"someBean");
assertTrue(am.isPerThisOrPerTarget());
@ -56,6 +53,7 @@ public class AspectMetadataTests extends TestCase { @@ -56,6 +53,7 @@ public class AspectMetadataTests extends TestCase {
assertEquals(PerClauseKind.PERTARGET, am.getAjType().getPerClause().getKind());
}
@Test
public void testPerThisAspect() {
AspectMetadata am = new AspectMetadata(PerThisAspect.class,"someBean");
assertTrue(am.isPerThisOrPerTarget());

41
org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java → org.springframework.aop/src/test/java/org/springframework/aop/aspectj/annotation/AspectProxyFactoryTests.java

@ -16,27 +16,26 @@ @@ -16,27 +16,26 @@
package org.springframework.aop.aspectj.annotation;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.junit.Test;
import org.springframework.aop.aspectj.autoproxy.MultiplyReturnValue;
import org.springframework.aop.aspectj.autoproxy.PerThisAspect;
import org.springframework.test.AssertThrows;
/**
* @author Rob Harrop
* @author Juergen Hoeller
* @author Chris Beams
*/
public class AspectProxyFactoryTests extends TestCase {
public void testWithNonAspect() throws Exception {
new AssertThrows(IllegalArgumentException.class) {
public void test() throws Exception {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
proxyFactory.addAspect(TestBean.class);
}
}.runTest();
public class AspectProxyFactoryTests {
@Test(expected=IllegalArgumentException.class)
public void testWithNonAspect() {
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
proxyFactory.addAspect(TestBean.class);
}
@Test
public void testWithSimpleAspect() throws Exception {
TestBean bean = new TestBean();
bean.setAge(2);
@ -46,6 +45,7 @@ public class AspectProxyFactoryTests extends TestCase { @@ -46,6 +45,7 @@ public class AspectProxyFactoryTests extends TestCase {
assertEquals("Multiplication did not occur", bean.getAge() * 2, proxy.getAge());
}
@Test
public void testWithPerThisAspect() throws Exception {
TestBean bean1 = new TestBean();
TestBean bean2 = new TestBean();
@ -65,15 +65,13 @@ public class AspectProxyFactoryTests extends TestCase { @@ -65,15 +65,13 @@ public class AspectProxyFactoryTests extends TestCase {
assertEquals(2, proxy1.getAge());
}
@Test(expected=IllegalArgumentException.class)
public void testWithInstanceWithNonAspect() throws Exception {
new AssertThrows(IllegalArgumentException.class) {
public void test() throws Exception {
AspectJProxyFactory pf = new AspectJProxyFactory();
pf.addAspect(new TestBean());
}
}.runTest();
AspectJProxyFactory pf = new AspectJProxyFactory();
pf.addAspect(new TestBean());
}
@Test
public void testWithInstance() throws Exception {
MultiplyReturnValue aspect = new MultiplyReturnValue();
int multiple = 3;
@ -90,13 +88,10 @@ public class AspectProxyFactoryTests extends TestCase { @@ -90,13 +88,10 @@ public class AspectProxyFactoryTests extends TestCase {
assertEquals(target.getAge() * multiple, proxy.getAge());
}
@Test(expected=IllegalArgumentException.class)
public void testWithNonSingletonAspectInstance() throws Exception {
new AssertThrows(IllegalArgumentException.class) {
public void test() throws Exception {
AspectJProxyFactory pf = new AspectJProxyFactory();
pf.addAspect(new PerThisAspect());
}
}.runTest();
AspectJProxyFactory pf = new AspectJProxyFactory();
pf.addAspect(new PerThisAspect());
}

48
org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/MultiplyReturnValue.java

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
/*
* Copyright 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.aspectj.autoproxy;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
/**
* @author Rod Johnson
*/
@Aspect
public class MultiplyReturnValue {
private int multiple = 2;
public int invocations;
public void setMultiple(int multiple) {
this.multiple = multiple;
}
public int getMultiple() {
return this.multiple;
}
@Around("execution(int *.getAge())")
public Object doubleReturnValue(ProceedingJoinPoint pjp) throws Throwable {
++this.invocations;
int result = (Integer) pjp.proceed();
return result * this.multiple;
}
}

0
org.springframework.testsuite/src/test/java/org/springframework/aop/aspectj/autoproxy/PerThisAspect.java → org.springframework.aop/src/test/java/org/springframework/aop/aspectj/autoproxy/PerThisAspect.java

Loading…
Cancel
Save