[jboss-user] [JBoss AOP] - Re: Using AOP to mock out dependecies for unit-test

stale.pedersen@jboss.org do-not-reply at jboss.com
Fri Mar 6 16:43:50 EST 2009


hi again. the problem is within the generated code and not in your pointcutdef. the PersistenceHelper constructor is "wrapped" in aop code when we instrument it, and that method will only accept an object of type PersistenceHelper. - not the interface. thats why it is throwing a classcastexception since it get a MockPersistenceHelper and not a PersistenceHelper.
atm there is no way around this, ill discuss with the team if this is something we should change, and ill let you know what we decide.

a solution for your problem would be to put the constructor in a method and just intercept that method. something like:public class AOPUnitTestManagerBean {
  |   
  |     private IPersistenceHelper helper;
  |     
  |     public AOPUnitTestManagerBean() {
  |         helper = init();
  |     }
  | 
  |     private IPersistenceHelper init() {
  |        return new PersistenceHelper(null);
  |     }
  |     
  |     public void createObject(Object o) {
  |         helper.create(o);
  |     }
  | }

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4215881#4215881

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4215881



More information about the jboss-user mailing list