From: Adam B. <ada...@cu...> - 2012-02-27 04:22:35
|
Hello again, Please disregard my last message - I've just found the answer to my own question. For future reference and completeness of this thread: the way the WFSDatacreateDataStore method is being tested without making http requests is by creating an inline extension of WFSDatacreateDataStore and overriding the loadCapabilities method. By doing this we can force the loadCapabilities method to just return a fixed XML byte[] rather than have it use http requests. eg. final WFSDataStoreFactory dsf = new WFSDataStoreFactory() { @Override byte[] loadCapabilities(final URL capabilitiesUrl, HTTPProtocol htp) throws IOException { // return specific xml information here } } Many thanks and apologies for the unnecessary question! Adam Brown ________________________________ From: Adam Brown Sent: 27 February 2012 11:01 To: geo...@li... Subject: How to break external dependencies (such as those that use http) when writing GeoTools tests? Hello all, Re: How to break external dependencies (such as those that use http) when writing GeoTools tests? I'm trying to write some new tests for GeoTools and am having some trouble understanding the best way to fake a dependency on SimpleHttpProtocol. More specifically, what I want to do is add a test for WFSDataStoreFactory's createDataStore method that *doesn't* initiate a http request. I just want to be able to manually specify what the http requests should return so that I can test the logic in the createDataStore method in isolation. The problem I have is that this method is tightly-coupled with SimpleHttpProtocol and there's no easy way for me to inject a fake or different implementation of this class. Could someone please point me in the right overcome this? Would there be any problems with acceptance of this code if I were to refactor it in such a way as to make dependency injection possible? Thanks in advance, Adam Brown |