From: Joakim O. <joa...@ag...> - 2007-01-31 06:40:02
|
If you hadn't mentioned coverlipse and I hadn't tried coverlipse myself I would never have thought about it. I'm happy it works now! /J On 1/30/07, Michael Nyika <ny...@ya...> wrote: > Hey what do you know? It works! It performed just as you said. I uninstalled > CoverClipse and installed EclEmma (havent used that just yet). I would never > have guessed the CoverClipse was the problem. Thank you very much for > helping out. > > I hope someone else can benefit from this too. Many thanks again. > > Joakim Ohlrogge <joa...@ag...> wrote: > 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 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() > > 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.(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 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. > > > > > > > > ________________________________ > We won't tell. Get more on shows you hate to love > (and love to hate): Yahoo! TV's Guilty Pleasures list. > > |