From: Joakim O. <joa...@ag...> - 2007-01-30 22:14:18
|
Oh come to think of it I actuially never got coverlipse to work with rMock. I think it has to do with some classloading issues with CGLIB and coverlipse (CGLIB uses a classloader to generate classes dynamically and I suspect coverlipse uses a classloader to instrument the code to be run). I started using eclemma instead: http://www.mountainminds.com/products/eclemma That works like charm. Try to run the tests without coverlipse and see if that helps. Let me know how it goes /Joakim Ohrogge On 1/30/07, Michael Nyika <ny...@ya...> wrote: > Ok, i understand, it is a little hard to tell: > > Here's the StackTrace: > ==================== > keepalive false > RemoteTestRunner: trying to connect:3363 > start send tree...done send tree - time(ms): 32 > java.lang.ClassCastException > at > com.esri.sln.ss.core.ctx.ApplicationContext$$EnhancerByCGLIB$$1e4df572.getEntityManager(<generated>) > at > test.gov.ct.event.servlet.rs.SelectAttributeByPointRSServletTest.testGetAttributeByPointWithThemeIdStringNotValid(SelectAttributeByPointRSServletTest.java:41) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native > Method) > at > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > at junit.framework.TestCase.runTest(TestCase.java:154) > at > com.agical.rmock.extension.junit.RMockTestCase.runBare(RMockTestCase.java:102) > at > junit.framework.TestResult$1.protect(TestResult.java:106) > at > junit.framework.TestResult.runProtected(TestResult.java:124) > at junit.framework.TestResult.run(TestResult.java:109) > at junit.framework.TestCase.run(TestCase.java:118) > at > org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128) > at > org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460) > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673) > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386) > at > org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196) > at > de.uka.ipd.coverage.plugin.remote.CoverageRemoteTestRunner.run(CoverageRemoteTestRunner.java:71) > at > de.uka.ipd.coverage.plugin.remote.CoverageRemoteTestRunner.<init>(CoverageRemoteTestRunner.java:37) > at > sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native > Method) > at > sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) > at > sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) > at > java.lang.reflect.Constructor.newInstance(Constructor.java:274) > at > de.uka.ipd.coverage.plugin.remote.CoverageRemoteTestRunner.main(CoverageRemoteTestRunner.java:48) > > ==================== > > **Dont worry about the RemoteTestRunner bit, that's output from CoverClipse > (code coverage plugin for eclipse) > > I do not have the source code for the methods in the ApplicationContext > class. It comes from a proprietary API. > > If the stacktrace isn't enough, would you at least suspect there are other > calls of a non-trivial nature inside the getEntityManager() method? Do you > think the results would be any different if I didn't mock out the interface, > but created my own EntityManager mock object with fake methods and tried > that out? > > See, RMock is great, but if I could just get past this, i'd be able to mock > and test anything. Wish it could be so. > > Joakim Ohlrogge <joa...@ag...> wrote: > 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 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() > > > > 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 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. > > > > > > > > ________________________________ > Need a quick answer? Get one in minutes from people who know. Ask your > question on Yahoo! Answers. > > |