1 4 package com.tctest.spring.aop; 5 6 import org.springframework.aop.framework.ProxyFactory; 7 8 import junit.framework.TestCase; 9 10 13 public class AopProxy_Test extends TestCase { 14 public AopProxy_Test(String name) { 15 super(name); 16 } 17 18 public static void testBeforeAdvice() { 19 MessageWriter target = new MessageWriter(); 20 ProxyFactory pf = new ProxyFactory(); 21 pf.addAdvice(new SimpleBeforeAdvice()); 22 pf.setTarget(target); 23 24 MessageWriter proxy = (MessageWriter) pf.getProxy(); 25 assertNotNull(proxy); 26 27 String msg = proxy.writeMessage(); 28 assertNotNull(msg); 29 assertEquals("World", msg); 30 } 31 32 public static void main(String [] args) { 33 junit.textui.TestRunner.run(suite()); 34 } 35 36 public static junit.framework.Test suite() { 37 return new junit.framework.TestSuite(AopProxy_Test.class); 38 } 39 } 40 | Popular Tags |