<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Musings about this and that</title>
	<atom:link href="http://ajesse.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ajesse.wordpress.com</link>
	<description>have a disney day ;)</description>
	<lastBuildDate>Fri, 13 Nov 2009 10:55:10 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='ajesse.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/6b102c9eac7df6a36833e521a27d7a15?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Musings about this and that</title>
		<link>http://ajesse.wordpress.com</link>
	</image>
			<item>
		<title>NPE comparing BigDecimal objects?</title>
		<link>http://ajesse.wordpress.com/2009/11/13/npe-comparing-bigdecimal-objects/</link>
		<comments>http://ajesse.wordpress.com/2009/11/13/npe-comparing-bigdecimal-objects/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 10:55:10 +0000</pubDate>
		<dc:creator>ajesse</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[BigDecimal]]></category>

		<guid isPermaLink="false">http://ajesse.wordpress.com/?p=69</guid>
		<description><![CDATA[BigDecimal.compareTo has a nasty precondition that can result in a NPE, but this is not documented.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=69&subd=ajesse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>After having learned that equals() is not equal enough (<a href="http://ajesse.wordpress.com/2009/10/27/when-equals-is-not-equal-enough/">my other post</a>) I just replaced equals by compareTo. After studying the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html#compareTo(java.math.BigDecimal)">Javadoc for BigDecimal.compareTo</a> I did not expect any problems&#8230; until some <a href="http://en.wikipedia.org/wiki/Boundary-value_analysis">Boundary-value analysis</a> occurred and there the NPE-issue was raised&#8230; What a NPE in a simple comparision?</p>
<p>A quick look into the compareTo code showed, what research into the Javadoc confirmed, even though not at the expected place.<br />
The Javadoc for <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html#compareTo(java.math.BigDecimal)">BigDecimal.compareTo(java.math.BigDecimal)</a> did not reveal any pitfalls or precoonditions. Neither did the Javadoc for <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Comparable.html#compareTo(T)">Comparable.compareTo(T)</a>. Nothing about preconditions&#8230;<br />
Only in the class-javadoc for Comparable an innocent sentence revealed the source of the problem. Whereas in other places <strong>null</strong> is just a special case of an <em>Object</em>, <em>Comparable</em> follows this credo: </p>
<blockquote><p>Note that null  is not an instance of any class, and e.compareTo(null) should throw a NullPointerException even though e.equals(null)  returns false.</p></blockquote>
<p>So another lesson learned. A pity that this precondition is not documented somewhere. NullPointerException obviously is a RuntimeExcpetion and as such does not need to be documented. But when a method should repsond with such a runtime expcetion to a precondition, this behaviour should be documented as a precondition to the method.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajesse.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajesse.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajesse.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajesse.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajesse.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajesse.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajesse.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajesse.wordpress.com/69/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajesse.wordpress.com/69/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajesse.wordpress.com/69/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=69&subd=ajesse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajesse.wordpress.com/2009/11/13/npe-comparing-bigdecimal-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/980962c822005ada86cdfe0df61095f2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajesse</media:title>
		</media:content>
	</item>
		<item>
		<title>When equals() is not equal enough</title>
		<link>http://ajesse.wordpress.com/2009/10/27/when-equals-is-not-equal-enough/</link>
		<comments>http://ajesse.wordpress.com/2009/10/27/when-equals-is-not-equal-enough/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 12:36:21 +0000</pubDate>
		<dc:creator>ajesse</dc:creator>
				<category><![CDATA[miscellaneous]]></category>
		<category><![CDATA[BigDecimal]]></category>
		<category><![CDATA[equals]]></category>

		<guid isPermaLink="false">http://ajesse.wordpress.com/?p=65</guid>
		<description><![CDATA[We learn that we should always use equals() to compare Java objects. But that is not always the best ticket...<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=65&subd=ajesse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The other day we were struggling doing comparisions with BigDecimals in a distributed application with BigDecimals originating from different sources. As we had learned we used equals() to compare the objects and even though everything seemed correct, even in the debugger, the logic that indicated an equality condition never was executed.</p>
<p>Check these two methods, and try to predict the outcome:</p>
<pre style="border:1px dashed #999999;overflow:auto;background-color:#ffffe0;font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;"><code>  private void sample1() {
    BigDecimal one1 = new BigDecimal("1");
    BigDecimal one2 = new BigDecimal("1.000");

    System.out.println("Comparing new BigDecimal(\"1\") and BigDecimal(\"1.000\"):");
    if (one1.equals(one2)) {
      System.out.println("  equals() indicates equality...");
    } else {
      System.out.println("  equals() indicates different values...");
      if (one1.compareTo(one2) == 0) {
        System.out.println("    but comparesTo() thinks the two BigDecimals are equal.");
      } else {
        System.out.println("    and comparesTo() thinks the same.");
      }
    }
  }

  private void sample2() {
    BigDecimal one1 = new BigDecimal(1);
    BigDecimal one2 = one1.setScale(3);

    System.out.println("Comparing new BigDecimal(1) and BigDecimal(1).setScale(3):");
    if (one1.equals(one2)) {
      System.out.println("  equals() indicates equality...");
    } else {
      System.out.println("  equals() indicates different values...");
      if (one1.compareTo(one2) == 0) {
        System.out.println("    but comparesTo() thinks the two BigDecimals are equal.");
      } else {
        System.out.println("    and comparesTo() thinks the same.");
      }
    }
  }
</code></pre>
<p>Looking into the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/math/BigDecimal.html">Javadoc (Java 5) of BigDecimals</a> gave a first hints:</p>
<blockquote><p>Note: care should be exercised if BigDecimal objects are used as keys in a SortedMap or elements in a SortedSet since BigDecimal&#8217;s natural ordering is inconsistent with equals. See Comparable, SortedMap or SortedSet for more information.</p></blockquote>
<p>and</p>
<blockquote><p>Compares this BigDecimal with the specified Object for equality. Unlike compareTo, this method considers two BigDecimal objects equal only if they are equal in value and scale (thus 2.0 is not equal to 2.00 when compared by this method).</p></blockquote>
<p>That definitely was a bit unexpected, but at least documented.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajesse.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajesse.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajesse.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajesse.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajesse.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajesse.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajesse.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajesse.wordpress.com/65/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajesse.wordpress.com/65/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajesse.wordpress.com/65/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=65&subd=ajesse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajesse.wordpress.com/2009/10/27/when-equals-is-not-equal-enough/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/980962c822005ada86cdfe0df61095f2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajesse</media:title>
		</media:content>
	</item>
		<item>
		<title>JadeLiquid first impressions</title>
		<link>http://ajesse.wordpress.com/2009/10/09/jadeliquid-first-impressions/</link>
		<comments>http://ajesse.wordpress.com/2009/10/09/jadeliquid-first-impressions/#comments</comments>
		<pubDate>Fri, 09 Oct 2009 12:24:33 +0000</pubDate>
		<dc:creator>ajesse</dc:creator>
				<category><![CDATA[JadeLiquid]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[UnitTest]]></category>

		<guid isPermaLink="false">http://ajesse.wordpress.com/?p=59</guid>
		<description><![CDATA[First 5 minutes using JadeLiquid testing "tool"<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=59&subd=ajesse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Time to test another testing tool. This time I&#8217;ll try to give a commercial tool possibility to convince me: <a href="http://www.jadeliquid.com/index.php" target="_blank">LiquidTest &#8211; Agile Functional Testing</a></p>
<p>The first installation attempt did fail, because the license key sent by mail was distorted by some element in the mail-chain. A call or an email will supply you with a test-file with a working license key.<br />
Once the eclipse plugin is installed and the license activated, you will find a new eclipse perspective and a sample project with the usual test-sample (a call to a famous search engine). Another nice touch is the creation of a new test-class. The plugin immediately offers to enter &#8220;record mode&#8221;&#8230;</p>
<p>to be continued</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajesse.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajesse.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajesse.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajesse.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajesse.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajesse.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajesse.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajesse.wordpress.com/59/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajesse.wordpress.com/59/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajesse.wordpress.com/59/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=59&subd=ajesse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajesse.wordpress.com/2009/10/09/jadeliquid-first-impressions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/980962c822005ada86cdfe0df61095f2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajesse</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Pearls: Really short production ready class</title>
		<link>http://ajesse.wordpress.com/2009/08/10/55/</link>
		<comments>http://ajesse.wordpress.com/2009/08/10/55/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 12:41:39 +0000</pubDate>
		<dc:creator>ajesse</dc:creator>
				<category><![CDATA[Java Pearls]]></category>

		<guid isPermaLink="false">http://ajesse.wordpress.com/?p=55</guid>
		<description><![CDATA[A sample of a really short java class.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=55&subd=ajesse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Browsing through project code for clean up has let us stumble upon this sample of a really short java class:</p>
<pre style="border:1px dashed #999999;overflow:auto;background-color:#ffffe0;font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;">package some.pkg;
public class CopyParameters {
}
</pre>
<p>The package this class was found in has already been declared production ready by the developer. Looking for checkstyle violations (missing type javadoc) let us stumble on that class. </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajesse.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajesse.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajesse.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajesse.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajesse.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajesse.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajesse.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajesse.wordpress.com/55/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajesse.wordpress.com/55/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajesse.wordpress.com/55/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=55&subd=ajesse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajesse.wordpress.com/2009/08/10/55/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/980962c822005ada86cdfe0df61095f2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajesse</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Pearls: the Void class</title>
		<link>http://ajesse.wordpress.com/2009/08/07/java-pearls-the-void-class/</link>
		<comments>http://ajesse.wordpress.com/2009/08/07/java-pearls-the-void-class/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 11:37:39 +0000</pubDate>
		<dc:creator>ajesse</dc:creator>
				<category><![CDATA[Java Pearls]]></category>

		<guid isPermaLink="false">http://ajesse.wordpress.com/?p=51</guid>
		<description><![CDATA[Void class a serializable null object.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=51&subd=ajesse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Browsing through project code for clean up has let us stumble upon this:</p>
<pre style="border:1px dashed #999999;overflow:auto;background-color:#ffffe0;font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;">package some.pkg;
import java.io.Serializable;
public class Void4MyProject implements Serializable{
  public static final Void4MyProject NULL = null;
  private Void4MyProject() {
  }
}
</pre>
<p>I never had the need to have a serializable null-instance. Simply beautifull and creative.</p>
<p>Just for playing&#8230;  how is it used&#8230;</p>
<pre style="border:1px dashed #999999;overflow:auto;background-color:#ffffe0;font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;">
  final protected IAccessor subTable() {
    return new IAccessor() {
      public String getId() {
        return SUB_TABLE;
      }
      public Class getStaticType() {
        return Void4MyProject.class;
      }
      public Void4MyProject getValue(T parent) {
        return <strong>null</strong>;
      }
      public void setValue(T parent, Void4MyProject value) {
        // nothing to do
      }
    };
  };
</pre>
<p>Here I consider it a <strong>big NoNo</strong> that the defined instance of Void4MyProject is not even used.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajesse.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajesse.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajesse.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajesse.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajesse.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajesse.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajesse.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajesse.wordpress.com/51/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajesse.wordpress.com/51/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajesse.wordpress.com/51/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=51&subd=ajesse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajesse.wordpress.com/2009/08/07/java-pearls-the-void-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/980962c822005ada86cdfe0df61095f2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajesse</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Pearls: Why not copy the attribute&#8217;s value onto itself</title>
		<link>http://ajesse.wordpress.com/2009/03/12/java-pearls-why-not-copy-the-attributes-value-onto-itself/</link>
		<comments>http://ajesse.wordpress.com/2009/03/12/java-pearls-why-not-copy-the-attributes-value-onto-itself/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 13:47:01 +0000</pubDate>
		<dc:creator>ajesse</dc:creator>
				<category><![CDATA[Java Pearls]]></category>

		<guid isPermaLink="false">http://ajesse.wordpress.com/?p=47</guid>
		<description><![CDATA[Java Pearls #2: How to burn lines of code copying an attribute value onto itself.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=47&subd=ajesse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I like it, when values are set into attributes from where they have been fetched. Makes for readable code.</p>
<pre style="border:1px dashed #999999;overflow:auto;background-color:#ffffe0;font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;">UserBean deputyChange = myTransferObject.getDeputy();
if (deputyChange != null &amp;&amp; deputyChange.getUid() != null) {
  if (!checkUserRole(deputyChange.getUid(), FunctionGroups.ROLE_TO_CHECK.getRole())) {
    throw new IllegalArgumentException("Deputy user-id not valid: " + deputyChange.getUid());
  }
  myTransferObject.setDeputy(deputyChange);
  myContext.getMyBean().getMyOtherTransferObject().setAssistanceUserDetail(deputyChange);
}
</pre>
<p>Apart from the fact that the webapplications user gets a nice looking Exception Message in his browser if he selected the wrong user from a list&#8230; It really makes sense to set the originating attribute to the value it delivered just a few lines above&#8230;</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajesse.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajesse.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajesse.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajesse.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajesse.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajesse.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajesse.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajesse.wordpress.com/47/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajesse.wordpress.com/47/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajesse.wordpress.com/47/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=47&subd=ajesse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajesse.wordpress.com/2009/03/12/java-pearls-why-not-copy-the-attributes-value-onto-itself/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/980962c822005ada86cdfe0df61095f2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajesse</media:title>
		</media:content>
	</item>
		<item>
		<title>JSFUnit 1.0.0.GA available</title>
		<link>http://ajesse.wordpress.com/2009/03/05/jsfunit-100ga-available/</link>
		<comments>http://ajesse.wordpress.com/2009/03/05/jsfunit-100ga-available/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 08:47:02 +0000</pubDate>
		<dc:creator>ajesse</dc:creator>
				<category><![CDATA[JSF]]></category>
		<category><![CDATA[JSFUnit]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[UnitTest]]></category>

		<guid isPermaLink="false">http://ajesse.wordpress.com/?p=44</guid>
		<description><![CDATA[According to the projects website JSFUnit has gone live with release 1.0.0.
Time to get serious about JSF unit testing again.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=44&subd=ajesse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>According to the <a title="JSFUnit project website" href="http://www.jboss.org/jsfunit/">projects website JSFUnit</a> has gone live with release 1.0.0.<br />
Time to get serious about JSF unit testing again.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajesse.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajesse.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajesse.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajesse.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajesse.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajesse.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajesse.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajesse.wordpress.com/44/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajesse.wordpress.com/44/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajesse.wordpress.com/44/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=44&subd=ajesse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajesse.wordpress.com/2009/03/05/jsfunit-100ga-available/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/980962c822005ada86cdfe0df61095f2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajesse</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Pearls: Pick the first and only item of a collection</title>
		<link>http://ajesse.wordpress.com/2009/02/16/java-pearls-pick-the-first-and-only-member-of-a-collection/</link>
		<comments>http://ajesse.wordpress.com/2009/02/16/java-pearls-pick-the-first-and-only-member-of-a-collection/#comments</comments>
		<pubDate>Sun, 15 Feb 2009 23:40:56 +0000</pubDate>
		<dc:creator>ajesse</dc:creator>
				<category><![CDATA[Java Pearls]]></category>

		<guid isPermaLink="false">http://ajesse.wordpress.com/?p=38</guid>
		<description><![CDATA[Java Pearls #1: How to burn lines of code to do a simple thing like checking that a collection only contains one single item.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=38&subd=ajesse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Every now and then I stumble upon real nice examples of Java code&#8230;</p>
<p>Like this pick method It should return the only item in a collection:</p>
<pre style="border:1px dashed #999999;overflow:auto;background-color:#ffffe0;font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;">package some.pkg;

import java.util.Collection;
import some.pkg.Helper4Exceptions;

/**
 * Helper for Collections.
 */
public class Helper4Collections {
	public static  E pick(Collection coll) {
		Helper4Exceptions.assertNotNull(coll); // throw a runtime exception if coll is null
		if(1!=coll.size()){
			throw new RuntimeException("zero or more than one element found");
		}
		Helper4Exceptions.assertEquals(1,coll.size()); //runtime exception if not exactly 1 member in coll
		return coll.iterator().next();
	}

	// and other methods
}</pre>
<p><span style="font-size:small;">Obviously the package and the class comment have been messed with to protect the original author</span></p>
<p>What impressed me first was the impossibility to reach the call of assertEquals in this method. Then I went further to look at the two used methods&#8230;</p>
<pre style="border:1px dashed #999999;overflow:auto;background-color:#ffffe0;font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;">package some.pkg;

import some.pkg.Helper4Comparison;

/**
 * This helper class contains several static methods that allows to do advanced
 * exception handling. Furthermore it provides certain assertion method similar
 * to the uses methods within junit test. (this has been done becaus the junit
 * test environment is not part of the produtive deployment.
 */
public class Helper4Exceptions {

	/**
	 * Assert equals.
	 *
	 * @param i
	 *            the i
	 * @param j
	 *            the j
	 */
	public static void assertEquals(int i, int j) {
		assertEquals(new Integer(i), new Integer(j));
	}

  /**
   * Assert equals.
   *
   * @param expectedValue
   *            the expected value
   * @param currentValue
   *            the current value
   * @param
   *            element type
   */
  public static  void assertEquals(T expectedValue, T currentValue) {
    assertEquals(expectedValue, currentValue, "");
  }

  /**
   * Assert equals.
   *
   * @param expectedValue
   *            the expected value
   * @param currentValue
   *            the current value
   * @param
   *            element type
   * @param msg
   *            the msg
   */
  public static  void assertEquals(T expectedValue, T currentValue,
      String msg) {
    boolean isEqual = Helper4Comparison.equals(expectedValue, currentValue);
    if (!isEqual) {
      String message = "objects are not equal";
      Helper4Exceptions.assertTrue(isEqual, message + ":\nexpected &lt;"
          + expectedValue + "&gt; \nbut was   &lt;" + currentValue + "&gt; \n"
          + msg);
      thisLineShouldNeverBeReached();
    }
  }

  /**
   * Assert true.
   *
   * @param condition
   *            the condition
   * @param string
   *            the string
   */
  public static void assertTrue(boolean condition, String string) {
    if (!condition) {
      throwRuntimeException("Assertion:\n" + string);
    }
  }

	/**
	 * Assert not null.
	 *
	 * @param object
	 *            the object
	 * @param msg
	 *            the msg
	 */
	public static void assertNotNull(Object object, String msg) {
		if (object == null) {
			throwRuntimeException("assertion: object is null but was expected not to be null. \n"
					+ msg);
		}
	}

	/**
	 * Assert not null.
	 *
	 * @param object
	 *            the object
	 * @param
	 *            element type
	 * @return the not null object
	 */
	public static  T assertNotNull(T object) {
		if (object == null) {
			assertNotNull(object, "");
			throw thisLineShouldNeverBeReached();
		} else {
			return object;
		}
	}

	/**
	 * throws runtime exception "This line should never be reached".
	 *
	 * @return the runtime exception
	 */
	public static RuntimeException thisLineShouldNeverBeReached() {
		return thisLineShouldNeverBeReached(null);
	}

	/**
	 * throws runtime exception "This line should never be reached".
	 *
	 * @param msg
	 *            the msg
	 *
	 * @return the runtime exception
	 */
	public static RuntimeException thisLineShouldNeverBeReached(String msg) {
		return throwRuntimeException("this line should never be reached"
				+ (msg == null ? "" : ":\n" + msg));
	}

	/**
	 * Throw runtime exception.
	 *
	 * @param msg
	 *            the msg
	 *
	 * @return the runtime exception
	 */
	static public RuntimeException throwRuntimeException(String msg) {
		throw new RuntimeException("\n" + msg);
	}

  // and other methods
}</pre>
<p>and the method called in this second class</p>
<pre style="border:1px dashed #999999;overflow:auto;background-color:#ffffe0;font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;">package some.pkg;
/**
 * This class provides several static helper methods for topic Comparison.
 */
public class Helper4Comparison {

	/**
	 * Equals.
	 *
	 * @param value1
	 *            the value1
	 * @param value2
	 *            the value2
	 *
	 * @return true if both values are equal, and considers the different null
	 *         combinations
	 */
	public static boolean equals(Object value1, Object value2) {
		Boolean equals = isEqualCausedByNulls(value1, value2);
		if (equals != null) {
			return equals.booleanValue();
		} else {
			// now we know that both values are not null
			return value1.equals(value2);
		}
	}

	/**
	 * return true if both values are identical or both null, 

	 * false if one value is null and the other is not null, 

	 * returns null if both values are not null.
	 *
	 * @param value1
	 *            the value1
	 * @param value2
	 *            the value2
	 *
	 * @return true, if checks if is equal caused by nulls
	 */
	private static Boolean isEqualCausedByNulls(Object value1, Object value2) {
		if (value1 == value2) {
			// identical values return true (also checks for both null)
			return new Boolean(true);
		} else if (value1 == null || value2 == null) {
			// this means one value is null but the other is not null
			return new Boolean(false);
		} else {
			// means both values are not null, but not identical
			return null;
		}
	}
}</pre>
<p>Well, I&#8217;m impressed. Especially because this developer told us once, when we proposed some simple solution to another problem, that we would be stone age developers and he was doing better&#8230;</p>
<p>I&#8217;d really like to hear hat other developers think about these coding samples.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajesse.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajesse.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajesse.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajesse.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajesse.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajesse.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajesse.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajesse.wordpress.com/38/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajesse.wordpress.com/38/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajesse.wordpress.com/38/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=38&subd=ajesse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajesse.wordpress.com/2009/02/16/java-pearls-pick-the-first-and-only-member-of-a-collection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/980962c822005ada86cdfe0df61095f2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajesse</media:title>
		</media:content>
	</item>
		<item>
		<title>Let’s meet in Vienna again &#8211; JSFDays 2009</title>
		<link>http://ajesse.wordpress.com/2009/01/27/let%e2%80%99s-meet-in-vienna-again-jsfdays-2009/</link>
		<comments>http://ajesse.wordpress.com/2009/01/27/let%e2%80%99s-meet-in-vienna-again-jsfdays-2009/#comments</comments>
		<pubDate>Tue, 27 Jan 2009 13:20:50 +0000</pubDate>
		<dc:creator>ajesse</dc:creator>
				<category><![CDATA[JSF]]></category>
		<category><![CDATA[JSFDays]]></category>

		<guid isPermaLink="false">http://ajesse.wordpress.com/?p=33</guid>
		<description><![CDATA[Last years JSFDays in Vienna have been a huge success. The organization was superb and the event definitely focused on JSF. This year the event will be bigger and contains now two tracks. One of them is focused on JSF while the second track has a larger enterprise Java focus. Check out the website.
With JSF [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=33&subd=ajesse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Last years JSFDays in Vienna have been a huge success. The organization was superb and the event definitely focused on JSF. This year the event will be bigger and contains now two tracks. One of them is focused on JSF while the second track has a larger enterprise Java focus. <strong><a href="http://www.jsfdays.com">Check out the website.</a></strong></p>
<p>With <strong>JSF 2</strong> on the horizon you definitely should consider making the trip to Vienna. Several of the sessions for JSF will concentrate on that. And who could you tell better about JSF 2 than the guys that shaped it working for the Expert Group. And JSFDays will feature several expert Group members giving you the information from the source.</p>
<p>Let&#8217;s meet there and have some fun too. Vienna definitely is a city to enjoy, so consider staying for the weekend as well and discover its many features.</p>
<p>Already booked?</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajesse.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajesse.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajesse.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajesse.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajesse.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajesse.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajesse.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajesse.wordpress.com/33/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajesse.wordpress.com/33/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajesse.wordpress.com/33/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=33&subd=ajesse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajesse.wordpress.com/2009/01/27/let%e2%80%99s-meet-in-vienna-again-jsfdays-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/980962c822005ada86cdfe0df61095f2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajesse</media:title>
		</media:content>
	</item>
		<item>
		<title>JUnit-testing BigDecimals: watch your JUnit version</title>
		<link>http://ajesse.wordpress.com/2008/12/04/junit-testing-bigdecimals-watch-your-junit-version/</link>
		<comments>http://ajesse.wordpress.com/2008/12/04/junit-testing-bigdecimals-watch-your-junit-version/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 09:55:02 +0000</pubDate>
		<dc:creator>ajesse</dc:creator>
				<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[UnitTest]]></category>

		<guid isPermaLink="false">http://ajesse.wordpress.com/?p=21</guid>
		<description><![CDATA[Consider this test:
  public void testBigDecimalAssertEquals() {
    BigDecimal number1 = new BigDecimal("0.01");
    BigDecimal number2 = new BigDecimal("0.99");

    System.out.println("number1.equals(number2)= " + number1.equals(number2));
    assertEquals(number1, number2);
    System.out.println("  but JUnit thinks its equals...");
    assertTrue(number1.equals(number2));
    System.out.println(  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=21&subd=ajesse&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Consider this test:</p>
<pre style="border:1px dashed #999999;overflow:auto;background-color:#ffffe0;font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;"><code>  public void testBigDecimalAssertEquals() {
    BigDecimal number1 = new BigDecimal("0.01");
    BigDecimal number2 = new BigDecimal("0.99");

    System.out.println("number1.equals(number2)= " + number1.equals(number2));
    assertEquals(number1, number2);
    System.out.println("  but JUnit thinks its equals...");
    assertTrue(number1.equals(number2));
    System.out.println(  "  only testing for BigDecimal.equals() == "
                       + "true will yield the correct result.");
  }

</code></pre>
<p>I definitely expected the assertEquals condition to report a failure, but&#8230;</p>
<p>In my Eclipse environment I had JUnit 4.3.1 loaded and the test only failed on the assertTrue condition.</p>
<p>After some download- and debug-sessions I learned that some JUnit-versions (&gt; 3.8.x and &lt; 4.4) had some code in the Assert.isEquals() method which caused this behaviour:</p>
<pre style="border:1px dashed #999999;overflow:auto;background-color:#ffffe0;font-family:Andale Mono, Lucida Console, Monaco, fixed, monospace;"><code>private static boolean isEquals(Object expected, Object actual) {
  if (expected instanceof Number &amp;&amp; actual instanceof Number)
    return ((Number) expected).longValue() == ((Number) actual).longValue();
  return expected.equals(actual);
}
</code></pre>
<p>Versions before and after 4.4 do not check for a Number-instance, they just call the objects equals method.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/ajesse.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/ajesse.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/ajesse.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/ajesse.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/ajesse.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/ajesse.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/ajesse.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/ajesse.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/ajesse.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/ajesse.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ajesse.wordpress.com&blog=1325848&post=21&subd=ajesse&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://ajesse.wordpress.com/2008/12/04/junit-testing-bigdecimals-watch-your-junit-version/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/980962c822005ada86cdfe0df61095f2?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">ajesse</media:title>
		</media:content>
	</item>
	</channel>
</rss>