Brian's Waste of Time

Thu, 08 Jan 2004

Support for Mocking Classes as well as Interfaces

MockObjects have a great dyanamic proxy based mock object implementation available, but it is limited to mocking interfaces up. A coworker needed (well, wanted) to dynamically mock up a class instead of an interface so I tossed together support in intercepts for mocking arbitrary objects. If you want to mock a class it requires an instance of that class, as Java doesn't allow you to instantiate subclasses without being able to instantiate the super class, but it guarantees that no methods will be invoked on the object it is given.

Also fixed a pretty major bug where interceptors could be invoked out of order if objects were wrapped, and interceptors added, in a specific way. I fixed it via changing a map to a list of tuples. Sometimes Java's static typing instead of dynamic typing really bugs me.

Posted new snapshots as this involved a fix to the first bug found!

7 writebacks [/src/java/commons-intercept] permanent link