From: Laurent D. <ldu...@ya...> - 2004-05-05 20:45:57
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> <title></title> </head> <body bgcolor="#ffffff" text="#000000"> Steve Freeman wrote: <blockquote cite="mid...@m3..." type="cite">Well, you can always just hand code a subclass that does what you want. The Expectations library is quite useful for this. Or you can try the cglib extension to jmock.org, although that's still not quite released. Or you can use the cglib extension to EasyMock. Or you can extract an interface from your class. <br> <br> </blockquote> <br> Unfortunately, I can't do that. I have to subclass. I would prefer the use of an interface, but I can't.<br> <br> <blockquote cite="mid...@m3..." type="cite">The trick is to create an instance of the exception (it's just an object), and then throw it in the mock implementation of the method. <br> <br> </blockquote> <br> If possible, I'd like to generate a skeleton of a class that could give me the basic code I need to set up exceptions, setup test cases, etc. is there something that will do this on a class instead of an interface? I originally tried the MockCreator package but it generated a file that was 300K large... *Really* not what I was looking for. <br> <br> What I'd like is to have something like this automatically generated:<br> <br> <pre>public class MyClass extends AnAbstractClass { Vector _v; int _int; public getInt() throws Eception { return _int; } public getVector() throws Exception { return _v; } } </pre> <pre>public class MyMockClass extends MyClass {</pre> <pre> Vector _getVector;</pre> <pre> int _getInt; int getInt() throws Exception { return _getInt; } void setupGetInt(int anInt) { _getInt = anInt; } void setupGetIntException(Exception anException) { // Some voodoo here to make it throw an exception when getInt is called } . . . // Similar stuff for _getVector </pre> <pre>}</pre> Is there a way to do this fairly painlessly? Or am I stuck coding each of the methods by hand? :-(<br> <br> L<br> <br> <br> </body> </html> |