1 16 17 package org.springframework.aop.framework; 18 19 import org.springframework.aop.TargetSource; 20 21 25 public class MockTargetSource implements TargetSource { 26 27 private Object target; 28 29 public int gets; 30 31 public int releases; 32 33 public void reset() { 34 this.target = null; 35 gets = releases = 0; 36 } 37 38 public void setTarget(Object target) { 39 this.target = target; 40 } 41 42 45 public Class getTargetClass() { 46 return target.getClass(); 47 } 48 49 52 public Object getTarget() throws Exception { 53 ++gets; 54 return target; 55 } 56 57 60 public void releaseTarget(Object pTarget) throws Exception { 61 if (pTarget != this.target) 62 throw new RuntimeException ("Released wrong target"); 63 ++releases; 64 } 65 66 70 public void verify() { 71 if (gets != releases) 72 throw new RuntimeException ("Expectation failed: " + gets + " gets and " + releases + " releases"); 73 } 74 75 78 public boolean isStatic() { 79 return false; 80 } 81 82 } 83 | Popular Tags |