From: Joakim O. <joa...@ag...> - 2007-01-30 20:44:22
|
---------- Forwarded message ---------- From: Joakim Ohlrogge <joa...@ag...> Date: Jan 30, 2007 9:40 PM Subject: Re: [Rmock-developer] ClassCastException: Why is it occurring? To: Michael Nyika <ny...@ya...> 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 |