Hi Chuck,

A better way to do this is to customize the NRE engine (create a MyEngine
subclass for example) and override the createHelper(Client) method. See
Javadocs at:
http://www.restlet.org/docs/nre/com/noelios/restlet/Engine.html#createHelper
(org.restlet.Client)

The Helper instance will intercept all the "handle()" method calls and will
give you an opportunity to simulate an actual connector.

Once this is done, you will need to manually register the customized Engine
with the API before actually using the API:
http://www.restlet.org/docs/api/org/restlet/util/Engine.html#setInstance(org
.restlet.util.Engine)

Just do something like: "MyEngine.register();"

Another more sophisticated way is to develop a pluggable Mock connector,
similar to the real ones but that wouldn't actually do the work. This would
require you to modify the classpath to remove the real connector and add the
mock one. Let me know if you are interested by this other approach.

Best regards,
Jerome  

> -----Message d'origine-----
> De : Chuck Hinson [mailto:[EMAIL PROTECTED] 
> Envoyé : dimanche 18 février 2007 06:23
> À : [email protected]
> Objet : Unit testing and the Client class
> 
> 
> Before I go off and reinvent the wheel, I was wondering if anyone has
> done anything along the lines of mocking up the Client class to make
> unit testing easier.
> 
> One way to do this is to subclass Client and then override 
> handle(), but
> then I'll have to create some sort of Client factory for constructing
> Client instances so that the mock gets used during testing 
> and the real
> one gets used in production.
> 
> Is there something underneath Client whereby I can intercept outgoing
> requests and insert my own respone without having to do 
> anything special
> in the production code?
> 
> --Chuck
> 
> ------------------------------------
> Chuck Hinson
> Gestalt LLC
> phone: 610.994.2833
> IM: chucking24 (Yahoo)
>  

Reply via email to