You can subscribe to this list here.
2005 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(5) |
Dec
|
---|---|---|---|---|---|---|---|---|---|---|---|---|
2006 |
Jan
(17) |
Feb
(7) |
Mar
(2) |
Apr
|
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
(4) |
Oct
|
Nov
(6) |
Dec
(4) |
2007 |
Jan
(1) |
Feb
|
Mar
(10) |
Apr
(3) |
May
(4) |
Jun
(7) |
Jul
|
Aug
(5) |
Sep
|
Oct
|
Nov
|
Dec
(3) |
2008 |
Jan
|
Feb
|
Mar
(1) |
Apr
(3) |
May
(8) |
Jun
(7) |
Jul
(12) |
Aug
(3) |
Sep
|
Oct
|
Nov
|
Dec
|
2009 |
Jan
(3) |
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: David C. <dc...@al...> - 2007-04-23 14:00:36
|
When mocking a class that takes constructor arguments, I'd like to see mock(Class klass) not blow up but simply pass a default value (null, 0, false) for each argument. Normally, if I'm mocking a class, I don't care about them. The rare exception is the class that tries to use those arguments in the contructor, and in that case I have no choice and would fall back on the existing method. Likewise, just because I pass a set of constructor arguments, doesn't mean that I want to name the mock explicitly yet it seems that I'm forced to. Thanks David |
From: Daniel B. <dan...@gm...> - 2007-04-06 17:49:06
|
True. I tried to get it up last weekend, but the maven upload guys were a bit slow in the start and then they needed one more bundle from us. :-P I will generate that now and send it to them. Hopefully it will be up in the start of next week. Cheers Daniel On 4/6/07, David Corbin <dc...@al...> wrote: > Rmock 2.0 does not appear to be in the maven 2.0 repository. > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Rmock-users mailing list > Rmo...@li... > https://lists.sourceforge.net/lists/listinfo/rmock-users > -- __________________________ Dan...@Gm... |
From: David C. <dc...@al...> - 2007-04-06 14:48:40
|
Rmock 2.0 does not appear to be in the maven 2.0 repository. |
From: David C. <dc...@al...> - 2007-03-26 15:22:39
|
On Monday 26 March 2007 11:08, Joakim Ohlrogge wrote: > > I don't understand why that *should* matter (though I can see that it > > might). If the original CLASS is not modified from the original, why > > should having something else in the package matter? > > I have no experience with signing so I should have clarified what I > meant instead of confusing you with my ignorance: I made the > assumption that by signing the jar you could seal a package. Like for > instance you cannot put classes in the java.lang package. I thought it > was the same mechanism as signing and that would have some effect on > whether it is possible to generate more classes in that package. I'm not an expert either. > If that is the case you should not be able to create classes in those > packages even with the normal way (by making a java file in that > package) either. Right. It's a reasonable extrapolation I think. Just seems like a stupid feature to me for signing to have. > I just checked and there is an "isSealed" method on a > java.lang.Package. I'm thinking that this is related to signing and > perhaps even that you could sign a jar without sealing it? Maybe that > would work for you (assuming you are in fact sealing it). I'll dig around and see what I can find. > > That does seem to work, at least in one case. But here's the wiered > > thing. The case it works on is an interface not a class. Has there been > > a switch to code-generation for interfaces? > > As far as I know It has always been code generation for interfaces, > the thing that has changed is the naming policy and given my > assumptions about "sealed" packages that might affect interfaces as > well. Though we could treat interfaces separately since they will > never have any package private members. > > I'm not sure I understood whether the workaround worked or if you > could simply mock an interface from a signed jar.Or if you used to be > able to do that but can't anymore. The workaround worked for an interface. I did not try it for a class yet. In RC5, interfaces worked all the time, and classes encountered 'the signing problem.' With the final version, even interfaces started to have the problem. |
From: Joakim O. <joa...@ag...> - 2007-03-26 15:08:12
|
> > I think the naming policy of CGLIB tends to put the mocked classes in > > the same package as the original class. This is necessary in order to > > be able to use package private methods from within the mock. I will > > investigate to see if it's possible for us to provide some way around > > this issue. I suspect being able to specify the package of the mock > > could be a viable solution. > > > I don't understand why that *should* matter (though I can see that it might). > If the original CLASS is not modified from the original, why should having > something else in the package matter? I have no experience with signing so I should have clarified what I meant instead of confusing you with my ignorance: I made the assumption that by signing the jar you could seal a package. Like for instance you cannot put classes in the java.lang package. I thought it was the same mechanism as signing and that would have some effect on whether it is possible to generate more classes in that package. If that is the case you should not be able to create classes in those packages even with the normal way (by making a java file in that package) either. I just checked and there is an "isSealed" method on a java.lang.Package. I'm thinking that this is related to signing and perhaps even that you could sign a jar without sealing it? Maybe that would work for you (assuming you are in fact sealing it). > > > I think you can work around the issue by subclassing the external > > class you want to mock and then mock that subclass: > > > > public class MyApplicationContext extends ClasspathXmlApplicationContext { > > }; > > > > That way your subclass won't be in a signed jar and rMock can mock it. > > That makes sense, given the above hypothesis and supporting evidence. > > > My general recommendation, regardless of whether the external jar is > > signed or not, would be to wrap the external classes behind some > > interface you own and then mock that one. I understand this may not > > always be possible and maybe more of a longterm strategy than > > something that solves your immediate problem. > > > > Let me know if the suggested workaround works for you. > > That does seem to work, at least in one case. But here's the wiered thing. > The case it works on is an interface not a class. Has there been a switch > to code-generation for interfaces? > As far as I know It has always been code generation for interfaces, the thing that has changed is the naming policy and given my assumptions about "sealed" packages that might affect interfaces as well. Though we could treat interfaces separately since they will never have any package private members. I'm not sure I understood whether the workaround worked or if you could simply mock an interface from a signed jar.Or if you used to be able to do that but can't anymore. > I *think* I'm going to try to run with unsigned files, and only use the signed > files for the one piece that needs them. > If that's possible it would probably be the fastest solution. That or if there is a way to sign a jar without sealing it (if that is what you're doing, thats just a stab in the dark from my side). Let me know how it goes. /Joakim Ohlrogge |
From: David C. <dc...@al...> - 2007-03-26 14:45:34
|
On Saturday 24 March 2007 04:30, Joakim Ohlrogge wrote: > Ok, > > I think the naming policy of CGLIB tends to put the mocked classes in > the same package as the original class. This is necessary in order to > be able to use package private methods from within the mock. I will > investigate to see if it's possible for us to provide some way around > this issue. I suspect being able to specify the package of the mock > could be a viable solution. I don't understand why that *should* matter (though I can see that it might). If the original CLASS is not modified from the original, why should having something else in the package matter? > I think you can work around the issue by subclassing the external > class you want to mock and then mock that subclass: > > public class MyApplicationContext extends ClasspathXmlApplicationContext { > }; > > That way your subclass won't be in a signed jar and rMock can mock it. That makes sense, given the above hypothesis and supporting evidence. > My general recommendation, regardless of whether the external jar is > signed or not, would be to wrap the external classes behind some > interface you own and then mock that one. I understand this may not > always be possible and maybe more of a longterm strategy than > something that solves your immediate problem. > > Let me know if the suggested workaround works for you. That does seem to work, at least in one case. But here's the wiered thing. The case it works on is an interface not a class. Has there been a switch to code-generation for interfaces? I *think* I'm going to try to run with unsigned files, and only use the signed files for the one piece that needs them. > Regards > /Joakim Ohlrogge > > On 3/23/07, David Corbin <dc...@al...> wrote: > > In addition to having problems by signing cglib, problems also arise > > when you attempt to mock a class that is in a signed jar. |
From: Joakim O. <joa...@ag...> - 2007-03-24 08:30:56
|
Ok, I think the naming policy of CGLIB tends to put the mocked classes in the same package as the original class. This is necessary in order to be able to use package private methods from within the mock. I will investigate to see if it's possible for us to provide some way around this issue. I suspect being able to specify the package of the mock could be a viable solution. I think you can work around the issue by subclassing the external class you want to mock and then mock that subclass: public class MyApplicationContext extends ClasspathXmlApplicationContext { }; That way your subclass won't be in a signed jar and rMock can mock it. My general recommendation, regardless of whether the external jar is signed or not, would be to wrap the external classes behind some interface you own and then mock that one. I understand this may not always be possible and maybe more of a longterm strategy than something that solves your immediate problem. Let me know if the suggested workaround works for you. Regards /Joakim Ohlrogge On 3/23/07, David Corbin <dc...@al...> wrote: > In addition to having problems by signing cglib, problems also arise when you > attempt to mock a class that is in a signed jar. > |
From: Joakim O. <joa...@ag...> - 2007-03-23 14:26:28
|
> > Which version of java are you running? > > 1.4.2 No problems there, good > > Do you have any other versions of CGLIB on your class path than the > > one bundled with rMock? > > Not that I can find. Ok, that one out of the picture. > > Which version of spring are you using? > > 1.2.8 Ok, at my current assignment we run 1.2.5 without problems so I don't think that there is a problem there. I can't tell wether signing the jars would have this impact (you do sign the Spring jars yourself right or are there signed jars to download from Springs site? > I have this same problem trying to mock my own classes (at least under RC5). Ok, did you run any version of rMock before RC5 that did not show this problem? > With 2.0, a whole bunch of tests started failing that I'm not familiar with. > I'll re-verify that with 2.0, I still have problems with *my* classes to keep > things simple. > Weird, does not sound good. I guess you don't package those into signed jars before you run your tests right? I know that one thing that we released in 2.0.0 is a custom cglib naming-policy. Perhaps that confuses the security manager when that package is signed... If that is the case we may be able to make that one optional. > > It would help us a lot if you could isolate the problem to something > > that we can easily run on our side in order to be able to track this > > one down. > > A reasonable request. I'll work on it. As soon as we have the example we will do our best to come up with something promptly. Thank you for your cooperation on this issue. /Joakim Ohlrogge |
From: David C. <dc...@al...> - 2007-03-23 14:09:14
|
On Friday 23 March 2007 08:31, Joakim Ohlrogge wrote: > Hi David, > > When I dig deep down in the stacktrace this comes up: > > Caused by: java.lang.SecurityException: > > class "org.springframework.context.ApplicationContextMock"'s signer > > information does not match signer information of other classes in the > > same package > > at java.lang.ClassLoader.checkCerts(ClassLoader.java:611) > > at java.lang.ClassLoader.defineClass(ClassLoader.java:532) > > ... 38 more > > Do you run the tests under a security manager? Not conciously. I"m just running it inside eclipse. Our production code does (webstart) and all of jars are signed. > Which version of java are you running? 1.4.2 > Do you have any other versions of CGLIB on your class path than the > one bundled with rMock? Not that I can find. > > I'm thinking that the problem may be related to the fact that rMock > generates dynamic classes when you mock a class. That could confuse a > security manager if it's currently running under a policy. > > Which version of spring are you using? 1.2.8 > > Is it possible for you to mock the BeanFactory-interface instead of a > class? Does that change anything? I have this same problem trying to mock my own classes (at least under RC5). With 2.0, a whole bunch of tests started failing that I'm not familiar with. I'll re-verify that with 2.0, I still have problems with *my* classes to keep things simple. > It would help us a lot if you could isolate the problem to something > that we can easily run on our side in order to be able to track this > one down. A reasonable request. I'll work on it. > > I'm sorry that I can only give you questions at this time. > David |
From: Joakim O. <joa...@ag...> - 2007-03-23 12:32:18
|
Hi David, When I dig deep down in the stacktrace this comes up: > Caused by: java.lang.SecurityException: > class "org.springframework.context.ApplicationContextMock"'s signer > information does not match signer information of other classes in the same > package > at java.lang.ClassLoader.checkCerts(ClassLoader.java:611) > at java.lang.ClassLoader.defineClass(ClassLoader.java:532) > ... 38 more Do you run the tests under a security manager? Which version of java are you running? Do you have any other versions of CGLIB on your class path than the one bundled with rMock? I'm thinking that the problem may be related to the fact that rMock generates dynamic classes when you mock a class. That could confuse a security manager if it's currently running under a policy. Which version of spring are you using? Is it possible for you to mock the BeanFactory-interface instead of a class? Does that change anything? It would help us a lot if you could isolate the problem to something that we can easily run on our side in order to be able to track this one down. I'm sorry that I can only give you questions at this time. Best regars, Joakim Ohlrogge On 3/23/07, David Corbin <dc...@al...> wrote: > I've been using Rmock 2.0RC5 for a bit. It works fine for me when mocking > interfaces, but every attempt to mock classes gets me an exception like the > one below. > > I tried 2.0 (final) and a bunch of tests that worked fine started breaking in > the same manner. > > Any ideas? > > David > net.sf.cglib.core.CodeGenerationException: > java.lang.reflect.InvocationTargetException-->null > at > net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:236) > at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) > at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285) > at > com.agical.rmock.extension.cglib.CglibProxyFactory.createInterfaceProxy(CglibProxyFactory.java:61) > at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > at > com.agical.rmock.core.hub.ProxySetMethodConnectionStrategy$ConsumableInvocationHandler.invoke(ProxySetMethodConnectionStrategy.java:34) > at $Proxy3.createInterfaceProxy(Unknown Source) > at > com.agical.rmock.extension.junit.RMockTestCase.mock(RMockTestCase.java:106) > at com.agical.rmock.extension.junit.RMockTestCase.mock(RMockTestCase.java:87) > at > com.enttek.cim.service.rest.client.service.RestServiceFactoryImpl_UT.setUp(RestServiceFactoryImpl_UT.java:31) > at > com.agical.rmock.extension.junit.BasicJUnitStrategyTestCase$1.run(BasicJUnitStrategyTestCase.java:32) > at > com.agical.rmock.core.strategy.impl.CompositeStep.run(CompositeStep.java:24) > at com.agical.rmock.core.strategy.impl.FinallyStep.run(FinallyStep.java:19) > at com.agical.rmock.core.expectation.Engine.runStrategy(Engine.java:142) > at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > at > com.agical.rmock.core.hub.ProxySetMethodConnectionStrategy$ConsumableInvocationHandler.invoke(ProxySetMethodConnectionStrategy.java:34) > at $Proxy7.runStrategy(Unknown Source) > at > com.agical.rmock.extension.junit.AbstractStrategyTestCase.runBare(AbstractStrategyTestCase.java:112) > 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 junit.framework.TestSuite.runTest(TestSuite.java:208) > at junit.framework.TestSuite.run(TestSuite.java:203) > 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) > Caused by: java.lang.reflect.InvocationTargetException > at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source) > at > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384) > at > net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:218) > ... 33 more > Caused by: java.lang.SecurityException: > class "org.springframework.context.ApplicationContextMock"'s signer > information does not match signer information of other classes in the same > package > at java.lang.ClassLoader.checkCerts(ClassLoader.java:611) > at java.lang.ClassLoader.defineClass(ClassLoader.java:532) > ... 38 more > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Rmock-users mailing list > Rmo...@li... > https://lists.sourceforge.net/lists/listinfo/rmock-users > |
From: David C. <dc...@al...> - 2007-03-23 10:20:25
|
I've been using Rmock 2.0RC5 for a bit. It works fine for me when mocking interfaces, but every attempt to mock classes gets me an exception like the one below. I tried 2.0 (final) and a bunch of tests that worked fine started breaking in the same manner. Any ideas? David net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:236) at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285) at com.agical.rmock.extension.cglib.CglibProxyFactory.createInterfaceProxy(CglibProxyFactory.java:61) at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at com.agical.rmock.core.hub.ProxySetMethodConnectionStrategy$ConsumableInvocationHandler.invoke(ProxySetMethodConnectionStrategy.java:34) at $Proxy3.createInterfaceProxy(Unknown Source) at com.agical.rmock.extension.junit.RMockTestCase.mock(RMockTestCase.java:106) at com.agical.rmock.extension.junit.RMockTestCase.mock(RMockTestCase.java:87) at com.enttek.cim.service.rest.client.service.RestServiceFactoryImpl_UT.setUp(RestServiceFactoryImpl_UT.java:31) at com.agical.rmock.extension.junit.BasicJUnitStrategyTestCase$1.run(BasicJUnitStrategyTestCase.java:32) at com.agical.rmock.core.strategy.impl.CompositeStep.run(CompositeStep.java:24) at com.agical.rmock.core.strategy.impl.FinallyStep.run(FinallyStep.java:19) at com.agical.rmock.core.expectation.Engine.runStrategy(Engine.java:142) at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at com.agical.rmock.core.hub.ProxySetMethodConnectionStrategy$ConsumableInvocationHandler.invoke(ProxySetMethodConnectionStrategy.java:34) at $Proxy7.runStrategy(Unknown Source) at com.agical.rmock.extension.junit.AbstractStrategyTestCase.runBare(AbstractStrategyTestCase.java:112) 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 junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) 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) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384) at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:218) ... 33 more Caused by: java.lang.SecurityException: class "org.springframework.context.ApplicationContextMock"'s signer information does not match signer information of other classes in the same package at java.lang.ClassLoader.checkCerts(ClassLoader.java:611) at java.lang.ClassLoader.defineClass(ClassLoader.java:532) ... 38 more |
From: David C. <dc...@al...> - 2007-03-22 19:11:35
|
I've been using Rmock 2.0RC5 for a bit. It works fine for me when mocking interfaces, but every attempt to mock classes gets me an exception like the one below. I tried 2.0 (final) and a bunch of tests that worked fine started breaking in the same manner. Any ideas? David net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:236) at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377) at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285) at com.agical.rmock.extension.cglib.CglibProxyFactory.createInterfaceProxy(CglibProxyFactory.java:61) at sun.reflect.GeneratedMethodAccessor6.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at com.agical.rmock.core.hub.ProxySetMethodConnectionStrategy$ConsumableInvocationHandler.invoke(ProxySetMethodConnectionStrategy.java:34) at $Proxy3.createInterfaceProxy(Unknown Source) at com.agical.rmock.extension.junit.RMockTestCase.mock(RMockTestCase.java:106) at com.agical.rmock.extension.junit.RMockTestCase.mock(RMockTestCase.java:87) at com.enttek.cim.service.rest.client.service.RestServiceFactoryImpl_UT.setUp(RestServiceFactoryImpl_UT.java:31) at com.agical.rmock.extension.junit.BasicJUnitStrategyTestCase$1.run(BasicJUnitStrategyTestCase.java:32) at com.agical.rmock.core.strategy.impl.CompositeStep.run(CompositeStep.java:24) at com.agical.rmock.core.strategy.impl.FinallyStep.run(FinallyStep.java:19) at com.agical.rmock.core.expectation.Engine.runStrategy(Engine.java:142) at sun.reflect.GeneratedMethodAccessor36.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at com.agical.rmock.core.hub.ProxySetMethodConnectionStrategy$ConsumableInvocationHandler.invoke(ProxySetMethodConnectionStrategy.java:34) at $Proxy7.runStrategy(Unknown Source) at com.agical.rmock.extension.junit.AbstractStrategyTestCase.runBare(AbstractStrategyTestCase.java:112) 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 junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) 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) Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:324) at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384) at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:218) ... 33 more Caused by: java.lang.SecurityException: class "org.springframework.context.ApplicationContextMock"'s signer information does not match signer information of other classes in the same package at java.lang.ClassLoader.checkCerts(ClassLoader.java:611) at java.lang.ClassLoader.defineClass(ClassLoader.java:532) ... 38 more |
From: Daniel B. <dan...@gm...> - 2007-03-18 19:30:59
|
Hello everybody! We have released the RMock 2.0.0 final version. Please check it out on sourceforge downloads: http://sf.net/projects/rmock or visit the project website: http://rmock.sourceforge.net/ Some new goodies, but mostly the same test-double framework as before! Cheers! The RMock Team -- __________________________ Dan...@Gm... |
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. > > |
From: Joakim O. <joa...@ag...> - 2006-12-21 13:11:10
|
you're right that modify() is the way to go but you should modify it t return the instance you want. In the CVS-version I would do like this: B b fakeAndIntercept(B.class); myMock.a(); modify().returnValue(b); in rc6 fakeAndIntercept does not exist. The easiest way forward there is to create a stub of B or if B is simple enough return an instance of B. Just to clarify, because of automatic return-values you get a mock back. If automatic return values where not there you would get null so you would have to modify either way. So to remove the effect of automatic return values you could just do this: myMock.a(); modify().returnValue(null); I hope this helps, let me know if it doesn't! Cheers Joakim Ohlrogge On 12/21/06, Private-old <ra...@o2...> wrote: > Hi > > I have 2 methods a and b. > Method a calls method b (which returns an interface type). > After that there are some calls to returned(by method b) object methods. > When i test method a i want to be sure that it calls method b, I > don't care if some methods on returned object are called or not. > But as a consequence of "Automatic return values" the test fails > beacouse of unexpected method call on returned object. > How to solve this problem ? I think i should modify the recording but > I don't know how. I tried: > > modify().returnValue(is.ANYTHING); > > Bu it doesn't work, i don't even know if it is the right way to solve > this. > > Regards > Daniel Lipski > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Rmock-users mailing list > Rmo...@li... > https://lists.sourceforge.net/lists/listinfo/rmock-users > |
From: Private-old <ra...@o2...> - 2006-12-21 09:36:32
|
Hi I have 2 methods a and b. Method a calls method b (which returns an interface type). After that there are some calls to returned(by method b) object methods. When i test method a i want to be sure that it calls method b, I don't care if some methods on returned object are called or not. But as a consequence of "Automatic return values" the test fails beacouse of unexpected method call on returned object. How to solve this problem ? I think i should modify the recording but I don't know how. I tried: modify().returnValue(is.ANYTHING); Bu it doesn't work, i don't even know if it is the right way to solve this. Regards Daniel Lipski |
From: Private-old <ra...@o2...> - 2006-12-20 16:16:59
|
From: Mick K. <mic...@gm...> - 2006-12-11 17:43:54
|
Well, here is the method I have created. public void testPrepareBusinessNpiMassUpdate() throws Exception { // JUnitDoclet begin method prepareBusinessNpiMassUpdate ProviderSearchResponse providerSearchResponse1 = new ProviderSearchResponse(); providerSearchResponse1.setTaxIdentifier("752451107"); ProviderSearchResponse providerSearchResponse2 = new ProviderSearchResponse(); providerSearchResponse1.setTaxIdentifier("752451107"); List providers = new ArrayList(); providers.add(providerSearchResponse1); providers.add(providerSearchResponse2); // create mock service object ProviderServiceImpl providerServiceImpl = (ProviderServiceImpl) mock( ProviderServiceImpl.class, "providerServiceImpl" ); providerServiceImpl.isBusinessNPIConsistent (providerSearchResponse1); providerServiceImpl.isBusinessNPIUnique(providerSearchResponse1); // setup the call that the providerserviceimpl will be using modify().multiplicity(expect.atLeastOnce()).args(is.ANYTHING ).returnValue(true); // Change state to verification, IMPORTANT!!! startVerification(); providerbackingbean.setProvider(providers); providerbackingbean.setMassBusinessNPI("1234567893"); providerbackingbean.setTin("752451107"); providerbackingbean.setService(providerServiceImpl); // Check that the class returns the value from the mocked interface (defaults to null) assertThat( providerbackingbean.prepareBusinessNpiMassUpdate("752451107"), is.eq(true) ); // JUnitDoclet end method prepareBusinessNpiMassUpdate } And here is the error I get: =========================================================== ------------------------------------------------------------------------------- Test set: org.delta.provider.npi.web.ProviderBackingBeanTest ------------------------------------------------------------------------------- Tests run: 69, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.875 sec <<< FAILURE! testPrepareBusinessNpiMassUpdate( org.delta.provider.npi.web.ProviderBackingBeanTest) Time elapsed: 0.25 sec <<< FAILURE! com.agical.rmock.core.exception.UnsatisfiedExpectationsException: UNSATISFIED! 2 expectations(s) have not yet been matched (indicated by '->' in the listing below) -------------------------------------------------------------------------- Unordered section:Default root section { -> 0(1) providerServiceImpl.isBusinessNPIConsistent(eq(< org.delta.provider.npi.service.ProviderSearchResponse@89cf1e>)) -> 0(1..*) providerServiceImpl.isBusinessNPIUnique (anything(<null>)) } at com.agical.rmock.core.expectation.Engine.endVerify(Engine.java:88) at com.agical.rmock.extension.junit.RMockTestCase.runBare( RMockTestCase.java:111) 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 junit.framework.TestSuite.runTest(TestSuite.java:208) at junit.framework.TestSuite.run(TestSuite.java:203) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.maven.surefire.junit.JUnitTestSet.execute( JUnitTestSet.java:210) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet( AbstractDirectoryTestSuite.java:135) at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute( AbstractDirectoryTestSuite.java:122) at org.apache.maven.surefire.Surefire.run(Surefire.java:129) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess( SurefireBooter.java:225) at org.apache.maven.surefire.booter.SurefireBooter.main( SurefireBooter.java:747) ---------- Forwarded message ---------- From: Daniel Brolund <dan...@gm...> Date: Dec 9, 2006 1:24 AM Subject: Re: [Rmock-users] Best practice for multiple scenario test. To: Mick Knutson <mic...@gm...> Hi! Is it ok for you to post it on the rmock-users list so that others can benefit from the answer(s)? You can use the multiplicity modification: dao.isBusinessNPIConsistent(""); modify().multiplicity(expect.atLeastOnce()).args(is.ANYTHING ).returnValue(true); if you are content with returning the same value for all calls. If you want to return a value depending on the argument of the mocked call, do something like this (I mocked a Map, but the principle is the same): import java.util.Map; import com.agical.rmock.core.Action; import com.agical.rmock.core.MethodHandle; import com.agical.rmock.extension.junit.RMockTestCase; public class TestMassiveConditionalReturnValue extends RMockTestCase { public void testConditionalReturnValueInMockedCall() throws Exception { Map map = (Map) mock(Map.class, "map"); map.get(null); modify().multiplicity(expect.atLeast(0)).args(is.ANYTHING).perform( getActionForConditionalReturnValueInMockedCall()); startVerification(); assertThat(map.get("a"), is.eq("A")); assertThat(map.get("b"), is.eq("B")); assertThat(map.get("c"), is.NULL); } private Action getActionForConditionalReturnValueInMockedCall() { return new Action() { public Object invocation(Object[] arg0, MethodHandle arg1) throws Throwable { if (arg0[0].equals("a")) { return "A"; } else if (arg0[0].equals("b")) { return "B"; } return null; } }; } } Cheers Daniel On 12/9/06, Mick Knutson <mic...@gm...> wrote: > I have a scenario where I have a method I want to test (performMassUpdate()) > and inside that method, there are 2 different calls to a single DAO > (dao.isBusinessNPIConsistent(String):boolean) and > dao.isBusinessNPIUnique(String):boolean) > > How can I setup 2 mock calls and returns for my test? > > > > > > > On 11/22/06, Daniel Brolund < dan...@gm...> wrote: > > Ok, good to hear! > > > > Cheers > > Daniel > > > > > > On 11/22/06, Mick Knutson <mic...@gm...> wrote: > > > Yes, I got most of the items to work. > > > I am just using Spring to create objects/DTO's. > > > > > > The hard part was creating new test methods for each scenario as I use > > > JUnitDoclet to create test methods, and this had to be manually put into > > > place... > > > > > > > > > > > > On 11/22/06, Daniel Brolund < dan...@gm...> wrote: > > > > Hi Mick! > > > > How did it go? > > > > > > > > Cheers > > > > Daniel > > > > > > > > On 11/16/06, Daniel Brolund < dan...@gm...> wrote: > > > > > Hi again! > > > > > We strongly recommend you to split those iterations i separate tests > > > > > (test methods) instead. In your case maybe: > > > > > > > > > > testGetOneStateCode() {...} > > > > > testGetTwoStateCodes() {...} > > > > > ... > > > > > testGetManyStateCodes() {...} > > > > > ... > > > > > > testWhenGetStateCodesReturnsNullMyClassDoesntGoNuts() > > > {...} > > > > > > > > > > etc for any border condition of your class. > > > > > > > > > > The reasons to split the tests in separate methods are many, and > from > > > > > the top of my mind I can come up with the following: > > > > > * When a test fails you want to know what went wrong as fast as > > > possible. > > > > > * You want to communicate your intent with the test as clearly as > > > possible > > > > > * You want your test code to be simple to read and understand, i.e . > > > > > short and concise. > > > > > > > > > > The same principle holds for when you want to test for when the > mocked > > > > > object throws an exception: > > > > > > > > > > > > > > testWhenGetStateCodesThrowsExceptionTheExceptionIsHandled() > > > {...} > > > > > > > > > > To make RMock throw exception, do like this example: > > > > > > > > > > public void testExceptionThrowing() > > > > > { > > > > > // Create a mocked object > > > > > Runnable runnable = (Runnable) mock(Runnable.class, "runnable"); > > > > > > > > > > // Set it up to throw an exception when called > > > > > RuntimeException runtimeException = new RuntimeException( "My > > > > > faked exception" ); > > > > > runnable.run(); > > > > > modify().throwException( runtimeException ); > > > > > > > > > > startVerification(); > > > > > > > > > > // Setup this test to expect an exception from the execution > > > > > expectThatExceptionThrown( is.same(runtimeException) ); > > > > > // If your class catches the exception and rethrows another > > > > > // exception, alter the above to reflect that using an > appropriate > > > > > // "is" expression. > > > > > > > > > > // Call the mock that throws an exception (this mock should > really > > > be > > > > > // passed to the class under test in a more realistic situation) > > > > > runnable.run (); > > > > > } > > > > > > > > > > > > > > > Did that make any sense? > > > > > > > > > > Cheers > > > > > Daniel > > > > > > > > > > On 11/16/06, Mick Knutson < mic...@gm...> wrote: > > > > > > I have the following test: > > > > > > > > > > > > public void testGetStateCodes() throws Exception { > > > > > > // JUnitDoclet begin method getStateCodes > > > > > > > > > > > > // create mock service object > > > > > > ProviderDAOServiceImpl providerDAOServiceImpl = > > > > > > (ProviderDAOServiceImpl) mock( ProviderDAOServiceImpl.class, > > > > > > "providerDAOServiceImpl" ); > > > > > > > > > > > > ArrayList list = new ArrayList(); > > > > > > list.add("CA"); > > > > > > > > > > > > // Iteration 1 > > > > > > > > > > ------------------------------------------------------// > > > > > > // Also need to check for a null, and an exception returned... > > > > > > // setup the call that the providerbackingbean will be > using > > > > > > providerDAOServiceImpl.getStateCodes(); > > > > > > // Modify argument expectation > > > > > > modify().returnValue(list); > > > > > > // Change state to verification, IMPORTANT!!! > > > > > > startVerification(); > > > > > > providerserviceimpl.setDao (providerDAOServiceImpl); > > > > > > // Check that the class returns the value from the mocked > > > interface > > > > > > (defaults to null) > > > > > > assertThat( > > > > > > providerserviceimpl.getStateCodes().size(), > is.eq(1) > > > ); > > > > > > > > > > > > // Iteration 2 > > > > > > > > > > ------------------------------------------------------// > > > > > > list.add("AK"); > > > > > > /*//// setup the call that the providerbackingbean will be > > > using > > > > > > //providerDAOServiceImpl.getStateCodes(); > > > > > > // Modify argument expectation > > > > > > modify().returnValue(list); > > > > > > // Change state to verification, IMPORTANT!!! > > > > > > startVerification(); > > > > > > providerserviceimpl.setDao(providerDAOServiceImpl); > > > > > > // Check that the class returns the value from the mocked > > > interface > > > > > > (defaults to null) > > > > > > assertThat( > > > > > > providerserviceimpl.getStateCodes().size(), > is.eq(2) > > > );*/ > > > > > > > > > > > > // JUnitDoclet end method getStateCodes > > > > > > } > > > > > > > > > > > > > > > > > > > > > > > > I am trying to find the best practice for altering the return > values > > > during > > > > > > a test for multiple iterations like this. > > > > > > > > > > > > I also need to understand how to have my rMock return/throw an > > > Exception > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > > > > > > > > Thanks > > > > > > > > > > > > DJ MICK > > > > > > http://www.djmick.com > > > > > > http://www.myspace.com/mickknutson > > > > > > > > > > ------------------------------------------------------------------------- > > > > > > Take Surveys. Earn Cash. Influence the Future of IT > > > > > > Join SourceForge.net's Techsay panel and you'll get the chance to > > > share your > > > > > > opinions on IT & business topics through brief surveys - and earn > cash > > > > > > > > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > > > > > > > > > > _______________________________________________ > > > > > > Rmock-users mailing list > > > > > > Rmo...@li... > > > > > > > > > > https://lists.sourceforge.net/lists/listinfo/rmock-users > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > -- > > > > > __________________________ > > > > > Dan...@Gm... > > > > > > > > > > > > > > > > > -- > > > > __________________________ > > > > Dan...@Gm... > > > > > > > > > > > > > > > > -- > > > > > > > > > Thanks > > > > > > DJ MICK > > > http://www.djmick.com > > > http://www.myspace.com/mickknutson > > > > > > -- > > __________________________ > > Dan...@Gm... > > > > > > -- > > > Thanks > > DJ MICK > http://www.djmick.com > http://www.myspace.com/mickknutson -- __________________________ Dan...@Gm... -- Thanks DJ MICK http://www.djmick.com http://www.myspace.com/mickknutson |
From: Daniel B. <dan...@gm...> - 2006-11-22 21:36:51
|
Hi Mick! How did it go? Cheers Daniel On 11/16/06, Daniel Brolund <dan...@gm...> wrote: > Hi again! > We strongly recommend you to split those iterations i separate tests > (test methods) instead. In your case maybe: > > testGetOneStateCode() {...} > testGetTwoStateCodes() {...} > ... > testGetManyStateCodes() {...} > ... > testWhenGetStateCodesReturnsNullMyClassDoesntGoNuts() {...} > > etc for any border condition of your class. > > The reasons to split the tests in separate methods are many, and from > the top of my mind I can come up with the following: > * When a test fails you want to know what went wrong as fast as possible. > * You want to communicate your intent with the test as clearly as possible > * You want your test code to be simple to read and understand, i.e. > short and concise. > > The same principle holds for when you want to test for when the mocked > object throws an exception: > > testWhenGetStateCodesThrowsExceptionTheExceptionIsHandled() {...} > > To make RMock throw exception, do like this example: > > public void testExceptionThrowing() > { > // Create a mocked object > Runnable runnable = (Runnable) mock(Runnable.class, "runnable"); > > // Set it up to throw an exception when called > RuntimeException runtimeException = new RuntimeException( "My > faked exception" ); > runnable.run(); > modify().throwException( runtimeException ); > > startVerification(); > > // Setup this test to expect an exception from the execution > expectThatExceptionThrown( is.same(runtimeException) ); > // If your class catches the exception and rethrows another > // exception, alter the above to reflect that using an appropriate > // "is" expression. > > // Call the mock that throws an exception (this mock should really be > // passed to the class under test in a more realistic situation) > runnable.run(); > } > > > Did that make any sense? > > Cheers > Daniel > > On 11/16/06, Mick Knutson <mic...@gm...> wrote: > > I have the following test: > > > > public void testGetStateCodes() throws Exception { > > // JUnitDoclet begin method getStateCodes > > > > // create mock service object > > ProviderDAOServiceImpl providerDAOServiceImpl = > > (ProviderDAOServiceImpl) mock( ProviderDAOServiceImpl.class, > > "providerDAOServiceImpl" ); > > > > ArrayList list = new ArrayList(); > > list.add("CA"); > > > > // Iteration 1 > > ------------------------------------------------------// > > // Also need to check for a null, and an exception returned... > > // setup the call that the providerbackingbean will be using > > providerDAOServiceImpl.getStateCodes(); > > // Modify argument expectation > > modify().returnValue(list); > > // Change state to verification, IMPORTANT!!! > > startVerification(); > > providerserviceimpl.setDao(providerDAOServiceImpl); > > // Check that the class returns the value from the mocked interface > > (defaults to null) > > assertThat( > > providerserviceimpl.getStateCodes().size(), is.eq(1) ); > > > > // Iteration 2 > > ------------------------------------------------------// > > list.add("AK"); > > /*//// setup the call that the providerbackingbean will be using > > //providerDAOServiceImpl.getStateCodes(); > > // Modify argument expectation > > modify().returnValue(list); > > // Change state to verification, IMPORTANT!!! > > startVerification(); > > providerserviceimpl.setDao(providerDAOServiceImpl); > > // Check that the class returns the value from the mocked interface > > (defaults to null) > > assertThat( > > providerserviceimpl.getStateCodes().size(), is.eq(2) );*/ > > > > // JUnitDoclet end method getStateCodes > > } > > > > > > > > I am trying to find the best practice for altering the return values during > > a test for multiple iterations like this. > > > > I also need to understand how to have my rMock return/throw an Exception > > > > > > > > -- > > > > Thanks > > > > DJ MICK > > http://www.djmick.com > > http://www.myspace.com/mickknutson > > ------------------------------------------------------------------------- > > Take Surveys. Earn Cash. Influence the Future of IT > > Join SourceForge.net's Techsay panel and you'll get the chance to share your > > opinions on IT & business topics through brief surveys - and earn cash > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > > _______________________________________________ > > Rmock-users mailing list > > Rmo...@li... > > https://lists.sourceforge.net/lists/listinfo/rmock-users > > > > > > > > > -- > __________________________ > Dan...@Gm... > -- __________________________ Dan...@Gm... |
From: Daniel B. <dan...@gm...> - 2006-11-16 19:21:07
|
Hi again! We strongly recommend you to split those iterations i separate tests (test methods) instead. In your case maybe: testGetOneStateCode() {...} testGetTwoStateCodes() {...} ... testGetManyStateCodes() {...} ... testWhenGetStateCodesReturnsNullMyClassDoesntGoNuts() {...} etc for any border condition of your class. The reasons to split the tests in separate methods are many, and from the top of my mind I can come up with the following: * When a test fails you want to know what went wrong as fast as possible. * You want to communicate your intent with the test as clearly as possible * You want your test code to be simple to read and understand, i.e. short and concise. The same principle holds for when you want to test for when the mocked object throws an exception: testWhenGetStateCodesThrowsExceptionTheExceptionIsHandled() {...} To make RMock throw exception, do like this example: public void testExceptionThrowing() { // Create a mocked object Runnable runnable = (Runnable) mock(Runnable.class, "runnable"); // Set it up to throw an exception when called RuntimeException runtimeException = new RuntimeException( "My faked exception" ); runnable.run(); modify().throwException( runtimeException ); startVerification(); // Setup this test to expect an exception from the execution expectThatExceptionThrown( is.same(runtimeException) ); // If your class catches the exception and rethrows another // exception, alter the above to reflect that using an appropriate // "is" expression. // Call the mock that throws an exception (this mock should really be // passed to the class under test in a more realistic situation) runnable.run(); } Did that make any sense? Cheers Daniel On 11/16/06, Mick Knutson <mic...@gm...> wrote: > I have the following test: > > public void testGetStateCodes() throws Exception { > // JUnitDoclet begin method getStateCodes > > // create mock service object > ProviderDAOServiceImpl providerDAOServiceImpl = > (ProviderDAOServiceImpl) mock( ProviderDAOServiceImpl.class, > "providerDAOServiceImpl" ); > > ArrayList list = new ArrayList(); > list.add("CA"); > > // Iteration 1 > ------------------------------------------------------// > // Also need to check for a null, and an exception returned... > // setup the call that the providerbackingbean will be using > providerDAOServiceImpl.getStateCodes(); > // Modify argument expectation > modify().returnValue(list); > // Change state to verification, IMPORTANT!!! > startVerification(); > providerserviceimpl.setDao(providerDAOServiceImpl); > // Check that the class returns the value from the mocked interface > (defaults to null) > assertThat( > providerserviceimpl.getStateCodes().size(), is.eq(1) ); > > // Iteration 2 > ------------------------------------------------------// > list.add("AK"); > /*//// setup the call that the providerbackingbean will be using > //providerDAOServiceImpl.getStateCodes(); > // Modify argument expectation > modify().returnValue(list); > // Change state to verification, IMPORTANT!!! > startVerification(); > providerserviceimpl.setDao(providerDAOServiceImpl); > // Check that the class returns the value from the mocked interface > (defaults to null) > assertThat( > providerserviceimpl.getStateCodes().size(), is.eq(2) );*/ > > // JUnitDoclet end method getStateCodes > } > > > > I am trying to find the best practice for altering the return values during > a test for multiple iterations like this. > > I also need to understand how to have my rMock return/throw an Exception > > > > -- > > Thanks > > DJ MICK > http://www.djmick.com > http://www.myspace.com/mickknutson > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys - and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > _______________________________________________ > Rmock-users mailing list > Rmo...@li... > https://lists.sourceforge.net/lists/listinfo/rmock-users > > > -- __________________________ Dan...@Gm... |
From: Mick K. <mic...@gm...> - 2006-11-16 17:13:06
|
I have the following test: public void testGetStateCodes() throws Exception { // JUnitDoclet begin method getStateCodes // create mock service object ProviderDAOServiceImpl providerDAOServiceImpl = (ProviderDAOServiceImpl) mock( ProviderDAOServiceImpl.class, "providerDAOServiceImpl" ); ArrayList list = new ArrayList(); list.add("CA"); // Iteration 1 ------------------------------------------------------// // Also need to check for a null, and an exception returned... // setup the call that the providerbackingbean will be using providerDAOServiceImpl.getStateCodes(); // Modify argument expectation modify().returnValue(list); // Change state to verification, IMPORTANT!!! startVerification(); providerserviceimpl.setDao(providerDAOServiceImpl); // Check that the class returns the value from the mocked interface (defaults to null) assertThat( providerserviceimpl.getStateCodes().size(), is.eq(1) ); // Iteration 2 ------------------------------------------------------// list.add("AK"); /*//// setup the call that the providerbackingbean will be using //providerDAOServiceImpl.getStateCodes(); // Modify argument expectation modify().returnValue(list); // Change state to verification, IMPORTANT!!! startVerification(); providerserviceimpl.setDao(providerDAOServiceImpl); // Check that the class returns the value from the mocked interface (defaults to null) assertThat( providerserviceimpl.getStateCodes().size(), is.eq(2) );*/ // JUnitDoclet end method getStateCodes } I am trying to find the best practice for altering the return values during a test for multiple iterations like this. I also need to understand how to have my rMock return/throw an Exception -- Thanks DJ MICK http://www.djmick.com http://www.myspace.com/mickknutson |
From: Daniel B. <dan...@gm...> - 2006-11-16 07:12:10
|
Hi Mick! Is the problem basically that you want to use RMock's mocking capabilities, but you don't want to extend RMockTestCase? If so, at the moment it will be kind of tricky. RMocks test lifecycle is currently a bit too tightly coupled with the JUnit class. We're hoping to address this problem in a not so far future. >From your mail I get the feeling that you test a lot of things at the same time. Is there any way you could divide the code (and the tests) in smaller pieces and by doing so you don't need the functionality from two base test classes? Also, by arbitrary, do you actually mean arbitrary or do you mean random? And for creating objects from XML, I got like 900 hits on Google for <"xml to object" java>. Are they all bad? :-) Cheers Daniel On 11/14/06, Mick Knutson <mic...@gm...> wrote: > I have a UserDto that I need to populate with values, before I can send it > to my UserManager. Then my UserManager needs a mock UserDAO service. So > rMock creates my UserDAO, but I need to still create a few different > UserDTO's to test various scenarios inside my UserManager. > > > > > > On 11/14/06, Daniel Brolund <dan...@gm...> wrote: > > Hello Mick! > > I'm not quite sure what you are looking for here. > > Do you want to use RMocks mocking ability? Or are you after > > assertThat(...) ? Or am I totally off...? > > > > A code example/sketch of what you would like to do would probably help > > us a lot to understand your needs and provide you with further help. > > > > Cheers > > Daniel > > > > On 11/13/06, Mick Knutson <mic...@gm...> wrote: > > > I have several business objects that I want to rMock test. They all take > > > various types of DTO's as inputs, then I am creating DAO mocks that will > > > return another DTO back to these BO's. > > > > > > So, I have looked at JTestCase, DDTUnit and Jetif to help create > arbitrary > > > Objects, but DDTUnit needs to extend it's own TestCase, and I can't seem > to > > > get JTestCase with Jice integration to work. > > > > > > S0, can someone please help me solve creating arbitrary Objects from XML > > > descriptors? > > > > > > -- > > > > > > Thanks > > > > > > DJ MICK > > > http://www.djmick.com > > > http://www.myspace.com/mickknutson > > > > ------------------------------------------------------------------------- > > > Using Tomcat but need to do more? Need to support web services, > security? > > > Get stuff done quickly with pre-integrated technology to make your job > > > easier > > > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > > > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > > > > > _______________________________________________ > > > Rmock-users mailing list > > > Rmo...@li... > > > > https://lists.sourceforge.net/lists/listinfo/rmock-users > > > > > > > > > > > > > > > -- > > __________________________ > > Dan...@Gm... > > > > > > -- > > > Thanks > > DJ MICK > http://www.djmick.com > http://www.myspace.com/mickknutson -- __________________________ Dan...@Gm... |
From: Daniel B. <dan...@gm...> - 2006-11-14 20:09:11
|
Hello Mick! I'm not quite sure what you are looking for here. Do you want to use RMocks mocking ability? Or are you after assertThat(...) ? Or am I totally off...? A code example/sketch of what you would like to do would probably help us a lot to understand your needs and provide you with further help. Cheers Daniel On 11/13/06, Mick Knutson <mic...@gm...> wrote: > I have several business objects that I want to rMock test. They all take > various types of DTO's as inputs, then I am creating DAO mocks that will > return another DTO back to these BO's. > > So, I have looked at JTestCase, DDTUnit and Jetif to help create arbitrary > Objects, but DDTUnit needs to extend it's own TestCase, and I can't seem to > get JTestCase with Jice integration to work. > > S0, can someone please help me solve creating arbitrary Objects from XML > descriptors? > > -- > > Thanks > > DJ MICK > http://www.djmick.com > http://www.myspace.com/mickknutson > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job > easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 > > _______________________________________________ > Rmock-users mailing list > Rmo...@li... > https://lists.sourceforge.net/lists/listinfo/rmock-users > > > -- __________________________ Dan...@Gm... |
From: Mick K. <mic...@gm...> - 2006-11-13 17:13:15
|
I have several business objects that I want to rMock test. They all take various types of DTO's as inputs, then I am creating DAO mocks that will return another DTO back to these BO's. So, I have looked at JTestCase, DDTUnit and Jetif to help create arbitrary Objects, but DDTUnit needs to extend it's own TestCase, and I can't seem to get JTestCase with Jice integration to work. S0, can someone please help me solve creating arbitrary Objects from XML descriptors? -- Thanks DJ MICK http://www.djmick.com http://www.myspace.com/mickknutson |
From: Joakim O. <joa...@ag...> - 2006-09-26 07:37:43
|
>From the top of my head it would look something like this. Explanations after the example. public TestSomething extends RMockTestCase { public void testSomething() { SomeInterface someInterface = (SomeInterface)mock(SomeInterface.class, "someMock"); someInterface.doSomething(); modify().multiplicity(expect.atLeast(0)).perform(returnOneByOne(new String[] {"first", "second", "third" } )); startVerification(); <performTestHere> } public Action returnOneByOne(final String[] values) { return new Action() { int index; public Object invocation(Object[] arguments, MethodHandle implementationMethod) throws Throwable { if (index > 0) { return null; } else { return values[index++]; } } } } (I have not tested this code but with some curly braces and typo fixes it should work) When I create a custom action I genreally start out with an anonymous one like the one above. If I need the action in a second test I create a common base class derived from RMockTestCase and move the custom action there. As you have probably figured out the above expectation will return "first", "second", "third" and then null (infinately) in that order. It can be good to include a safety-net by using an atMost(1000) muliplicity. Doing so will fail the test if the expectation is called in an infinate loop. MethodHandle in the Action deserves an explanation: if you are mocking a concrete class, method-handle will point to the implementations method. So you could for instance return mocked values from the array and when you run out of those, instead of returning null; forward to the implementation. It's just a different way of setting up three different atMost(1) expectations and finish with setting up an atLeast(0) exectation but it may be a better choice if you have more than X atMost(1) expectations. I hope this helps. Don't hesitate to ask if something is not clear. I wrote the code very fast and my pedagogical skills are not turned on at the moment :) /J On 9/26/06, James Carr <jam...@gm...> wrote: > Joakim, > > Have any examples? > > Thanks, > james > > On 9/21/06, Joakim Ohlrogge <joa...@ag...> wrote: > > Reading your post again you could also do with a custom action and an > > atleast(0) expectation so the action is preloaded with the values you > > want to be returned and returns a new value on each invocation until > > there are no more values and it will return null. > > > > Alternatively a compisite actions that executes several actions, one > > at the time. Then you could setup that the first 3 invocations returns > > different strings and the 4th one throws an exception or forwards to > > an underlying implementation for instance. > > > > If you have any ideas on some neat syntax that would acomplish this in > > a simpler way we could make it a part of the rMock library. > > > > /Joakim Ohlrogge > > > > On 9/21/06, Joakim Ohlrogge <joa...@ag...> wrote: > > > When it comes to readers I usually create a StringReader. But to > > > answer your question the alternative I immediately think of: > > > > > > Setup the expectations you want in the order you want them. > > > Finish with an "atleast(0)" expectation. > > > > > > Hope that helps > > > /Joakim Ohlrogge > > > > > > On 9/21/06, James Carr <jam...@gm...> wrote: > > > > Hi, > > > > > > > > I was curious if there was a way to create mocks that don't have any > > > > expectations. For example, sometimes I want to fake out a > > > > BufferedReader and don't care at all how many times it's called, but > > > > rather only care that it returns, say, 5 different strings and then > > > > finally null when called more than 6 times. > > > > > > > > If you have any ideas, please let me know. > > > > > > > > Thanks, > > > > James > > > > > > > > ------------------------------------------------------------------------- > > > > Take Surveys. Earn Cash. Influence the Future of IT > > > > Join SourceForge.net's Techsay panel and you'll get the chance to share your > > > > opinions on IT & business topics through brief surveys -- and earn cash > > > > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > > > > _______________________________________________ > > > > Rmock-users mailing list > > > > Rmo...@li... > > > > https://lists.sourceforge.net/lists/listinfo/rmock-users > > > > > > > > > > |