From: Joakim O. <joa...@ag...> - 2007-01-30 21:13:59
|
I would need to see the complete exception with stacktrace and the definition of the getEntityManager method to be able to help out further. I can't see anything obviously wrong with what you're doing with the information I have right now. I'm not aware of any bugs in this area that would cause this... On 1/30/07, Michael Nyika <ny...@ya...> wrote: > Thanks for replying Joakim: It seems I still have a problem, the exact same > error pops up (ClassCastException): > > Here's my exact setup in code: > ======================= > applicationContext = (ApplicationContext)intercept(ApplicationContext.class, > "applicationContext"); > > applicationContext.getEntityManager(); > EntityManager manager = (EntityManager)mock(EntityManager.class, > "mockManager"); > > modify().returnValue(manager); > startVerification(); > > > And the Error is still: > ================== > java.lang.ClassCastException > at > com.esri.sln.ss.core.ctx.ApplicationContext$$EnhancerByCGLIB$$1e4df572.getEntityManager(<generated>) > > Also note that EntityManager is an Interface, but that's no problem with the > way i've mocked it out. There's a ton of abstract methods i'd rather not > quickly implement from the interface, so i'd prefer to mock it out...... > > > > > Joakim Ohlrogge <joa...@ag...> wrote: > It took me a little while to spot the problem: > > > Here you are saying: > > > > > ctx.getEntityManager(); > > * expect that ctx.getEntityManager() is called > - once > - return null (or if EntityManager is an interface, a mocked entity manager) > > > modify().returnValue(is.instanceOf(EntityManager.class)); > > Here you are changing the recorded expectation to return an instance > of InstanceOfConstraint primed with EntityManager.class. This gives a > class cast exception since what you should be returning is an instance > of an EntityManager. > > What you want to do here to fix it is: > > EntityManager entityManager = new EntityManager(); // or a mock if you > prefer > modify().returnValue(entityManager); > > I hope this helps some. > Regards Joakim Ohlrogge > > > > ________________________________ > Need a quick answer? Get one in minutes from people who know. Ask your > question on Yahoo! Answers. > > |