<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>Nothing Too Serious</title>
	<atom:link href="http://www.jblewitt.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.jblewitt.com/blog</link>
	<description>Just another WordPress weblog</description>
	<pubDate>Sun, 11 Apr 2010 14:28:30 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Goals of Test Driven Development</title>
		<link>http://www.jblewitt.com/blog/?p=379</link>
		<comments>http://www.jblewitt.com/blog/?p=379#comments</comments>
		<pubDate>Sun, 11 Apr 2010 13:46:53 +0000</pubDate>
		<dc:creator>jim</dc:creator>
		
		<category><![CDATA[Software Architecture]]></category>

		<category><![CDATA[Software Development]]></category>

		<category><![CDATA[Technology]]></category>

		<category><![CDATA[Add new tag]]></category>

		<category><![CDATA[JUnit]]></category>

		<category><![CDATA[TDD]]></category>

		<category><![CDATA[test driven]]></category>

		<category><![CDATA[testability]]></category>

		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.jblewitt.com/blog/?p=379</guid>
		<description><![CDATA[Why should you adopt Test Driven Development?  The answer is actually more complex than many people think.
Of course we all want to have fully tested code to ensure that the code operates as expected.  We also want to ensure that any new features do not break existing functionality (regressions), but what other reasons are there?

1. [...]]]></description>
			<content:encoded><![CDATA[<p>Why should you adopt <a href="http://en.wikipedia.org/wiki/Test-driven_development">Test Driven Development</a>?  The answer is actually more complex than many people think.</p>
<p>Of course we all want to have fully tested code to ensure that the code operates as expected.  We also want to ensure that any new features do not break existing functionality (<a href="http://en.wikipedia.org/wiki/Software_regression" target="_blank">regressions</a>), but what other reasons are there?</p>
<p><span id="more-379"></span></p>
<p>1. <strong>Documenting code behavior by providing examples of usage:</strong> Developers can look at a unit test in order to better understand what the code is supposed to do.  A good test might also test exotic inputs (null values and invalid parameters) to ensure that they are handled correctly.  Such tests also demonstrate to readers of tests exactly what the code expects for input.  This is especially helpful when working in a team practicing &#8220;<a href="http://en.wikipedia.org/wiki/Extreme_Programming_Practices#Collective_code_ownership" target="_blank">Collective Code Ownership</a>&#8221; and in the highly likely case that a different developer will one day work on the code after the original author has moved on.</p>
<p>2. <strong>Ensure code testability:</strong> Writing unit tests for existing code can be a very frustrating experience, especially if code is too tightly coupled with other classes or a <a href="http://en.wikipedia.org/wiki/Test_harness" target="_blank">test harness</a> cannot easily be constructed.  The cost can easily outweight the benefit in such cases and often it is simply too expensive to write tests for more than small pieces of untested code.  If this happens then you might have to just accept that your code isn&#8217;t ever going to have decent <a href="http://en.wikipedia.org/wiki/Code_Coverage" target="_blank">test coverage</a>.  If tests are written before they are implemented then the implementation will implicitly be &#8220;testable&#8221;.  When new features are added to the class, it will be trivial to add a new unit test for the new logic.</p>
<p>3. <strong>Testable code is also well designed code:</strong> The reason why testable code is testable is because it has a clean separation of concerns and is usually well encapsulated.  This is means that your testable code is also well designed code.  Yes&#8230; <em>writing tests will actually improve your code design.</em></p>
<p>4. <strong>Trying out new code first helps make its API better:</strong> How many times have you written a class that you&#8217;ve been proud of only to find out that when you actually start using it you find yourself wishing that the interface had been ever so slightly different.  Often some subtle (and unforseen) reason surfaces once you start actually trying to use your code that means that you have to change the methods on that class.  By writing a test first you are creating a client for your code.  This gives you the opportunity to look at how the design of the class from a unique perspective.  Perhaps the method calls could be made more readable with some small change, or perhaps some of the parameters are superfluous.  By trying out your class before it even exists, you can write your implementation code with the knowledge that it will be easy to use by client code.</p>
<p>5. <strong>Refactoring becomes a breeze:</strong> Actually, you shouldn&#8217;t really refactor code unless it has a unit test ensuring its correct operation.  The unit test should be run frequently between refactoring steps to ensure that your changes do not in fact modify the class behavior.  If programmers can refactor with a safety net then they are much more likely to actually do it, meaning better code for everyone.</p>
<p><em>Notice that 3 of the benefits only apply if the test is written before the implementation (i.e. using Test Driven Development).  By writing tests afterwards you are doing at least the same amount of work but missing out on some key benefits.</em></p>
<p><strong>Writing unit tests does not always make sense however:</strong></p>
<p>Contrary to popular belief, writing unit tests does have a cost associated with it which may be greater than the benefit.  More often than not, unit tests are seen as a holy grail which should always be applied.  Simply writing tests does not automatically mean that your project will be fault free and it certainly doesn&#8217;t automatically mean that your team will be more effective.  Instead, it should to be looked at like an monetary investment.  You will be incurring a real cost with the hope of recouping some benefit.  It may be that you lose out if you are not careful, but equally you can reap huge benefits if you do it right.  You should consider whether or not the benefit outweighs the cost on a case by case basis.  The factors for consideration should be:</p>
<p>1.<strong> How many developers will work on this project during its life?</strong> Better code APIs and documentation through tests means that the need for unit tests increases with the number of developers working on the project.</p>
<p>2. <strong>What is the skill level of your developers? </strong>Writing a good unit test is not easy.  Having poorly written tests which test the implementation too rigidly, or that are non repeatable, or slow, or test only trivial logic may incur a great deal of maintenance overhead.  It might be worth investing in some training before blindly jumping on the TDD bandwagon.  Developers should know what makes a good unit test and what makes a bad one.</p>
<p>2. <strong>Where is the project in its lifetime?</strong> If a project is nearing the end of its life and you are sure that it won&#8217;t be developed further then writing tests might not make sense.  You are making an investment with the hope that you can reap a benefit in the future.  If there is no future for the project, then the effort could be better invested in other ways.  A project just starting out however can benefit greatly over its lifetime with little initial investment.</p>
<p><strong>On a final note:</strong></p>
<p>Generally, bad test practices breed more bad test practices and good test practices breed more good test practices.  A team that is not performing well with regard to unit testing will find it only gets harder and increasingly more expensive to start.  A well performing team will find that writing tests and refactoring becomes a breeze and will continues to do so.  If you want to make a really good job of it make sure that you get it right, right from the project kick off.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jblewitt.com/blog/?feed=rss2&amp;p=379</wfw:commentRss>
		</item>
		<item>
		<title>Getting The Context Path (Without a HttpRequest)</title>
		<link>http://www.jblewitt.com/blog/?p=365</link>
		<comments>http://www.jblewitt.com/blog/?p=365#comments</comments>
		<pubDate>Sat, 10 Apr 2010 16:06:00 +0000</pubDate>
		<dc:creator>jim</dc:creator>
		
		<category><![CDATA[Web Applications]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[servlet]]></category>

		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://www.jblewitt.com/blog/?p=365</guid>
		<description><![CDATA[Web programmers know that they shouldn&#8217;t go writing JSPs with the Context Path hard coded in them.
If you do the following:
   &#60;a href="/MyApp/path/to/controller/home.htm&#62; Home &#60;/a&#62;
You&#8217;ll notice that as soon as you decide to deploy your web application using a different name than &#8220;MyApp&#8221; then none of your links will work anymore.
To avoid this [...]]]></description>
			<content:encoded><![CDATA[<p>Web programmers know that they shouldn&#8217;t go writing JSPs with the Context Path hard coded in them.</p>
<p>If you do the following:</p>
<pre>   &lt;a href="/MyApp/path/to/controller/home.htm&gt; Home &lt;/a&gt;</pre>
<p>You&#8217;ll notice that as soon as you decide to deploy your web application using a different name than &#8220;MyApp&#8221; then none of your links will work anymore.<br />
To avoid this you need to get the context path from the HttpRequest object as follows:</p>
<pre>   &lt;a href="&lt;%=request.getContextPath() %&gt;/path/to/controller/home.htm&gt;
     Home
   &lt;/a&gt;</pre>
<p>or by using a JSTL tag:</p>
<pre>    &lt;a href="&lt;c:url value="/path/to/controller/home.htm"/&gt;"&gt; Home &lt;/a&gt;</pre>
<p>What happens when you are rendering HTML in your Java code and you don&#8217;t have access to a HttpRequest object for whatever reason?</p>
<p><span id="more-365"></span></p>
<p>You can of course define a global property somewhere and update it whenever the application name changes.  A nicer solution however would be to have the servlet context set the property automatically at startup.</p>
<p>To achieve this you will need to define a <a href="http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/ServletContext.html">ServletContextListener</a>:</p>
<pre>public class ContextRootListener implements ServletContextListener {

	@Override
	public void contextDestroyed(final ServletContextEvent event) {
	   // Do nothing
	}

	@Override
	public void contextInitialized(ServletContextEvent event) {
	   ServletContextInfo
              .setContextPath(event.getServletContext().getContextPath());
	}

}</pre>
<p><em> Note: ServletContextInfo is my property container class.  It contains static getters and setters in this example. </em></p>
<p>Then you&#8217;ll need to register it as a listener in your web.xml.</p>
<pre>	&lt;listener&gt;
		&lt;listener-class&gt;
                       com.snail.web.ContextRootListener
                &lt;/listener-class&gt;
	&lt;/listener&gt;</pre>
<p>After this is complete you can get the context root at anytime using the static <em>ServletContextInfo.getContextPath()</em> method.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jblewitt.com/blog/?feed=rss2&amp;p=365</wfw:commentRss>
		</item>
		<item>
		<title>POWDER Roguelike Game</title>
		<link>http://www.jblewitt.com/blog/?p=359</link>
		<comments>http://www.jblewitt.com/blog/?p=359#comments</comments>
		<pubDate>Sat, 10 Apr 2010 15:46:04 +0000</pubDate>
		<dc:creator>jim</dc:creator>
		
		<category><![CDATA[Gaming]]></category>

		<category><![CDATA[rogue]]></category>

		<guid isPermaLink="false">http://www.jblewitt.com/blog/?p=359</guid>
		<description><![CDATA[
POWDER proves that graphics really isn&#8217;t everything when it comes to games.  POWDER is a Roguelike game, which means that you kill monsters, gain levels, zap things with magical wands and generally get involved in all sorts of fantasy RPG shenanigans.  Classic Roguelikes of the likes of Nethack and Angband are purely ASCII based and [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-360" title="POWDER" src="http://www.jblewitt.com/blog/wp-content/uploads/2010/04/powder.png" alt="POWDER" width="522" height="413" /></p>
<p><a href="http://www.zincland.com/powder/index.php?pagename=about">POWDER</a> proves that graphics really isn&#8217;t everything when it comes to games.  <span class="me">POWDER is a <a href="http://en.wikipedia.org/wiki/Roguelike" target="_blank">Roguelike</a> game, which means that </span>you kill monsters, gain levels, zap things with magical wands and generally get involved in all sorts of fantasy RPG <span class="me">shenanigans.  Classic Roguelikes of the likes of <a href="http://en.wikipedia.org/wiki/Nethack" target="_blank">Nethack</a> and <a href="http://en.wikipedia.org/wiki/Angband" target="_blank">Angband</a> are purely ASCII based and (in my opinion) aren&#8217;t very accessible.  With POWDER the entire game can be played using the mouse, and the keyboard shortcuts can be picked up bit by bit once you&#8217;ve got into the game.<br />
</span></p>
<p>It has been designed with hand held consoles in mind, but can be downloaded and played on Windows and Linux alike from the <a href="http://www.zincland.com/powder/index.php?pagename=about">author&#8217;s web page</a>.</p>
<p>Behind a somewhat simplistic facade is a deep and complex game that will take you a very long time to master.  Each time you play (and die) there is something new to be learned for the next time you delve into the dungeon.  The first time I played the game indicated that I was hungry.  I decided to eat a slug that I had just killed, only to be poisoned and die.  Naturally I avoided doing that in subsequent attempts.   There is even a tutorial to help you get started.</p>
<p>A <a href="http://www.armoredtactics.com/powder/index.php/Main_Page" target="_blank">wiki</a> exists for impatient players who don&#8217;t want to find everything out for themselves.  I still haven&#8217;t figured out how to stop myself from starving to death once I get a bit deeper into the dungeon.</p>
<p><strong>Update:</strong> Two interesting things I also think are worth mentioning.</p>
<p>Roguelikes aren&#8217;t purely fantasy based.  There are a great deal of science fiction based games, include a version of <a href="http://doom.chaosforge.org/" target="_blank">Doom implemented in ASCII</a>.</p>
<p>Also, there is a <a href="http://roguebasin.roguelikedevelopment.org/index.php?title=7DRL" target="_blank">yearly competition</a> where programmers try to create a fully playable Roguelike in just 7 days.  The short time encourages programmers to try out and explore new ideas and end up with a finished product at the end.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jblewitt.com/blog/?feed=rss2&amp;p=359</wfw:commentRss>
		</item>
		<item>
		<title>Health and safety at work</title>
		<link>http://www.jblewitt.com/blog/?p=354</link>
		<comments>http://www.jblewitt.com/blog/?p=354#comments</comments>
		<pubDate>Tue, 17 Nov 2009 20:57:03 +0000</pubDate>
		<dc:creator>jim</dc:creator>
		
		<category><![CDATA[Fun]]></category>

		<category><![CDATA[Travel]]></category>

		<category><![CDATA[dangerous]]></category>

		<guid isPermaLink="false">http://www.jblewitt.com/blog/?p=354</guid>
		<description><![CDATA[This is a photo I took in Bejing a few years ago and have been meaning to upload it for ages.  The picture is of a couple of guys repairing a telephone line (or some sort of overhead cable).  The work was undertaken in the face of oncoming traffic.
]]></description>
			<content:encoded><![CDATA[<p>This is a photo I took in Bejing a few years ago and have been meaning to upload it for ages.  The picture is of a couple of guys repairing a telephone line (or some sort of overhead cable).  The work was undertaken in the face of oncoming traffic.</p>
<div class="wp-caption aligncenter" style="width: 160px"><a rel="lightbox" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/11/ladder_guy.jpg"><img class="aligncenter size-medium wp-image-355" title="ladder_guy" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/11/ladder_guy-199x300.jpg" alt="ladder_guy" width="199" height="300" /></a><p class="wp-caption-text">Street work in Bejing</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.jblewitt.com/blog/?feed=rss2&amp;p=354</wfw:commentRss>
		</item>
		<item>
		<title>Introducing JTestConnect</title>
		<link>http://www.jblewitt.com/blog/?p=347</link>
		<comments>http://www.jblewitt.com/blog/?p=347#comments</comments>
		<pubDate>Mon, 16 Nov 2009 18:51:26 +0000</pubDate>
		<dc:creator>jim</dc:creator>
		
		<category><![CDATA[Software Architecture]]></category>

		<category><![CDATA[Technology]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[TDD]]></category>

		<category><![CDATA[test driven]]></category>

		<category><![CDATA[unit testing]]></category>

		<guid isPermaLink="false">http://www.jblewitt.com/blog/?p=347</guid>
		<description><![CDATA[
A couple of months ago I finished the first version of JTestConnect.  It is a tool for supporting development teams with their unit test strategies.
You can annotate your interfaces/classes with annotations describing how the object should be tested.  The tool then sits in the build process and can interrupt a build if test [...]]]></description>
			<content:encoded><![CDATA[<p><a title="JTestConnect" href="http://jtestconnect.sourceforge.net/" target="_blank"><img class="aligncenter size-full wp-image-351" title="logo" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/11/logo.png" alt="logo" width="220" height="76" /></a></p>
<p>A couple of months ago I finished the first version of <a title="JTestConnect on Sourceforge" href="http://sourceforge.net/projects/jtestconnect/" target="_blank">JTestConnect</a>.  It is a tool for supporting development teams with their unit test strategies.</p>
<p>You can annotate your interfaces/classes with annotations describing how the object should be tested.  The tool then sits in the build process and can interrupt a build if test classes/methods are missing.</p>
<p>Ideally, this would be added to a Continuous Integration build system to enforce test coverage of important classes.</p>
<p>A more detailed description of what it does can be found on the <a title="JTestConnect home page" href="http://jtestconnect.sourceforge.net/" target="_blank">project home page</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jblewitt.com/blog/?feed=rss2&amp;p=347</wfw:commentRss>
		</item>
		<item>
		<title>Detecting HTML5 Features in Javascript</title>
		<link>http://www.jblewitt.com/blog/?p=344</link>
		<comments>http://www.jblewitt.com/blog/?p=344#comments</comments>
		<pubDate>Mon, 16 Nov 2009 18:40:36 +0000</pubDate>
		<dc:creator>jim</dc:creator>
		
		<category><![CDATA[Technology]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[Web Applications]]></category>

		<category><![CDATA[html5]]></category>

		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.jblewitt.com/blog/?p=344</guid>
		<description><![CDATA[How can you detect if your browser supports HTML5 features in javascript?  Here&#8217;s how:
function isHTML5CanvasSupported() {
    return (typeof HTMLCanvasElement != 'undefined');
}

function isHTML5VideoSupported() {
    return (typeof HTMLVideoElement != 'undefined');
}

function isHTMLClientSideDBSupported() {
    return (window.openDatabase);
}
Have fun!
]]></description>
			<content:encoded><![CDATA[<p>How can you detect if your browser supports HTML5 features in javascript?  Here&#8217;s how:</p>
<pre>function isHTML5CanvasSupported() {
    return (typeof HTMLCanvasElement != 'undefined');
}

function isHTML5VideoSupported() {
    return (typeof HTMLVideoElement != 'undefined');
}

function isHTMLClientSideDBSupported() {
    return (window.openDatabase);
}</pre>
<p>Have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jblewitt.com/blog/?feed=rss2&amp;p=344</wfw:commentRss>
		</item>
		<item>
		<title>A Nice Place For A Swim&#8230;</title>
		<link>http://www.jblewitt.com/blog/?p=330</link>
		<comments>http://www.jblewitt.com/blog/?p=330#comments</comments>
		<pubDate>Mon, 09 Mar 2009 21:12:47 +0000</pubDate>
		<dc:creator>jim</dc:creator>
		
		<category><![CDATA[Fun]]></category>

		<category><![CDATA[Travel]]></category>

		<guid isPermaLink="false">http://www.jblewitt.com/blog/?p=330</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<div id="attachment_331" class="wp-caption aligncenter" style="width: 160px"><a rel="lightbox" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/03/croc.jpg"><img class="size-thumbnail wp-image-331" title="crocodiles" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/03/croc-150x150.jpg" alt="A nice place for a swim!" width="150" height="150" /></a><p class="wp-caption-text">Near to Tikal in Northern Guatemala</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.jblewitt.com/blog/?feed=rss2&amp;p=330</wfw:commentRss>
		</item>
		<item>
		<title>Using EasyMock to Create Stub Objects</title>
		<link>http://www.jblewitt.com/blog/?p=316</link>
		<comments>http://www.jblewitt.com/blog/?p=316#comments</comments>
		<pubDate>Fri, 06 Mar 2009 15:48:53 +0000</pubDate>
		<dc:creator>jim</dc:creator>
		
		<category><![CDATA[Software Architecture]]></category>

		<category><![CDATA[Technology]]></category>

		<category><![CDATA[Uncategorized]]></category>

		<category><![CDATA[Web Applications]]></category>

		<category><![CDATA[EasyMock]]></category>

		<category><![CDATA[Java]]></category>

		<category><![CDATA[JUnit]]></category>

		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.jblewitt.com/blog/?p=316</guid>
		<description><![CDATA[There are two competing philosophies with regard to unit testing strategies; state based testing and behavior based testing. In state based testing we configure a starting state, execute a test method, and then examine the resultant state/returned result. In behavior driven testing we ensure that our test object collaborates with its dependencies in an expected [...]]]></description>
			<content:encoded><![CDATA[<p>There are two competing philosophies with regard to unit testing strategies; state based testing and behavior based testing. In state based testing we configure a starting state, execute a test method, and then examine the resultant state/returned result. In behavior driven testing we ensure that our test object collaborates with its dependencies in an expected way.</p>
<p><span id="more-316"></span></p>
<p>When applying a strictly state driven unit test strategy we can experience an explosion in the number of stub objects in our test code. Our System Under Test (SUT) requires dependencies that operate in a predetermined way (so that we can successfully predict the outcome/resultant state). This is more complex to set up, but gives the advantage that we are less fragile in the face of changes to our SUT implementation.</p>
<p>Our behavior driven brethren are laughing fanatically at our test strategy ideology, whilst enjoying the benefits of <a title="EasyMock" href="http://www.easymock.org/" target="_blank">EasyMock</a>.<br />
<a title="Mocks vs. Stubs" href="http://martinfowler.com/articles/mocksArentStubs.html#TheDifferenceBetweenMocksAndStubs" target="_blank">Mock objects are different to stub objects</a> in that they record behavior rather than returning canned values. EasyMock is a nice tool that allows us to record operations and expectations on classes, replay those expectations against the actual operations performed and then verify that what really occurred matches that which was expected. Easy mock makes building a test very easy, although if the implementation changes the order in which methods are called, or the parameters used, or indeed which methods are executed at all, our test may break. This can lead to tests which are potentially fragile, and difficult to maintain.</p>
<p>The ideal of testing purely for state rather than behavior is somewhat of a pipe dream however in that we still have to supply stub objects/dependencies so that our SUT can execute. We still need to make <em>some </em>assumptions about our implementation to know that it will fetch data from a particular stub, or that it will use a particular getter. It is more general however and a stub could be made general enough to support multiple test methods or multiple tests. Getting this right is what makes a unit test, a good unit test.</p>
<p>Wouldn&#8217;t it be nice if we could use a tool like EasyMock to generate our stubs, rather than program them over and over again, or maintaining a large set of shared stubs?   EasyMock is, thankfully, powerful enough to allow us to create stubs.</p>
<p>In the example we will create a stub for the following interface:</p>
<pre>public interface IMyService {

    public Integer getData();

    public String convert(Object object);

}</pre>
<p>The code that could be added to a unit test class to provide a stub for this interface with canned responses is as follows:</p>
<pre>/**
  * Sets up all mock objects.
  */
@Before
protected void prepareStubs() {
    this.myStubObject = EasyMock.createMock(IMyService.class);
    prepareStubResponses();
}

/**
 * Generates the canned responses.
 */
private void prepareStubResponses() {
    EasyMock.expect(this.myStubObject.getData()).andReturn(new Integer(5)).anyTimes();
    EasyMock.expect(this.myStubObject.convert(EasyMock.anyObject())).andReturn("ABC").anyTimes();
    EasyMock.checkOrder(this.myStubObject, false);
    EasyMock.replay(this.myStubObject);
}</pre>
<p>First we create the stub object, then we configure an expected call to &#8220;getData&#8221; and we return the canned response &#8220;new Integer(5)&#8221;. The important thing that we have done here is to relax the expected number of calls to &#8220;.anyTimes()&#8221;. This means that we are not interested in the number of executions. We also switch off the expected ordering of calls.   Setting &#8220;false&#8221; in check order means that EasyMock doesn&#8217;t care anymore if &#8220;getData&#8221; is called first, or if &#8220;convert&#8221; comes first.   Finally we replay the stub in order to &#8220;start&#8221; it.</p>
<p>There is a shorter way to implement this however using &#8220;andStubReturn(..)&#8221;.  The code would then look as follows:</p>
<pre>
private void prepareStubResponses() {
    EasyMock.expect(this.myStubObject.getData()).andStubReturn(new Integer(5));
    EasyMock.expect(this.myStubObject.convert(EasyMock.anyObject())).andStubReturn("ABC");
    EasyMock.replay(this.myStubObject);
}</pre>
<p>Using &#8220;andStubReturn(..)&#8221; instead of &#8220;andReturn(..)&#8221; means that the call can be made any number of times.  Order is no longer checked, so we can eliminate the &#8220;.anyTimes()&#8221; suffix and the order disabling command.</p>
<p>To further improve our stub code, we can use &#8220;EasyMock.createNiceMock(..)&#8221; instead of &#8220;EasyMock.createMock(..)&#8221;.  A &#8220;nice&#8221; mock always returns a value regardless of whether behavior has been specified or not, rather than causing an error.</p>
<p>We will never verify the stub, so we are not checking that the methods are called, we don&#8217;t care about the order or the number of executions. We simply state that if this method is called, this response is to be returned. The stub can still be made general enough to be shared between tests and it carries no <em>more </em>assumptions than creating an explicit stub does, but eliminates the burden of having lots of extra classes.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jblewitt.com/blog/?feed=rss2&amp;p=316</wfw:commentRss>
		</item>
		<item>
		<title>Security Conference 2009 Protests</title>
		<link>http://www.jblewitt.com/blog/?p=286</link>
		<comments>http://www.jblewitt.com/blog/?p=286#comments</comments>
		<pubDate>Sat, 07 Feb 2009 14:43:01 +0000</pubDate>
		<dc:creator>jim</dc:creator>
		
		<category><![CDATA[Politics]]></category>

		<category><![CDATA[conference]]></category>

		<category><![CDATA[photos]]></category>

		<category><![CDATA[protest]]></category>

		<guid isPermaLink="false">http://www.jblewitt.com/blog/?p=286</guid>
		<description><![CDATA[Some photos from the growing crowd protesting the Munich security conference.  The pictures were taken from Marienplatz (where the town hall is).  The birds eye view pictures were taken from the upper floors of a bookshop in the square.  I had been chatting away to a pair who were also enjoying the same [...]]]></description>
			<content:encoded><![CDATA[<p>Some photos from the growing crowd protesting the <a href="http://www.securityconference.de/">Munich security conference</a>.  The pictures were taken from Marienplatz (where the town hall is).  The birds eye view pictures were taken from the upper floors of a bookshop in the square.  I had been chatting away to a pair who were also enjoying the same vantage point.  I mentioned that I had asked myself whether or not it would be a good idea to go taking pictures of all the police and vehicles and what ever else.  One of them asked me &#8220;why?&#8221;, and I answered that &#8220;you never know&#8221;.  He seemed irritated at my apparent mistrust of the police.  I don&#8217;t mistrust the police (at least not in Germany), but you can always be in the wrong place at the wrong time.  As I walked away my girlfriend pointed out that they both had hidden walkie-talkies and were actually under cover police officers.  I went to the next floor up to get some more photos and noticed another man standing taking a picture with his mobile phone.  After a few seconds of me pointing and clicking (and chatting) I heard his hidden radio (turned down to not attract undue attention).  There were two more men on the top floor idly chatting with a bag at their feet and huddled against the window blocking the view.  I received a strange look as I approached them as if their fellow officers had radioed up for them to look out for a suspiciously chatty Englishman.<br />
<a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_1.jpg"><img class="alignnone size-thumbnail wp-image-287" title="g8_1" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_1-150x150.jpg" alt="g8_1" width="150" height="150" /></a><a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_2.jpg"><img class="alignnone size-thumbnail wp-image-288" title="g8_2" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_2-150x150.jpg" alt="g8_2" width="150" height="150" /></a><a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_3.jpg"><img class="alignnone size-thumbnail wp-image-289" title="g8_3" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_3-150x150.jpg" alt="g8_3" width="150" height="150" /></a><a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_4.jpg"><img class="alignnone size-thumbnail wp-image-290" title="g8_4" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_4-150x150.jpg" alt="g8_4" width="150" height="150" /></a><br />
<span id="more-286"></span><a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_5.jpg"><img class="alignnone size-thumbnail wp-image-291" title="g8_5" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_5-150x150.jpg" alt="g8_5" width="150" height="150" /></a><a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_6.jpg"><img class="alignnone size-thumbnail wp-image-292" title="g8_6" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_6-150x150.jpg" alt="g8_6" width="150" height="150" /></a><a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_7.jpg"><img class="alignnone size-thumbnail wp-image-293" title="g8_7" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_7-150x150.jpg" alt="g8_7" width="150" height="150" /></a><a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_8.jpg"><img class="alignnone size-thumbnail wp-image-294" title="g8_8" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_8-150x150.jpg" alt="g8_8" width="150" height="150" /></a><br />
<a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_9.jpg"><img class="alignnone size-thumbnail wp-image-295" title="g8_9" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_9-150x150.jpg" alt="g8_9" width="150" height="150" /></a><a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_10.jpg"><img class="alignnone size-thumbnail wp-image-296" title="g8_10" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_10-150x150.jpg" alt="g8_10" width="150" height="150" /></a><a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_11.jpg"><img class="alignnone size-thumbnail wp-image-297" title="g8_11" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_11-150x150.jpg" alt="g8_11" width="150" height="150" /></a><a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_12.jpg"><img class="alignnone size-thumbnail wp-image-298" title="g8_12" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_12-150x150.jpg" alt="g8_12" width="150" height="150" /></a><a rel="lightbox[g8]" href="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_13.jpg"><img class="alignnone size-thumbnail wp-image-299" title="g8_13" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/g8_13-150x150.jpg" alt="g8_13" width="150" height="150" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jblewitt.com/blog/?feed=rss2&amp;p=286</wfw:commentRss>
		</item>
		<item>
		<title>Random Number Generator</title>
		<link>http://www.jblewitt.com/blog/?p=278</link>
		<comments>http://www.jblewitt.com/blog/?p=278#comments</comments>
		<pubDate>Thu, 05 Feb 2009 20:37:28 +0000</pubDate>
		<dc:creator>jim</dc:creator>
		
		<category><![CDATA[Art]]></category>

		<category><![CDATA[Fun]]></category>

		<category><![CDATA[Technology]]></category>

		<category><![CDATA[cats]]></category>

		<category><![CDATA[GIMP]]></category>

		<category><![CDATA[pixel art]]></category>

		<category><![CDATA[random numbers]]></category>

		<guid isPermaLink="false">http://www.jblewitt.com/blog/?p=278</guid>
		<description><![CDATA[
]]></description>
			<content:encoded><![CDATA[<div id="attachment_279" class="wp-caption aligncenter" style="width: 470px"><img class="size-full wp-image-279" title="catrandom" src="http://www.jblewitt.com/blog/wp-content/uploads/2009/02/catrandom.png" alt="Random Numbers" width="460" height="335" /><p class="wp-caption-text">Random Numbers</p></div>
]]></content:encoded>
			<wfw:commentRss>http://www.jblewitt.com/blog/?feed=rss2&amp;p=278</wfw:commentRss>
		</item>
	</channel>
</rss>
