<?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>Outrospective.org &#187; Java</title>
	<atom:link href="http://outrospective.org/wordpress/categories/software-development/languages/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://outrospective.org/wordpress</link>
	<description></description>
	<lastBuildDate>Mon, 16 Jan 2012 11:06:45 +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>Access restriction: The constructor NotSupposedToUseThisClass() is not accessible due to restriction on required library</title>
		<link>http://outrospective.org/wordpress/2011/12/access-restriction-the-constructor-notsupposedtousethisclass-is-not-accessible-due-to-restriction-on-required-library/</link>
		<comments>http://outrospective.org/wordpress/2011/12/access-restriction-the-constructor-notsupposedtousethisclass-is-not-accessible-due-to-restriction-on-required-library/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 12:57:36 +0000</pubDate>
		<dc:creator>Kon</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://outrospective.org/wordpress/?p=484</guid>
		<description><![CDATA[So following from my previous post about compiling Java 5 with a Java 6 compiler and the real reason that I am posting today, was to talk about a curly error message I got in Eclipse today. I had the same &#8230; <a href="http://outrospective.org/wordpress/2011/12/access-restriction-the-constructor-notsupposedtousethisclass-is-not-accessible-due-to-restriction-on-required-library/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So following from my previous post about compiling <a href="http://outrospective.org/wordpress/?p=481">Java 5 with a Java 6 compiler</a> and the real reason that I am posting today, was to talk about a curly error message I got in Eclipse today.</p>
<p>I had the same Eclipse 3.7 project both on Windows and Mac, but only the Mac version complained with a very unusal message.</p>
<div id="attachment_487" class="wp-caption alignleft" style="width: 1255px"><a href="http://outrospective.org/wordpress/2011/12/access-restriction-the-constructor-notsupposedtousethisclass-is-not-accessible-due-to-restriction-on-required-library/2011-12-12_23-40-27/" rel="attachment wp-att-487"><img class="size-full wp-image-487" title="sun.misc.Base64 on mac JDK 5" src="http://outrospective.org/wordpress/wp-content/uploads/2011/12/2011-12-12_23-40-27.png" alt="" width="1245" height="282" /></a><p class="wp-caption-text">sun.misc.Base64 on mac JDK 5</p></div>
<p>The complaint was against an internal sun.misc.Base64Encoder class which every 2nd Java dev on the internet recommends replacing its internal implementation with an Apache Commons alternative.</p>
<p>Initially I thought it had something to do with the manifest and access restrictions preventing code outside of the jar accessing the internal code &#8211; something I recall the JavaPosse talking about from their days of Java Studio. Since it was only isolated to the Mac JDK, perhaps Apple had included these restrictions in the manifest for the classes.jar that these classes were defined.</p>
<p>Turns out it has to do with Eclipse.  I found out that when I add a JRE/JDK in Eclipse, it appears to add Access Rules to a bunch of select classes in the classes jar.  Its a white list.  Anything not there is forbidden.</p>
<p>I don&#8217;t know what defines this, and they are &#8216;non modifiable&#8217; but adding in an access rule at the top leads this to go.</p>
<div id="attachment_488" class="wp-caption alignleft" style="width: 1150px"><a href="http://outrospective.org/wordpress/2011/12/access-restriction-the-constructor-notsupposedtousethisclass-is-not-accessible-due-to-restriction-on-required-library/2011-12-12_23-50-11/" rel="attachment wp-att-488"><img class="size-full wp-image-488" title="Java Build Path with Access Rules avoided" src="http://outrospective.org/wordpress/wp-content/uploads/2011/12/2011-12-12_23-50-11.png" alt="" width="1140" height="890" /></a><p class="wp-caption-text">Java Build Path with Access Rules avoided</p></div>
<p>Looks like this has been <a href="http://www.eclipsezone.com/eclipse/forums/t96756.html">tormenting people since Eclipse 3.3</a></p>
]]></content:encoded>
			<wfw:commentRss>http://outrospective.org/wordpress/2011/12/access-restriction-the-constructor-notsupposedtousethisclass-is-not-accessible-due-to-restriction-on-required-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Like rt.jar for like javac</title>
		<link>http://outrospective.org/wordpress/2011/12/like-rt-jar-for-like-javac/</link>
		<comments>http://outrospective.org/wordpress/2011/12/like-rt-jar-for-like-javac/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 12:34:57 +0000</pubDate>
		<dc:creator>Kon</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://outrospective.org/wordpress/?p=481</guid>
		<description><![CDATA[Today I switched an Eclipse project using JDK 6 on OS X to JDK 5. Even though there are command line tags in javac to produce 1.5 compatible source, the need to use JDK 5 comes into being when implementing &#8230; <a href="http://outrospective.org/wordpress/2011/12/like-rt-jar-for-like-javac/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Today I switched an Eclipse project using JDK 6 on OS X to JDK 5.</p>
<p>Even though there are command line tags in javac to produce 1.5 compatible source, the need to use JDK 5 comes into being when implementing interfaces that have grown in the number of methods since Java 5.  A good example is the JDBC classes.  The number of methods in Java 6 versions of the <a href="http://docs.oracle.com/javase/6/docs/api/java/sql/Connection.html">java.sql.Connection</a> interface has grown by at least 6 (look for Since 1.6)</p>
<p>Having the Java 6 rt.jar or classes.jar where that interface resides will expect those new methods to be implemented and lead to a compilation error when you try to build.  On the opposite end, if you blindly start using the latest version of Java, you can easily start using new methods without realising.  Your colleagues will tell you when their 1.5 only environment stops compiling. <img src='http://outrospective.org/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://outrospective.org/wordpress/2011/12/like-rt-jar-for-like-javac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building Jetty-Ant for Jetty 7</title>
		<link>http://outrospective.org/wordpress/2011/10/jetty-ant/</link>
		<comments>http://outrospective.org/wordpress/2011/10/jetty-ant/#comments</comments>
		<pubDate>Fri, 21 Oct 2011 07:39:13 +0000</pubDate>
		<dc:creator>Kon</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Jetty]]></category>

		<guid isPermaLink="false">http://outrospective.org/wordpress/?p=463</guid>
		<description><![CDATA[Jetty-ant for Jetty 7 is a hard find. The documentation is all wrong, but that if you look at the Jetty Developer page they do concede that. The split between eclipse and codehaus doesnt help either. There are a lot of &#8230; <a href="http://outrospective.org/wordpress/2011/10/jetty-ant/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Jetty-ant for Jetty 7 is a hard find.<br />
The <a href="http://docs.codehaus.org/display/JETTY/Ant+Jetty+Plugin">documentation</a> is all wrong, but that if you look at the Jetty Developer page they do concede that.<br />
The split between eclipse and codehaus doesnt help either. There are a lot of options to try and search, Maven repo (http://repo1.maven.org/maven2/org/eclipse/jetty/), other bits in svn.codehaus.org (<a href="http://svn.codehaus.org/jetty-contrib/sandbox/jetty-ant/">http://svn.codehaus.org/jetty-contrib/sandbox/jetty-ant/</a>), eclipse vs hightide release dirs (http://dist.codehaus.org/jetty/),&#8230;. aaarghh!<br />
To make things extra sucky, the SVN URLs in the doc for where you get jetty-ant have moved too.<br />
After a lot of searching it looks like this one is the key</p>
<p>https://svn.codehaus.org/jetty/archived/jetty-7/</p>
<p>instead of the one the docs refer to (https://svn.codehaus.org/jetty/jetty/branches/jetty-7 ) which 404s.</p>
<p>There are a lot of other resources that are required jetty-integration-project is req&#8217;d by the POM.  Its created in the main jetty-7 that I linked above.  Build that first (I only got as far as building the hightide-distribution) but it was enough to download all the required jars to build jetty-ant.  Phew!</p>
<p>&nbsp;</p>
<p>in super short</p>
<pre>svn co https://svn.codehaus.org/jetty/archived/jetty-7/
cd jetty-7
mvn install</pre>
<p>&#8230; builds a few different things, ultimately fails</p>
<pre>cd jetty-ant
mvn install</pre>
<p>&#8230; great success (now I just have to try it out &#8211; found in <code>jetty-ant\target\jetty-ant-7.5.0-SNAPSHOT.jar</code>)</p>
<p><strong>EDIT: </strong>When I last checked the documentation on the Eclipse documentation notes, it had thankfully been updated with an updated URL to download the ant target directly (18 Dec)</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://outrospective.org/wordpress/2011/10/jetty-ant/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rick Wagner&#8217;s Blog: How to find which .jar a class is in (easily)</title>
		<link>http://outrospective.org/wordpress/2010/10/rick-wagners-blog-how-to-find-which-jar-a-class-is-in-easily/</link>
		<comments>http://outrospective.org/wordpress/2010/10/rick-wagners-blog-how-to-find-which-jar-a-class-is-in-easily/#comments</comments>
		<pubDate>Tue, 26 Oct 2010 07:23:02 +0000</pubDate>
		<dc:creator>Kon</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Outrospective.org]]></category>

		<guid isPermaLink="false">http://outrospective.org/wordpress/?p=424</guid>
		<description><![CDATA[Holy heck, I needed this earlier today Rick Wagner&#8217;s Blog: How to find which .jar a class is in (easily). Makes mention of JBoss&#8217; tattletale utility. The comments also mention the Java Class Finder plugin for Eclipse (I used the &#8230; <a href="http://outrospective.org/wordpress/2010/10/rick-wagners-blog-how-to-find-which-jar-a-class-is-in-easily/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Holy heck, I needed this earlier today</p>
<p><a href="http://rickwagner.blogspot.com/2010/10/how-to-find-which-jar-class-is-in.html">Rick Wagner&#8217;s Blog: How to find which .jar a class is in (easily)</a>.</p>
<p>Makes mention of JBoss&#8217; tattletale utility.</p>
<p>The comments also mention the Java Class Finder plugin for Eclipse (I used the CTRL+SHIFT+T today personally which did the same job)</p>
<p>There is also LibraryFinder plugin for IntelliJ and classjarsearch command line tool to search a directory of Jars for a class.</p>
]]></content:encoded>
			<wfw:commentRss>http://outrospective.org/wordpress/2010/10/rick-wagners-blog-how-to-find-which-jar-a-class-is-in-easily/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Serialization under the magnifying glass</title>
		<link>http://outrospective.org/wordpress/2010/10/serialization-under-the-magnifying-glass/</link>
		<comments>http://outrospective.org/wordpress/2010/10/serialization-under-the-magnifying-glass/#comments</comments>
		<pubDate>Sat, 23 Oct 2010 23:22:21 +0000</pubDate>
		<dc:creator>Kon</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Outrospective.org]]></category>

		<guid isPermaLink="false">http://outrospective.org/wordpress/?p=415</guid>
		<description><![CDATA[The Java serialization algorithm revealed &#124; JavaWorld&#8217;s Daily Brew. A good post about what happens when Java takes your class and serializes it, including its fields, parents and collaborators and the class definitions of the object and the parents and collaborators involved.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.javaworld.com/community/node/2915">The Java serialization algorithm revealed | JavaWorld&#8217;s Daily Brew</a>.</p>
<p>A good post about what happens when Java takes your class and serializes it, including its fields, parents and collaborators and the class definitions of the object and the parents and collaborators involved.</p>
]]></content:encoded>
			<wfw:commentRss>http://outrospective.org/wordpress/2010/10/serialization-under-the-magnifying-glass/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google&#8217;s guava java: the easy parts</title>
		<link>http://outrospective.org/wordpress/2010/10/googles-guava-java-the-easy-parts/</link>
		<comments>http://outrospective.org/wordpress/2010/10/googles-guava-java-the-easy-parts/#comments</comments>
		<pubDate>Sun, 17 Oct 2010 04:11:21 +0000</pubDate>
		<dc:creator>neversleepz</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://outrospective.org/wordpress/?p=407</guid>
		<description><![CDATA[More Guava goodness dzone.com &#8211; Google&#8217;s guava java: the easy parts.]]></description>
			<content:encoded><![CDATA[<p>More Guava goodness</p>
<p><a href="http://www.dzone.com/links/r/googles_guava_java_the_easy_parts.html">dzone.com &#8211; Google&#8217;s guava java: the easy parts</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://outrospective.org/wordpress/2010/10/googles-guava-java-the-easy-parts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Junit Kungfu</title>
		<link>http://outrospective.org/wordpress/2010/10/junit-kungfu/</link>
		<comments>http://outrospective.org/wordpress/2010/10/junit-kungfu/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 15:40:04 +0000</pubDate>
		<dc:creator>Kon</dc:creator>
				<category><![CDATA[Groovy]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[hamcrest]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[mockito]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://outrospective.org/wordpress/2010/10/junit-kungfu/</guid>
		<description><![CDATA[A great presentation with audio that talks about Junit 4, test naming and other things.  I liked this presentation because it starts expression Behaviour Driven Development concepts without actually using a Behaviour Driven Development Framework.  Additionally its one of the &#8230; <a href="http://outrospective.org/wordpress/2010/10/junit-kungfu/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://www.dzone.com/links/r/junit_kung_fu_getting_more_out_of_your_unit_tests.html" target="_blank">great presentation with audio</a> that talks about Junit 4, test naming and other things.  I liked this presentation because it starts expression Behaviour Driven Development concepts without actually using a Behaviour Driven Development Framework.  Additionally its one of the more in-depth presentations covering the new features of JUnit like Rules.</p>
<p>The presenter is John Ferguson Smart who runs testing and agile tools bootcamps around Australia and NZ (as well as elsewhere) so if you are in the vacinity you should consider looking into em.</p>
<p>My notes from the presentation:</p>
<h3>Naming tests</h3>
<p>Dont use the name <strong>testXXX</strong> – you aren’t testing methods of your code</p>
<p>You are testing use cases – what should your class be doing</p>
<p>Take out private methods, maybe extract to a separate class and test those separately if they are getting too big.</p>
<p>Use the word <em>should</em>.  Express an outcome</p>
<p><strong>Class Name: </strong>When is a behaviour applicable<br />
<strong>Method Name:</strong> When at is the behaviour testing</p>
<p>Tests become more readable.</p>
<h3>Arrange-Act-Assert</h3>
<p>Create the test collaborators &#8211; Inputs and Expected Outputs (Arrange)</p>
<p>Test the behaviour (Act)</p>
<p>Verify behaviour is correct (Assert)</p>
<h3>Extending Hamcrest Matchers</h3>
<p>Combine matchers together – hasItem(someOtherHasPropertyMatcherYouPreviouslyDefined)</p>
<p>Create a new matcher –</p>
<ol>
<li>Extend TypeSafeMatcher&lt;type of thing you are checking against)</li>
<li>Implement Constructor take in  a matcher of expected value</li>
<li>Implement matchesSafely(type of thing you are checking against)</li>
<li>Implement describeTo – decorate the existing test result/matcher description…  description.appendText(“WuzUp!”); matcher.describeTo(Description);</li>
<li>Create a Factory Class for your matchers with static factory methods to return a new matcher</li>
<li>Use It</li>
</ol>
<p>Multiple asserts per test are bad (see also Integration Tests are a Scam)</p>
<p>You can combine hamcrest matchers into one test</p>
<p>assertThat(itesm, allOf(hasSize(1), hasItem(“java”)));</p>
<p>assertThat(itesm, hasSize(greaterThan(1)));</p>
<p>The error messages will be cleaner too – expect list size of one, and has item java but received &lt;blah&gt;</p>
<h3>Parameterized Tests</h3>
<p>Usually just one test per Parameterized test class – they get run once</p>
<p>Ways to get test data</p>
<p>Use an xls spreadsheet source</p>
<p>Use Selenium 2’s WebElement to get a webpage</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@FindBy(name=<span style="color: #006080;">"HD_EN"</span>) WebElement importerName;</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@FindBy(name=<span style="color: #006080;">"HD_EA"</span>) WebElement importerAddress;</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@FindBy(name=<span style="color: #006080;">"HD_ER"</span>) WebElement importerRepresentative;</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000;">
</span></pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000;">// getters and setters</span></pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000;"> </span><span style="color: #008000;">// getter </span><span style="color: #0000ff;">return</span> importerName.getValue();</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000;">
</span></pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000;">// setter</span>
<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> setImporterName(String value) {</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">     enter(value, into(importerName));</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">}</pre>
</div>
<p>Smoke test to make sure getters and setters are correct</p>
<p><a href="http://outrospective.org/wordpress/wp-content/uploads/2010/10/image.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="image" src="http://outrospective.org/wordpress/wp-content/uploads/2010/10/image_thumb.png" border="0" alt="image" width="397" height="125" /></a></p>
<p>Make sure the annotations aren’t wrong</p>
<h3>JUnit Rules</h3>
<h4>Delete folders after test run</h4>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@Rule public TemporaryFolder folder = <span style="color: #0000ff;">new</span> TemporaryFolder()</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">folder.newFile(“a file name”);</pre>
</div>
<h4>ErrorCollection,</h4>
<p>accumulate errors rather than fail on first.  This saves having to write 20 different tests with large setup that check 20 things on the same page (eg login and load webpage table then verify each cell)</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@Rule <span style="color: #0000ff;">public</span> ErrorCollector collector = <span style="color: #0000ff;">new</span> ErrorCollector();</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000;">// in your test</span></pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #008000;"> </span>collector.addError(<span style="color: #0000ff;">new</span> Throwable(“blah”));</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">collector.addError(<span style="color: #0000ff;">new</span> Throwable(“something <span style="color: #0000ff;">else</span>”));</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">collector.checkThat(result, yourMatcher);</pre>
</div>
<p>The result will show “blah”, “something else” and the result of your failed matcher, as well as fail the test.</p>
<h4>TimeoutRules</h4>
<p>When you know something should have a short response time, a DAO for example should be shorter than 1 second</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@Rule <span style="color: #0000ff;">public</span> MethodRule globalTimeout = <span style="color: #0000ff;">new</span> Timeout(1000);</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@Test <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> catchInfiniteLoopInTest() { <span style="color: #0000ff;">for</span>(;;); }</pre>
</div>
<p>Catch any major issues before they get into production and become embarassing</p>
<h4>Verifier Rule</h4>
<p>Something that happens after a test is completed, like an assert</p>
<p>Inject behaviour to make JUnit add checks after each test…. kind of like a test post-condition or invariant from Betrand Meyers OO Software construction, but just for the tests themselves.</p>
<div id="codeSnippetWrapper">
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">private</span> List&lt;String&gt; systemErrorMessages = <span style="color: #0000ff;">new</span> ArrayList&lt;String&gt;();</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@Rule</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">public</span> MethodRule verifier = <span style="color: #0000ff;">new</span> Verifier() {</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    @Override</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span> verify() {</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">        assertThat(systemErrorMessages.size(), is(0));</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">    }};</pre>
</div>
<p>A good example I see would be using it to tie up mock verification calls in EasyMock</p>
<h4>Watchman Rule</h4>
<p>Called when a test fails or succeeds.  Additional logging perhaps?  How about restarting a GUI, or take a screenshot when a test fails.</p>
<h3>Categories</h3>
<p>Group tests in your own hierarchy based on your classification of the test rather than writing test suites.  Performance tests  that integration tests.  Slow running or fast running tests?</p>
<p><img src="http://yuml.me/diagram/scruffy/class/%23%20Cool%20UML%20Diagram,%20%5BIntegrationTest%5D%5E-.-%5BPerformance%20Test%5D" alt="" /></p>
<p>You can setup plain old normal interfaces for your categories, and have them extend each other via subclassing.  There is no Junit annotation here to indicate its an interface for testing, so you can potentially use any interface in your source.  I’m not sure if this is good practice or not, but say you wanted all your DAO tests that implemented a GenericDAO to be tested, you could do this…. or how about test all classes that implements Serializable?</p>
<p>You can annotate a test class, or tests methods with @Category(InterfaceName.class)</p>
<p>When running a category suite however you still need to include the classes to inspect as well as the category name.</p>
<div>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@RunWith(Categories.<span style="color: #0000ff;">class</span>)</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@IncludeCategory(PerformanceTests.<span style="color: #0000ff;">class</span>)</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@SuiteClasses( { CellTest.<span style="color: #0000ff;">class</span>, WhenYouCreateANewUniverse.<span style="color: #0000ff;">class</span> })</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> PerformanceTestSuite {}</pre>
</div>
<div>You can also exclude from a Run and run a</div>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@RunWith(Categories.<span style="color: #0000ff;">class</span>)</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@<strong>ExcludeCategory</strong>(PerformanceTests.<span style="color: #0000ff;">class</span>)</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;">@SuiteClasses( { CellTest.<span style="color: #0000ff;">class</span>, WhenYouCreateANewUniverse.<span style="color: #0000ff;">class</span> })</pre>
<pre id="codeSnippet" style="text-align: left; line-height: 12pt; background-color: #f4f4f4; margin: 0em; width: 100%; font-family: 'Courier New', courier, monospace; direction: ltr; color: black; font-size: 8pt; overflow: visible; border-style: none; padding: 0px;"><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span> PerformanceTestSuite {}</pre>
<p>But how about scanning your whole test bed?  Can we programmatically inject suite classes and use them with Categories?  At this point it is a limitation unless you want to use a classpath hack.</p>
<h3>Parallel Tests</h3>
<p>If you have fast IO and multicore (like my new work PC <img class="wlEmoticon wlEmoticon-smile" style="border-style: none;" src="http://outrospective.org/wordpress/wp-content/uploads/2010/10/wlEmoticonsmile.png" alt="Smile" />) and well written tests that don’t trodd on each others data.</p>
<p>U use Maven’s surefire 2.5 plugin to achieve this, and say methods, classes or both in parallel.  Classes is probably safer since most people write the test slipping thru later tests in the same class depend on earlier test methods accidentally.</p>
<h3>Infinitest</h3>
<p>This is a tool for IntelliJ and Eclipse that runs tests when you save your source and tells you if you have failed runs.  I remember twittering about how cool this would be if it existed a while back, and I’m glad I wasnt the only one with this idea and that someone actually implemented it <img class="wlEmoticon wlEmoticon-openmouthedsmile" style="border-style: none;" src="http://outrospective.org/wordpress/wp-content/uploads/2010/10/wlEmoticonopenmouthedsmile.png" alt="Open-mouthed smile" />.</p>
<p>Also there was a plugin for IntelliJ called Fireworks but I could never get it to run tests properly on my Windows PC; always complaining about not being able to find a JDK home <img class="wlEmoticon wlEmoticon-sadsmile" style="border-style: none;" src="http://outrospective.org/wordpress/wp-content/uploads/2010/10/wlEmoticonsadsmile.png" alt="Sad smile" />.</p>
<p>This tool seems pretty cheap at $29 for an individual license, I’ll check it out and give it a shot.</p>
<p><a href="http://improvingworks.com/products/infinitest/">http://improvingworks.com/products/infinitest/</a></p>
<p>What would be super cool is if it worked with Categories mentioned above, to be able to exclude GUI tests from being executed.  There may be a feature in Infinitest that handles it but I’d be keen to see.</p>
<h3>Mockito</h3>
<p>I’m traditionally an EasyMock guy but <a href="http://mockito.org" target="_blank">Mockito</a> has always had good buzz.  At my new job we dont actually have a mocking framework yet so I’m keen to give it a look.</p>
<p>Mockito seems to have less verbose setup of tests, something that when learning EasyMock bashed me around a bit – ever forget to get out of record mode and get a green test accidentally.</p>
<p>As per Integration Tests are a scam ypresso recommends, you can verify interactions, verify a method is being called with certain params.</p>
<h3>Other Stuff (comments from the Q&amp;A of the presso)</h3>
<p>Hibernate mappings – use an in-memory database</p>
<p>FEST asserts – an alternate to Hamcrest that avoids the Generic issues that plague Hamcrest!!! (boy this frustrates me a lot as a Hamcrest user)</p>
<p><a href="http://cobertura.sourceforge.net/" target="_blank">Cobertura</a> – a code coverage tool, alternate to Emma</p>
<p>Private methods shouldn’t be tested explicitly – you should be able to sufficiently test a class by its public facing API.</p>
]]></content:encoded>
			<wfw:commentRss>http://outrospective.org/wordpress/2010/10/junit-kungfu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing Presentations</title>
		<link>http://outrospective.org/wordpress/2010/09/testing-presentations/</link>
		<comments>http://outrospective.org/wordpress/2010/09/testing-presentations/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 03:50:49 +0000</pubDate>
		<dc:creator>Kon</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[asynchronous systems]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[techiniques]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://outrospective.org/wordpress/2010/09/testing-presentations/</guid>
		<description><![CDATA[Their has been a presentation I watched last year that absolutely changed my opinion on how I tested and how I designed.&#160; It was one of those presentations that just made sense and I cant believe I haven’t blogged about &#8230; <a href="http://outrospective.org/wordpress/2010/09/testing-presentations/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Their has been a presentation I watched last year that absolutely changed my opinion on how I tested and how I designed.&nbsp; It was one of those presentations that just made sense and I cant believe I haven’t blogged about it until now.
<p><a href="http://www.infoq.com/presentations/integration-tests-scam" target="_blank">Integration Tests are a Scam</a> by Joe Rainsberger
<p>This was my favourite presentation from last year. It talks about writing the correct type of unit tests to get get fast results and reduce the need for slower integration tests that are generally slower are require a lot of maintenance. He makes a compelling argument about the number of tests in your system don’t improve the sense of security you get from your tests by the same amount. So he talks about what needs to be unit tested from the contract class and the opposite collaborator class and how doing so gives you a better picture of what tests you need to give you a sense of security with quick feedback. The blurb explains it better<br />
<blockquote>
<p>Integration tests are a scam. You’re probably writing 2-5% of the integration tests you need to test thoroughly. You’re probably duplicating unit tests all over the place. Your integration tests probably duplicate each other all over the place. When an integration test fails, who knows what’s broken? Learn the two-pronged attack that solves the problem: collaboration tests and contract tests.</p>
</blockquote>
<hr />
<p><a href="http://www.infoq.com/presentations/TDD-of-Asynchronous-Systems" target="_blank">TDD of Asynchronous Systems</a>
<p>This presentation by the author of a new book, “growing object oriented software, guided by tests” Nat Pryce, which talks about testing at the integration/functional level and techniques to get around all the painful ‘flickering tests’ &amp; ‘false positives’ issues that occur when you have them. The examples talk about testing legacy systems, swing gui’s and JMS queues.
<p>One of the key ideas is that one must find a point to synchronise on before executing the assertions and those assertions must wait (and retry if not true) until the state has changed or a timeout occurs (and the test then fails)
<p>As a user of UISpec4j with its Assertions that have a timeout, and some perilious test code when someone innocently mixed junit assertions with a UI test, I could relate to this really well.</p>
]]></content:encoded>
			<wfw:commentRss>http://outrospective.org/wordpress/2010/09/testing-presentations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tempus library for programmatic thread dumps</title>
		<link>http://outrospective.org/wordpress/2010/09/tempus-library-for-programmatic-thread-dumps/</link>
		<comments>http://outrospective.org/wordpress/2010/09/tempus-library-for-programmatic-thread-dumps/#comments</comments>
		<pubDate>Mon, 06 Sep 2010 23:49:57 +0000</pubDate>
		<dc:creator>Kon</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[threads]]></category>

		<guid isPermaLink="false">http://outrospective.org/wordpress/?p=366</guid>
		<description><![CDATA[Turns out doing a CTRL+Break (or equivalent kill &#60;signal&#62; &#60;pid&#62; on *nix) programmatically is a bit harder than I thought.  This thread talks about ways to do it, but the easiest was to use the Tempus library which has a &#8230; <a href="http://outrospective.org/wordpress/2010/09/tempus-library-for-programmatic-thread-dumps/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Turns out doing a CTRL+Break (or equivalent kill &lt;signal&gt; &lt;pid&gt; on *nix) programmatically is a bit harder than I thought.  <a href="http://www.javalobby.org/java/forums/t6712.html?start=15" target="_blank">This thread</a> talks about ways to do it, but the easiest was to use the <a href="http://http//code.google.com/p/tempus-fugit/wiki/Documentation?tm=6">Tempus </a>library which has a lot of threading tools, including a simple</p>
<pre>ThreadDump.dumpThreads(yourPrintstream);</pre>
<p>to get a stacktrace of running threads in a current environment.</p>
]]></content:encoded>
			<wfw:commentRss>http://outrospective.org/wordpress/2010/09/tempus-library-for-programmatic-thread-dumps/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedding Tomcat 7 in your App</title>
		<link>http://outrospective.org/wordpress/2010/08/embedding-tomcat-7-in-your-app/</link>
		<comments>http://outrospective.org/wordpress/2010/08/embedding-tomcat-7-in-your-app/#comments</comments>
		<pubDate>Sun, 22 Aug 2010 05:28:50 +0000</pubDate>
		<dc:creator>Kon</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Jetty]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://outrospective.org/wordpress/2010/08/embedding-tomcat-7-in-your-app/</guid>
		<description><![CDATA[So what if you ship with a plain old Apache server just to run some aging PHP.  If you have an server app running all the time, according to this post, it looks like you can embed Tomcat, just like &#8230; <a href="http://outrospective.org/wordpress/2010/08/embedding-tomcat-7-in-your-app/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So what if you ship with a plain old Apache server just to run some aging PHP.  If you have an server app running all the time, according to <a href="http://www.copperykeenclaws.com/embedding-tomcat-7/">this post</a>, it looks like you can embed Tomcat, just like you can embed Jetty</p>
]]></content:encoded>
			<wfw:commentRss>http://outrospective.org/wordpress/2010/08/embedding-tomcat-7-in-your-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

