{"id":663,"date":"2011-11-29T17:40:00","date_gmt":"2011-11-29T17:40:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/creating-stubs-for-legacy-code-testing-techniques-6.html"},"modified":"2012-10-21T20:35:12","modified_gmt":"2012-10-21T20:35:12","slug":"creating-stubs-for-legacy-code-testing","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html","title":{"rendered":"Creating Stubs for Legacy Code &#8211; Testing Techniques 6"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\">Any one who reads this blog will probably have realised that at present I\u2019m working on a project that contains a whole bunch of legacy code that\u2019s large, expansive, and written without any tests what so ever.<\/p>\n<p>In working with this legacy code, there\u2019s been one very badly behaved class that\u2019s all pervasive, which the whole team have tripped over time and time again.<\/p>\n<p>In order to protect the guilty, I\u2019ll call it Mr. X although its real name is <i>SitePropertiesManager<\/i> as it manages the web site\u2019s properties. It\u2019s badly behaved because it:<\/p>\n<ul style=\"text-align: left\">\n<li>breaks the single responsibility principal<\/li>\n<li>has uses singleton pattern summarised by a getInstance() factory method,<\/li>\n<li>has an init() method that must be called before any other method,<\/li>\n<li>loads its data using direct access to the database rather than using a DAO,<\/li>\n<li>uses an complex map of maps to store its data,<\/li>\n<li>accesses the file system to cache data returned by the database<\/li>\n<li>has a timer to decide when up update its cache.<\/li>\n<li>was written before generics and has a multitude of superfluous findXXXX() methods.<\/li>\n<li>doesn\u2019t implement an interface,<\/li>\n<li>employs lots of copy and paste programming.<\/li>\n<\/ul>\n<p>This makes it hard to create stubs when writing unit tests for new code and leaves the legacy code littered with:<\/p>\n<pre class=\"brush:java\">SitePropertiesManager propman = SitePropertiesManager.getInstance();\r\n<\/pre>\n<p>This blog takes a look at ways of dealing with awkward characters and demonstrates how to create stubs for them, whilst negating the effect of the Singleton pattern. As with my previous Testing Techniques blogs, I\u2019m basing my demo code on my Address web app <a href=\"\/\/github.com\/roghughe\/captaindebug.git\">sample<\/a>.<\/p>\n<div class=\"separator\" style=\"clear: both;text-align: center\"><a href=\"http:\/\/3.bp.blogspot.com\/-yH4AkqVLOAg\/TrvNnaMIzKI\/AAAAAAAAAXk\/6xOz3GWqj9U\/s320\/Screen+Shot+2011-11-10+at+12.58.52.png\"><img decoding=\"async\" border=\"0\" src=\"http:\/\/3.bp.blogspot.com\/-yH4AkqVLOAg\/TrvNnaMIzKI\/AAAAAAAAAXk\/6xOz3GWqj9U\/s320\/Screen+Shot+2011-11-10+at+12.58.52.png\" \/><\/a><\/div>\n<p>In the other blogs in this series, I\u2019ve been demonstrating how to test the <i>AddressService<\/i> and this blog is no different. In this scenario, however, the <i>AddressService<\/i> has to load a site property and decide whether or not to return an address, but before we take a look at that I first of all needed the badly written <i>SitePropertiesManager<\/i> to play with. However, I don\u2019t own that code, so I\u2019ve written a stunt-double version, which breaks as many rules as I can think of. I\u2019m not going to bore you with the details here as all the source code for <i>SitePropertiesManager<\/i> is available at: git:\/\/github.com\/roghughe\/captaindebug.git<\/p>\n<p>As I said above, in this scenario, the <i>AddressService<\/i> is using a site property to determine if it\u2019s enabled. If it is, then it\u2019ll send back an address object. I\u2019m also going to pretend that the AddressService is some legacy code that uses the site properties static factory method as shown below:<\/p>\n<pre class=\"brush:java\">public Address findAddress(int id) {\r\n\r\n    logger.info(\"In Address Service with id: \" + id);\r\n\r\n    Address address = Address.INVALID_ADDRESS;\r\n\r\n    if (isAddressServiceEnabled()) {\r\n      address = addressDao.findAddress(id);\r\n      address = businessMethod(address);\r\n    }\r\n\r\n    logger.info(\"Leaving Address Service with id: \" + id);\r\n    return address;\r\n  }\r\n\r\n  private boolean isAddressServiceEnabled() {\r\n\r\n    SitePropertiesManager propManager = SitePropertiesManager.getInstance();\r\n    return new Boolean(propManager.findProperty(\"address.enabled\"));\r\n  }\r\n<\/pre>\n<p>In taming this type of class, he first thing to do is to stop using <i>getInstance()<\/i> to get hold and an object, removing it from the above method and to start using dependency injection. There has to be at least one call to <i>getInstance()<\/i>, but that can go somewhere in the program\u2019s start-up code. In the Spring world, the solution is to wrap a badly behaved class in a Spring FactoryBean implementation, which becomes the sole location of <i>getInstance()<\/i> in your application &#8211; at least for new \/ enhancement code.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java\">public class SitePropertiesManagerFactoryBean implements\r\n    FactoryBean {\r\n\r\n  private static SitePropertiesManager propsManager = SitePropertiesManager\r\n      .getInstance();\r\n\r\n  @Override\r\n  public SitePropertiesManager getObject() throws Exception {\r\n\r\n    return propsManager;\r\n  }\r\n\r\n  @Override\r\n  public Class getObjectType() {\r\n\r\n    return SitePropertiesManager.class;\r\n  }\r\n\r\n  @Override\r\n  public boolean isSingleton() {\r\n\r\n    return true;\r\n  }\r\n}\r\n<\/pre>\n<p>This can now be autowired into the AddressService class:<\/p>\n<pre class=\"brush:java\">@Autowired\r\n  void setPropertiesManager(SitePropertiesManager propManager) {\r\n    this.propManager = propManager;\r\n  }\r\n<\/pre>\n<p>These changes, however, don\u2019t mean that we can write some proper unit tests for <i>AddressService<\/i>, they just prepare the ground. The next step is to extract an interface for <i>SitePropertiesManager<\/i>, which is easily achieved using eclipse.<\/p>\n<pre class=\"brush:java\">public interface PropertiesManager {\r\n\r\n  public abstract String findProperty(String propertyName);\r\n\r\n  public abstract String findProperty(String propertyName, String locale);\r\n\r\n  public abstract List findListProperty(String propertyName);\r\n\r\n  public abstract List findListProperty(String propertyName, String locale);\r\n\r\n  public abstract int findIntProperty(String propertyName);\r\n\r\n  public abstract int findIntProperty(String propertyName, String locale);\r\n\r\n}\r\n<\/pre>\n<p>In moving to interfaces, we also need to manually configure an instance of <i>SitePropertiesManager<\/i> in the Spring config file so that Spring knows which class to connect to what interface: <\/p>\n<pre class=\"brush:xml\">&lt;beans:bean id=\"propman\" class=\"com.captaindebug.siteproperties.SitePropertiesManager\" \/&gt;\r\n<\/pre>\n<p>We also need to update the <i>AddressService\u2019s<\/i> <i>@Autowired<\/i> annotation with a qualifier:<\/p>\n<pre class=\"brush:java\">@Autowired\r\n  @Qualifier(\"propman\")\r\n  void setPropertiesManager(PropertiesManager propManager) {\r\n    this.propManager = propManager;\r\n  }\r\n<\/pre>\n<p>With an interface, we can now easily write a simple <i>SitePropertiesManager<\/i> stub:<\/p>\n<pre class=\"brush:java\">public class StubPropertiesManager implements PropertiesManager {\r\n\r\n  private final Map propMap = new HashMap();\r\n\r\n  public void setProperty(String key, String value) {\r\n    propMap.put(key, value);\r\n  }\r\n\r\n  @Override\r\n  public String findProperty(String propertyName) {\r\n    return propMap.get(propertyName);\r\n  }\r\n\r\n  @Override\r\n  public String findProperty(String propertyName, String locale) {\r\n    throw new UnsupportedOperationException();\r\n  }\r\n\r\n  @Override\r\n  public List findListProperty(String propertyName) {\r\n    throw new UnsupportedOperationException();\r\n  }\r\n\r\n  @Override\r\n  public List findListProperty(String propertyName, String locale) {\r\n    throw new UnsupportedOperationException();\r\n  }\r\n\r\n  @Override\r\n  public int findIntProperty(String propertyName) {\r\n    throw new UnsupportedOperationException();\r\n  }\r\n\r\n  @Override\r\n  public int findIntProperty(String propertyName, String locale) {\r\n    throw new UnsupportedOperationException();\r\n  }\r\n}\r\n<\/pre>\n<p>From having stub, it\u2019s pretty easy to write a unit test for the <i>AddressService<\/i> that uses the stub and is isolated from the database and the file system<\/p>\n<pre class=\"brush:java\">public class AddressServiceUnitTest {\r\n\r\n  private StubAddressDao addressDao;\r\n\r\n  private StubPropertiesManager stubProperties;\r\n\r\n  private AddressService instance;\r\n\r\n  @Before\r\n  public void setUp() {\r\n    instance = new AddressService();\r\n\r\n    stubProperties = new StubPropertiesManager();\r\n    instance.setPropertiesManager(stubProperties);\r\n  }\r\n\r\n  @Test\r\n  public void testAddressSiteProperties_AddressServiceDisabled() {\r\n\r\n    \/* Set up the AddressDAO Stubb for this test *\/\r\n    Address address = new Address(1, \"15 My Street\", \"My Town\", \"POSTCODE\",\r\n        \"My Country\");\r\n    addressDao = new StubAddressDao(address);\r\n    instance.setAddressDao(addressDao);\r\n\r\n    stubProperties.setProperty(\"address.enabled\", \"false\");\r\n\r\n    Address expected = Address.INVALID_ADDRESS;\r\n    Address result = instance.findAddress(1);\r\n\r\n    assertEquals(expected, result);\r\n  }\r\n\r\n  @Test\r\n  public void testAddressSiteProperties_AddressServiceEnabled() {\r\n\r\n    \/* Set up the AddressDAO Stubb for this test *\/\r\n    Address address = new Address(1, \"15 My Street\", \"My Town\", \"POSTCODE\",\r\n        \"My Country\");\r\n    addressDao = new StubAddressDao(address);\r\n    instance.setAddressDao(addressDao);\r\n\r\n    stubProperties.setProperty(\"address.enabled\", \"true\");\r\n\r\n    Address result = instance.findAddress(1);\r\n\r\n    assertEquals(address, result);\r\n  }\r\n}\r\n<\/pre>\n<p>All of which is pretty hunky-dory, but what happens if you can\u2019t extract an interface? I\u2019m saving that for another day&#8230;<\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/www.captaindebug.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html\">Creating Stubs for Legacy Code &#8211; Testing Techniques 6<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> <span class=\"post-author vcard\"><span class=\"fn\">Roger Hughes <\/span><\/span>at the <a href=\"http:\/\/www.captaindebug.com\/\">Captain Debug blog<\/a><\/p>\n<p><strong><i>Related Articles :<\/i><\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/testing-techniques-not-writing-tests.html\">Testing Techniques &#8211; Not Writing Tests<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/misuse-of-end-to-end-tests-testing.html\">The Misuse of End To End Tests &#8211; Testing Techniques 2<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/what-should-you-unit-test-testing.html\">What Should you Unit Test? &#8211; Testing Techniques 3<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/regular-unit-tests-and-stubs-testing.html\">Regular Unit Tests and Stubs &#8211; Testing Techniques 4<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/11\/unit-testing-using-mocks-testing.html\">Unit Testing Using Mocks &#8211; Testing Techniques 5<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/12\/more-on-creating-stubs-for-legacy-code.html\">More on Creating Stubs for Legacy Code &#8211; Testing Techniques 7<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/12\/why-you-should-write-unit-tests-testing.html\">Why You Should Write Unit Tests &#8211; Testing Techniques 8<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/12\/some-definitions-testing-techniques-9.html\">Some Definitions &#8211; Testing Techniques 9<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/02\/using-findbugs-to-produce-substantially.html\">Using FindBugs to produce substantially less buggy code<\/a><\/li>\n<li><a href=\"http:\/\/www.javacodegeeks.com\/2011\/07\/developing-and-testing-in-cloud.html\">Developing and Testing in the Cloud<\/a><\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Any one who reads this blog will probably have realised that at present I\u2019m working on a project that contains a whole bunch of legacy code that\u2019s large, expansive, and written without any tests what so ever. In working with this legacy code, there\u2019s been one very badly behaved class that\u2019s all pervasive, which the &hellip;<\/p>\n","protected":false},"author":65,"featured_media":176,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[274,273],"class_list":["post-663","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-junit","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Creating Stubs for Legacy Code - Testing Techniques 6 - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Any one who reads this blog will probably have realised that at present I\u2019m working on a project that contains a whole bunch of legacy code that\u2019s large,\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Creating Stubs for Legacy Code - Testing Techniques 6 - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Any one who reads this blog will probably have realised that at present I\u2019m working on a project that contains a whole bunch of legacy code that\u2019s large,\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2011-11-29T17:40:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-21T20:35:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Roger Hughes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Roger Hughes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html\"},\"author\":{\"name\":\"Roger Hughes\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c9feacaf8e783104a69621cd65bf1f07\"},\"headline\":\"Creating Stubs for Legacy Code &#8211; Testing Techniques 6\",\"datePublished\":\"2011-11-29T17:40:00+00:00\",\"dateModified\":\"2012-10-21T20:35:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html\"},\"wordCount\":783,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"keywords\":[\"JUnit\",\"Testing\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html\",\"name\":\"Creating Stubs for Legacy Code - Testing Techniques 6 - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"datePublished\":\"2011-11-29T17:40:00+00:00\",\"dateModified\":\"2012-10-21T20:35:12+00:00\",\"description\":\"Any one who reads this blog will probably have realised that at present I\u2019m working on a project that contains a whole bunch of legacy code that\u2019s large,\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2011\\\/11\\\/creating-stubs-for-legacy-code-testing.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Creating Stubs for Legacy Code &#8211; Testing Techniques 6\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/c9feacaf8e783104a69621cd65bf1f07\",\"name\":\"Roger Hughes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g\",\"caption\":\"Roger Hughes\"},\"sameAs\":[\"http:\\\/\\\/www.captaindebug.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Roger-Hughes\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Creating Stubs for Legacy Code - Testing Techniques 6 - Java Code Geeks","description":"Any one who reads this blog will probably have realised that at present I\u2019m working on a project that contains a whole bunch of legacy code that\u2019s large,","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html","og_locale":"en_US","og_type":"article","og_title":"Creating Stubs for Legacy Code - Testing Techniques 6 - Java Code Geeks","og_description":"Any one who reads this blog will probably have realised that at present I\u2019m working on a project that contains a whole bunch of legacy code that\u2019s large,","og_url":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2011-11-29T17:40:00+00:00","article_modified_time":"2012-10-21T20:35:12+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","type":"image\/jpeg"}],"author":"Roger Hughes","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Roger Hughes","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html"},"author":{"name":"Roger Hughes","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c9feacaf8e783104a69621cd65bf1f07"},"headline":"Creating Stubs for Legacy Code &#8211; Testing Techniques 6","datePublished":"2011-11-29T17:40:00+00:00","dateModified":"2012-10-21T20:35:12+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html"},"wordCount":783,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","keywords":["JUnit","Testing"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html","url":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html","name":"Creating Stubs for Legacy Code - Testing Techniques 6 - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","datePublished":"2011-11-29T17:40:00+00:00","dateModified":"2012-10-21T20:35:12+00:00","description":"Any one who reads this blog will probably have realised that at present I\u2019m working on a project that contains a whole bunch of legacy code that\u2019s large,","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2011\/11\/creating-stubs-for-legacy-code-testing.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Creating Stubs for Legacy Code &#8211; Testing Techniques 6"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/c9feacaf8e783104a69621cd65bf1f07","name":"Roger Hughes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/db9d1e5362dbc3f8007b383b852473b59fb8c5282a6066a13ab1cef761a9d5d6?s=96&d=mm&r=g","caption":"Roger Hughes"},"sameAs":["http:\/\/www.captaindebug.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Roger-Hughes"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/663","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/65"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=663"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/663\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/176"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=663"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=663"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=663"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}