<?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>Flaming Penguin</title>
	<atom:link href="http://www.flamingpenguin.co.uk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.flamingpenguin.co.uk/blog</link>
	<description>Programming and Software</description>
	<lastBuildDate>Fri, 03 Feb 2012 15:34: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>Dollar</title>
		<link>http://www.flamingpenguin.co.uk/blog/2012/02/03/dollar/</link>
		<comments>http://www.flamingpenguin.co.uk/blog/2012/02/03/dollar/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 15:33:41 +0000</pubDate>
		<dc:creator>flamingpenguin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[libraries]]></category>

		<guid isPermaLink="false">http://www.flamingpenguin.co.uk/blog/?p=50</guid>
		<description><![CDATA[Java API that unifies collections, arrays, iterators/iterable, and char sequences (String, StringBuilder, etc). https://bitbucket.org/dfa/dollar/wiki/Home Interesting fluent interface.]]></description>
			<content:encoded><![CDATA[<p>Java API that unifies collections, arrays, iterators/iterable, and char sequences (String, StringBuilder, etc).</p>
<p><a href="https://bitbucket.org/dfa/dollar/wiki/Home" title="dollar">https://bitbucket.org/dfa/dollar/wiki/Home</a></p>
<p>Interesting fluent interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flamingpenguin.co.uk/blog/2012/02/03/dollar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JMX Metrics LIbrary</title>
		<link>http://www.flamingpenguin.co.uk/blog/2012/02/03/jmx-metrics-library/</link>
		<comments>http://www.flamingpenguin.co.uk/blog/2012/02/03/jmx-metrics-library/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 11:56:59 +0000</pubDate>
		<dc:creator>flamingpenguin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[libraries]]></category>

		<guid isPermaLink="false">http://www.flamingpenguin.co.uk/blog/?p=49</guid>
		<description><![CDATA[Nice looking library to make adding JMX metrics easier: http://metrics.codahale.com/getting-started.html]]></description>
			<content:encoded><![CDATA[<p>Nice looking library to make adding JMX metrics easier: <a href="http://metrics.codahale.com/getting-started.html" title="metrics">http://metrics.codahale.com/getting-started.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.flamingpenguin.co.uk/blog/2012/02/03/jmx-metrics-library/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedding and Extending Apache Ant &#8211; testing properties</title>
		<link>http://www.flamingpenguin.co.uk/blog/2012/02/02/embedding-and-extending-apache-ant-testing-properties/</link>
		<comments>http://www.flamingpenguin.co.uk/blog/2012/02/02/embedding-and-extending-apache-ant-testing-properties/#comments</comments>
		<pubDate>Thu, 02 Feb 2012 11:32:11 +0000</pubDate>
		<dc:creator>flamingpenguin</dc:creator>
				<category><![CDATA[ant]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.flamingpenguin.co.uk/blog/?p=48</guid>
		<description><![CDATA[If you want to test a property from a custom task in Apache Ant 1.8, you can use the testUnlessCondition and testIfCondition in org.apache.tools.ant.PropertyHelper: @Override public void execute&#40;&#41; throws BuildException &#123; final PropertyHelper propertyHelper = PropertyHelper.getPropertyHelper&#40;getProject&#40;&#41;&#41;; if&#40;propertyHelper.testUnlessCondition&#40;requiredPropertyName&#41;&#41; &#123; // property is missing &#125; &#125;]]></description>
			<content:encoded><![CDATA[<p>If you want to test a property from a custom task in Apache Ant 1.8, you can use the <code>testUnlessCondition</code> and <code>testIfCondition</code> in <code>org.apache.tools.ant.PropertyHelper</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Override
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> execute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> BuildException
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">final</span> PropertyHelper propertyHelper <span style="color: #339933;">=</span> PropertyHelper.<span style="color: #006633;">getPropertyHelper</span><span style="color: #009900;">&#40;</span>getProject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">if</span><span style="color: #009900;">&#40;</span>propertyHelper.<span style="color: #006633;">testUnlessCondition</span><span style="color: #009900;">&#40;</span>requiredPropertyName<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">// property is missing</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flamingpenguin.co.uk/blog/2012/02/02/embedding-and-extending-apache-ant-testing-properties/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert URL to URI using lambdaj</title>
		<link>http://www.flamingpenguin.co.uk/blog/2012/01/23/convert-url-to-uri-using-lambdaj/</link>
		<comments>http://www.flamingpenguin.co.uk/blog/2012/01/23/convert-url-to-uri-using-lambdaj/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 17:47:46 +0000</pubDate>
		<dc:creator>flamingpenguin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.flamingpenguin.co.uk/blog/?p=45</guid>
		<description><![CDATA[import ch.lambdaj.function.convert.Converter; &#160; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; &#160; public class ConvertUrlToUri implements Converter&#60;URL, URI&#62; &#123; public static ConvertUrlToUri convertUrlToUri&#40;&#41; &#123; return new ConvertUrlToUri&#40;&#41;; &#125; &#160; @Override public URI convert&#40;final URL from&#41; &#123; try &#123; return from.toURI&#40;&#41;; &#125; catch &#40;final URISyntaxException e&#41; &#123; throw new RuntimeException&#40;&#34;unable to convert &#34; + from + &#34; to [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ch.lambdaj.function.convert.Converter</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URI</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URISyntaxException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URL</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConvertUrlToUri <span style="color: #000000; font-weight: bold;">implements</span> Converter<span style="color: #339933;">&lt;</span>URL, URI<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> ConvertUrlToUri convertUrlToUri<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ConvertUrlToUri<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   @Override
   <span style="color: #000000; font-weight: bold;">public</span> URI convert<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">URL</span> from<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">try</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">return</span> from.<span style="color: #006633;">toURI</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> URISyntaxException e<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">RuntimeException</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unable to convert &quot;</span> <span style="color: #339933;">+</span> from <span style="color: #339933;">+</span> <span style="color: #0000ff;">&quot; to URI&quot;</span>, e<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flamingpenguin.co.uk/blog/2012/01/23/convert-url-to-uri-using-lambdaj/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert URL to filename using lambdaj</title>
		<link>http://www.flamingpenguin.co.uk/blog/2012/01/23/convert-url-to-filename-using-lambdaj/</link>
		<comments>http://www.flamingpenguin.co.uk/blog/2012/01/23/convert-url-to-filename-using-lambdaj/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 17:46:51 +0000</pubDate>
		<dc:creator>flamingpenguin</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.flamingpenguin.co.uk/blog/?p=44</guid>
		<description><![CDATA[import ch.lambdaj.function.convert.Converter; &#160; import java.net.URL; &#160; public class ConvertUrlToFileName implements Converter&#60;URL, String&#62; &#123; public static ConvertUrlToFileName convertUrlToFileName&#40;&#41; &#123; return new ConvertUrlToFileName&#40;&#41;; &#125; &#160; @Override public String convert&#40;final URL from&#41; &#123; return from.getFile&#40;&#41;; &#125; &#125;]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">ch.lambdaj.function.convert.Converter</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URL</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ConvertUrlToFileName <span style="color: #000000; font-weight: bold;">implements</span> Converter<span style="color: #339933;">&lt;</span>URL, String<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> ConvertUrlToFileName convertUrlToFileName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ConvertUrlToFileName<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   @Override
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> convert<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">URL</span> from<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> from.<span style="color: #006633;">getFile</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flamingpenguin.co.uk/blog/2012/01/23/convert-url-to-filename-using-lambdaj/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unzip with Apache VFS 2.0 (Java)</title>
		<link>http://www.flamingpenguin.co.uk/blog/2012/01/23/unzip-with-apache-vfs-2-0-java/</link>
		<comments>http://www.flamingpenguin.co.uk/blog/2012/01/23/unzip-with-apache-vfs-2-0-java/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 16:34:31 +0000</pubDate>
		<dc:creator>flamingpenguin</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.flamingpenguin.co.uk/blog/?p=43</guid>
		<description><![CDATA[Apache VFS 2.0 is strange but super powerful. Uncompress a file at a given URI to a given output location: &#60;dependency&#62; &#60;groupId&#62;org.apache.commons&#60;/groupId&#62; &#60;artifactId&#62;commons-vfs2&#60;/artifactId&#62; &#60;version&#62;2.0&#60;/version&#62; &#60;/dependency&#62; import java.io.File; import java.io.IOException; import java.net.URI; &#160; import org.apache.commons.vfs2.AllFileSelector; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.FileSystemManager; import org.apache.commons.vfs2.VFS; &#160; public class ZipfileUnpacker &#123; private final FileSystemManager fileSystemManager; private final URI packLocation; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://commons.apache.org/vfs/" title="commons vfs">Apache VFS 2.0</a> is strange but super powerful. Uncompress a file at a given URI to a given output location:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.commons<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>commons-vfs2<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>2.0<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.File</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URI</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.vfs2.AllFileSelector</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.vfs2.FileObject</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.vfs2.FileSystemException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.vfs2.FileSystemManager</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.commons.vfs2.VFS</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> ZipfileUnpacker
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> FileSystemManager fileSystemManager<span style="color: #339933;">;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> URI packLocation<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> ZipfileUnpacker<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> URI packLocation<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> FileSystemException
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">fileSystemManager</span> <span style="color: #339933;">=</span> VFS.<span style="color: #006633;">getManager</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">packLocation</span> <span style="color: #339933;">=</span> packLocation<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   @Override
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> unpack<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">File</span> outputDir<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span>
   <span style="color: #009900;">&#123;</span>
      outputDir.<span style="color: #006633;">mkdirs</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">final</span> FileObject packFileObject <span style="color: #339933;">=</span> fileSystemManager.<span style="color: #006633;">resolveFile</span><span style="color: #009900;">&#40;</span>packLocation.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">try</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">final</span> FileObject zipFileSystem <span style="color: #339933;">=</span> fileSystemManager.<span style="color: #006633;">createFileSystem</span><span style="color: #009900;">&#40;</span>packFileObject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #000000; font-weight: bold;">try</span>
         <span style="color: #009900;">&#123;</span>
            fileSystemManager.<span style="color: #006633;">toFileObject</span><span style="color: #009900;">&#40;</span>outputDir<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">copyFrom</span><span style="color: #009900;">&#40;</span>zipFileSystem, <span style="color: #000000; font-weight: bold;">new</span> AllFileSelector<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
         <span style="color: #000000; font-weight: bold;">finally</span>
         <span style="color: #009900;">&#123;</span>
            zipFileSystem.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">finally</span>
      <span style="color: #009900;">&#123;</span>
         packFileObject.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flamingpenguin.co.uk/blog/2012/01/23/unzip-with-apache-vfs-2-0-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hamcrest regexp matcher</title>
		<link>http://www.flamingpenguin.co.uk/blog/2012/01/13/hamcrest-regexp-matcher/</link>
		<comments>http://www.flamingpenguin.co.uk/blog/2012/01/13/hamcrest-regexp-matcher/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 11:24:12 +0000</pubDate>
		<dc:creator>flamingpenguin</dc:creator>
				<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.flamingpenguin.co.uk/blog/?p=41</guid>
		<description><![CDATA[Matches a string against a regular expression, inspired by Piotr Gabryanczyk with a couple of issues fixed. import java.util.regex.Pattern; &#160; import org.hamcrest.Description; import org.hamcrest.Matcher; import org.hamcrest.TypeSafeMatcher; &#160; /** * Matchers that use regular expressions * * @author t.wood */ public class RegexMatcher &#123; private static abstract class AbstractRegexpMatcher extends TypeSafeMatcher&#60;String&#62; &#123; protected final String regex; [...]]]></description>
			<content:encoded><![CDATA[<p>Matches a string against a regular expression, inspired by <a href="http://piotrga.wordpress.com/2009/03/27/hamcrest-regex-matcher/" title="hamcrest regexp matcher">Piotr Gabryanczyk</a> with a couple of issues fixed.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.regex.Pattern</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hamcrest.Description</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hamcrest.Matcher</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.hamcrest.TypeSafeMatcher</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * Matchers that use regular expressions
 *
 * @author t.wood
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> RegexMatcher
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">abstract</span> <span style="color: #000000; font-weight: bold;">class</span> AbstractRegexpMatcher <span style="color: #000000; font-weight: bold;">extends</span> TypeSafeMatcher<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> regex<span style="color: #339933;">;</span>
      <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000000; font-weight: bold;">final</span> Pattern compiledRegex<span style="color: #339933;">;</span>
&nbsp;
      <span style="color: #000000; font-weight: bold;">private</span> AbstractRegexpMatcher<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> regex<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">regex</span> <span style="color: #339933;">=</span> regex<span style="color: #339933;">;</span>
         compiledRegex <span style="color: #339933;">=</span> Pattern.<span style="color: #006633;">compile</span><span style="color: #009900;">&#40;</span>regex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> MatchesRegexpMatcher <span style="color: #000000; font-weight: bold;">extends</span> AbstractRegexpMatcher
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">private</span> MatchesRegexpMatcher<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> regex<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>regex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      @Override
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> matchesSafely<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> item<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">return</span> compiledRegex.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">matches</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      @Override
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> describeTo<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Description description<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         description.<span style="color: #006633;">appendText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;matches regex &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">appendValue</span><span style="color: #009900;">&#40;</span>regex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000000; font-weight: bold;">class</span> ContainsMatchRegexpMatcher <span style="color: #000000; font-weight: bold;">extends</span> AbstractRegexpMatcher
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">private</span> ContainsMatchRegexpMatcher<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> regex<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">super</span><span style="color: #009900;">&#40;</span>regex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      @Override
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">boolean</span> matchesSafely<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> item<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         <span style="color: #000000; font-weight: bold;">return</span> compiledRegex.<span style="color: #006633;">matcher</span><span style="color: #009900;">&#40;</span>item<span style="color: #009900;">&#41;</span>.<span style="color: #006633;">find</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
&nbsp;
      @Override
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> describeTo<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Description description<span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         description.<span style="color: #006633;">appendText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;contains match for regex &quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">appendValue</span><span style="color: #009900;">&#40;</span>regex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #008000; font-style: italic; font-weight: bold;">/**
    * Match the regexp against the whole input string
    *
    * @param regex the regular expression to match
    *
    * @return a matcher which matches the whole input string
    */</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Matcher<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> matches<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> regex<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> MatchesRegexpMatcher<span style="color: #009900;">&#40;</span>regex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #008000; font-style: italic; font-weight: bold;">/**
    * Match the regexp against any substring of the input string
    *
    * @param regex the regular expression to match
    *
    * @return a matcher which matches anywhere in the input string
    */</span>
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> Matcher<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> containsMatch<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> regex<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ContainsMatchRegexpMatcher<span style="color: #009900;">&#40;</span>regex<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flamingpenguin.co.uk/blog/2012/01/13/hamcrest-regexp-matcher/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>maven-enunciate-plugin java 7</title>
		<link>http://www.flamingpenguin.co.uk/blog/2011/12/21/maven-enunciate-plugin-java-7/</link>
		<comments>http://www.flamingpenguin.co.uk/blog/2011/12/21/maven-enunciate-plugin-java-7/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 16:29:54 +0000</pubDate>
		<dc:creator>flamingpenguin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jax-rs]]></category>
		<category><![CDATA[maven]]></category>

		<guid isPermaLink="false">http://www.flamingpenguin.co.uk/blog/?p=39</guid>
		<description><![CDATA[It is possible to get the maven-enuniciate-plugin to work with Java 7. You might see an error like this: [ERROR] Failed to execute goal org.codehaus.enunciate:maven-enunciate-plugin:1.24:docs (default) on project Pluto: Execution default of goal org.codehaus.enunciate:maven-enunciate-plugin:1.24:docs failed: A required class was missing while executing org.codehaus.enunciate:maven-enunciate-plugin:1.24:docs: com/sun/mirror/apt/AnnotationProcessorFactory Looks like the tools.jar is not available in Java 7 by [...]]]></description>
			<content:encoded><![CDATA[<p>It is possible to get the maven-enuniciate-plugin to work with Java 7. You might see an error like this:</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">[ERROR] Failed to execute goal org.codehaus.enunciate:maven-enunciate-plugin:1.24:docs (default) on project Pluto: Execution default of goal org.codehaus.enunciate:maven-enunciate-plugin:1.24:docs failed: A required class was missing while executing org.codehaus.enunciate:maven-enunciate-plugin:1.24:docs: com/sun/mirror/apt/AnnotationProcessorFactory</pre></div></div>

<p>Looks like the tools.jar is not available in Java 7 by default. You need to add it as a dependency of the enunciate plugin. If you are using some other (non sun/oracle) JDK then the solution will be different, you may need to use maven profiles for each JDK you want to use. </p>
<p>You can add tools.jar as a dependency like this:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.codehaus.enunciate<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>maven-enunciate-plugin<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>src/main/doc/enunciate.xml<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configFile<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>docs<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goal<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/goals<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
            ...
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/configuration<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/execution<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/executions<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>com.sun<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/groupId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>tools<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/artifactId<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${java.version}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>system<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/scope<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
         <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;systemPath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>${java.home}/../lib/tools.jar<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/systemPath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependency<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
   <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dependencies<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plugin<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>You will now get a warning, which hopefully enunciate will fix sometime before java 8!</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">warning: The apt tool and its associated API are planned to be
removed in the next major JDK release.  These features have been
superseded by javac and the standardized annotation processing API,
javax.annotation.processing and javax.lang.model.  Users are
recommended to migrate to the annotation processing features of
javac; see the javac man page for more information.</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flamingpenguin.co.uk/blog/2011/12/21/maven-enunciate-plugin-java-7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating guice and junit4</title>
		<link>http://www.flamingpenguin.co.uk/blog/2011/11/11/integrating-guice-and-junit4/</link>
		<comments>http://www.flamingpenguin.co.uk/blog/2011/11/11/integrating-guice-and-junit4/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 15:58:10 +0000</pubDate>
		<dc:creator>flamingpenguin</dc:creator>
				<category><![CDATA[guice]]></category>
		<category><![CDATA[java]]></category>

		<guid isPermaLink="false">http://www.flamingpenguin.co.uk/blog/?p=37</guid>
		<description><![CDATA[A JUnit4 Method rule to perform injection on your test fixture before each test case: import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Module; &#160; import org.junit.rules.MethodRule; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.Statement; &#160; public class PerTestGuiceRule implements MethodRule &#123; private final Module module; &#160; public PerTestGuiceRule&#40;final Module module&#41; &#123; this.module = module; &#125; &#160; @Override public Statement apply&#40; final [...]]]></description>
			<content:encoded><![CDATA[<p>A JUnit4 Method rule to perform injection on your test fixture before each test case:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.inject.Guice</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.inject.Injector</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.inject.Module</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.rules.MethodRule</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.runners.model.FrameworkMethod</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.junit.runners.model.Statement</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> PerTestGuiceRule <span style="color: #000000; font-weight: bold;">implements</span> MethodRule
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> Module module<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> PerTestGuiceRule<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> Module module<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">module</span> <span style="color: #339933;">=</span> module<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   @Override
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">Statement</span> apply<span style="color: #009900;">&#40;</span>
            <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Statement</span> base,
            @SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;unused&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">final</span> FrameworkMethod method,
            <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">Object</span> target<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">Statement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
      <span style="color: #009900;">&#123;</span>
         @Override
         <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> evaluate<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Throwable</span>
         <span style="color: #009900;">&#123;</span>
            <span style="color: #000000; font-weight: bold;">final</span> Injector injector <span style="color: #339933;">=</span> Guice.<span style="color: #006633;">createInjector</span><span style="color: #009900;">&#40;</span>module<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            injector.<span style="color: #006633;">injectMembers</span><span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
            base.<span style="color: #006633;">evaluate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
         <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Use it by putting this code in you test fixture:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@Rule <span style="color: #000000; font-weight: bold;">public</span> PerTestGuiceRule guiceRule <span style="color: #339933;">=</span> 
                   <span style="color: #000000; font-weight: bold;">new</span> PerTestGuiceRule<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> MyModule<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
@Inject MyInjectableType myInjectableType<span style="color: #339933;">;</span></pre></div></div>

<p>You might want to check out <a href="http://code.google.com/p/guiceberry/" title="guiceberry">GuiceBerry</a>. I tried to use it, but for my case it seems very complex, or maybe impossible, to create your module per-test due to the static map of module class -> module instance used internally by guiceberry. There is a test scope included, but I don&#8217;t see a really clean way to use that if you want to test your production guice modules.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.flamingpenguin.co.uk/blog/2011/11/11/integrating-guice-and-junit4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Marshalling Immutable Types in Jaxb</title>
		<link>http://www.flamingpenguin.co.uk/blog/2010/10/08/marshalling-immutable-types-in-jaxb/</link>
		<comments>http://www.flamingpenguin.co.uk/blog/2010/10/08/marshalling-immutable-types-in-jaxb/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 10:01:30 +0000</pubDate>
		<dc:creator>flamingpenguin</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[jaxb]]></category>

		<guid isPermaLink="false">http://www.flamingpenguin.co.uk/blog/?p=35</guid>
		<description><![CDATA[Unfortunately Jaxb requires any classes it creates during unmarshalling to have a default no-arguments constructor, and some way of mutating the fields. This prevents the use of types which enforce immutability using final fields. A way to get around this is to use the @XmlJavaTypeAdapter annotation and implement custom marshalling and unmarshalling. For example, create [...]]]></description>
			<content:encoded><![CDATA[<p>Unfortunately Jaxb requires any classes it creates during unmarshalling to have a default no-arguments constructor, and some way of mutating the fields. This prevents the use of types which enforce immutability using final fields.</p>
<p>A way to get around this is to use the <a href="http://download.oracle.com/javase/6/docs/api/javax/xml/bind/annotation/adapters/XmlJavaTypeAdapter.html">@XmlJavaTypeAdapter</a> annotation and implement custom marshalling and unmarshalling.</p>
<p>For example, create a class like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">@XmlJavaTypeAdapter<span style="color: #009900;">&#40;</span>value <span style="color: #339933;">=</span> MyValueXmlAdapter.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyValue
<span style="color: #009900;">&#123;</span>
   <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> value<span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">private</span> MyValue<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> value<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">value</span> <span style="color: #339933;">=</span> value<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   @Override
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> toString<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> value<span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> MyValue valueOf<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> value<span style="color: #009900;">&#41;</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> MyValue<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>and another like this:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> MyValueXmlAdapter <span style="color: #000000; font-weight: bold;">extends</span> XmlAdapter<span style="color: #339933;">&lt;</span>String, MyValue<span style="color: #339933;">&gt;</span>
<span style="color: #009900;">&#123;</span>
   @Override
   <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #003399;">String</span> marshal<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> MyValue value<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> value.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   @Override
   <span style="color: #000000; font-weight: bold;">public</span> MyValue unmarshal<span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">final</span> <span style="color: #003399;">String</span> value<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">Exception</span>
   <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">return</span> MyValue.<span style="color: #006633;">valueOf</span><span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.flamingpenguin.co.uk/blog/2010/10/08/marshalling-immutable-types-in-jaxb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

