<?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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Transient Technology &#187; java</title>
	<atom:link href="http://martinaharris.com/category/development/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://martinaharris.com</link>
	<description>Next time you look it might be gone</description>
	<lastBuildDate>Tue, 24 Jan 2012 18:14:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Unitils update &#8211; TestListeners</title>
		<link>http://martinaharris.com/2012/01/unitils-update-testlisteners/</link>
		<comments>http://martinaharris.com/2012/01/unitils-update-testlisteners/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 18:08:02 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[ldap]]></category>
		<category><![CDATA[unitils]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=1108</guid>
		<description><![CDATA[In a previous post I got some help from Tim Ducheyne to work out a way to use a spring wired DataSource with Unitils.  He mentioned a better way was coming&#8230; Sometime back now they added the support for TestListener which &#8230; <a href="http://martinaharris.com/2012/01/unitils-update-testlisteners/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In a <a title="How to link unitils to a spring wired datasource" href="http://martinaharris.com/2010/05/unitils-spring-wired-datasource/">previous post</a> I got some help from Tim Ducheyne to work out a way to use a spring wired DataSource with Unitils.  He mentioned a better way was coming&#8230;</p>
<p>Sometime back now they added the support for TestListener which solves this issue.</p>
<p><a title="Unitils - TestListerer API" href="http://www.unitils.org/apidocs/org/unitils/core/TestListener.html">Unitils &#8211; TestListerer API</a></p>
<p>I don&#8217;t work with conventional databases much now, but was intrigued to see this post explaining how to extend unitils and use TestListeners to test ldap.  Neat eh!</p>
<p><a title="unitils library for enhance unit test by using annotation approach" href="http://blog.esofthead.com/unitils-library-for-enhance-unit-test-by-using-annotation-approach/">Extending Unitils to test LDap.</a></p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F&amp;title=Unitils+update+-+TestListeners" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F&amp;title=Unitils+update+-+TestListeners" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F&amp;title=Unitils+update+-+TestListeners" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F&amp;headline=Unitils+update+-+TestListeners" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Unitils+update+-+TestListeners&amp;url=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Unitils+update+-+TestListeners&amp;u=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Unitils+update+-+TestListeners&amp;url=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Unitils+update+-+TestListeners&amp;url=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Unitils+update+-+TestListeners&amp;url=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F&amp;title=Unitils+update+-+TestListeners&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2012%2F01%2Funitils-update-testlisteners%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2012/01/unitils-update-testlisteners/';
var dzone_title = 'Unitils update &#8211; TestListeners';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2012/01/unitils-update-testlisteners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The power of XMLUnit with google Predicate</title>
		<link>http://martinaharris.com/2010/12/the-power-of-xmlunit-with-google-predicate/</link>
		<comments>http://martinaharris.com/2010/12/the-power-of-xmlunit-with-google-predicate/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 22:46:19 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[filter]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[predicate]]></category>
		<category><![CDATA[XMLUnit]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=1069</guid>
		<description><![CDATA[I have been interested in XMLUnit and google collections predicate system for awhile now and recently wrote the following as part of a test.  I have removed some of the test and left just the bits that illustrate this point. The test needs &#8230; <a href="http://martinaharris.com/2010/12/the-power-of-xmlunit-with-google-predicate/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have been interested in <a title="XMLUnit on sourceforge" href="http://xmlunit.sourceforge.net/" target="_blank">XMLUnit</a> and <a title="Google Collections" href="http://code.google.com/p/google-collections/" target="_blank">google collections</a> predicate system for awhile now and recently wrote the following as part of a test.  I have removed some of the test and left just the bits that illustrate this point.</p>
<p>The test needs to perform a check that the result of transforming some xml is correct.  A reference file is available so we can use XMLUnit to perform a difference.  In my file there is a seconds attribute and because seconds vary with each parse we choose to ignore the value.  There are other ways to achieve this, but its more complex and uses more XMLUnit code. Using a google predicate simplifies this check.</p>
<p>First produce your output file and load the sample and output into strings.  Normally for a test I produce a smaller sample xml file.  Then using XMLUnit difference engine get all differences.</p>
<pre class="brush: java; gutter: false; wrap-lines: false">    Diff d = new Diff(expectedAsString, outputAsString);
    DetailedDiff dd = new DetailedDiff(d);
    List listOfDifferences = dd.getAllDifferences();
</pre>
<p>Next call a function to check that the only differences found are within the seconds attribute.  This uses a predicates from google to perform the matching.</p>
<pre class="brush: java; gutter: false; wrap-lines: false">
    assertTrue(onlyDiffsMatchThisAttributeName("seconds",listOfDifferences));
    }

    private static boolean onlyDiffsMatchThisAttributeName(final String attrName, Iterable it) {

    Iterable filtered = Iterables.filter(it, new Predicate() {

        @Override
        public boolean apply(Difference input) {

                final NodeDetail testNodeDetail = input.getTestNodeDetail();
                if (nodeDetail == null) return false;

                final Node node = nodeDetail.getNode();
                if (node == null) return false;

                final String nodeName = node.getNodeName();
                if (nodeName == null) return false;

                return !nodeName.equals(attrName);
            }
        });
        return (newArrayList(filtered).isEmpty());
    }</pre>
<p>Note that what is happening here is the predicate is filtering away all the seconds matches.  If anything remains in the list false is returned.  Neat huh!  <img src='http://martinaharris.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F&amp;title=The+power+of+XMLUnit+with+google+Predicate" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F&amp;title=The+power+of+XMLUnit+with+google+Predicate" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F&amp;title=The+power+of+XMLUnit+with+google+Predicate" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F&amp;headline=The+power+of+XMLUnit+with+google+Predicate" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=The+power+of+XMLUnit+with+google+Predicate&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=The+power+of+XMLUnit+with+google+Predicate&amp;u=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=The+power+of+XMLUnit+with+google+Predicate&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=The+power+of+XMLUnit+with+google+Predicate&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=The+power+of+XMLUnit+with+google+Predicate&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F&amp;title=The+power+of+XMLUnit+with+google+Predicate&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F12%2Fthe-power-of-xmlunit-with-google-predicate%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2010/12/the-power-of-xmlunit-with-google-predicate/';
var dzone_title = 'The power of XMLUnit with google Predicate';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2010/12/the-power-of-xmlunit-with-google-predicate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The idea of non backward compatible Java?</title>
		<link>http://martinaharris.com/2010/09/the-idea-of-non-backward-compatible-java/</link>
		<comments>http://martinaharris.com/2010/09/the-idea-of-non-backward-compatible-java/#comments</comments>
		<pubDate>Thu, 23 Sep 2010 20:19:42 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jvm]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=1065</guid>
		<description><![CDATA[I have not been blogging much, but I have been reading. Java is somewhat disappointing of late for various reasons.  Then I stumbled across this: the_next_big_jvm_language1 from Stephen Colebourne.  It seems like an interesting idea to me.  It would take some doing, &#8230; <a href="http://martinaharris.com/2010/09/the-idea-of-non-backward-compatible-java/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I have not been blogging much, but I have been reading. Java is somewhat disappointing of late for various reasons.  Then I stumbled across this: <a title="The next big JVM language" href="http://www.jroller.com/scolebourne/entry/the_next_big_jvm_language1" target="_blank">the_next_big_jvm_language1</a> from Stephen Colebourne.  It seems like an interesting idea to me.  It would take some doing, but the advantages could be huge.  It could encompass some of the best ideas and leave behind some of the old ideas we still struggle to shrug off.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F&amp;title=The+idea+of+non+backward+compatible+Java%3F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F&amp;title=The+idea+of+non+backward+compatible+Java%3F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F&amp;title=The+idea+of+non+backward+compatible+Java%3F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F&amp;headline=The+idea+of+non+backward+compatible+Java%3F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=The+idea+of+non+backward+compatible+Java%3F&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=The+idea+of+non+backward+compatible+Java%3F&amp;u=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=The+idea+of+non+backward+compatible+Java%3F&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=The+idea+of+non+backward+compatible+Java%3F&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=The+idea+of+non+backward+compatible+Java%3F&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F&amp;title=The+idea+of+non+backward+compatible+Java%3F&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F09%2Fthe-idea-of-non-backward-compatible-java%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2010/09/the-idea-of-non-backward-compatible-java/';
var dzone_title = 'The idea of non backward compatible Java?';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2010/09/the-idea-of-non-backward-compatible-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to link unitils to a spring wired datasource</title>
		<link>http://martinaharris.com/2010/05/unitils-spring-wired-datasource/</link>
		<comments>http://martinaharris.com/2010/05/unitils-spring-wired-datasource/#comments</comments>
		<pubDate>Mon, 31 May 2010 22:06:35 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[datasource]]></category>
		<category><![CDATA[how-to]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[unitils]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=963</guid>
		<description><![CDATA[Unitils provides its own DataSource. This causes problems if you want to use Spring IOC to inject your own. There is a way around this but its not elegant. In future versions of unitils I believe the team is going &#8230; <a href="http://martinaharris.com/2010/05/unitils-spring-wired-datasource/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://unitils.org/" target="_blank">Unitils</a> provides its own DataSource. This causes problems if you want to use Spring IOC to inject your own. There is a way around this but its not elegant. In future versions of unitils I believe the team is going to provide better support for less intrusive methods. This post documents a way to use your own spring defined DataSource.<br />
<span id="more-963"></span><br />
Currently there is a unitils property that allows you to specify your own SpringDataSourceFactory.</p>
<p># unitils.properties</p>
<p># Assign the SpringDataSourceFactory DataSource.<br />
org.unitils.database.config.DataSourceFactory.implClassName= com.tek.design.unitils.SpringDataSourceFactory</p>
<p>Write your SpringDataSourceFactory and implement both DataSourceFactory and springs ApplicationContextAware interfaces. Then in the init method you will be able to fetch your spring DataSource bean from the application context using a service look up. Not ideal, but until future releases it will do just fine.</p>
<pre class="brush: java; gutter: false">package com.tek.design.unitils;

import java.util.Properties;
import javax.sql.DataSource;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.unitils.database.config.DataSourceFactory;

/**
 *
 * Unitil's provides a way to override the default DataSourceFactory.  This class provides facility to
 * spring wire in the same datasource used by your ORM by fetching it from the ApplicationContext.
 *
 * Use the org.unitils.database.config.DataSourceFactory.implClassName property to supply this factory to unitils.
 *
 */
public class SpringDataSourceFactory implements DataSourceFactory, ApplicationContextAware {

    private static ApplicationContext appContext;

    private DataSource dataSource;

    @Override
    public DataSource createDataSource() {
        return this.dataSource;
    }

    @Override
    public void init(Properties arg0) {

        if (null == this.dataSource) {
            String dataSourceBeanName = "TekDesignDataSource";
            this.dataSource = (DataSource) appContext.getBean(dataSourceBeanName);
            if (this.dataSource == null) {
                throw new SpringBeanLookupException(DataSource.class, "Cant find bean named " + dataSourceName);
            }
        }

    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        appContext = applicationContext;

    }

}</pre>
<h2>Full unitils properties file:</h2>
<p># unitils.properties</p>
<p># Provide a CSV of all used database schemas. ie schema1,schema2.<br />
# The first schema name is the default one.<br />
# If no schema name is specified in a dbunit data set the default one is used.<br />
#<br />
# A schema names are case sensitive when surrounded by database identifier quotes (e.g. &#8220;&#8221; for oracle)<br />
#<br />
# Example unitils description using a schema<br />
#<br />
#&lt;dataset xmlns:frt=&#8221;FRUIT&#8221;&gt;<br />
#   &lt;frt:APPLE NAME=&#8221;COX&#8221;<br />
#                           DESCRIPTION=&#8221;[null]&#8221; /&gt;<br />
#&lt;/dataset&gt;<br />
#<br />
database.schemaNames=fruit,veg</p>
<p># This property specifies the underlying DBMS implementation. Supported values are &#8216;oracle&#8217;, &#8216;db2&#8242;, &#8216;mysql&#8217;, &#8216;hsqldb&#8217;,<br />
# &#8216;postgresql&#8217;, &#8216;derby&#8217; and &#8216;mssql&#8217;. The value of this property defines which vendor specific implementations of<br />
# DbSupport and ConstraintsDisabler are chosen.<br />
database.dialect=oracle</p>
<p># The dao tests often share the same data in the setup files, so its important to<br />
# rollback between tests otherwise constraints will be violated.<br />
DatabaseModule.Transactional.value.default=rollback</p>
<p># Assign the SpringDataSourceFactory DataSource.<br />
org.unitils.database.config.DataSourceFactory.implClassName=<br />
com.tek.design.unitils.SpringDataSourceFactory</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F&amp;title=How+to+link+unitils+to+a+spring+wired+datasource" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F&amp;title=How+to+link+unitils+to+a+spring+wired+datasource" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F&amp;title=How+to+link+unitils+to+a+spring+wired+datasource" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F&amp;headline=How+to+link+unitils+to+a+spring+wired+datasource" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=How+to+link+unitils+to+a+spring+wired+datasource&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=How+to+link+unitils+to+a+spring+wired+datasource&amp;u=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=How+to+link+unitils+to+a+spring+wired+datasource&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=How+to+link+unitils+to+a+spring+wired+datasource&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=How+to+link+unitils+to+a+spring+wired+datasource&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F&amp;title=How+to+link+unitils+to+a+spring+wired+datasource&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funitils-spring-wired-datasource%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2010/05/unitils-spring-wired-datasource/';
var dzone_title = 'How to link unitils to a spring wired datasource';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2010/05/unitils-spring-wired-datasource/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Unit Testing with a GigaSpaceFactoryBean</title>
		<link>http://martinaharris.com/2010/05/unit-testing-gigaspacefactorybean/</link>
		<comments>http://martinaharris.com/2010/05/unit-testing-gigaspacefactorybean/#comments</comments>
		<pubDate>Mon, 24 May 2010 10:29:26 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[gigaspacefactorybean]]></category>
		<category><![CDATA[gigaspaces]]></category>
		<category><![CDATA[junit]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=976</guid>
		<description><![CDATA[I was talking to Shay Banon (Gigaspace Software Architect) he mentioned using GigaSpaceFactoryBean for writing gigaspace unit tests. I could find no examples on their site, although I concede it may be there somewhere. This shows post shows a simple &#8230; <a href="http://martinaharris.com/2010/05/unit-testing-gigaspacefactorybean/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was talking to <span class="conn-name">Shay </span><span class="conn-name">Banon</span> (Gigaspace Software Architect) he mentioned using GigaSpaceFactoryBean for writing gigaspace unit tests.  I could find no examples on their site, although I concede it may be there somewhere.  This shows post shows a simple example.</p>
<p>He also mentioned using the admin api to do full end to end integration testing.  The admin api has huge potential as its able to control gigaspace containers, deploy into them and collect statistics.  Its a powerful api.</p>
<p>This is documented on their site: <a title="GS Admin API" href="http://www.gigaspaces.com/wiki/display/XAP7/Administration+and+Monitoring+API" target="_blank">http://www.gigaspaces.com/wiki/display/XAP7/Administration+and+Monitoring+API</a><br />
<span id="more-976"></span></p>
<h2>Example unit test using GigaSpaceFactoryBean</h2>
<p>The GigaSpaceFactoryBean does have javadoc: <a title="GIgaSpaceFactoryBean API" href="http://www.gigaspaces.com/docs/JavaDoc7.1/index.html" target="_blank">http://www.gigaspaces.com/docs/JavaDoc7.1/index.html</a>.  It can be used to provide a unit test with a gigaspace implementation for the duration of the test.</p>
<h3>Step 1 Provide a spring definition of the GigaSpaceFactoryBean</h3>
<pre class="brush: xml; gutter: false">&lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:os-core="http://www.openspaces.org/schema/core"
xmlns:os-events="http://www.openspaces.org/schema/events"
xmlns:os-remoting="http://www.openspaces.org/schema/remoting"
xmlns:os-sla="http://www.openspaces.org/schema/sla"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://www.openspaces.org/schema/core http://www.openspaces.org/schema/core/openspaces-core.xsd
http://www.openspaces.org/schema/events http://www.openspaces.org/schema/events/openspaces-events.xsd
http://www.openspaces.org/schema/remoting http://www.openspaces.org/schema/remoting/openspaces-remoting.xsd
http://www.openspaces.org/schema/sla http://www.openspaces.org/schema/sla/openspaces-sla.xsd"&gt;

&lt;os-core:local-tx-manager id="gs.transactionManager" space="testGigaSpace" default-timeout="1000" /&gt;
&lt;os-core:space id="testGigaSpace" url="/./my-test-pu" /&gt;

&lt;bean id="gigaSpace"&gt;
&lt;property name="space" ref="testGigaSpace" /&gt;
&lt;property name="transactionManager" ref="gs.transactionManager" /&gt;
&lt;/bean&gt;</pre>
<p>Follow with other beans needed by the test.  I.e service beans and their dependencies.  Note that the space defined here will also need to be injected into services that need it.  So you will need to use the same bean id.  Careful separation of the spring files means you will be able to substitute a test space for the real one during testing.</p>
<h3>Step 2 Write a unit test</h3>
<pre class="brush: java; gutter: false; wrap-lines: false">@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/somewhere/sometest-pu.xml")
public class SomeGigaspaceTest {

    @Resource
	private ServiceUnderTest myservice;

    @Resource
    private GigaSpace gigaSpace;

    @Before
    public void setUp() {

        // Setup anything you may wish to be
        // in the space before the test starts.
        this.gigaSpace.write(stuff);

    }

    @Test
    public void testSomething() throws InterruptedException {

        ImmutableSet dataFromGS = this.myservice.getStuff();
        assertFalse(dataFromGS.isEmpty());
        assertThat(dataFromGS.size(), is(100));

    }</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F&amp;title=Unit+Testing+with+a+GigaSpaceFactoryBean" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F&amp;title=Unit+Testing+with+a+GigaSpaceFactoryBean" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F&amp;title=Unit+Testing+with+a+GigaSpaceFactoryBean" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F&amp;headline=Unit+Testing+with+a+GigaSpaceFactoryBean" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;u=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F&amp;title=Unit+Testing+with+a+GigaSpaceFactoryBean&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Funit-testing-gigaspacefactorybean%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2010/05/unit-testing-gigaspacefactorybean/';
var dzone_title = 'Unit Testing with a GigaSpaceFactoryBean';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2010/05/unit-testing-gigaspacefactorybean/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tumble dried BDD from Studio Pragmatists</title>
		<link>http://martinaharris.com/2010/05/tumble-dried-bdd/</link>
		<comments>http://martinaharris.com/2010/05/tumble-dried-bdd/#comments</comments>
		<pubDate>Fri, 21 May 2010 22:02:32 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[scrum and agile]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[behavior]]></category>
		<category><![CDATA[collaboration]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[product-owner]]></category>
		<category><![CDATA[scrum]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[teams]]></category>
		<category><![CDATA[test-specialist]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=1027</guid>
		<description><![CDATA[On the 18th of May, 2010, the very new tumbler-glass project by Studio Pragmatists uploaded Tumbler 0.2.1 to Maven.  Having recently written about JBehave I found myself really liking the concept of behavior driven development.  So I decided to write &#8230; <a href="http://martinaharris.com/2010/05/tumble-dried-bdd/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>On the 18th of May, 2010, the very new tumbler-glass project by <a title="Studio Pragmatists Blog" href="http://studiopragmatists.blogspot.com/" target="_blank">Studio Pragmatists</a> uploaded Tumbler 0.2.1 to Maven.  Having recently written about <a title="JBehave article" href="/2010/05/bad-or-good-bdd-within-scrum/" target="_blank">JBehave</a> I found myself really liking the concept of behavior driven development.  So I decided to write a similar article about Tumbler.  If you want the project code its available in my <a title="Testing Project" href="http://github.com/mhgit/TerribleJavaTestingMadeGood" target="_blank">example project</a>.</p>
<h2>4 hour time box in 20 minutes!</h2>
<p>Once again I decided to time box the work to 4 hours.  This time though the whole process only took about 20 minutes.  The product owner and testers produce a story file.  The Tumbler format allows for multiple stories each containing scenarios, so its possible to cover a complex set of requirements in one file.  This allows for flexibility when breaking down the work into tasks.  As per the usual behavior driven approach, a scenario contains the <strong>Given</strong>, <strong>When</strong> and <strong>Then</strong> sections which describe the behavior.<span id="more-1027"></span></p>
<h3>A simple tumbler behavior file</h3>
<pre>Story: Building a simple page

Scenario: should create a page 4 lines long with 5 data items in each line
Given a data fixture capable of complex page checking
When a page is created with 'twenty' items on a page
Then there should be 'four' lines on a page with 'five' data items on each line</pre>
<h2>Generating the Java files</h2>
<p>The next step is to generate java from the scenario files I used an eclipse run configuration but the command line is:</p>
<pre>java -classpath Tumbler.jar tumbler.ScenarioToJavaConverter YOUR_STORY.scenario</pre>
<p>For the above scenario this was the result.  Note the generation of given, when and then methods and @story, @Scenario annotations that match up with the original file.</p>
<pre class="brush: java; gutter: false; wrap-lines: false">import org.junit.*;
import static org.junit.Assert.*;
import static tumbler.Tumbler.*;

@RunWith(TumblerRunner.class)
@Story("Building a simple page")
public class BuildingASimplePageScenarios {

        @Scenario(pending = true)
        public void shouldCreateAPage4LinesLongWith5DataItemsInEachLine() {
                given("a data fixture capable of complex page checking");

                when("a page is created with 'twenty' items on a page");

                then("there should be 'four' lines on a page with 'five' data items on each line");
        }
}</pre>
<h3>Which just leaves filling in the behavior and the actual test</h3>
<pre class="brush: java; gutter: false; wrap-lines: false">@RunWith(TumblerRunner.class)
@Story("Building a simple page")
public class BuildingASimplePageScenarios {
	private SimplePage page;

	@Scenario(pending = false)
	public void shouldCreateAPage4LinesLongWith5DataItemsInEachLine() {
		given("a data fixture capable of complex page checking");
		final PageDataFixture dataFixture = new PageDataFixture();

		when("a page is created with 'twenty' items on a page");
		page = SimplePage.newInstance(dataFixture.getDataItem(), 20);

		then("there should be 'four' lines on a page with 'five' data items on each line");
		Map expectedLines = dataFixture.createPageExpectation(4, 5);

		Map actualMap = page.getMap();

		assertThat(actualMap, is(expectedLines));
       }
}</pre>
<p>Finally there are two flags that can be applied to the test runner which turn on the production of a report. (-DgenerateReport=html -DoutputFolder=target)  It would be easy to configure a maven profile that picked up all your scenario files, and passed in these two flags.  The standard report uses Freemarker so it would be easy to produce your own.  Its a simple list of scenarios and their detail.</p>
<h3>This is what my report looked like</h3>
<div id="attachment_1038" class="wp-caption alignnone" style="width: 160px"><a href="http://martinaharris.com/wp-content/uploads/2010/05/tumblerReport.jpg"><img class="size-thumbnail wp-image-1038" title="tumblerReport" src="http://martinaharris.com/wp-content/uploads/2010/05/tumblerReport-150x150.jpg" alt="Tumbler Report" width="150" height="150" /></a><p class="wp-caption-text">Tumbler Report - Scenario Detail Page</p></div>
<h2>Good Points</h2>
<ul>
<li>As per JBehave I like the attempt to draw the product owner closer to the testing and development team members.</li>
<li>Its a very simple system with very small learning curve</li>
<li>Generating the Java improves productivity and allows the product owner to work on separate artifacts</li>
</ul>
<h2>Bad Points</h2>
<ul>
<li>Currently its a very early beta release.  Not so much a criticism as a reminder that things might evolve in a breaking fashion at this stage.</li>
<li>I would like to see the ability to generate parameters out of the scenario files.  If not, then a way to edit the tests to introduce parameter driven testing.</li>
<li>Scrum and agile are iterative.  Adding to the original scenario files would mean generating the classes again.  This leaves the developer with the unpleasant task of transferring over changes. This might be solved if the inputs were the scenario file, and the finished test Java, with output that modifies and adds.  Running them would show the breaks if the parameters were also part of the generation.</li>
</ul>
<h2>Conclusion</h2>
<p>I can&#8217;t wait to see a full version, or at least a release candidate version because I can see a future for this project.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F&amp;title=Tumble+dried+BDD+from+Studio+Pragmatists" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F&amp;title=Tumble+dried+BDD+from+Studio+Pragmatists" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F&amp;title=Tumble+dried+BDD+from+Studio+Pragmatists" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F&amp;headline=Tumble+dried+BDD+from+Studio+Pragmatists" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Tumble+dried+BDD+from+Studio+Pragmatists&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Tumble+dried+BDD+from+Studio+Pragmatists&amp;u=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Tumble+dried+BDD+from+Studio+Pragmatists&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Tumble+dried+BDD+from+Studio+Pragmatists&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Tumble+dried+BDD+from+Studio+Pragmatists&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F&amp;title=Tumble+dried+BDD+from+Studio+Pragmatists&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Ftumble-dried-bdd%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2010/05/tumble-dried-bdd/';
var dzone_title = 'Tumble dried BDD from Studio Pragmatists';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2010/05/tumble-dried-bdd/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bad or Good? Behavior Driven Development within Scrum.</title>
		<link>http://martinaharris.com/2010/05/bad-or-good-bdd-within-scrum/</link>
		<comments>http://martinaharris.com/2010/05/bad-or-good-bdd-within-scrum/#comments</comments>
		<pubDate>Mon, 17 May 2010 17:46:35 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[scrum and agile]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[agile]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[BDD]]></category>
		<category><![CDATA[behavior]]></category>
		<category><![CDATA[collaboration]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[product-owner]]></category>
		<category><![CDATA[scrum]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[teams]]></category>
		<category><![CDATA[test-specialist]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=1001</guid>
		<description><![CDATA[I wanted to explore the possibility of using JBehave to formalise scrums definition of done. The idea being to encapsulate a definition of done as a JBehave scenario. So in true scrum style I decided to timebox 4 hours of &#8230; <a href="http://martinaharris.com/2010/05/bad-or-good-bdd-within-scrum/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I wanted to explore the possibility of using <a title="JBehave about" href="http://jbehave.org/reference/stable/index.html" target="_blank">JBehave</a> to formalise scrums definition of done.  The idea being to encapsulate a definition of done as a JBehave scenario.  So in true scrum style I decided to timebox 4 hours of work dedicated to JBehave.</p>
<p>From a scrum point of view BDD can be used to turn the definition of done into a test artifact. The team produces scenarios for each task.  With JBehave a scenario file describes the required behavior and test steps it will need to pass to be considered done.  I.e Given some prerequisites, perform some action and expect some results.  See the JBehave project for more detail as this is only a simple example.<span id="more-1001"></span></p>
<h2>BDD in 4 hours?</h2>
<p>So scenarios are just text files describing the required functionality in terms of expected behavior.  Even before development though, its possible to run them and see the pending expectations.  Lets wizz though a simple example showing who in a scrum team is responsible for what.  I already have a project that I use to <a title="Testing Project" href="http://github.com/mhgit/TerribleJavaTestingMadeGood" target="_blank">explore test patterns</a> so I thought I would just introduce it to that.  If you want the working version just take a fork from github.</p>
<p>Nb. I have a data fixture used in testing a complex page component.  So whilst not a pure scenario I can make its existence part of the Givens.  In this project, its likely that no real given is required, but a developer would add it during the build.</p>
<p><strong>First</strong> the product owner and tester produce a simple scenario file describing behavior and expectations.</p>
<pre>Given a data fixture
When a page is created with 20 items on a page
Then expected lines on a page is 4 with data items in a line 5</pre>
<p><strong>Next</strong> developers write a harness and flesh out the steps required to meet the behaviour.</p>
<p>We need to bootstrap the scenario and add steps to it.  The general idea is to have a scenario test, that then includes the steps.  This is one way of bootstrapping in the steps, other ways are available including a spring system that uses <a title="SpringStepsFactory API" href="http://jbehave.org/reference/stable/javadoc/spring/org/jbehave/scenario/steps/spring/SpringStepsFactory.html" target="_blank">SpringStepsFactory</a>.  I ran into problems with the spring system as my project uses spring 3 and JBehave is still locked into spring 2.5.6.  In addition I am using junit 4.8 and spring 2.5.6 requires 4.4.  This is ultimately an issue as on many projects.  I would not want to tie in those older versions.  In fact other ideas in my project prevent me from doing this too.  So in my timebox I avoid the issue and bootstrap manually.</p>
<h2>The Bootstrap test class</h2>
<pre class="brush: java; gutter: false; wrap-lines: false">public class SimplePageScenario extends JUnitScenario {
	public SimplePageScenario() {
		super(new MostUsefulConfiguration() {
			@Override
			public ScenarioDefiner forDefiningScenarios() {
				return new ClasspathScenarioDefiner(
						new UnderscoredCamelCaseResolver(".scn"),
						new PatternScenarioParser());
                        }
                });

		addSteps(new SimplePageSteps());
        }
}</pre>
<p>Before adding the call to addSteps()) running the scenario shows the steps that are pending.</p>
<pre>(org/testpatterns/scenarios/example_scenario.scn)
Scenario:
Given a spring data fixture (PENDING)
When a page is created with 20 items on a page (PENDING)
Then expected lines on a page is 4 with data items in a line 5 (PENDING)</pre>
<p><strong>Finally</strong> the developers fill in the Steps class adding sections that match against the scenario keywords, Given, When and Then.  Development is done until the behavior passes the test.</p>
<pre class="brush: java; gutter: false; wrap-lines: false">public class SimplePageSteps extends Steps {

	private SimplePage page;

	private final PageDataFixture dataFixture = new PageDataFixture();

	@Given("a data fixture")
	public void givenASpringDataFixture() {
		notNull(dataFixture);
	}

	@When("a page is created with $itemsOnAPage items on a page")
	public void createPage(int itemsOnAPage) {
		page = SimplePage.newInstance(dataFixture.getDataItem(), itemsOnAPage);
	}

	@Then("expected lines on a page is $linesOnAPage with data items in a line $itemsInALine")
	public void validatePage(int linesOnAPage, int itemsInALine) {
		Map expectedLines = dataFixture.createPageExpectation(linesOnAPage, itemsInALine);

		Map actualMap = page.getMap();

		ensureThat(actualMap, is(expectedLines));
	}

}</pre>
<h2>Good Points</h2>
<ul>
<li> I like the potential to get key scrum members interacting.  The collaboration between the testers and product owner is an important one as it should flesh out questions about behaviour at an early stage.  Similar benefits occur when the development team starts to get to grip with the behavior.</li>
<li> Having a simple scenario artifact means the product owner can get involved with something that actually becomes part of the continuous integration.</li>
</ul>
<h2>Bad Points</h2>
<ul>
<li>The bootstrap is clumsy.  Having to add steps means that after producing the new scenarios development have to get involved before the pending steps appear.  There are other ways to bootstrap.  The spring system is a step in the right direction, in fact I would like to use injection throughout the application.  This still does not solve the problem of having to edit something before the steps appear.  I would prefer that once the scenario is in place, steps are automatically found as they are written, and appear as not started until they are cut.</li>
<li> Extending Junit Testcase is also a problem.  Its highly likely that in more complex projects we would need mocking techniques or spring based tests.  These have their own runners brought in with the @RunWith annotation.  It would be better if there were some way to bootstrap the behaviour into any other test framework.</li>
<li> In my 4 hour timebox I did not get the reporting working.  Unfortunately the reporting requires more coding, and setup and is far from being just a bit of maven configuration.</li>
<li> When running from maven things did not work until I configured the maven-resource-plugin to copy over the scenario files.  This should have just worked out of the box.</li>
<li>Most of my 4 hours was taken up with configuration which was compounded by the slim documentation.</li>
</ul>
<h2>Conclusion</h2>
<p>Attempting a behavior driven approach using scenarios is worth doing.  I could see the benefits.  Not sure if JBehave is the solution for me though.  Difficult to configure, and incompatibilities with other frameworks would put me off at the moment.  I will find some time to have a look at <a title="Easyb" href="http://www.easyb.org/" target="_blank">easyb</a> another java BDD system next.</p>
<div id="_mcePaste" style="overflow: hidden; position: absolute; left: -10000px; top: 823px; width: 1px; height: 1px;"></div>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F&amp;title=Bad+or+Good%3F+Behavior+Driven+Development+within+Scrum." target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F&amp;title=Bad+or+Good%3F+Behavior+Driven+Development+within+Scrum." target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F&amp;title=Bad+or+Good%3F+Behavior+Driven+Development+within+Scrum." target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F&amp;headline=Bad+or+Good%3F+Behavior+Driven+Development+within+Scrum." target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Bad+or+Good%3F+Behavior+Driven+Development+within+Scrum.&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Bad+or+Good%3F+Behavior+Driven+Development+within+Scrum.&amp;u=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Bad+or+Good%3F+Behavior+Driven+Development+within+Scrum.&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Bad+or+Good%3F+Behavior+Driven+Development+within+Scrum.&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Bad+or+Good%3F+Behavior+Driven+Development+within+Scrum.&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F&amp;title=Bad+or+Good%3F+Behavior+Driven+Development+within+Scrum.&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F05%2Fbad-or-good-bdd-within-scrum%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2010/05/bad-or-good-bdd-within-scrum/';
var dzone_title = 'Bad or Good? Behavior Driven Development within Scrum.';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2010/05/bad-or-good-bdd-within-scrum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hamcrest Collection Matching with Junit 4.8</title>
		<link>http://martinaharris.com/2010/04/hamcrest-collection-matching-with-junit-4-8/</link>
		<comments>http://martinaharris.com/2010/04/hamcrest-collection-matching-with-junit-4-8/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 22:46:09 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[collections]]></category>
		<category><![CDATA[hamcrest]]></category>
		<category><![CDATA[matcher]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=989</guid>
		<description><![CDATA[Sometime back I wrote about some testing anti-patterns.  Recently I came back to the project and made some trivial changes.  I fixed a bug upgraded spring and junit and migrated the test assertions to hamcrest fluid style.  The full project &#8230; <a href="http://martinaharris.com/2010/04/hamcrest-collection-matching-with-junit-4-8/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sometime back I wrote about some testing <a title="Test Anti Patterns" href="/2009/11/anti-patterns-testing/" target="_blank">anti-patterns</a>.  Recently I came back to the project and made some trivial changes.  I fixed a bug upgraded spring and junit and migrated the test assertions to hamcrest fluid style.  The full project is <a title="GitHub Project" href="http://github.com/mhgit/TerribleJavaTestingMadeGood" target="_blank">available on git</a>.</p>
<p>I find hamcrest to be a much cleaner way of writing assertions.  This test demonstrates the use of its fluid interface with some simple collection assertions.  There are newer versions of Hamcrest and the collection package may have moved into core, but the version I use here (1.0) was available on maven.  Note the integration with Junit.  The <strong>hasItem</strong> and <strong>hasItems</strong> methods are sourced from <strong>Junit 4.8.1</strong>.</p>
<pre class="brush: java; gutter: false; wrap-lines: false">package org.testpatterns.hamcrestexamples;

import java.util.Arrays;
import org.junit.Test;
import static org.hamcrest.collection.IsArrayContaining.hasItemInArray;
import static org.junit.matchers.JUnitMatchers.*;
import static org.junit.Assert.assertThat;

public class CollectionExamples {

  //Hamcrest with Collections and Arrays:
  static final String[] array = { "A", "B", "C" };
  static final List&lt;String&gt; list = Arrays.asList(array);

  @Test
  public void oneThingInArray () {
    assertThat(array, hasItemInArray("A"));
  }

  @Test
  public void arrayOfItemsInList () {
  String[] expected = { "A", "B", "C" };
    assertThat(list, hasItems(expected));
  }

  @Test
  public void itemInAList () {
    assertThat(list, hasItem("A"));
  }

  @Test
  public void itemsInAList () {
    assertThat(list, hasItems("A", "C"));
  }

}
</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F&amp;title=Hamcrest+Collection+Matching+with+Junit+4.8" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F&amp;title=Hamcrest+Collection+Matching+with+Junit+4.8" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F&amp;title=Hamcrest+Collection+Matching+with+Junit+4.8" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F&amp;headline=Hamcrest+Collection+Matching+with+Junit+4.8" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Hamcrest+Collection+Matching+with+Junit+4.8&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Hamcrest+Collection+Matching+with+Junit+4.8&amp;u=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Hamcrest+Collection+Matching+with+Junit+4.8&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Hamcrest+Collection+Matching+with+Junit+4.8&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Hamcrest+Collection+Matching+with+Junit+4.8&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F&amp;title=Hamcrest+Collection+Matching+with+Junit+4.8&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F04%2Fhamcrest-collection-matching-with-junit-4-8%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2010/04/hamcrest-collection-matching-with-junit-4-8/';
var dzone_title = 'Hamcrest Collection Matching with Junit 4.8';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2010/04/hamcrest-collection-matching-with-junit-4-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KeySet v EntrySet code tidy</title>
		<link>http://martinaharris.com/2010/03/keyset-v-entryset-code-tidy/</link>
		<comments>http://martinaharris.com/2010/03/keyset-v-entryset-code-tidy/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 18:02:25 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[software quality]]></category>
		<category><![CDATA[entryset]]></category>
		<category><![CDATA[keyset]]></category>
		<category><![CDATA[map]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=939</guid>
		<description><![CDATA[Its astounding how often I find maps being used like this. for(String name: names.keySet()) { mymap.put(mymap.get(name),name); }﻿ Its inefficient because you have to fetch the keys and perform a lookup in the map with the key. Instead using the EntrySet &#8230; <a href="http://martinaharris.com/2010/03/keyset-v-entryset-code-tidy/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Its astounding how often I find maps being used like this.</p>
<pre class="brush: java; gutter: false; wrap-lines: false">
for(String name: names.keySet()) {
    mymap.put(mymap.get(name),name);
}﻿
</pre>
<p>Its inefficient because you have to fetch the keys and perform a lookup in the map with the key.</p>
<p>Instead using the EntrySet you can get all the keys and values in one hit.  This saves having to perform the map lookup.</p>
<pre class="brush: java; gutter: false; wrap-lines: false">
for (Entry&lt;String, String&gt; entry : entrySet) {
    mymap.put(entry.getValue(),entry.getKey());
}
</pre>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F&amp;title=KeySet+v+EntrySet+code+tidy" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F&amp;title=KeySet+v+EntrySet+code+tidy" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F&amp;title=KeySet+v+EntrySet+code+tidy" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F&amp;headline=KeySet+v+EntrySet+code+tidy" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=KeySet+v+EntrySet+code+tidy&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=KeySet+v+EntrySet+code+tidy&amp;u=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=KeySet+v+EntrySet+code+tidy&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=KeySet+v+EntrySet+code+tidy&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=KeySet+v+EntrySet+code+tidy&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F&amp;title=KeySet+v+EntrySet+code+tidy&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F03%2Fkeyset-v-entryset-code-tidy%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2010/03/keyset-v-entryset-code-tidy/';
var dzone_title = 'KeySet v EntrySet code tidy';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2010/03/keyset-v-entryset-code-tidy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google Objects.equal, useful but be careful.</title>
		<link>http://martinaharris.com/2010/02/google-objects-equal-useful-but-be-careful/</link>
		<comments>http://martinaharris.com/2010/02/google-objects-equal-useful-but-be-careful/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 20:20:14 +0000</pubDate>
		<dc:creator>Martin Harris</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[software quality]]></category>
		<category><![CDATA[testing]]></category>
		<category><![CDATA[compareto]]></category>
		<category><![CDATA[equals]]></category>
		<category><![CDATA[google]]></category>

		<guid isPermaLink="false">http://martinaharris.com/?p=818</guid>
		<description><![CDATA[Google have a nice equals method to make boiler plate equals easier to read. Particularly good if you have many attributes in the method. http://publicobject.com/2007/09/coding-in-small-with-google-collections_8175.html Be careful to check that your objects are consistent with equals though.  I have mentioned &#8230; <a href="http://martinaharris.com/2010/02/google-objects-equal-useful-but-be-careful/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Google have a nice equals method to make boiler plate equals easier to read.  Particularly good if you have many attributes in the method.  <a title="Google Object.equals method." href="http://publicobject.com/2007/09/coding-in-small-with-google-collections_8175.html" target="_blank">http://publicobject.com/2007/09/coding-in-small-with-google-collections_8175.html</a></p>
<p>Be careful to check that your objects are consistent with equals though.  I have mentioned this <a title="Equals Generation" href="/2009/10/ide-generation-of-equals-methods-has-its-moments/" target="_blank">before</a>.<br />
<span id="more-818"></span><br />
In the following method I am using the Objects.equal with a BigDecimal class.  It does not work because BigDecimal equals treats 0 and 0.0 as not equal, which is probably not what you need.</p>
<pre class="brush: java; light: true">
public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }

    final TestEquals other = (TestEquals) obj;

    return Objects.equal(this.bigDecimal, other);
}</pre>
<p>The common solution is to use the compareTo method instead like so.</p>
<pre class="brush: java; light: true">  final TestEquals other = (TestEquals) obj;
  if (this.bigDecimal != other.bigDecimal &amp;&amp;
      (this.bigDecimal == null
      || this.bigDecimal.compareTo(other.bigDecimal) != 0)) {
    return false;
  }
  return true;</pre>
<p>I will be using this technique, especially where the object has many attributes but I will be <a title="Testing Equals" href="/2009/10/testing-java-equals-and-hashcode-methods-essential/" target="_blank">testing the equals method</a>.</p>
<div class="lightsocial_container"><a class="lightsocial_a" href="http://digg.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F&amp;title=Google+Objects.equal%2C+useful+but+be+careful." target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/digg.png" alt="Digg This" title="Digg This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.reddit.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F&amp;title=Google+Objects.equal%2C+useful+but+be+careful." target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/reddit.png" alt="Reddit This" title="Reddit This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.stumbleupon.com/submit?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F&amp;title=Google+Objects.equal%2C+useful+but+be+careful." target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/stumbleupon.png" alt="Stumble Now!" title="Stumble Now!" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://buzz.yahoo.com/buzz?targetUrl=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F&amp;headline=Google+Objects.equal%2C+useful+but+be+careful." target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/yahoo_buzz.png" alt="Buzz This" title="Buzz This" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dzone.com/links/add.html?title=Google+Objects.equal%2C+useful+but+be+careful.&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dzone.png" alt="Vote on DZone" title="Vote on DZone" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.facebook.com/sharer.php?t=Google+Objects.equal%2C+useful+but+be+careful.&amp;u=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/facebook.png" alt="Share on Facebook" title="Share on Facebook" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://delicious.com/save?title=Google+Objects.equal%2C+useful+but+be+careful.&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/delicious.png" alt="Bookmark this on Delicious" title="Bookmark this on Delicious" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.dotnetkicks.com/kick/?title=Google+Objects.equal%2C+useful+but+be+careful.&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetkicks.png" alt="Kick It on DotNetKicks.com" title="Kick It on DotNetKicks.com" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://dotnetshoutout.com/Submit?title=Google+Objects.equal%2C+useful+but+be+careful.&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/dotnetshoutout.png" alt="Shout it" title="Shout it" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F&amp;title=Google+Objects.equal%2C+useful+but+be+careful.&amp;summary=&amp;source=" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/linkedin.png" alt="Share on LinkedIn" title="Share on LinkedIn" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.technorati.com/faves?add=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/technorati.png" alt="Bookmark this on Technorati" title="Bookmark this on Technorati" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://twitter.com/home?status=Reading+http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/twitter.png" alt="Post on Twitter" title="Post on Twitter" /></a>&nbsp;&nbsp;<a class="lightsocial_a" href="http://www.google.com/buzz/post?url=http%3A%2F%2Fmartinaharris.com%2F2010%2F02%2Fgoogle-objects-equal-useful-but-be-careful%2F" target="_blank"><img class="lightsocial_img" src="http://martinaharris.com/wp-content/plugins/light-social/google_buzz.png" alt="Google Buzz (aka. Google Reader)" title="Google Buzz (aka. Google Reader)" /></a>&nbsp;&nbsp;</div><div class="dzone_button" style="float: right; margin-left: 5px;">
<script type="text/javascript">
var dzone_url = 'http://martinaharris.com/2010/02/google-objects-equal-useful-but-be-careful/';
var dzone_title = 'Google Objects.equal, useful but be careful.';
var dzone_blurb = '';
var dzone_style = '2';
</script>
<script language="javascript" src="http://widgets.dzone.com/links/widgets/zoneit.js"></script>
</div>]]></content:encoded>
			<wfw:commentRss>http://martinaharris.com/2010/02/google-objects-equal-useful-but-be-careful/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

