<?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>Blog.Project13.pl &#187; java</title>
	<atom:link href="http://www.blog.project13.pl/index.php/tag/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blog.project13.pl</link>
	<description>The Blog of a Coder</description>
	<lastBuildDate>Sun, 05 Feb 2012 02:28:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[conference] Deep Dive Into RoboGuice @ Cracow.Mobi</title>
		<link>http://www.blog.project13.pl/index.php/project13/1389/conference-deep-dive-into-roboguice-cracow-mobi/</link>
		<comments>http://www.blog.project13.pl/index.php/project13/1389/conference-deep-dive-into-roboguice-cracow-mobi/#comments</comments>
		<pubDate>Sat, 10 Dec 2011 00:12:54 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[polish]]></category>
		<category><![CDATA[Project13]]></category>
		<category><![CDATA[conference]]></category>
		<category><![CDATA[di]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[guice]]></category>
		<category><![CDATA[ioc]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jsr330]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[slides]]></category>
		<category><![CDATA[tweets]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1389</guid>
		<description><![CDATA[Today I have presented yet another *new* Android Talk at the Cracow.Mobi conference. This time I focused on RoboGuice, and Guice in general. As from what I&#8217;ve seen a lot of android apps still get written without dependency injection &#8211; which saddens me &#8211; static global variables or weird helpers still come up in apps [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.cracow.mobi" onclick="urchinTracker('/outgoing/www.cracow.mobi?referer=');"><img class="alignright size-medium wp-image-1413" style="background: white; padding: 5px; margin: 5px;" title="logo" src="http://www.blog.project13.pl/wp-content/uploads/2011/12/logo-300x107.png" alt="" width="150" height="70" /></a><br />
Today I have presented yet another *new* <strong>Android</strong> Talk at the <a href="http://cracow.mobi" onclick="urchinTracker('/outgoing/cracow.mobi?referer=');">Cracow.Mobi</a> conference. This time I focused on <a href="http://code.google.com/p/roboguice/" onclick="urchinTracker('/outgoing/code.google.com/p/roboguice/?referer=');"><strong>RoboGuice</strong></a>, and Guice in general.</p>
<p>As from what I&#8217;ve seen a lot of android apps still get written without dependency injection &#8211; which saddens me &#8211; static global variables or weird helpers still come up in apps I do security / performance / code quality audits for &#8211; so I thought that&#8217;s something I need to teach the general audience.</p>
<p>The conference is a 2 day event. Organized by 2 students from Politechnika Krakowska (and a few of their helpers of course), and it&#8217;s a free event. We, as <a href="http://www.llp.pl" onclick="urchinTracker('/outgoing/www.llp.pl?referer=');">Lunar Logic Polska</a>, were proud to be one of the main sponsors of the event. I also personally helped out with a few tips etc, as part of the <a href="http://www.java.pl" onclick="urchinTracker('/outgoing/www.java.pl?referer=');">PolishJUG</a> and <a href="http://krakow.gtug.pl" onclick="urchinTracker('/outgoing/krakow.gtug.pl?referer=');">KrakówGTUG</a>. We also got some swag from the polish Google office which was a really nice gesture from them&#8230; :-) <em>But back to the presentation! Here it is:</em></p>
<p><iframe id="android-conference-deep-dive" src="http://www.blog.project13.pl/wp-content/uploads/2011/12/presentation.html" width="100%" height="450"></iframe></p>
<p><script type="text/javascript">// < ![CDATA[
// < ![CDATA[
// < ![CDATA[
(function() {
function resizeMe(){
   var iFrame =  document.getElementById('android-conference-deep-dive');
   var iFrameBody;
   if ( iFrame.contentDocument ) 
   { // FF
     iFrameBody = iFrame.contentDocument.getElementsByTagName('body')[0];
   }
   else if ( iFrame.contentWindow ) 
   { // IE
     iFrameBody = iFrame.contentWindow.document.getElementsByTagName('body')[0];
   }
 iFrameBody.style.cssText = "zoom: 0.5; -moz-transform: scale(0.5); -moz-transform-origin: 0 0;"
 }
resizeMe();
setTimeout(resizeMe, 500);
})();
// ]]&gt;</script></p>
<p><strong>You can actually use RIGHT/LEFT and H controls in the above iframe to go through the presentation!</strong> <a title="Sources for it are available on my github" href="https://github.com/ktoso/cracow-mobi-android-di" target="_blank" onclick="urchinTracker('/outgoing/github.com/ktoso/cracow-mobi-android-di?referer=');">Sources for it are available on my github</a>.</p>
<p><a href="http://www.blog.project13.pl/wp-content/uploads/2011/12/awesome_tweet_thanks.png"><img class="aligncenter size-medium wp-image-1421" title="awesome_tweet_thanks" src="http://www.blog.project13.pl/wp-content/uploads/2011/12/awesome_tweet_thanks-300x122.png" alt="" width="400" /></a></p>
<p>From the audiences response etc, it seems that this one has been the cleanest, in the sense of &#8220;most fluent&#8221; presentation I&#8217;ve done up until today. I&#8217;ve also went into the code and showed off some minor details. <em>In <a href="http://www.jetbrains.com/idea/" onclick="urchinTracker('/outgoing/www.jetbrains.com/idea/?referer=');">Intellij IDEA 11</a> of course &#8211; be sure to check it out if you&#8217;re an Android (or any kind of) developer! The productivity boost it gives you is &#8220;zomg wooot!&#8221; ;-)</em></p>
<p>I also really enjoyed the talks I was able to attend, and met some old (and possibly quite a few new?) friends. Hope to see you all again!</p>
<p><strong>UPDATE!</strong></p>
<p>This post has been awesomely mentioned by @roboguice :-)</p>
<p><a href="http://www.blog.project13.pl/wp-content/uploads/2011/12/roboguice_cool_tweet.png"><img class="aligncenter size-medium wp-image-1429" title="roboguice_cool_tweet" src="http://www.blog.project13.pl/wp-content/uploads/2011/12/roboguice_cool_tweet-300x135.png" alt="" width="400" /></a></p>
<p><strong>UPDATE 2!</strong></p>
<p>An awesome insider tip from within LLP I recieved today:</p>
<blockquote><p>One guy told me that he was on an Android presentation by some long-haired guy and that it was really good, way better than the rest ;)</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/project13/1389/conference-deep-dive-into-roboguice-cracow-mobi/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[JDK7] java.util.Objects &#8211; forgotten feature?</title>
		<link>http://www.blog.project13.pl/index.php/coding/1284/jdk7-java-lang-objects-forgotten-feature/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/1284/jdk7-java-lang-objects-forgotten-feature/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 09:08:51 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jdk7]]></category>
		<category><![CDATA[lang]]></category>
		<category><![CDATA[oop]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1284</guid>
		<description><![CDATA[This time just a quick post about something I&#8217;d really want to share with you all, and that&#8217;s been kind of forgotten during the release of JDK7 &#8211; java.util.Objects! Be sure to check out it&#8217;s javadoc to see what this small helper class can do for you :-) We&#8217;ll focus on two of it&#8217;s methods. [...]]]></description>
			<content:encoded><![CDATA[<p>This time just a quick post about something I&#8217;d really want to share with you all, and that&#8217;s been kind of forgotten during the release of JDK7 &#8211; <strong>java.util.Objects</strong>! Be sure to check out <a href="http://download.java.net/jdk7/docs/api/java/util/Objects.html" onclick="urchinTracker('/outgoing/download.java.net/jdk7/docs/api/java/util/Objects.html?referer=');">it&#8217;s <strong>javadoc</strong></a> to see what this small helper class can do for you :-) We&#8217;ll focus on two of it&#8217;s methods.</p>
<p>Now, we all remember how painful it it to write good equals and hashCode methods, yet we really should implement them to make our collections work the way they should work (HashAnythings, Lists, Sets). So we sometimes use <strong>Apache Commons</strong> to implement these, or just leave the coding to <strong>IntelliJ</strong> or <strong>NetBeans</strong>. The problem with the second, code generating, solution is that it&#8217;s a hell of a mess. Don&#8217;t believe me&#8230;? Just a quick reminder then&#8230;</p>
<div class="geshi no java">
<div class="head">class Test {</div>
<ol>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">private</span> <span class="kw3">String</span> &nbsp;name<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">private</span> <span class="kw3">String</span> &nbsp;surname<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">private</span> <span class="kw3">Integer</span> age<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; @Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">public</span> <span class="kw4">boolean</span> equals<span class="br0">&#40;</span><span class="kw3">Object</span> o<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw2">this</span> == o<span class="br0">&#41;</span> <span class="kw2">return</span> <span class="kw2">true</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>o == <span class="kw2">null</span> || getClass<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">!</span>= o.<span class="me1">getClass</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw2">return</span> <span class="kw2">false</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Test test = <span class="br0">&#40;</span>Test<span class="br0">&#41;</span> o<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>age <span class="sy0">!</span>= <span class="kw2">null</span> <span class="sy0">?</span> <span class="sy0">!</span>age.<span class="me1">equals</span><span class="br0">&#40;</span>test.<span class="me1">age</span><span class="br0">&#41;</span> : test.<span class="me1">age</span> <span class="sy0">!</span>= <span class="kw2">null</span><span class="br0">&#41;</span> <span class="kw2">return</span> <span class="kw2">false</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>name <span class="sy0">!</span>= <span class="kw2">null</span> <span class="sy0">?</span> <span class="sy0">!</span>name.<span class="me1">equals</span><span class="br0">&#40;</span>test.<span class="me1">name</span><span class="br0">&#41;</span> : test.<span class="me1">name</span> <span class="sy0">!</span>= <span class="kw2">null</span><span class="br0">&#41;</span> <span class="kw2">return</span> <span class="kw2">false</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>surname <span class="sy0">!</span>= <span class="kw2">null</span> <span class="sy0">?</span> <span class="sy0">!</span>surname.<span class="me1">equals</span><span class="br0">&#40;</span>test.<span class="me1">surname</span><span class="br0">&#41;</span> : test.<span class="me1">surname</span> <span class="sy0">!</span>= <span class="kw2">null</span><span class="br0">&#41;</span> <span class="kw2">return</span> <span class="kw2">false</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">return</span> <span class="kw2">true</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; @Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">public</span> <span class="kw4">int</span> hashCode<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> result = name <span class="sy0">!</span>= <span class="kw2">null</span> <span class="sy0">?</span> name.<span class="me1">hashCode</span><span class="br0">&#40;</span><span class="br0">&#41;</span> : <span class="nu0">0</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; result = <span class="nu0">31</span> <span class="sy0">*</span> result + <span class="br0">&#40;</span>surname <span class="sy0">!</span>= <span class="kw2">null</span> <span class="sy0">?</span> surname.<span class="me1">hashCode</span><span class="br0">&#40;</span><span class="br0">&#41;</span> : <span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; result = <span class="nu0">31</span> <span class="sy0">*</span> result + <span class="br0">&#40;</span>age <span class="sy0">!</span>= <span class="kw2">null</span> <span class="sy0">?</span> age.<span class="me1">hashCode</span><span class="br0">&#40;</span><span class="br0">&#41;</span> : <span class="nu0">0</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">return</span> result<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Now that we&#8217;ve remembered how painful it looks, let&#8217;s dive into JDK7:  The full code would look like this (this time equals is also accepting subclasses of Test, the above example didn&#8217;t):</p>
<div class="geshi no java">
<div class="head">package pl.project13;</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.Objects;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* Date: 4/19/11</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* @author Konrad Malawski</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> Test <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">private</span> <span class="kw3">String</span> &nbsp;name<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">private</span> <span class="kw3">String</span> &nbsp;surname<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">private</span> <span class="kw3">Integer</span> age<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">public</span> Test<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">public</span> Test<span class="br0">&#40;</span><span class="kw3">String</span> name, <span class="kw3">String</span> surname, <span class="kw3">Integer</span> age<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">name</span> = name<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">surname</span> = surname<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">age</span> = age<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">public</span> Test<span class="br0">&#40;</span><span class="kw3">String</span> name, <span class="kw3">String</span> surname<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">name</span> = name<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">surname</span> = surname<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; @Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">public</span> <span class="kw4">boolean</span> equals<span class="br0">&#40;</span><span class="kw3">Object</span> o<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="kw2">this</span> == o<span class="br0">&#41;</span> <span class="kw2">return</span> <span class="kw2">true</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><span class="br0">&#40;</span>o <span class="kw2">instanceof</span> Test<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="kw2">return</span> <span class="kw2">false</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1">// &nbsp; &nbsp;if (o == null || getClass() != o.getClass()) return false;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Test that = <span class="br0">&#40;</span>Test<span class="br0">&#41;</span> o<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">boolean</span> result = <span class="kw2">true</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; result = result <span class="sy0">&amp;&amp;</span> Objects.<span class="me1">equals</span><span class="br0">&#40;</span><span class="kw2">this</span>.<span class="me1">name</span>, that.<span class="me1">name</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; result = result <span class="sy0">&amp;&amp;</span> Objects.<span class="me1">equals</span><span class="br0">&#40;</span><span class="kw2">this</span>.<span class="me1">surname</span>, that.<span class="me1">surname</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; result = result <span class="sy0">&amp;&amp;</span> Objects.<span class="me1">equals</span><span class="br0">&#40;</span><span class="kw2">this</span>.<span class="me1">age</span>, that.<span class="me1">age</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">return</span> result<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; @Override</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">public</span> <span class="kw4">int</span> hashCode<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">return</span> Objects.<span class="me1">hash</span><span class="br0">&#40;</span>name, surname, age<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Note the<strong> Objects.hash() </strong>method, wich is really a lifesaver and also the <strong>Objects.equals()</strong> method which makes our code NullPointerException safe, which the previous version had to tackle by using <strong>?:</strong>&#8230; And it read&#8217;s much nicer, Of course, you could skip the result variable, but I decided to do it like this for the sake of easy reading.</p>
<p>And here is it&#8217;s test:</p>
<div class="geshi no java">
<div class="head">package pl.project13;</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.HashSet;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.Set;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import java.util.TreeSet;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import static junit.framework.Assert.assertEquals;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import static junit.framework.Assert.assertFalse;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co2">import static junit.framework.Assert.assertTrue;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">/**</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* Date: 4/19/11</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;* @author Konrad Malawski</span></div>
</li>
<li class="li1">
<div class="de1"><span class="coMULTI">&nbsp;*/</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> TestTest <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; @org.<span class="me1">junit</span>.<span class="me1">Test</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">public</span> <span class="kw4">void</span> testEquals<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw2">throws</span> <span class="kw3">Exception</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Test test = <span class="kw2">new</span> Test<span class="br0">&#40;</span><span class="st0">&quot;Konrad&quot;</span>, <span class="st0">&quot;Malawski&quot;</span>, <span class="nu0">21</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// true</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; assertTrue<span class="br0">&#40;</span>test.<span class="me1">equals</span><span class="br0">&#40;</span>test<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; assertTrue<span class="br0">&#40;</span>test.<span class="me1">equals</span><span class="br0">&#40;</span><span class="kw2">new</span> Test<span class="br0">&#40;</span><span class="st0">&quot;Konrad&quot;</span>, <span class="st0">&quot;Malawski&quot;</span>, <span class="nu0">21</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">// false</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; assertFalse<span class="br0">&#40;</span>test.<span class="me1">equals</span><span class="br0">&#40;</span><span class="kw2">new</span> Test<span class="br0">&#40;</span><span class="st0">&quot;Wacław&quot;</span>, <span class="st0">&quot;Malawski&quot;</span>, <span class="nu0">1825</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; assertFalse<span class="br0">&#40;</span>test.<span class="me1">equals</span><span class="br0">&#40;</span><span class="kw2">new</span> Test<span class="br0">&#40;</span><span class="st0">&quot;Wacław&quot;</span>, <span class="st0">&quot;Malawski&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; assertFalse<span class="br0">&#40;</span>test.<span class="me1">equals</span><span class="br0">&#40;</span><span class="kw2">new</span> Test<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; assertFalse<span class="br0">&#40;</span>test.<span class="me1">equals</span><span class="br0">&#40;</span><span class="kw2">new</span> <span class="kw3">Object</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; assertFalse<span class="br0">&#40;</span>test.<span class="me1">equals</span><span class="br0">&#40;</span><span class="kw2">null</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; @org.<span class="me1">junit</span>.<span class="me1">Test</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">public</span> <span class="kw4">void</span> testHashCodeOnCollections<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw2">throws</span> <span class="kw3">Exception</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Test test = <span class="kw2">new</span> Test<span class="br0">&#40;</span><span class="st0">&quot;Konrad&quot;</span>, <span class="st0">&quot;Malawski&quot;</span>, <span class="nu0">21</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> sizeBefore<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> sizeAfter<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">Set</span> treeSet = <span class="kw2">new</span> HashSet<span class="sy0">&amp;</span>lt<span class="sy0">;&amp;</span>gt<span class="sy0">;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; treeSet.<span class="me1">add</span><span class="br0">&#40;</span>test<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; sizeBefore = treeSet.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; treeSet.<span class="me1">add</span><span class="br0">&#40;</span>test<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; sizeAfter = treeSet.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; assertEquals<span class="br0">&#40;</span>sizeBefore, sizeAfter<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; @org.<span class="me1">junit</span>.<span class="me1">Test</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw2">public</span> <span class="kw4">void</span> testHashCodeOnCollectionsOtherObject<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw2">throws</span> <span class="kw3">Exception</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Test test = <span class="kw2">new</span> Test<span class="br0">&#40;</span><span class="st0">&quot;Konrad&quot;</span>, <span class="st0">&quot;Malawski&quot;</span>, <span class="nu0">21</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Test test2 = <span class="kw2">new</span> Test<span class="br0">&#40;</span><span class="st0">&quot;Konrad&quot;</span>, <span class="st0">&quot;Malawski&quot;</span>, <span class="nu0">21</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> sizeBefore<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw4">int</span> sizeAfter<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">Set</span> treeSet = <span class="kw2">new</span> HashSet<span class="sy0">&amp;</span>lt<span class="sy0">;&amp;</span>gt<span class="sy0">;</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; treeSet.<span class="me1">add</span><span class="br0">&#40;</span>test<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; sizeBefore = treeSet.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; treeSet.<span class="me1">add</span><span class="br0">&#40;</span>test2<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; sizeAfter = treeSet.<span class="me1">size</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; assertEquals<span class="br0">&#40;</span>sizeBefore, sizeAfter<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>Now that was nice wasn&#8217;t it? :-) <strong>Objects </strong>probably isn&#8217;t &#8220;the&#8221; killer feature that JDK7 has, but it&#8217;s a really nice addition, so let&#8217;s get to using it :-) The other utility methods in this class are:</p>
<ul>
<li><strong>static &lt;T&gt; int	compare(T a, T b, Comparator &lt; ? super T&gt; c)</strong><br />
Returns 0 if the arguments are identical and c.compare(a, b) otherwise.</li>
<li><strong>static boolean	deepEquals(Object a, Object b)</strong><br />
Returns true if the arguments are deeply equal to each other and false otherwise.</li>
<li><strong>static boolean	equals(Object a, Object b)</strong><br />
Returns true if the arguments are equal to each other and false otherwise.</li>
<li><strong>static int	hash(Object&#8230; values)</strong><br />
Generates a hash code for a sequence of input values.</li>
<li><strong>static int	hashCode(Object o)</strong><br />
Returns the hash code of a non-null argument and 0 for a null argument.</li>
<li><strong>static &lt;T&gt; T	requireNonNull(T obj)</strong><br />
Checks that the specified object reference is not null.</li>
<li><strong>static &lt;T&gt; T	requireNonNull(T obj, String message)</strong><br />
Checks that the specified object reference is not null and throws a customized NullPointerException if it is.</li>
<li><strong>static String	toString(Object o)</strong><br />
Returns the result of calling toString for a non-null argument and &#8220;null&#8221; for a null argument.</li>
<li><strong>static String	toString(Object o, String nullDefault)</strong><br />
Returns the result of calling toString on the first argument if the first argument is not null and returns the second argument otherwise.</li>
</ul>
<p>Hooray for small litle improvements :-) This class officialy get&#8217;s Duke&#8217;s thumbs up image:</p>
<p style="text-align: center;"><img class="aligncenter" title="Java-duke" src="http://www.blog.project13.pl/wp-content/uploads/2011/04/Java-duke.jpg" alt="" width="200" height="235" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/1284/jdk7-java-lang-objects-forgotten-feature/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[review] CodeRetreat.SCKRK.com</title>
		<link>http://www.blog.project13.pl/index.php/fun/1230/review-coderetreat-sckrk-com/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/1230/review-coderetreat-sckrk-com/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 09:18:06 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[clean code]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[coderetreat]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[meeting]]></category>
		<category><![CDATA[objective-c]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1230</guid>
		<description><![CDATA[This Saturday we&#8217;ve (the Software Craftsmanship in Cracow guys) organized a Code Retreat, right after AgileCE. We&#8217;ve invited Corey Haines to join us and facilitate this meetup, and later on even Alexandru Bolboaca AND Maria Diaconu joined us in facilitating the event and so it got even better :-) Before we start, just a quick reminder [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://www.blog.project13.pl/wp-content/uploads/2011/04/cr-sckrk.gif"><img class="aligncenter size-full wp-image-1261" title="Code Retreat . SCKRK .com" src="http://www.blog.project13.pl/wp-content/uploads/2011/04/cr-sckrk.gif" alt="" width="520" /></a></p>
<p>This Saturday we&#8217;ve (the <a href="http://sckrk.com" onclick="urchinTracker('/outgoing/sckrk.com?referer=');">Software Craftsmanship in Cracow</a> guys) organized a <a href="http://www.coderetreat.com/" onclick="urchinTracker('/outgoing/www.coderetreat.com/?referer=');">Code Retreat</a>, <strong>right after AgileCE</strong>. We&#8217;ve invited <a href="http://www.coreyhaines.com/" onclick="urchinTracker('/outgoing/www.coreyhaines.com/?referer=');"><strong>Corey Haines</strong></a> to join us and facilitate this meetup, and later on even <a href="http://www.alexbolboaca.ro/" onclick="urchinTracker('/outgoing/www.alexbolboaca.ro/?referer=');"><strong>Alexandru Bolboaca</strong></a> AND <strong><a href="https://twitter.com/#!/fireladym" onclick="urchinTracker('/outgoing/twitter.com/_/fireladym?referer=');">Maria Diaconu</a> </strong> joined us in facilitating the event and so it got <strong>even better</strong> :-)</p>
<div class="wp-caption aligncenter" style="width: 557px"><img class=" " src="https://lh4.googleusercontent.com/_R79BchylD5A/TaI4-NlZY9I/AAAAAAAASrw/A7wNhXDuTd0/s1024/IMG_9268.jpg" alt="Corey doing the introductional Keynote" width="547" /><p class="wp-caption-text">Corey doing the introductional Keynote</p></div>
<p>Before we start, just a quick reminder what a CodeRetreat actually is (for the sake of everyone reading this blog not knowing what the hell I&#8217;m so excited about ;-)). The rules are really easy, take a bynch of passionate programmers, put them in a room for 1 whole day and tell them to code the game of life. There are about 6 sessions, where each time you&#8217;d <strong>pair up with another person </strong>and code away. After <strong>45 minutes you have to delete the code you&#8217;ve written</strong>, then after a 15m pause to talk about your results you find a new pair and code it again from scratch. It&#8217;s important to embrace the code deleting part &#8211; it&#8217;s somewhat like catharsis&#8230; :-) No matter how bad (or great) the code you&#8217;ve written was, on average in 22.5 minutes it will go away :-)  The idea is to embrace that you most probably won&#8217;t finish the problem in time, so you can just focus on honing your skills in TDD, pairing, IDE usage and generale code style and skillz. There&#8217;s no better way to learn these skills than to confront them with someone else&#8217;s &#8211; that way you both can learn new tricks or find out why some ol tricks you used actually suck :-) In the end of the day, you&#8217;ve become a better programmer&#8230; and will hopefully take these new skills into your workplace and <strong>improve the code quality</strong> there :-)</p>
<div class="wp-caption aligncenter" style="width: 557px"><img class=" " src="https://lh6.googleusercontent.com/_R79BchylD5A/TaI5H7DwO6I/AAAAAAAASsc/JuG5XZ0j8lA/s912/P1020923.jpg" alt="" width="547" height="410" /><p class="wp-caption-text">Happy hacking!</p></div>
<p>The response to our CR was really amazing. We&#8217;ve had quite a few sponsors &#8211; LunarLogic, AppliCake, ABB, Sii&#8230; and the PolishJUG helped out as well as it could with organizing the whole thing :-) Oh, and I hope you&#8217;ve seen our <a href="http://coderetreat.sckrk.com" onclick="urchinTracker('/outgoing/coderetreat.sckrk.com?referer=');">nice website</a> created by Olga from LLP? The interest from participants was equally big &#8211; all places where <strong>&#8220;sold out&#8221;</strong> <strong>in just about 3 hours</strong>&#8230; ;-) We where around 50 people in total and I think that&#8217;s a perfect number of coders for such an event. Some coded in <strong>Java</strong>, some in <strong>.NET</strong> and others in <strong>Ruby</strong> or <strong>Python</strong>, oh and there was an <strong>Objective-C</strong> and <strong>Scala</strong> team too. One of the nive things during a CR is being able to try out a new language, so the Ruby guys where really overflown by people wanting to try Ryby for example ;-) I&#8217;ve spent the rest of my sessions (4/5) coding in <strong>Java</strong> and just once had to lay hands on Eclipse&#8230; ;-) During one session I tried out ruby (<strong>ルビ</strong>) with Adam from SCKRK, which was fun as I did read some books/articles about it and really enjoyed the<strong> BDD</strong> that <strong>rspec</strong> uses. I also noticed that scala test seems to have derrived from it (or the other way arround :p)&#8230; :-)</p>
<div class="wp-caption aligncenter" style="width: 557px"><img src="https://lh6.googleusercontent.com/_R79BchylD5A/TZy8APe9mVI/AAAAAAAASlY/W2immHPMbrw/s912/P1000737.JPG" alt="The 2nd room was also full" width="547" height="410" /><p class="wp-caption-text">The 2nd room was also full</p></div>
<p style="text-align: left;">After two sessions we had <strong>nice long lunch</strong>, to relinquish our coding skills and ideas (we&#8217;ve ordered from <a href="http://thaisty.pl/" onclick="urchinTracker('/outgoing/thaisty.pl/?referer=');">thaist</a>y). And then a next set of 3 sessions followed. This time more focused on experimentation etc. For example one session we managed to <strong>not use if&#8217;s and for&#8217;s at all</strong> (sigh, upto one place but the time ran out then..). Google Guava was a great help there :-) On another sessions we&#8217;ve focused on <strong>Mockito</strong> and the more advanced mocking techniques such as parameter catching etc&#8230; In the end we really knew how much over engeenired it was but nevertheless it was really <strong>interesting to learn and play</strong> with these thoughts &#8211; that&#8217;s what CR is about.</p>
<div class="wp-caption aligncenter" style="width: 557px"><img class="  " title="Final Wrap Up" src="https://lh5.googleusercontent.com/_R79BchylD5A/TaI5gGby0xI/AAAAAAAAStU/vrCo3rVcnq4/s1024/IMG_9249.jpg" alt="" width="547" />1<p class="wp-caption-text">Final Wrap Up</p></div>
<p>Later on we&#8217;ve sent out a questionary on how much you enjoyed the CR and the response was also really positive. We&#8217;ll think about coffee next time &#8211; promissed. :-)</p>
<p>Stanley just pulled in my quick gallery commit to our website <strong>git</strong> repo a moment ago, so you can now visit <a href="http://coderetreat.sckrk.com/gallery/" onclick="urchinTracker('/outgoing/coderetreat.sckrk.com/gallery/?referer=');"><strong>coderetreat.</strong>sckrk.com/<strong>gallery</strong></a> and look for yourself on the pics :-) They&#8217;re fetched from <a href="https://picasaweb.google.com/ktosopl/CodeRetreat2011#" onclick="urchinTracker('/outgoing/picasaweb.google.com/ktosopl/CodeRetreat2011?referer=');">my picasa</a> so if you&#8217;d rather download them all from there, please do so :-)</p>
<div id="attachment_1274" class="wp-caption aligncenter" style="width: 557px"><a href="http://www.blog.project13.pl/wp-content/uploads/2011/04/P1020931.jpg"><img class="size-full wp-image-1274 " title="group photo coderetreat" src="http://www.blog.project13.pl/wp-content/uploads/2011/04/P1020931.jpg" alt="" width="547" height="410" /></a><p class="wp-caption-text">Group Photo</p></div>
<p>All in all&#8230; I&#8217;m really happy and proud to have been part of this event. It&#8217;s really been one of a kind and I hope all of you feel the same way about it. Well, it would certainly seem so after the opinions on the final wrap up and questionary later on. :-) So, once again, <strong>thank you for participating</strong> and see you soon on most major coding events :-) (ps: <a href="http://2011.geecon.org" onclick="urchinTracker('/outgoing/2011.geecon.org?referer=');"><strong>GeeCON</strong></a> is one of them).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/1230/review-coderetreat-sckrk-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[git] bisect + maven = automate &#8220;breaking&#8221; commit search</title>
		<link>http://www.blog.project13.pl/index.php/coding/1217/git-bisect-maven-automate-breaking-commit-search/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/1217/git-bisect-maven-automate-breaking-commit-search/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 21:34:31 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[#maven]]></category>
		<category><![CDATA[bisect]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[runner]]></category>
		<category><![CDATA[SCM]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1217</guid>
		<description><![CDATA[Hey there guys. I hope some you enjoyed my presentation on SFI last weekend. The workshop was kinda chaotic (network problems mailny) but I&#8217;m sure some of you got convinced to use, or begin with trying out, git in yout next projects&#8230; :-) Well, that was all nice and cool but git (other DVCS have [...]]]></description>
			<content:encoded><![CDATA[<p>Hey there guys. I hope some you enjoyed my presentation on SFI last weekend. The workshop was kinda chaotic (network problems mailny) but I&#8217;m sure some of you got convinced to use, or begin with trying out, git in yout next projects&#8230; :-)</p>
<p>Well, that was all nice and cool but git (other DVCS have this too) has a lot more to offer! :-) Today we&#8217;ll look into git bisect and how to automate it&#8217;s execution using maven to look for a commit that breakes something. You may run ANY SCRIPT and even write your own and git will use it to test if a commit is &#8220;bad&#8221; or &#8220;good&#8221;. Ok, but let&#8217;s slowdown a little&#8230; What git bisect basically does is performing an binary search, between a range of commits you specify looking for &#8220;the first bad commit&#8221; you you can easily find what caused the bug and fix it. You can drive it by hand and after starting git bisect just test the commit by hand and tell git if it&#8217;s good or bad by &#8220;git bisect bad&#8221; &#8220;git bisect good&#8221;. Git is smart enough to find what commit he should &#8220;git checkout &#8230;&#8221; next to perform a binary search based on your anwsers. </p>
<p>Today we&#8217;ll learn how to make git cooperate with maven and find the first commit that introduced a test failure. See bellow for the full workflow you showcasing this:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames breakMe $ mvn org.apache.maven.plugins:maven-archetype-plugin:<span class="nu0">1.0</span>-alpha<span class="nu0">-7</span>:create -<span class="re2">DarchetypeGroupId=</span>org.apache.maven.archetypes -<span class="re2">DarchetypeArtifactId=</span>maven-archetype-quickstart -<span class="re2">DartifactId=</span>bisectfun -<span class="re2">DgroupId=</span>pl.project13</div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames breakMe $ <span class="kw2">ls</span></div>
</li>
<li class="li1">
<div class="de1">bisectfun &nbsp;mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames breakMe $ <span class="kw3">cd</span> bisectfun<span class="sy0">/</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ <span class="kw2">mkdir</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ git init .</div>
</li>
<li class="li1">
<div class="de1">Initialized empty Git repository <span class="kw1">in</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>breakMe<span class="sy0">/</span>bisectfun<span class="sy0">/</span>.git<span class="sy0">/</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ git commit ^C</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ vim .gitignore</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ git add .</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ git commit </div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master <span class="br0">&#40;</span>root-commit<span class="br0">&#41;</span> 5b46510<span class="br0">&#93;</span> &nbsp;Initial commit</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">4</span> files changed, <span class="nu0">78</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">0</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> .gitignore</div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> pom.xml</div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> src<span class="sy0">/</span>main<span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>App.java</div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">********************************************************************************</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Git Achievement Unlocked<span class="sy0">!</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Master Author <span class="br0">&#40;</span>Level <span class="nu0">10</span><span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Made <span class="nu0">2</span>^Level commits using git commit. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">********************************************************************************</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ mvn <span class="kw3">test</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>INFO<span class="br0">&#93;</span> BUILD SUCCESSFUL</div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
</ol>
</div>
<p>Ok up until now we&#8217;ve just created a simple repository we&#8217;ll be running the tests on. Let&#8217;s tag this state as &#8220;yeah it&#8217;s working here&#8221; just so that I don&#8217;t have to remeber the SHA-1 of this commit. </p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git tag wasOkHere</div>
</li>
</ol>
</div>
<p>And now we&#8217;ll run a script that does some random commit action, just so that bisect has a lot of commits to work on.</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw1">for</span> i <span class="kw1">in</span> <span class="br0">&#123;</span><span class="nu0">1</span>..<span class="nu0">50</span><span class="br0">&#125;</span>; <span class="kw1">do</span> fortune <span class="sy0">&gt;</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span>fortune<span class="re1">$i</span>; git add .; git commit -a -m <span class="st0">&#39;some commit&#39;</span>; <span class="kw1">done</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master 20ae1c1<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">1</span> files changed, <span class="nu0">3</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">0</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span>fortune1</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master 64b779e<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">1</span> files changed, <span class="nu0">15</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">0</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span>fortune2</div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ mvn clean <span class="kw3">test</span> <span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null <span class="nu0">2</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw3">echo</span> <span class="re4">$?</span></div>
</li>
<li class="li1">
<div class="de1"><span class="nu0">0</span></div>
</li>
</ol>
</div>
<p>The tests are still passing&#8230; time to change that! We&#8217;ll break the build with the following commit. And then generate yet another 50 commits to &#8220;hide it&#8221;&#8230; ;-)</p>
<div class="geshi no bash">
<div class="head">ktoso@dynames bisectfun @ master $ echo &#8220;fail :D&#8221; >> src/test/java/pl/project13/AppTest.java</div>
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw3">echo</span> <span class="st0">&quot;fail :D&quot;</span> <span class="sy0">&gt;&gt;</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java </div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw3">echo</span> <span class="st0">&quot;fail :D&quot;</span> <span class="sy0">&gt;&gt;</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java </div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git add .</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git commit </div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master 09a58fb<span class="br0">&#93;</span> <span class="kw3">let</span> it crash</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">1</span> files changed, <span class="nu0">3</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">0</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw1">for</span> i <span class="kw1">in</span> <span class="br0">&#123;</span><span class="nu0">1</span>..<span class="nu0">50</span><span class="br0">&#125;</span>; <span class="kw1">do</span> fortune <span class="sy0">&gt;</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span>fortune<span class="re1">$i</span>; git add .; git commit -a -m <span class="st0">&#39;some commit&#39;</span>; <span class="kw1">done</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master f83cdae<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">1</span> files changed, <span class="nu0">3</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">3</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master 725c5ce<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">1</span> files changed, <span class="nu0">4</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">15</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;rewrite src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span>fortune2 <span class="br0">&#40;</span><span class="nu0">100</span><span class="sy0">%</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw1">for</span> i imvn clean <span class="kw3">test</span> <span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null <span class="nu0">2</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw3">echo</span> <span class="re4">$?</span></div>
</li>
<li class="li1">
<div class="de1"><span class="nu0">1</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw3">echo</span> <span class="st0">&#39;!!!!!!!!!!!!!!OH NO IT FAILS!!!!!!!!&#39;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">!!!!!!!!!!!!!!!!</span>OH NO IT FAILS<span class="sy0">!!!!!!!!</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git tag failsHere</div>
</li>
</ol>
</div>
<p>Ok the test&#8217;s fail now. But suppose you didn&#8217;t know which commit introduced the bug (in our case made the test&#8217;s fail). You&#8217;d have to guess which one, or check them all or just work it out by looking at your current repository state. But since you&#8217;re doing small commits and do them often &#8211; it&#8217;ll be great if you found out which commit caused this failure. As it&#8217;s preferably small, it&#8217;ll be very easy to find out what change caused the build to fail. No is the time to use <strong>git bisect</strong>!</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git bisect start</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git bisect bad failsHere </div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git bisect good wasOkHere </div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">50</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">6</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>ca199e0cbd19e498eabf6196036313e206b00a7f<span class="br0">&#93;</span> some commit</div>
</li>
</ol>
</div>
<p>We&#8217;ve started bisect, and told him which commit we&#8217;re sure is working and which we&#8217;re sure is failing. Git will now checkout a commit he found &#8220;somewhat in the middle&#8221; and will continue to bisect (binary search) the commit history based on wether a commit is &#8220;good&#8221; or &#8220;bad&#8221;. We could just tell it git by hand by doing &#8220;git bisect good/bad&#8221; etc. But let&#8217;s <strong>git bisect run</strong> a script to do this for us :</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> <span class="br0">&#40;</span>no branch<span class="br0">&#41;</span> $ git bisect run ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">25</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">5</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>c8658db8e0c5df1d603a9a96ae7a04e71c4ba9d1<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">12</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">4</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>ddc2100ab90d0624df74e81f17d7ed7ea0fc9a61<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">5</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">3</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>31ba35661eecb7a96159e483954d315a63a3789d<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">2</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">2</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>725c5cec8803b1e62dd36a3b74fd8c52d42e807c<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">0</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">1</span> step<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>f83cdaeb34072a6f9c9a63abf8bb8f2390b996de<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">0</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">0</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>09a58fbf2821c4f66c003a65f19f6ff99f5ee37d<span class="br0">&#93;</span> <span class="kw3">let</span> it crash</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">09a58fbf2821c4f66c003a65f19f6ff99f5ee37d is the first bad commit</div>
</li>
<li class="li1">
<div class="de1">commit 09a58fbf2821c4f66c003a65f19f6ff99f5ee37d</div>
</li>
<li class="li1">
<div class="de1">Author: Konrad Malawski <span class="sy0">&lt;</span>konrad .malawski<span class="sy0">@</span>project13.pl<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">Date: &nbsp; Wed Mar <span class="nu0">16</span> <span class="nu0">22</span>:<span class="nu0">02</span>:<span class="nu0">38</span> <span class="nu0">2011</span> <span class="nu0">+0100</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> it crash</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">:<span class="nu0">040000</span> <span class="nu0">040000</span> ef88527072e0b1532819a75f288a0e65a2737c6a 49083a7d820a731d5edad117a4af097bd9ffb444 M &nbsp; &nbsp; &nbsp;src</div>
</li>
<li class="li1">
<div class="de1">bisect run success</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> <span class="br0">&#40;</span>no branch<span class="br0">&#41;</span> $ git show 09a58fbf2821c4f66c003a65f19f6ff99f5ee37d</div>
</li>
<li class="li1">
<div class="de1">commit 09a58fbf2821c4f66c003a65f19f6ff99f5ee37d</div>
</li>
<li class="li1">
<div class="de1">Author: Konrad Malawski <span class="sy0">&lt;/</span>konrad<span class="sy0">&gt;&lt;</span>konrad .malawski<span class="sy0">@</span>project13.pl<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">Date: &nbsp; Wed Mar <span class="nu0">16</span> <span class="nu0">22</span>:<span class="nu0">02</span>:<span class="nu0">38</span> <span class="nu0">2011</span> <span class="nu0">+0100</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> it crash</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">diff</span> &#8211;git a<span class="sy0">/</span>src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java b<span class="sy0">/</span>src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java</div>
</li>
<li class="li1">
<div class="de1">index c6ffd44..b27c8b8 <span class="nu0">100644</span></div>
</li>
<li class="li1">
<div class="de1">&#8212; a<span class="sy0">/</span>src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java</div>
</li>
<li class="li1">
<div class="de1">+++ b<span class="sy0">/</span>src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">@@</span> <span class="nu0">-36</span>,<span class="nu0">3</span> <span class="nu0">+36</span>,<span class="nu0">6</span> <span class="sy0">@@</span> public class AppTest</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;assertTrue<span class="br0">&#40;</span> <span class="kw2">true</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">+fail :D</div>
</li>
<li class="li1">
<div class="de1">+fail :D</div>
</li>
<li class="li1">
<div class="de1">+fail :D</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> <span class="br0">&#40;</span>no branch<span class="br0">&#41;</span> $ git bisect reset </div>
</li>
<li class="li1">
<div class="de1">Previous HEAD position was 09a58fb&#8230; <span class="kw3">let</span> it crash</div>
</li>
<li class="li1">
<div class="de1">Switched to branch <span class="st0">&#39;master&#39;</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ </div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>konrad<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Yeah, we&#8217;ve found our failing commit :-) You could use any script you want here, it just has to return 0 if git should think it&#8217;s a &#8220;good commit&#8221; and &#8220;not 0&#8243; if it&#8217;s a &#8220;bad commit&#8221;. I&#8217;ve even seen runners written in PHP running or spellcheckers &#8211; you name it&#8230; :-) Ok but how does this magical script that we&#8217;ve just run look like?</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1"><span class="co0">#!/bin/sh</span></div>
</li>
<li class="li1">
<div class="de1">mvn clean <span class="kw3">test</span> <span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null <span class="nu0">2</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null</div>
</li>
</ol>
</div>
<p>Whoa, that&#8217;s simple&#8230; :-) Keep on git hacking guys! See you soon, with some more git or java tips&#8230; :-) Oh and I&#8217;ll post my presentation (holefully with video) from SFI soon, so keep an eye out! :-)</p>
<p>PS: Yup, the <strong>code retreat</strong> we&#8217;re (SCKRK with a little help from the <a href="http://www.java.pl" onclick="urchinTracker('/outgoing/www.java.pl?referer=');">PolishJUG</a>) organizing got &#8220;sold out&#8221; after just 3h&#8230; ;-) Be sure to take a look and be quicker next time! <a href="http://coderetreat.sckrk.com" onclick="urchinTracker('/outgoing/coderetreat.sckrk.com?referer=');">http://coderetreat.sckrk.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/1217/git-bisect-maven-automate-breaking-commit-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[review] Devmeeting &#8211; Javascript Game Development</title>
		<link>http://www.blog.project13.pl/index.php/fun/1181/review-devmeeting-javascript-game-development/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/1181/review-devmeeting-javascript-game-development/#comments</comments>
		<pubDate>Sun, 20 Feb 2011 23:21:12 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[clientside]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[meeting]]></category>
		<category><![CDATA[node.js]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[serverside]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[training]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1181</guid>
		<description><![CDATA[Yesterday and today I&#8217;ve been hacking some JavaScript during a free training organized by http://releasingforce.com/ although they&#8217;re not really braging that it&#8217;s them who do these meetings, more precisely: http://www.devmeetings.pl/ :-) As I&#8217;m coding quite a lot GWT and JS has also become quite powerfull in the last years I enlisted the training to learn [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday and today I&#8217;ve been hacking some JavaScript during a free training organized by <a href="http://releasingforce.com/" onclick="urchinTracker('/outgoing/releasingforce.com/?referer=');">http://releasingforce.com/</a> although they&#8217;re not really braging that it&#8217;s them who do these meetings, more precisely: <a href="http://www.devmeetings.pl/" onclick="urchinTracker('/outgoing/www.devmeetings.pl/?referer=');">http://www.<strong>devmeetings</strong>.pl/</a> :-)</p>
<p>As I&#8217;m coding quite a lot GWT and JS has also become quite powerfull in the last years I enlisted the training to learn more about JS optimalization and add some more tricks to my toolbox. Also some real life use scenarios would be very welcome. Turns out Tanadu (a polish &#8220;heroes-like&#8221; browser game) was implemented 100% in plain JS. Which is quite shocking and as we later agreed on developing such code can really be a pain in the neck. &#8220;Use GWT&#8221; would be my anwser to such an use case I guess &#8211; you wouldn&#8217;t loose the refactoring tooling Java gives you and could still fallback to JSNI if really needed. <strong>Did the &#8220;training&#8221; meet my expectations? Yup. Want more details? Read on&#8230; :-)</strong></p>
<p>It was really fun and I&#8217;ve even (and unexpectedly) met a friend of mine with whom (and one other developer) we&#8217;ve paired up and were coding a JS Mortal Kombat in JavaScript for those two days. We&#8217;ve learnt how to use CSS3 *-animation, *- transition and other cool new features (well, most of them &#8220;webkit only&#8221; but very cool nevertheless). Then we&#8217;ve coded a little and went on to dinner ate Jeff&#8217;s where I&#8217;ve lead the group to :-) Sadly dinner took a little too much time and we had less time to code than Poznań during their meeting a few weeks ago.</p>
<p>By the way&#8230; MVC in JavaScript is quite weird (<em>hey, most of the teams ended up with GodObjects anyways! ;-)</em>), as is any acting &#8220;hey, let&#8217;s just say we can have classess and inherit them blabla&#8230;&#8221;. We&#8217;ve seen quite a few examples on how to <strong>emulate OOP</strong> <strong>in JavaScript</strong> which was both: really weird and interesting at the same time. In the end, the thought &#8220;if you have no type system, in the end you develop your own&#8221; seems really true here. I believe this was said by someone from twitter about their Ruby code, which had a hell lot of assertions in it just to be sure &#8220;abc is really of type AbcType&#8221;. That&#8217;s why I&#8217;m more for Scalas apparoach than Groovy&#8217;s or Javascript/Ruby/Php, but I&#8217;m not that advanced in Scala yet to judge it as &#8220;super perfect&#8221;&#8230; ;-)</p>
<div id="attachment_1188" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.blog.project13.pl/wp-content/uploads/2011/02/mk1.png"><img class="size-medium wp-image-1188" title="mk1" src="http://www.blog.project13.pl/wp-content/uploads/2011/02/mk1-300x167.png" alt="" width="300" height="167" /></a><p class="wp-caption-text">MK in Javascript using Node.js</p></div>
<p>On the next day we implemented the serverside stuff, using <strong>node.js</strong> and <strong>socket.io</strong> for the clientside wich worked really well I have to addmit. Although I&#8217;m still wondering how I&#8217;d handle auth/security to be _really_ secure using such server instances (&#8220;nodes&#8221; ;-))&#8230; Finally our game had a very nice and developed state machine for all basic mortal kombat moves (including high/low punch etc, how much such state is blocking and which sprite to use for it, jumping etc.). As this state manipulation took most of our time, our server didn&#8217;t support an infinite number of players as some other implementations did but as a trade off they didn&#8217;t have any combo/move logic in their games :-) Of course the game was playable (well, &#8220;almost playable&#8221; &#8211; both players think they&#8217;re &#8220;on the left&#8221;, but we&#8217;d fix that very quick if needed&#8230; ;-)). A quick finishing talk touched some performance tweaks &#8211; quite some we should have used in mSejf etc &#8211; so I feel a little smarter than before :-) Sadly we didn&#8217;t talk too much about TDD using JavaScript which may be really a good idea (ugh this loose typing can make you mad sometimes&#8230; ;-)).</p>
<div id="attachment_1182" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.blog.project13.pl/wp-content/uploads/2011/02/mk2.png"><img class="size-medium wp-image-1182" title="mk2" src="http://www.blog.project13.pl/wp-content/uploads/2011/02/mk2-300x169.png" alt="mortal kombat" width="300" height="169" /></a><p class="wp-caption-text">Our mortal kombat game ;-)</p></div>
<p><strong>What could be definitely improved</strong> is the internet connection (well, &#8220;organization&#8221; as a whole I guess) as we had quite a lot problems with it (choose a hotel which is no noob in terms of IT meetings :-)) and the lead&#8217;s knowlage about git. Since it&#8217;s quite an deep tool, and we&#8217;re not here to focus on it but on JavaScript some quick info about how to use it and more developers who aren&#8217;t using it the first time in their lifes would have been really helpful. But fear not, I&#8217;ve helped out all the teams with learning git and all merges, push/pull flows and other weird problems :-) So it became quite an hybrid training where some of the participants learnt quite a lot about git :-) Some may actually like it in spite of the difficulties we encountered in our very chaotic flow during our hack sessions&#8230; :-) On the other hand, any way of introducing git to new people is a good thing, but I fear some may expierience some discomfort/distrust to a tool they&#8217;ve just &#8220;learnt&#8221; on a &#8220;fly by basis&#8221;, from&#8230; well, me &#8211; another participant. ;-)</p>
<p>From my perspective it was a great and fun meeting and I&#8217;d like to attend more such meetings, sharing the same  formula, or slightly improved. What I loved was of course the hacking and fun of working in a team + teaching people git&#8230; :-) If you&#8217;re hungry for some team coding you may want to checkout one of the upcomming meetings or wait for <strong>SCKRK</strong>s + <strong>PolishJUG</strong>s &#8220;<strong>Code Retreat</strong>&#8221; that we&#8217;ll be announcing really soon&#8230; :-)</p>
<p>PS: I&#8217;ve pushed our game implementation (less than 8h of real coding (rest of the time was talking/presentations/eating etc ;-)) to github, here: <a href="https://github.com/ktoso/mk-javascript" target="_blank" onclick="urchinTracker('/outgoing/github.com/ktoso/mk-javascript?referer=');">https://github.com/ktoso/<strong>mk-javascript</strong></a> so you may want to take a look. Event out of pure curiosity :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/1181/review-devmeeting-javascript-game-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[release] maven-git-commit-id-plugin</title>
		<link>http://www.blog.project13.pl/index.php/fun/1174/release-maven-git-commit-id-plugin/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/1174/release-maven-git-commit-id-plugin/#comments</comments>
		<pubDate>Sun, 13 Feb 2011 15:25:18 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[#maven]]></category>
		<category><![CDATA[build]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[release]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1174</guid>
		<description><![CDATA[Yup, today I&#8217;m releasing yet another piece of cool free software! It solves a problem we&#8217;ve had at our company, the tester tometimes tested stuff that wasn&#8217;t deployed yet, and the developers thought it was deployed and this caused some weird situations sometimes. Using the plugin I&#8217;ve written, we&#8217;re able to expose &#8220;which version is [...]]]></description>
			<content:encoded><![CDATA[<p>Yup, today I&#8217;m releasing yet another piece of cool free software! It solves a problem we&#8217;ve had at our company, the tester tometimes tested stuff that wasn&#8217;t deployed yet, and the developers thought it was deployed and this caused some weird situations sometimes. Using the plugin I&#8217;ve written, we&#8217;re able to expose &#8220;which version is this?&#8221; using repository information from<strong> git </strong>in our webapps. Yes there are maven plugins that do this, but none of them supported git &#8211; so I wrote my own and hope you guys will find it as useful as we do!</p>
<p><strong>UPDATE</strong><br />
The plugin is now available from <strong>Sonatype Nexus</strong>!</p>
<pre>
    <repository>
        <id>sonatype-releases</id>
        <name>Sonatype Releases</name>
        <url>https://oss.sonatype.org/content/repositories/releases/</url>
    </repository>
</pre>
<p><strong>END OF UPDATE</strong></p>
<p>Now I&#8217;ll be a bit lazy and just paste the README I&#8217;ve prepared for <strong><a href="https://github.com/ktoso/maven-git-commit-id-plugin/" target="_blank" onclick="urchinTracker('/outgoing/github.com/ktoso/maven-git-commit-id-plugin/?referer=');">maven-git-commit-id-plugin on github</a></strong>.</p>
<div id="readme">
<div>
<h2>Maven plugin: git-commit-id-plugin</h2>
<p><strong>git-commit-id-plugin</strong> is a plugin quite similar to <a href="https://fisheye.codehaus.org/browse/mojo/tags/buildnumber-maven-plugin-1.0-beta-4" target="_blank" onclick="urchinTracker('/outgoing/fisheye.codehaus.org/browse/mojo/tags/buildnumber-maven-plugin-1.0-beta-4?referer=');">build-number maven plugin</a> for example but as buildnumber only supports svn (which is very sad) and  cvs (which is even more sad, and makes bunnies cry) I had to quickly  develop an git version of such a plugin. For those who don&#8217;t know the  previous plugins, let me explain what this plugin does:</p>
<h3>Sample scenario why this plugin is useful</h3>
<p>If you develop your maven project inside an git repository (which you  hopefully already are docing) you may want to know exactly what changeset is currently deployed online. Why is this useful? Well,  the tester won&#8217;t come to you screaming &#8220;heeey that bug ain&#8217;t fixed&#8221; of  course you&#8217;d reply &#8220;but I fixed it this morning!&#8221; and after some  searching you notice &#8220;oh&#8230; it&#8217;ll be online after the next deployment,  sorry tester&#8230; :-(&#8220;.</p>
<p>This scenario keeps repeating sometimes, thus you can state which  commit fixes/closes the bug, note this in JIRA etc and then the tester  will know if it&#8217;s already online (by the commit date for example).</p>
<h2>Usage</h2>
<h3>Getting the plugin</h3>
<p>I&#8217;ll be trying to get this plugin out to sonatype for others to use if more simply, for now it&#8217;s quickest to just:</p>
<pre><code>  git clone git://github.com/ktoso/maven-git-commit-id-plugin.git maven-git-commit-id-plugin
  cd maven-git-commit-id-plugin
  mvn install
</code></pre>
<p>and you&#8217;re ready to use it ;-) I&#8217;m also thinking about making this  github repo a maven repository, which would make the above step not  needed &#8211; but first let&#8217;s wait if sonatype let me in with this project,  k? ;-)</p>
<h3>Using the plugin</h3>
<p>It&#8217;s really simple to setup this plugin, here&#8217;s a sample pom that you may base your <strong>pom.xml</strong> on:</p>
<pre><code>   &lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;project xmlns="http://maven.apache.org/POM/4.0.0"
            xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"&gt;
       &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

       &lt;groupId&gt;pl.project13.maven&lt;/groupId&gt;
       &lt;artifactId&gt;my-git-plugin-sample-app&lt;/artifactId&gt;
       &lt;packaging&gt;war&lt;/packaging&gt;
       &lt;version&gt;0.1&lt;/version&gt;
       &lt;name&gt;my-git-plugin-sample-app&lt;/name&gt;
       &lt;url&gt;http://www.blog.project13.pl&lt;/url&gt;

       &lt;parent/&gt;

       &lt;dependencies /&gt;

       &lt;build&gt;
           &lt;!-- GIT COMMIT ID PLUGIN CONFIGURATION --&gt;
           &lt;resources&gt;
               &lt;resource&gt;
                   &lt;directory&gt;src/main/resources&lt;/directory&gt;
                   &lt;filtering&gt;true&lt;/filtering&gt;
                   &lt;includes&gt;
                       &lt;include&gt;**/*.properties&lt;/include&gt;
                       &lt;include&gt;**/*.xml&lt;/include&gt;
                   &lt;/includes&gt;
               &lt;/resource&gt;
           &lt;/resources&gt;

           &lt;plugins&gt;
               &lt;plugin&gt;
                   &lt;groupId&gt;pl.project13.maven&lt;/groupId&gt;
                   &lt;artifactId&gt;git-commit-id-plugin&lt;/artifactId&gt;
                   &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
                   &lt;executions&gt;
                       &lt;execution&gt;
                           &lt;goals&gt;
                               &lt;goal&gt;revision&lt;/goal&gt;
                           &lt;/goals&gt;
                       &lt;/execution&gt;
                   &lt;/executions&gt;
                   &lt;configuration&gt;
                       &lt;prefix&gt;git&lt;/prefix&gt; &lt;!-- that's the default value --&gt;
                       &lt;dateFormat&gt;dd.MM.yyyy '@' HH:mm:ss z&lt;/dateFormat&gt; &lt;!-- that's the default value --&gt;
                       &lt;verbose&gt;true&lt;/verbose&gt; &lt;!-- false is default for this --&gt;
                       &lt;dotGitDirectory&gt;${project.basedir}/../.git&lt;/dotGitDirectory&gt; &lt;!-- required, you have to specify this path --&gt;
                   &lt;/configuration&gt;
               &lt;/plugin&gt;
               &lt;!-- END OF GIT COMMIT ID PLUGIN CONFIGURATION --&gt;

               &lt;!-- other plugins --&gt;
           &lt;/plugins&gt;
       &lt;/build&gt;
   &lt;/project&gt;
</code></pre>
<p>Based on the above part of a working POM you should be able to figure out the rest, I mean you are a maven user after all&#8230; ;-) Note that the resources filtering is important for this plugin to work, don&#8217;t omit it!</p>
<p>Now you just have to include such a properties file in your project under <code>/src/main/resources</code> (and call it <strong>git.properties</strong> for example) and maven will put the appropriate properties in the placeholders:</p>
<pre><code> git.branch=${git.branch}

 git.build.user.name=${git.build.user.name}
 git.build.user.email=${git.build.user.email}
 git.build.time=${git.build.time}

 git.commit.id=${git.commit.id}
 git.commit.user.name=${git.commit.user.name}
 git.commit.user.email=${git.commit.user.email}
 git.commit.message.full=${git.commit.message.full}
 git.commit.message.short=${git.commit.message.short}
 git.commit.time=${git.commit.time}
</code></pre>
<p>The <code>git</code> prefix may be configured in the plugin declaration above.</p>
<h3>Maven resource filtering + Spring = GitRepositoryState Bean</h3>
<p>You&#8217;ll most probably want to wire these plugins somehow to get easy  access to them during runtime. We&#8217;ll use spring as an example of doing  this. Start out with with adding the above steps to your project, next paste  this <strong>git-bean.xml</strong> into the <code>/src/main/resources/</code> directory (or any other, just adjust the paths later on):</p>
<pre><code>&lt;?xml version="1.0" encoding="UTF-8" standalone="no"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"&gt;

    &lt;bean name="gitRepositoryInformation"&gt;
        &lt;property name="branch" value="${git.branch}"/&gt;
        &lt;property name="commitId" value="${git.commit.id}"/&gt;
        &lt;property name="commitTime" value="${git.commit.time}"/&gt;
        &lt;property name="buildUserName" value="${git.build.user.name}"/&gt;
        &lt;property name="buildUserEmail" value="${git.build.user.email}"/&gt;
        &lt;property name="commitMessageFull" value="${git.commit.message.full}"/&gt;
        &lt;property name="commitMessageShort" value="${git.commit.message.short}"/&gt;
        &lt;property name="commitUserName" value="${git.commit.user.name}"/&gt;
        &lt;property name="commitUserEmail" value="${git.commit.user.email}"/&gt;
    &lt;/bean&gt;

&lt;/beans&gt;
</code></pre>
<p>And here&#8217;s the source of the bean we&#8217;re binding here:</p>
<pre><code>package pl.project13.maven.example.git;

import org.codehaus.jackson.annotate.JsonWriteNullProperties;

/**
 * A spring controlled bean that will be injected
 * with properties about the repository state at build time.
 * This information is supplied by my plugin - &lt;b&gt;pl.project13.maven.git-commit-id-plugin&lt;/b&gt;
 *
 * @author Konrad Malawski
 */
@JsonWriteNullProperties(true)
public class GitRepositoryState {
  String branch;                  // =${git.branch}
  String commitId;                // =${git.commit.id}
  String buildUserName;           // =${git.build.user.name}
  String buildUserEmail;          // =${git.build.user.email}
  String buildTime;               // =${git.build.time}
  String commitUserName;          // =${git.commit.user.name}
  String commitUserEmail;         // =${git.commit.user.email}
  String commitMessageFull;       // =${git.commit.message.full}
  String commitMessageShort;      // =${git.commit.message.short}
  String commitTime;              // =${git.commit.time}

  public GitRepositoryState() {
  }

  /* Generate setters and getters here */
}
</code></pre>
<p>The source for it is also on the repo of this plugin. Of course, <em>feel free to drop out the jackson annotation</em> if you won&#8217;t be using it.</p>
<p>The last configuration related thing we need to do is to load up this bean in your appContext, so open up your <strong>applicationContext.xml</strong> or whatever you call it in your project and add these lines in the  section:</p>
<pre><code>&lt;context:property-placeholder location="classpath:*.properties" /&gt;
&lt;import resource="classpath:/git-bean.xml"/&gt;
</code></pre>
<p>Of course, you may adjust the paths and file locations as you please, no problems here&#8230; :-) <em>Now you&#8217;re ready to use your GitRepositoryState Bean!</em> Let&#8217;s create an sample <strong>Spring MVC Controller</strong> to test it out:</p>
<pre><code> @Controller
 @RequestMapping("/git")
 public class GitService extends BaseWebService {

     @Autowired
     GitRepositoryState gitRepoState;

     @RequestMapping("/status")
     public ModelAndView checkGitRevision() throws WebServiceAuthenticationException {
       ServerResponse&lt;GitRepositoryState&gt; response = new ServerResponse&lt;GitRepositoryState&gt;(gitRepoState);
       return createMAV(response);
     }
 }
</code></pre>
<p>Don&#8217;t mind the createMAV and responses stuff, it&#8217;s just example code.  And feel free to use constructor injection, it&#8217;s actually a better idea  ;-)</p>
<p>In the end <em>this is what this service would return</em>:</p>
<pre><code> {
     "branch" : "testing-maven-git-plugin",
     "commitTime" : "06.01.1970 @ 16:16:26 CET",
     "commitId" : "787e39f61f99110e74deed68ab9093088d64b969",
     "commitUserName" : "Konrad Malawski",
     "commitUserEmail" : "konrad.malawski@java.pl",
     "commitMessageFull" : "releasing my fun plugin :-)
                            + fixed some typos
                            + cleaned up directory structure
                            + added license etc",
     "commitMessageShort" : "releasing my fun plugin :-)",
     "buildTime" : "06.01.1970 @ 16:17:53 CET",
     "buildUserName" : "Konrad Malawski",
     "buildUserEmail" : "konrad.malawski@java.pl"
 }
</code></pre>
<p>That&#8217;s all folks! <strong>Happy hacking!</strong></p>
<h2>Configuration details</h2>
<p>Just a short recap of the available parameters&#8230;</p>
<p>Required parameters:</p>
<ul>
<li> <strong>dotGitDirectory</strong> &#8211; (required) the location of your .git  folder. Try to use ${project.basedir} as root for this, and navigate  using ../ to higher up folder to easily use this plugin in multi module  enviroments etc. An example would be: <code>${project.basedir}/../.git</code></li>
</ul>
<p>Optional parameters:</p>
<ul>
<li> <strong>prefix</strong> &#8211; (default: git) is the &#8220;namespace&#8221; for all exposed properties</li>
<li> <strong>dateFormat</strong> &#8211; (default: dd.MM.yyyy &#8216;@&#8217; HH:mm:ss z) is a  normal SimpleDateFormat String and will be used to represent  git.build.time and git.commit.time</li>
<li> <strong>verbose</strong> &#8211; (default: false) if true the plugin will print a summary of all collected properties when it&#8217;s done</li>
</ul>
<h2>License</h2>
<p>I&#8217;m releasing this plugin under the <strong>GNU Lesser General Public License 3.0</strong>. You&#8217;re free to use it as you wish, the license text is attached in the LICENSE file. You may contact me if you want this to be released on a different license, just send me an email konrad.malawski@java.pl :-)</p>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/1174/release-maven-git-commit-id-plugin/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>[PL] Trzeźwe spojrzenie na: CoFoJa (Design By Contract form Google)</title>
		<link>http://www.blog.project13.pl/index.php/coding/1168/pl-trzezwe-spojrzenie-na-cofoja-design-by-contract-form-google/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/1168/pl-trzezwe-spojrzenie-na-cofoja-design-by-contract-form-google/#comments</comments>
		<pubDate>Thu, 10 Feb 2011 22:18:51 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[codnig]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[jee]]></category>
		<category><![CDATA[libs]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1168</guid>
		<description><![CDATA[Design By Contract Dzisiejszy wpis będzie o znanej i generalnie dość znanej i mającej wiele zalet metodyce Design By Contract. Temat &#8220;wypłynął&#8221; ponownie dla wielu javovców tym razem dzięki wydaniu biblioteki  CoFoJa (o którym właśnie będzie ten post) przez dwóch pracowników Google przy ścisłej współpracy z autorem pierwowzoru tego projektu. Dlaczego jednak nietypowy tytuł posta [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Design By Contract</strong></p>
<p>Dzisiejszy wpis będzie o znanej i generalnie dość znanej i mającej wiele zalet metodyce <strong>Design By Contract</strong>. Temat &#8220;wypłynął&#8221; ponownie dla wielu javovców tym razem dzięki wydaniu biblioteki  <strong>CoFoJa</strong> (o którym właśnie będzie ten post) przez dwóch pracowników <strong>Google</strong> przy ścisłej współpracy z <a href="http://www.linkedin.com/pub/dir/Johannes/Rieken" onclick="urchinTracker('/outgoing/www.linkedin.com/pub/dir/Johannes/Rieken?referer=');">autorem pierwowzoru tego projektu</a>. Dlaczego jednak nietypowy tytuł posta &#8211; &#8220;trzeźwe spojrzenie&#8221;? Ponieważ w odróżnieniu od niektórych nie oceniam technologii na podstawie &#8220;wow factor&#8221; a realnej używalności. Gotowi mini review tego toola? No to lecimy&#8230; :-)</p>
<p><strong>Contracts For Java</strong></p>
<p>Na początek warto rzucić okiem na <a href="http://google-opensource.blogspot.com/2011/02/contracts-for-java.html" onclick="urchinTracker('/outgoing/google-opensource.blogspot.com/2011/02/contracts-for-java.html?referer=');">googlowy blog</a> gdzie ogłoszono premierę tego narzędzia oraz oczywiście samą <a href="http://code.google.com/p/cofoja/" onclick="urchinTracker('/outgoing/code.google.com/p/cofoja/?referer=');">stronę domową projektu </a><acronym title="Contracts For Java"><a href="http://code.google.com/p/cofoja/" onclick="urchinTracker('/outgoing/code.google.com/p/cofoja/?referer=');"><strong>CoFoJa</strong></a></acronym>. Oczywiście na samym przekierowaniu nie poprzestanę więc zaczniemy od mini definicji od strony użytkownika metodyki design by contract. Jak możemy przeczytać chociażby <strong>w pragmatycznym programiście </strong>metodyka ta ma dość spory potencjał i ciekawe możliwości &#8211; generalnie chodzi o określanie &#8220;kontraktów&#8221; na naszych metodach. Zakładanie kontraktów ma pewną wyższość nad pisanie testów jednostkowych ponieważ możemy kontrakt założyć na interfejsie a wszystkie implementujące go klasy będą z nim związane</p>
<p>Kontrakt może na przykład zapewnić:</p>
<ul>
<li>wykonanie danej metody tylko i wyłącznie wtedy gdy przekazane jej argumenty spełniają pewne kryteria (w kontekście CoFoJa byłoby to <strong>@Requires</strong>)</li>
<li>zagwarantowanie spełnienia pewnych warunków po opuszczeniu metody (w kontekście CoFoJa byłoby to <strong>@Ensures</strong> ewentualnie <strong>@ThrowEnsures</strong> jeśli chcemy mieć kontrakt na rzucenie wyjątku)</li>
<li>zagwarantowanie ogólnych warunków na konkretnej np. klasie (<strong>@Invariant</strong>)</li>
</ul>
<p>Ok, skoro znamy podstawowe building blocks (zaczerpnięte skądżeby inąd niż z <a href="http://en.wikipedia.org/wiki/Eiffel_%28programming_language%29" onclick="urchinTracker('/outgoing/en.wikipedia.org/wiki/Eiffel_28programming_language_29?referer=');">Eiffla</a> oczywiście) zobaczmy jakieś przykładowe poadnotowane nimi API:</p>
<p><script src="https://gist.github.com/817547.js?file=gistfile1.java"></script> <strong>A teraz praktycznie</strong></p>
<p>Najlepiej jest chwilkę się w niego wgryźć, powinien być stosunkowo zrozumiały. Nie chcemy nigdy mieć ujemnej ilości bananów &#8211; spowodowałoby to złamanie kontraktu. Podobne przykładowe kontrakty wejściowe/wyjściowe widzimy na metodach oraz jeden mały tip: metoda <strong>old()</strong> jest dostarczana automagicznie i oznacza &#8220;starą wartość tego wywołania&#8221; czyli przed wykonaniem metody na którą zakładamy ten kontrakt. Poza tym mamy tutaj do czynienia w sumie z zwyczajnym kodem Java który niestety jest wewnątrz stringa&#8230; Świadomy programista zapewne już ma zapaloną lampkę alarmową, że to będzie nie refaktorowalne i bez sensu&#8230; Na pocieszenie dodam iż kod Java zawarty w tych stringach faktycznie jest &#8220;kompilowany&#8221;i jak coś popsujemy składniowo, kontrakty się nie skompilują i dostaniemy normalne informacje jakby to się nam nie kompilował normalny &#8220;nasz kod&#8221;. Co do wygody refaktoringu&#8230; Na szczęscie korzystam z porządnego IDE (<strong>IntelliJ IDEA</strong>) i takie &#8220;problemy&#8221; mnie nie dotyczą ;-). Wybrałem inject języka <strong>Groovy</strong> do tych stringów aby parser składniowy nie dziwił się pojawienia się metody old() &#8220;z nikąd&#8221;:<a href="http://xlab.pl/wp-content/uploads/2011/02/intellij.png" onclick="urchinTracker('/outgoing/xlab.pl/wp-content/uploads/2011/02/intellij.png?referer=');"><img class="aligncenter size-full wp-image-1752" title="intellij" src="http://xlab.pl/wp-content/uploads/2011/02/intellij.png" alt="" width="600" /></a> <strong>Problem</strong> z &#8220;nie podpowiadaniem metod&#8221; jak i &#8220;nie da się refaktorować&#8221; jak widać został od razu <strong>wyeliminowany</strong> :-) <em><strong>Hooray for JetBrains.</strong></em> Poszukajmy jednak kolejnego problemu z tym API&#8230; Tak jest, <strong>@ThrowEnsures </strong>jest trochę brzydki a nie koniecznie musi być cały w stringu. Jak działa obecnie? Przekazujemy mu listę stringów gdzie parami występują &#8220;wyjątek&#8221; + &#8220;warunek kiedy ma zostać rzucony&#8221;. Chętniej zobaczył bym to w formie podobnej do poniższej (tylko szybki szkic taki), a wy?</p>
<p><script src="https://gist.github.com/817695.js?file=gistfile1.java"></script></p>
<p>Ok czas na uruchomienie kodu z &#8220;włączonymi kontraktami&#8221;&#8230; I&#8230; niestety nie okazało się to takie trywialne na obecnym etapie projektu. Niestety trzeba sobie ręcznie poustawiać processowanie adnotacji (norma, tutaj się niewiele zmieni) jednak trochę problemów nastarcza mi obecnie widoczność klas/pól dla CoFoJa w intellij. Classpath (dla procesora) zdaje się być ustawiony poprawny oraz jego klasa jak i inne opcje też jednak nie dochodzi do poprawnego przeparsowania wszystkich reguł. No cóż, może jutro się uda &#8211; tymczasem odsyłam do <a href="http://fsteeg.com/2011/02/07/setting-up-contracts-for-java-in-eclipse/" onclick="urchinTracker('/outgoing/fsteeg.com/2011/02/07/setting-up-contracts-for-java-in-eclipse/?referer=');">poradnika dla użytkowników Eclipse</a> gdzie to członek społeczności sprawnie poradził sobie z tym problemem :-)</p>
<p><strong>Trzeźwe spojrzenie: &#8220;Czy obecnie warto?</strong>&#8221;</p>
<p>Pozostaje pytanie&#8230; Czy warto się zainteresować CoFoJa jak i samym DBC? Pytanie jest chyba równie ogólne jak &#8220;czy warto meta-programować?&#8221; także wprost odpowiedzi nie udzielę. Miejmy jednak na uwadze że jak na razie używanie CoFoJa nie jest zbyt wygodne a adnotacje można by jeszcze trochę poszlifować. Trzeba by jeszcze rzucić okiem jak stoimy z integracją tego z Maven &#8211; aby normalnie testując bądź klikając sobie po projekcie te kontrakty mogły się przydawać. Sama idea jest ciekawa i jakby integracja z narzędziami była wygodniejsza &#8211; a może od razu pluginy do IDE &#8211; można by się nad tym porządniej zastanawiać. <strong>Jak na razie projekcik odkładamy ten projekt spokojnie na półkę &#8220;worth watching&#8221; i liczymy na rychłe wydanie 2.0.</strong> :-)</p>
<p>PS: Jeżeli interesują Cię takie jak i inne ciekawe metodyki i sposoby tworzenia <strong>pięknego</strong>, czystego<strong> kodu, </strong>zapraszam serdecznie na co 2 tygodniowe spotkania <em><a href="http://sckrk.com" onclick="urchinTracker('/outgoing/sckrk.com?referer=');">SCKRK </a></em>gdzie obecnie dyskutujemy w formie &#8220;reading club&#8221; nad <strong>D</strong>omain <strong>D</strong>riven <strong>D</strong>esign :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/1168/pl-trzezwe-spojrzenie-na-cofoja-design-by-contract-form-google/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>git-hacking: pre-commit hook and custom command</title>
		<link>http://www.blog.project13.pl/index.php/fun/1076/git-hacking-pre-commit-hook-and-custom-command/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/1076/git-hacking-pre-commit-hook-and-custom-command/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 02:07:39 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[#eclipse]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[intellij]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[SCM]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[xsolve]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1076</guid>
		<description><![CDATA[As my team is using a kinda weird source eclipse code formatter setup, that other IDEs can&#8217;t emulate in 100% I sometimes found myself committing in a file with only a few changed spaces. Of course, I could use &#8220;external-formatter&#8221; plugins etc but that&#8217;s no good. Running eclipse&#8217;s formatter each time I want to format [...]]]></description>
			<content:encoded><![CDATA[<p>As my team is using a kinda weird source eclipse code formatter setup, that other IDEs can&#8217;t emulate in 100% I sometimes found myself committing in a file with only a few changed spaces. Of course, I could use &#8220;external-formatter&#8221; plugins etc but that&#8217;s no good. Running eclipse&#8217;s formatter each time I want to format my source (_very_ often) proved to be too slow and really getting on my nerves.</p>
<p>So&#8230; Since I&#8217;ve started using <strong>git</strong>-svn at work, I do have an possibility to make things better now! The answer lies in client-side-<strong>hooks</strong> and <strong>git aliases</strong> (&#8220;custom commands&#8221;). First let&#8217;s write this as an simple bash script, that we&#8217;ll locate in the <strong>.git/hooks/</strong> folder:<br />
<script src="https://gist.github.com/708972.js?file=gistfile1.sh"></script> It&#8217;s a fairly simple script, so I wont bore you explaining it in detail &#8211; if in doubt, feel free to ask. We only need to place this script as &#8220;<strong>.git/hooks/pre-commit</strong>&#8221; and make it executable and git will take care of the rest for us. Oh and in case you&#8217;re wondering where that <strong>org.eclipse.jdt.core.prefs</strong> came from. It&#8217;s created by eclipse into the .settings folder when you check some option to &#8220;use formatter per project&#8221; &#8211; that&#8217;s the only time I had to fire up and click around in eclipse to get it&#8217;s formatter running &#8220;headless&#8221;. Ok, let&#8217;s check if it works&#8230; <script src="https://gist.github.com/708982.js?file=gistfile1.java"></script><br />
<script src="https://gist.github.com/708976.js?file=gistfile1.sh"></script> <script src="https://gist.github.com/708981.js?file=gistfile1.java"></script><br />
Yup, you can agree or not with the formatting rules &#8211; but what matters is that the whole team decided on it and that we keep it consistent throughout the whole project. This hook will definitely help with this. :-)  Step two for me was changing this into a git command, so that I wouldn&#8217;t launch eclipse each time I just do some quick local commiting. The solution is to drop the hook idea (although it&#8217;s quite nice) and create an custom git command. We do this by doing an alias like that:</p>
<pre>git config --global alias.eclipse-formatter '!~/git-hook-eclipse-formatter'</pre>
<p>The <strong>!command </strong>alias<strong> </strong>support is with us in git since 1.5.0 and it enables us to launch any program/script as an git command. Great, just what I wanted! Let&#8217;s now see what this command really did:</p>
<p><script src="https://gist.github.com/708977.js?file=gistfile1.sh"></script><br />
As you can see, adding an alias is as simple as adding it to your<strong> ~/.gitconfig</strong> or, if you want to setup the alias &#8220;per project&#8221;, to <strong>.git/config</strong> &#8211; pretty cool, ay? Also, this command will be included in bash-autocompletition suggestions! :-)</p>
<p>That&#8217;s it for today&#8230; <em>happy hacking!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/1076/git-hacking-pre-commit-hook-and-custom-command/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[review] JavaCamp 5</title>
		<link>http://www.blog.project13.pl/index.php/project13/1089/review-javacamp-5/</link>
		<comments>http://www.blog.project13.pl/index.php/project13/1089/review-javacamp-5/#comments</comments>
		<pubDate>Thu, 18 Nov 2010 02:11:51 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[polish]]></category>
		<category><![CDATA[Project13]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[JavaCamp]]></category>
		<category><![CDATA[JUG]]></category>
		<category><![CDATA[lombok]]></category>
		<category><![CDATA[meeting]]></category>
		<category><![CDATA[polishjug]]></category>
		<category><![CDATA[review]]></category>
		<category><![CDATA[TDD]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1089</guid>
		<description><![CDATA[Yes, it&#8217;s time for another JavaCamp mini-review&#8230; :-) Without further intros, let&#8217;s get down do the presentations: Łukasz Lenart &#8211; “Nie samym kodem programista żyje” Łukasz&#8217;s presentation was not a technical one this time. He talked about how to be/become an effective programmer. A nice tip he noted was to carry a notebook and note [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img title="pjug3" src="http://www.blog.project13.pl/wp-content/uploads/2010/11/pjug3.jpg" alt="" width="126" height="157" /><br />
Yes, it&#8217;s time for another JavaCamp mini-review&#8230; :-) Without further intros, let&#8217;s get down do the presentations:</p>
<h2><a href="http://www.lenart.org.pl/" onclick="urchinTracker('/outgoing/www.lenart.org.pl/?referer=');"><strong>Łukasz Lenart</strong></a> &#8211; “Nie samym kodem programista żyje”</h2>
<p>Łukasz&#8217;s presentation was not a technical one this time. He talked about how to be/become an effective programmer. A nice tip he noted was to carry a notebook and note your ideas in it &#8211; i sometimes try to but did find myself forgetting some &#8220;amazing idea&#8221; due to the lack of discipline in carring such notebook (yeah, an paper-notebook&#8230; :-)) so it&#8217;s definitely something worth reminding. He also talked a little about Kaizen, <a href="http://zenhabits.net/zen-to-done-the-simple-productivity-e-book/" onclick="urchinTracker('/outgoing/zenhabits.net/zen-to-done-the-simple-productivity-e-book/?referer=');"><strong>ZenToDone</strong></a> and the <a href="http://www.pomodorotechnique.com/" onclick="urchinTracker('/outgoing/www.pomodorotechnique.com/?referer=');"><strong>Pomodoro</strong> Technique</a> which all kinda share the same idea but explain it a little bit differently. I also was quite happy to find out that I&#8217;m not the only one that gets slown down in development when actually being in the company &#8211; with lots of stuff happening around me. Admit it &#8211; we all work more productive when there&#8217;s noone bugging us ;-)</p>
<p>The most notable tips where the &#8220;<strong>alone-zone</strong>&#8221; (as explained in <a href="http://37signals.com/rework/" onclick="urchinTracker('/outgoing/37signals.com/rework/?referer=');">REWORK</a> (good book, I recommend it)) which is really great and I love it, but sometimes it&#8217;s hard to enforce &#8211; coding is usualy team work, ain&#8217;t it..? Using <strong>multiple desktops</strong> &#8211; and monitors at best, to seperate your work space from fun space. <strong>Cutting oneself off from the internet</strong> is, while extreme, very effective by the way. I noticed it quite a few times &#8211; there&#8217;s simply nothing distracting you &#8211; same goes for anything that might take your attention. By the way, I&#8217;m not really convinced about Pomodoro &#8211; what if you get into an v. nice flow and then the pomodoro snaps you out of it? I guess it may be more targeted at people working at bigger companies &#8211; not as myself in an small nice team and nowadays, mostly from home.</p>
<p>All in all he warmed up the audience perfectly and let&#8217;s hope some of theese tips help us become better programmers&#8230; :-)</p>
<ul>
<li>//TODO: watch on parleys.com</li>
<li>//TODO: download slides</li>
<li><a href="http://camp.java.pl/dl.php?f=jc5-1-nie-samym-kodem-pl-min.flv" onclick="urchinTracker('/outgoing/camp.java.pl/dl.php?f=jc5-1-nie-samym-kodem-pl-min.flv&amp;referer=');">download video</a></li>
</ul>
<h2><a onclick="alert('hey, youre already on my website... :-)')" href="#"><strong>Konrad Malawski</strong></a> &#8211;  “Git (tak. po prostu.)”</h2>
<p>The PJUG guys asked me to tell a little about git and I happily agreed to do it &#8211; thus, my first &#8220;public presentation&#8221;. Firstly I&#8217;d like to explain why the slides where so &#8220;weird&#8221;. It&#8217;s because I wanted them to be something like an &#8220;break&#8221;, and most of the session was live terminal typing. They were all hand drawn by me and my girlfriend, then scanned and recoloured in GIMP. Took a few evenings to prepare them, but I hope they where quite memorable, fun, and did point out the important aspects of what the next topic would be about &#8211; an 3 headed dragon as symbol for lots of HEADs in an git repo etc&#8230; ;-)</p>
<p><span id="click-git-slides-here">Click to show presentation</span></p>
<div id="git-slides-here" style="text-align: center;"><object id="__sse5689507" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="425" height="355" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0"><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always" /><param name="src" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=slides-101106175416-phpapp01&amp;stripped_title=slides-5689507&amp;userName=ktoso" /><param name="name" value="__sse5689507" /><param name="allowfullscreen" value="true" /><embed id="__sse5689507" type="application/x-shockwave-flash" width="425" height="355" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=slides-101106175416-phpapp01&amp;stripped_title=slides-5689507&amp;userName=ktoso" name="__sse5689507" allowscriptaccess="always" allowfullscreen="true"></embed></object></div>
<p><script type="text/javascript">// < ![CDATA[
// < ![CDATA[
// < ![CDATA[
$(document).ready(function(){
   $("#git-slides-here").hide();
   $("#click-git-slides-here").click(function(){
      $("#git-slides-here").slideToggle();
   });
});
// ]]&gt;</script></p>
<p>I&#8217;ve been preparing the flow of all examples before but during the presentation I missed out a few steps and made a <a href="http://www.blog.project13.pl/index.php/fun/1069/gitjavacamp-fix-1-when-does-git-see-an-rename-explicitly/">some stupid mistakes</a> (see my previous git post on this blog ;-). Well, it wasn&#8217;t anything world breaking I guess and I&#8217;d really like to thank the audience for such great support. We strayed a little of the path I&#8217;ve prepared sometimes, but that&#8217;s ok as it was interesting to interact with the audience during an presentation &#8211; not just stand there and &#8220;praise git to zee heavnz&#8221; ;-) Such interaction is something I (personally) really like in presentations, even if they break a little due to this :-)</p>
<p>All in all, we managed to go through all of git&#8217;s basic features and in the end even mentioned <strong>rebase</strong> &#8211; which can be used to change the history of ones commits (there&#8217;s also the very useful <a href="http://book.git-scm.com/3_distributed_workflows.html" onclick="urchinTracker('/outgoing/book.git-scm.com/3_distributed_workflows.html?referer=');">git commit &#8211;amend</a>), <a href="http://sitaramc.github.com/concepts/detached-head.html" onclick="urchinTracker('/outgoing/sitaramc.github.com/concepts/detached-head.html?referer=');"><strong>detached-HEADs</strong></a> and <strong>git-svn</strong>, which I didn&#8217;t use before as I feared a little to make a mess in the company svn-repo (and in all &#8220;my&#8221; projects I&#8217;m using git, so I never felt the need to use git-svn). Some guys sucessfully used it and really recommended it, thus&#8230; here I am, doing git svn dcommits on an daily basis&#8230; :-) I&#8217;m glad to have also learned something from this presentation, not just &#8220;showed what I had to show&#8221; :-) Now just a few links to very good resources about git:</p>
<ul>
<li><a href="http://nvie.com/posts/a-successful-git-branching-model/" onclick="urchinTracker('/outgoing/nvie.com/posts/a-successful-git-branching-model/?referer=');">A Successful Git Branching Model</a></li>
<li><a href="http://excess.org/article/2008/07/ogre-git-tutorial/" onclick="urchinTracker('/outgoing/excess.org/article/2008/07/ogre-git-tutorial/?referer=');">Very good </a><a href="http://excess.org/article/2008/07/ogre-git-tutorial/" onclick="urchinTracker('/outgoing/excess.org/article/2008/07/ogre-git-tutorial/?referer=');">video tutorial on git</a></li>
<li><a href="https://git.wiki.kernel.org/index.php/GitFaq" onclick="urchinTracker('/outgoing/git.wiki.kernel.org/index.php/GitFaq?referer=');">https://git.wiki.kernel.org/index.php/GitFaq</a></li>
<li><a href="http://git-plumbing-preso.heroku.com/" onclick="urchinTracker('/outgoing/git-plumbing-preso.heroku.com/?referer=');">http://git-plumbing-preso.heroku.com</a> &#8211; internals</li>
<li><a href="https://github.com/" onclick="urchinTracker('/outgoing/github.com/?referer=');">https://github.com/</a> &#8211; free opensource project hosting</li>
<li>and of course: <a href="http://git-scm.com/documentation" onclick="urchinTracker('/outgoing/git-scm.com/documentation?referer=');">http://git-scm.com/documentation</a></li>
</ul>
<p>After the presentation I made an small sms-contest where you could win an PJUG tshirt for guessing what github&#8217;s mascot is called like. I hope it was an nice positive accent to finish the session. Next up was the pizza and then 2 more Łukasz&#8217;s&#8230; :-)</p>
<ul>
<li>//TODO: watch on parleys.com</li>
<li><a href="http://camp.java.pl/dl.php?f=jc5-2-git-pl-slides.pdf" onclick="urchinTracker('/outgoing/camp.java.pl/dl.php?f=jc5-2-git-pl-slides.pdf&amp;referer=');">download slides</a></li>
<li><a href="http://camp.java.pl/dl.php?f=jc5-2-git-pl-min.flv" onclick="urchinTracker('/outgoing/camp.java.pl/dl.php?f=jc5-2-git-pl-min.flv&amp;referer=');">download video</a></li>
</ul>
<h2><strong>Łukasz Żmudziński</strong> &#8211; “Project Lombok &#8211; Cause We Hate Boilerplate!”</h2>
<p>Lombok, if you didn&#8217;t see it before is this -&gt; <a href="http://projectlombok.org/" onclick="urchinTracker('/outgoing/projectlombok.org/?referer=');">http://projectlombok.org/</a> It&#8217;s a &#8220;total hack&#8221;, as the author describes it (and he&#8217;s right ;-)) but it allows some funny compile time hacks while writing Plain Old Java Code. Łukasz showed us around all the annotations which Lombok provides and how they work, what code exactly would be generated by them etc. The most &#8220;let&#8217;s you write less code&#8221; annotation would be @Data, which at compile time would cause Lombok (&#8230;here comes the important part:) to write the <strong>source</strong> for all setters, getters and toString hashcodes etc &#8211; so javac in the end, thinks it&#8217;s just compiling plain odl java&#8230; Here&#8217;s a link on how it works: <a href="http://projectlombok.org/features/Data.html" onclick="urchinTracker('/outgoing/projectlombok.org/features/Data.html?referer=');">Data.html</a> The funny part about it is that it&#8217;s an compile time tool &#8211; much similar to <a href="http://www.springsource.org/roo" onclick="urchinTracker('/outgoing/www.springsource.org/roo?referer=');">Spring Roo</a> in that aspect if you ask me -  and what it actually modifies is the AST (AbstractSourceTree) that javac then uses to generate it&#8217;s bytecode&#8230; So no bytecode magic &#8211; just how I&#8217;d call it&#8230; source code injection during compile time? Yeah, weird stuff.</p>
<p>And if you ask me not really something I&#8217;d be using all over the place. Sure it&#8217;d spare me the writing of some getters and setters and some more tricks but in the end, it&#8217;s a problem for not supported IDEs. (How do you explain IDEA that this class really *will have* an setBla() method&#8230;?) While NetBeans and Eclipse do have plugins to enable them to unserstand lomboks annotations. It&#8217;s not really enough &#8211; what about static code analisis tools? They&#8217;d go nuts with code that calls methods which dont exist in the source etc :-) Nevertheless if was a fun topic and it definitely is an quite funny javac hack, but if I&#8217;d be desperate for such features&#8230; I&#8217;d go polyglot coding with groovy or scala etc&#8230; :-)</p>
<ul>
<li>//TODO: watch on parleys.com</li>
<li><a href="http://camp.java.pl/dl.php?f=jc5-3-lombok-pl-slides.pdf" onclick="urchinTracker('/outgoing/camp.java.pl/dl.php?f=jc5-3-lombok-pl-slides.pdf&amp;referer=');">download <strong>slides</strong></a></li>
<li><a href="http://camp.java.pl/dl.php?f=jc5-3-lombok-pl-min.flv" onclick="urchinTracker('/outgoing/camp.java.pl/dl.php?f=jc5-3-lombok-pl-min.flv&amp;referer=');">download <strong>video</strong></a></li>
</ul>
<h2><a href="http://czerpak.eu/blog/page/2/" onclick="urchinTracker('/outgoing/czerpak.eu/blog/page/2/?referer=');"><strong>Łukasz Czerpak</strong></a> &#8211; “Testy jednostkowe i integracyjne w przykładach”</h2>
<p>By now you probably noticed it&#8230; There where almost only Łukasz&#8217;s presenting on this Camp&#8230;! :-) Łukasz Czerpak&#8217;s topic was about, generally speaking, TDD. He focused (as the title suggests, if you can read polish ;-)) on unit and integration tests. The border between them is sometimes a little blury, but the definitions he have were nice and clear &#8211; 1 class = unit, long setup involved = integration. It&#8217;s as easy as that, yet sometimes during discussions with other coders these sometimes get confised. Next he went on to some examples of how TDD is useful and finally to a lot of code examples. As he&#8217;s using EJBs at his day job, this part was mostly covered &#8211; and very interesting (for me, who&#8217;d usually just use spring and be done with it).</p>
<p>The mocking framework he used in his examples was of course our Polish Mockito&#8230; :-) It&#8217;s really great and lot&#8217;s of fun to work with, unlike some other mocking frameworks out there. Although easymock would take the 2nd place if I&#8217;d were to make an ranking. I&#8217;ve also seen a little JMock but it doesn&#8217;t &#8220;feel good&#8221; &#8211; but if youre interested in pure &#8220;what X can do&#8221;, they all do offer the same things, so why bother with some cluttery syntax? :-)</p>
<p>Next, Łukasz showcased using glassfish as an embeded container which definitely is on my &#8220;good to know&#8221; list and then continued on to an very awesome JBoss library: <strong>Arquillian </strong>[<a href="http://jboss.org/arquillian" onclick="urchinTracker('/outgoing/jboss.org/arquillian?referer=');">arquillian homepage</a>] (see? It&#8217;s so cool I even had to mark it bold ;-)) It&#8217;s an lib which enables you to deploy (yes, &#8220;deploy&#8221; &#8211; perfect word choice) EJBs or even whole archives to an testing enviroment &#8211; which would then be started using an embeded container, although as seen on their homepage, they also support remote containers&#8230; interesting! Here&#8217;s another nice usecase of it: <a href="http://ocpsoft.com/seam/cdi-powered-unit-testing-using-arquillian/" onclick="urchinTracker('/outgoing/ocpsoft.com/seam/cdi-powered-unit-testing-using-arquillian/?referer=');">http://ocpsoft.com/seam/cdi-powered-unit-testing-using-arquillian/</a> The presentation was really well prepared and most probably the high</p>
<ul>
<li>//TODO: watch on <strong>parleys.com</strong></li>
<li>//TODO: download <strong>slides</strong></li>
<li><a href="http://camp.java.pl/dl.php?f=jc5-4-tdd-pl-min.flv" onclick="urchinTracker('/outgoing/camp.java.pl/dl.php?f=jc5-4-tdd-pl-min.flv&amp;referer=');">download <strong>video</strong></a></li>
</ul>
<h2>That&#8217;s all folks!</h2>
<p>We&#8217;ll be doing another JavaCamp in the near future (January perhaps&#8230;?). But for theese few weeks now we&#8217;ll be focusing on the upcomming GeeCON 2011 (Cracow) and kickstarting it&#8217;s call for papers <em>(yay, I&#8217;m it&#8217;s author ;p). </em> And if you&#8217;re interested in seeing all recordings on parleys.com and not just as videos &#8211; stay on your toes, because after Devoxx we&#8217;ll upload them there &#8211; I&#8217;ll update my blog then and we&#8217;ll write an quick news about it on java.pl In the mean time, you can go take a look at these and the previous (javacamp #4) recordings on <a href="http://camp.java.pl" onclick="urchinTracker('/outgoing/camp.java.pl?referer=');">camp.java.pl</a> &#8211; which I just quickly set up to allow you guys quick access to the movies&#8230;</p>
<p>Yup, that&#8217;s all I think&#8230; see you on <strong>GeeCON</strong> || JavaCamp <strong>#6</strong>! :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/project13/1089/review-javacamp-5/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>@RunWith JUnit4 with BOTH SpringJUnit4ClassRunner and Parameterized</title>
		<link>http://www.blog.project13.pl/index.php/coding/1077/runwith-junit4-with-both-springjunit4classrunner-and-parameterized/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/1077/runwith-junit4-with-both-springjunit4classrunner-and-parameterized/#comments</comments>
		<pubDate>Sat, 13 Nov 2010 00:05:39 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[jee]]></category>
		<category><![CDATA[junit]]></category>
		<category><![CDATA[junit4]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1077</guid>
		<description><![CDATA[Ok, now for a quick trick before I get into writing more about git and our last javacamp (movies are still being converted, sorry for the long wait). If you code in Java, you most probably use (you really should use) some dependecy injection mechanisms. They&#8217;re really great and take care about all the setup [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, now for a quick trick before I get into writing more about git and our last javacamp (movies are still being converted, sorry for the long wait).</p>
<p>If you code in Java, you most probably use (you really should use) some dependecy injection mechanisms. They&#8217;re really great and take care about all the setup that need&#8217;s to be done before you can move on to your coding. The same thigh applies to testing, you&#8217;d rather write:</p>
<div class="geshi no java">
<div class="head">//yay</div>
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Autowired</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; MyComponent component<span class="sy0">;</span></div>
</li>
</ol>
</div>
<p>Than use the new operator, or worse, perform some super weird setup to build this object. If you use spring, you&#8217;d write an test like this to make it support Spring&#8217;s DI:</p>
<div class="geshi no java">
<div class="head">//an JUnit test with spring DI</div>
<ol>
<li class="li1">
<div class="de1">@RunWith<span class="br0">&#40;</span>SpringJUnit4ClassRunner.<span class="kw2">class</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">@ContextConfiguration<span class="br0">&#40;</span>locations = <span class="br0">&#123;</span><span class="st0">&quot;classpath:applicationContext.xml&quot;</span><span class="br0">&#125;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw2">class</span> EmailTest <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Autowired</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; MyComponent component<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//&#8230; awesome tests</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>That&#8217;s all you need to make your tests properly autowire all components they&#8217;re using. So far so good &#8211; probably nothing new here, and nothing complicated. So let&#8217;s move on to some &#8220;super big data set&#8221; that needs to be tested, over the same flow over and over again. We&#8217;ll use an super conplicated example to showcase what I mean:</p>
<div class="geshi no java">
<div class="head">//inside an test class</div>
<ol>
<li class="li1">
<div class="de1">@Test</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">public</span> <span class="kw4">void</span> testIsValidEmail<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw2">throws</span> <span class="kw3">Exception</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; assertTrue<span class="br0">&#40;</span><span class="st0">&quot;hey, that&#39;s an good email!&quot;</span>, isValidEmail<span class="br0">&#40;</span>validEmail1<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//&#8230; more tests&#8230;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; assertTrue<span class="br0">&#40;</span><span class="st0">&quot;hey, that&#39;s an good email!&quot;</span>, isValidEmail<span class="br0">&#40;</span>validEmail2<span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//&#8230;over and over again&#8230;</span></div>
</li>
</ol>
</div>
<p>Ok, that&#8217;s obviously stupid&#8230; :-) So, how do we deal with repetitive tests, that need some bigger dataset than just this email example (given here because it&#8217;s short and good enough for our example test)&#8230;? We&#8217;d use @RunWith(Parameterized.class), the class would then look something like this:</p>
<div class="geshi no java">
<div class="head">//my test with only params</div>
<ol>
<li class="li1">
<div class="de1">@RunWith<span class="br0">&#40;</span>Parameterized.<span class="kw2">class</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">class</span> EmailTest <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">String</span> validEmail<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="coMULTI">/** We&#39;re testing only good emails, for the sake of simplicity of the example */</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Parameters</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">static</span> Collection<span class="sy0">&amp;</span>lt<span class="sy0">;</span>Object<span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">&amp;</span>gt<span class="sy0">;</span> data<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="kw3">Arrays</span>.<span class="me1">asList</span><span class="br0">&#40;</span><span class="kw2">new</span> <span class="kw3">Object</span><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;a@a.pl&quot;</span> <span class="coMULTI">/*more params here*/</span><span class="br0">&#125;</span>, <span class="br0">&#123;</span><span class="st0">&quot;exmaple@example.com&quot;</span>, <span class="coMULTI">/* more params here*/</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> EmailTest<span class="br0">&#40;</span><span class="kw3">String</span> validEmail <span class="coMULTI">/* more params would land here*/</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">validEmail</span> = validEmail<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Test</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> testIsValidEmail<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw2">throws</span> <span class="kw3">Exception</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">boolean</span> wasOk = StringTools.<span class="me1">isEmail</span><span class="br0">&#40;</span>validEmail<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; assertTrue<span class="br0">&#40;</span><span class="st0">&quot;This should have been ok&quot;</span>, wasOk<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//&#8230; more stuff</span></div>
</li>
</ol>
</div>
<p>Ok, that&#8217;s a nice way to make your code in the tests smaller yet have an nice overview through all of your tested data. Each array will be inserted in the constructor, and then ran as an seperate test &#8211; with each dataset. Nice, isn&#8217;t it?</p>
<p>Ok, but what if we want to have both Spring&#8217;s DI and an @Parameters &#8220;test data provider&#8221;&#8230;? Can you spot the problem? Yup, JUnit4 can only have ONE @RunWith annotation, and it doesn&#8217;t accept multiple runners. Which totaly makes sense when you think about it, but then there is our special case of DI, which really doesn&#8217;t change the way an test wotks, it just makes setup easier&#8230; All that said, here&#8217;s how to use both spring and parameters in your Junit4 tests:</p>
<div class="geshi no java">
<div class="head">//mytest with DI and params</div>
<ol>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @RunWith<span class="br0">&#40;</span>Parameterized.<span class="kw2">class</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @ContextConfiguration<span class="br0">&#40;</span>locations = <span class="br0">&#123;</span><span class="st0">&quot;classpath:applicationContext.xml&quot;</span><span class="br0">&#125;</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">class</span> EmailTest <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">private</span> TestContextManager testContextManager<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">String</span> validEmail<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Before</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> setUpContext<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw2">throws</span> <span class="kw3">Exception</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">//this is where the magic happens, we actually do &quot;by hand&quot; what the spring runner would do for us,</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="co1">// read the JavaDoc for the class bellow to know exactly what it does, the method names are quite accurate though</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">testContextManager</span> = <span class="kw2">new</span> TestContextManager<span class="br0">&#40;</span>getClass<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">testContextManager</span>.<span class="me1">prepareTestInstance</span><span class="br0">&#40;</span><span class="kw2">this</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Parameters</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw2">static</span> Collection<span class="sy0">&lt;</span>object <span class="br0">&#91;</span><span class="br0">&#93;</span><span class="sy0">&gt;</span> data<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">return</span> <span class="kw3">Arrays</span>.<span class="me1">asList</span><span class="br0">&#40;</span><span class="kw2">new</span> <span class="kw3">Object</span><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#123;</span><span class="st0">&quot;a@a.pl&quot;</span><span class="br0">&#125;</span>,<span class="br0">&#123;</span><span class="st0">&quot;exmaple@example.com&quot;</span><span class="br0">&#125;</span>,</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> EmailTest<span class="br0">&#40;</span><span class="kw3">String</span> validEmail<span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw2">this</span>.<span class="me1">validEmail</span> = validEmail<span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; @Test</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw2">public</span> <span class="kw4">void</span> testIsValidEmail<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="kw2">throws</span> <span class="kw3">Exception</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw4">boolean</span> email = StringTools.<span class="me1">isEmail</span><span class="br0">&#40;</span>validEmail<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; assertTrue<span class="br0">&#40;</span><span class="st0">&quot;should be OK&quot;</span>, wasOk<span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="co1">//&#8230; more stuff&#8230;&lt;/object&gt;</span></div>
</li>
</ol>
</div>
<p>That&#8217;s it :-) We do what the spring Runner would do for us, instanciate an application context and prepare it &#8211; that&#8217;s when the DI happens. Note that we cant use another runner annotation, but we can as usual specify where to find the appContext.xml&#8217;s.</p>
<p>That&#8217;s all, hope this will prove useful to some of you :-) <strong>Keep your tests clean!</strong></p>
<p>PS: Warning, most of this code was written in wordpress, it may contain minor spelling errors ;-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/1077/runwith-junit4-with-both-springjunit4classrunner-and-parameterized/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

