<?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>Alexandre Martins &#187; Coding</title>
	<atom:link href="http://blog.m.artins.net/category/coding/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.m.artins.net</link>
	<description>On Agile Software Development</description>
	<lastBuildDate>Thu, 12 Aug 2010 20:09:21 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>TDD: Listen to the tests&#8230; they tell smells in your code!</title>
		<link>http://blog.m.artins.net/tdd-listen-to-the-tests-they-tell-smells-in-your-code/</link>
		<comments>http://blog.m.artins.net/tdd-listen-to-the-tests-they-tell-smells-in-your-code/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 02:30:11 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Object-Oriented Programming]]></category>
		<category><![CDATA[Test-Driven Development]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=305</guid>
		<description><![CDATA[These days, reading the Goos book, by Steve Freeman and Nat Pryce, it reminded me of a project I worked on a while ago. It was a one year old system, poorly tested, integrating to a handful of other systems, and the code-base... well I prefer not to remember. Despite this scenario, I joined the [...]]]></description>
			<content:encoded><![CDATA[<p>These days, reading the <strong><a href="http://www.amazon.com/Growing-Object-Oriented-Software-Guided-Tests/dp/0321503627">Goos</a></strong> book, by <a href="http://www.m3p.co.uk/blog/">Steve Freeman</a> and <a href="http://www.natpryce.com/">Nat Pryce</a>, it reminded me of a project I worked on a while ago. It was a one year old system, poorly tested, integrating to a handful of other systems, and the code-base... well I prefer not to remember. Despite this scenario, I joined the team to help them implement some new functionalities.</p>
<p>I remember sometimes it was difficult to write tests, the classes were tightly coupled, with no clear responsibilities, several attributes, bloated constructors, etc. And despite our best effort, working around the bits that were preventing us from writing the tests, we felt we were getting down the wrong road, trying to do it in such a crappy code-base. As a result some of our tests were massive! A bunch of lines of mocks, stubs, and expectations, making it impossible to understand their purpose.</p>
<h2>What have I learned?</h2>
<p>Reading one of the book chapters I learned that the same qualities that makes an object easy to test also makes the code responsive to change. In my situation, the tests were telling me how clumsy the code was and how difficult it would be to extend it.</p>
<p>I also learned that when we come across a functionality that is difficult to test,   asking ourselves <strong><em>how</em></strong> to test it is not enough, we also have to ask <strong><em>why</em></strong> is it difficult to test, and check whether it's an opportunity to improve our code. The trick is to do it driven by tests, so we can get rapid feedback on code's internal qualities and on whether it's doing what it's supposed to do.</p>
<p>So they introduced a variation for the well-known TDD cycle— <strong>"<em>Write a failing test</em>" =&gt; "<em>Make the test pass</em>" =&gt; "<em>Refactor</em>"</strong>. As described on the figure below (extracted from the book), if we're finding it hard to write the next failing test for our application, we should look again at the design of the production code and often refactor it before moving on, until we get to the point that we can write tests that reads well.</p>
<div style="text-align: center;"><img style="border: 0px none;" src="http://blog.m.artins.net/wp-content/uploads/2010/07/listen-to-tests.png" alt="" width="306" height="226" /></div>
<p><cite>Extracted from Growing Object-Oriented Software, Guided By Tests— Steve Freeman and Nat Pryce</cite></p>
<h2>An Example of a Smell Tests Might Be Telling You</h2>
<h3>Reference data rather than behavior</h3>
<p>When applying "<a href="http://pragprog.com/articles/tell-dont-ask">Tell Don't Ask</a>" or "<a href="http://pragprog.com/articles/tell-dont-ask">Law of Demeter</a>" consistently, we end up with a coding style where we tend to pass behavior into the system instead of pulling values up through the stack. So picking up the famous <em><strong>Paperboy</strong></em> example, before refactoring the code applying the "Law of Demeter" the code and test would look something along the lines of the snippet showed below.</p>
<pre style="background-color: #ffffe3; border-left: solid gray 4px; padding: 8px; margin-bottom: 10px; font-family: Courier New; font-size: 12px;">class Paperboy
  def collect_money(customer, due_amount)
    if due_amount &gt; customer.wallet.cash
      raise InsuficientFundsError
    else
      customer.wallet.cash -= due_amount
      @total_collected += due_amount
    end
  end
end
</pre>
<pre style="background-color: #ffffe3; border-left: solid gray 4px; padding: 8px; margin-bottom: 10px; font-family: Courier New; font-size: 12px;">it "should collect money from customer" do
  customer = Customer.new :wallet =&gt; Wallet.new(:amount =&gt; 200)
  paperboy = Paperboy.new
  paperboy.total_collected.should == 0
  paperboy.collect_money(customer, 50)
  customer.wallet.cash.should == 150
  paperboy.total_collected.should == 50
end
</pre>
<p>We can easily see that the test is telling us it knows too much detail about <span style="font-family: Courier New; font-size: 12px;">Customer</span> class implementation. We can see its internals, which objects it's related to, and even worse, we're also exposing implementation details of its peers. So it's clear for me that it needs some design improvement. My main goal here is to hide <span style="font-family: Courier New; font-size: 12px;">Customer</span> implementation details from the users of the <span style="font-family: Courier New; font-size: 12px;">Paperboy</span> class. Which means that I don't wanna see anything but <span style="font-family: Courier New; font-size: 12px;">Customer</span> and <span style="font-family: Courier New; font-size: 12px;">Money</span> classes referenced on the test!</p>
<pre style="background-color: #ffffe3; border-left: solid gray 4px; padding: 8px; margin-bottom: 10px; font-family: Courier New; font-size: 12px;">class Paperboy
  def collect_money(customer, due_amount)
    @collected_amount += customer.pay(due_amount)
  end
end
</pre>
<pre style="background-color: #ffffe3; border-left: solid gray 4px; padding: 8px; margin-bottom: 10px; font-family: Courier New; font-size: 12px;">it "should collect money from customer" do
  customer = Customer.new :total_cash =&gt; 200
  paperboy = Paperboy.new
  paperboy.total_collected.should == 0
  paperboy.collect_money(customer, 50)
  customer.total_cash.should == 150
  paperboy.total_collected.should == 50
end
</pre>
<p>The method <strong>customer.pay(due_amount)</strong> wraps all the implementation detail up behind a single call. The client of paperboy no longer needs to know anything about the types in the chain. We've reduced the risk that a design change might cause ripples in remote parts of the codebase.</p>
<p>As well as hiding information, there's a more subtle benefit from "Tell, Don't Ask." It forces us to make explicit and so name the interactions between objects, rather than leaving them implicit in the chain of getters. The shorter version above is much clearer about <em><strong>what</strong></em> it's for, not just <em><strong>how</strong></em> it happens to be implemented.</p>
<p>All the logic necessary to collect the money is inside the <span style="font-family: Courier New; font-size: 12px;">Customer</span> object, so it doesn't have to expose its state to its peers.</p>
<p>Now it's safer to continue writing new failing tests to our objects.<br />
Remember, listen to the tests!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/tdd-listen-to-the-tests-they-tell-smells-in-your-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Clojure: Integrating With Java</title>
		<link>http://blog.m.artins.net/clojure-integrating-with-java/</link>
		<comments>http://blog.m.artins.net/clojure-integrating-with-java/#comments</comments>
		<pubDate>Thu, 01 Jan 2009 06:44:04 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Clojure]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=145</guid>
		<description><![CDATA[Currently I am learning Clojure. It is a functional programming language, but not a pure one, since you can both write code that share state (mutable) and also ones that doesn't. Why Clojure? The main reason why I chose Clojure is its easy interoperability with Java, still one of the most used languages, bringing to [...]]]></description>
			<content:encoded><![CDATA[<p>Currently I am learning <a href="http://clojure.org/">Clojure</a>. It is a functional programming language, but not a <a href="http://en.wikipedia.org/wiki/Purely_functional">pure one</a>, since you can both write code that share state (mutable) and also ones that doesn't.</p>
<h2>Why Clojure?</h2>
<p>The main reason why I chose Clojure is its easy interoperability with <a href="http://java.com">Java</a>, still one of the most used languages, bringing to it the power of Lisp. It's fast, since the code is compiled, and it supplements some of Java's weakness, such as the Collections framework and concurrent programming. It is pretty straightforward to write concurrent programs, everything is automatic, no manual lock management!</p>
<h2>Integrating With Java</h2>
<h3>Importing classes</h3>
<p>A single class:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(import java.util.List)
</pre>
</p>
<p>Multiple classes from the same package:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(import '(java.util List Set))
</pre>
</p>
<h3>Creating instances</h3>
<p>Using Java's <span style="font-family: courier;">new</span> keyword:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(new java.util.ArrayList)
(new ArrayList) ; after importing
</pre>
</p>
<p>Assigning a new  <span style="font-family: courier;">List</span> to a Clojure variable:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(def list (new java.util.List))
-> #'user/list
</pre>
</p>
<p>Syntactic Sugar:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(ArrayList.)
</pre>
</p>
<h3>Accessing ﬁelds</h3>
<p>Static fields:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(. Math PI)
</pre>
</p>
<p>Syntactic Sugar:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
Math/PI
</pre>
</p>
<h3>Invoking methods</h3>
<p>
<h4>Static Methods</h4>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(.currentTimeMillis System)
</pre>
</p>
<p>Syntactic Sugar:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(System/currentTimeMillis)
</pre>
</p>
<p>
<h4>Non-static Methods</h4>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(. list size)
(. list get 0) ; returns the object stored at index 0
</pre>
</p>
<p>Syntactic Sugar:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(.size list)
</pre>
</p>
<h3>Mixing Them All</h3>
<p>Clojure provides a macro called  <span style="font-family: courier;">memfn</span> that makes possible execute Java methods as functions. So, for a list of String objects, if I want to make all of them upper-case, all I have to do is:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(map (memfn toUpperCase) ["a" "short" "message"])
</pre>
<p>The  <span style="font-family: courier;">map</span> function applies the function/method  <span style="font-family: courier;"> toUpperCase</span> to each element in  <span style="font-family: courier;">["a" "short" "message"]</span></p>
<p>You can also use the  <span style="font-family: courier;">bean</span> function to wrap a Java bean in an immutable Clojure map.</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(bean (new Person "Alexandre" "Martins"))
-> {:firstName "Alexandre", :lastName "Martins"}
</pre>
<p>Once converted, you can manipulate the new map using any of Clojure’s map functions, like:</p>
<pre style="border: solid gray 1px; width: 60%; padding: 5px;">
(:firstName (bean (new Person "Alexandre" "Martins")))
-> Alexandre
</pre>
<p>The code above extracts the <span style="font-family: courier;">firstName</span> key, originally from the  <span style="font-family: courier;">Person</span> object.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/clojure-integrating-with-java/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>First Sydney Coding Dojo</title>
		<link>http://blog.m.artins.net/first-sydney-coding-dojo/</link>
		<comments>http://blog.m.artins.net/first-sydney-coding-dojo/#comments</comments>
		<pubDate>Thu, 06 Nov 2008 13:33:57 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Behaviour-Driven Development]]></category>
		<category><![CDATA[Dojo]]></category>
		<category><![CDATA[Pair Programming]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=111</guid>
		<description><![CDATA[Last Wednesday, 5th of November, we run our first Coding Dojo session at Sydney office. We had a reasonable number of attendants, and the experience was fantastic, although we still have some points to improve. The Initiative The idea was originally from my friend and flat-mate Mark Needham. Since we moved in to our new [...]]]></description>
			<content:encoded><![CDATA[<p>Last Wednesday, 5th of November, we run our first <a href="http://www.codingdojo.org/">Coding Dojo</a> session at Sydney office. We had a reasonable number of attendants, and the experience was fantastic, although we still have some points to improve.</p>
<h4>The Initiative</h4>
<p>The idea was originally from my friend and flat-mate <a href="http://www.markhneedham.com/blog/">Mark Needham</a>. Since we moved in to our new place, he came up with the idea of getting together every week to solve some <a href="http://codekata.pragprog.com/">CodeKatas</a> at home, exploring a different language. We decided it would be more interesting if we could broaden the idea, and decided to organise a session at the Community College in the <a href="http://www.thoughtworks.com/">ThoughtWorks</a> office.</p>
<h4>How did we run:</h4>
<p>There were six people attending, so we decided to split it into three pairs, each with their own solution, rotating every ten minutes.<br />
We had three design discussion breaks, one in the beginning, one in the middle and another at the end of the session. Since the focus was on object-oriented design, we chose to implement the bowling game, extracted from <a href="http://tinyurl.com/5v9qq2">Uncle Bob Martin's book</a>. We did it following the <a href="http://www.pragprog.com/titles/twa/thoughtworks-anthology">Object Calisthenics</a> rules, which are:</p>
<ul>
<li>Use only one level of indentation per method</li>
<li>Don't use the else keyword</li>
<li>Wrap all primitives and strings (strong types)</li>
<li>Use only one dot per line</li>
<li>Don't abbreviate</li>
<li>Keep all entities small</li>
<li>Don't use any classes with more than two instance variables</li>
<li>Use first-class collections</li>
<li>Don't use any getters/setters/properties</li>
</ul>
<h4>What was cool:</h4>
<p>Apart from being an amusing experience, it was quite interesting to see the different approaches that people take to solve the same problem, -  the design, the way they write tests, the code style, pretty cool. The pair swapping was also another nice experience. It was gratifying to pair with ThoughtWorkers other than the ones on my current project, like David Cameron and <a href="http://ca.rroll.net/">Nick Carroll</a>.</p>
<h4>Future improvements:</h4>
<p>For the next session, I would like to experiment with another approach.<br />
Restrict the number participants from seven to ten developers. And instead of splitting them into as many pairs as possible, having all seated around a table, where there would be only one pair working on the solution, while the others are watching through a projector. They are free to help whenever they want, providing suggestions, ideas for design, algorithm, etc. The developers pairing would be swapped every ten minutes, by other ones participating. Although the number of developers participating is restricted, anyone is welcome to attend as a watcher.</p>
<p>I reckon we would be much more productive this way, when everyone is working on the same thing, centralizing the focus, and learning even more from other developers.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/first-sydney-coding-dojo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Benefits of supporting tools</title>
		<link>http://blog.m.artins.net/benefits-of-supporting-tools/</link>
		<comments>http://blog.m.artins.net/benefits-of-supporting-tools/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 23:16:34 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open-Source]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=25</guid>
		<description><![CDATA[One of the deliverables to our current client is a project template, containing tools to guide them to build better software, ensuring lower bug occurrence and system integrity. One tool we are using is Findbugs. One day, when running it, we came across an interesting issue, Findbugs was complaining that a class in a project [...]]]></description>
			<content:encoded><![CDATA[<p>One of the deliverables to our current client is a project template, containing tools to guide them to build better software, ensuring lower bug occurrence and system integrity.<br />
One tool we are using is <a href="http://findbugs.sourceforge.net/">Findbugs</a>. One day, when running it, we came across an interesting issue, Findbugs was complaining that a class in a project was exposing its internal state, subjecting it to unexpected modifications. The class contained a single constructor with parameters setting its initial state and a set of getter methods. Any Java developer used to getters and setters pattern would say that the code below is valid. </p>
<pre name="code" class="java">
public class Person {

	private String name;
	private Date dateOfBirth;

	public Person(String name, Date dateOfBirth) {
		this.name = name;
		this.dateOfBirth = dateOfBirth;
	}

	public Date getDateOfBirth() {
		return dateOfBirth;
	}
	public String getName() {
		return name;
	}
}
</pre>
<p>What would happen if you create a Person instance passing as parameter, pre-defined name and dateOfBirth variables and then, perform operations over these variables, modifying its states? And what if you retrieve these attributes (through getter methods), assigning them to new variables and start performing operations over them? For the name attribute it wouldn't be a problem, since String objects are immutable, but certainly both cases would affect the dateOfBirth attribute, corrupting the state of the object.</p>
<p>One of the solutions to this problem would be to make getter methods always return a new object, copy of the original one and during object construction, initialize instance variables with new objects, copy from the original ones passed as constructor parameters.</p>
<pre name="code" class="java">
public class Person {
	...

	public Person(String name, Date dateOfBirth) {
		this.name = name;
		this.dateOfBirth = new Date(dateOfBirth.getTime());
	}

	public Date getDateOfBirth() {
		return new Date(dateOfBirth.getTime());
	}
	...
}
</pre>
<p>So, unless the objects you are implementing are <a href="http://docs.codehaus.org/display/PICO/Good+Citizen">good citizens</a> and contains <a href="http://safari.oreilly.com/0321125215/ch10lev1sec2">side-effect-free functions</a>, you should consider programming in a more defensive way, to avoid unexpected behaviors in your project and also make use of tools like Findbugs to turn the development easier. <a href="http://checkstyle.sourceforge.net/">Checkstyle</a> and <a href="http://cobertura.sourceforge.net/">Cobertura</a> are a good start.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/benefits-of-supporting-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JBehave Matchers</title>
		<link>http://blog.m.artins.net/jbehave-matchers/</link>
		<comments>http://blog.m.artins.net/jbehave-matchers/#comments</comments>
		<pubDate>Thu, 05 Jul 2007 03:29:32 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Behaviour-Driven Development]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBehave]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=11</guid>
		<description><![CDATA[JBehave and JMock2 are tools I've been using on my latest projects to define the behaviours of my objects. Both, when used together supplies pretty much all the resources needed to write effective behaviour verification. But in this topic I'm going to talk about JBehave Matchers. Matchers are handy objects, inspired by JUnit Assert class, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://jbehave.org/">JBehave</a> and <a href="http://jmock.org/">JMock2</a> are tools I've been using on my latest projects to define the behaviours of my objects. Both, when used together supplies pretty much all the resources needed to write effective behaviour verification. But in this topic I'm going to talk about JBehave Matchers.</p>
<p>Matchers are handy objects, inspired by <a href="http://www.junit.org">JUnit</a> <a href="http://junit.sourceforge.net/javadoc/junit/framework/Assert.html">Assert</a> class, but much more elaborated. They can help us in loads of scenarios, without the need to write repeated code, such as <code>loops, ifs, elses</code>, turning out the code cleaner and much more intuitive. Currently there are six matcher subtypes: <strong>UsingArrayMatchers</strong>, <strong>UsingCollectionMatchers</strong>, <strong>UsingEqualityMatchers</strong>, <strong>UsingExceptions</strong>, <strong>UsingLogicalMatchers</strong> e <strong>UsingStringMatchers</strong>. For now, I'm just going to talk about four of them, which for me are the most innovative ones.</p>
<h3>UsingArrayMatchers e UsingCollectionMatchers</h3>
<p>Both are quite similar in their behaviours, the only thing that distinguishes them, as their names indicates, is the object on which operations are executed upon. I decided using the UsingArrayMatchers matcher to show some examples of features it comprises:</p>
<p>1 - Check if a Collection/Array contains a certain object:</p>
<pre name="code" class="java">
Integer[] array = new Integer[] {3};
Ensure.that(array, contains(3));
Ensure.that(array, not(contains(5)c));
</pre>
<p>2 - Check if a Collection/Array contains a certain set of objects:</p>
<pre name="code" class="java">
Integer[] array = new Integer[] {3, 4, 5};
Ensure.that(array, contains(3, 4));
Ensure.that(array, contains(3, 4, 5));
</pre>
<p>3 - Check if a Collection/Array contains only a certain set of objects, and nothing more:</p>
<pre name="code" class="java">
Integer[] array = new Integer[] {3, 4, 5};
Ensure.that(array, containsOnly(3, 4, 5));
Ensure.that(array, not(containsOnly(3, 4)));
</pre>
<p>4 - Check if a Collection/Array contains a certain set of objects, in a defined order:</p>
<pre name="code" class="java">
Integer[] array = new Integer[] {3, 4, 5};
Ensure.that(array, containsInOrder(3, 4, 5));
Ensure.that(array, not(containsInOrder(4, 5, 3)));
</pre>
<h3>UsingStringMatchers</h3>
<p>The methods in this class are self-explanatory, just check it out:</p>
<pre name="code" class="java">
Ensure.that("octopus", contains("top"));
Ensure.that("octopus", not(contains("pee")));
Ensure.that("octopus", startsWith("octo"));
Ensure.that("octopus", not(startsWith("pee")));
Ensure.that("octopus", endsWith("pus"));
Ensure.that("octopus", not(endsWith("pee")));
</pre>
<h3>UsingLogicalMatchers</h3>
<p>Using this class, it's possible to negate any matcher and define matcher compositions using AND, OR, EITHER, BOTH. This class for me is the most powerful one, it gives us a wide range of interesting possibilities. Let's try some of them, so you can see how far you can go.</p>
<p>1 - Using conditional matchers:</p>
<pre name="code" class="java">
String horse = "horse";
String cow = "cow";

Ensure.that(horse, or(eq(horse), eq(cow)));
Ensure.that(cow, either(eq(horse), eq(cow)));

Ensure.that(horse, and(eq(horse), contains("ors")));
Ensure.that(cow, both(eq(cow), endsWith("ow")));
</pre>
<p>2 - Using negative matcher:</p>
<pre name="code" class="java">
Ensure.that("horse", not(eq("cow")));
</pre>
<p>There are still a couple of matchers to talk about, one is the <strong>UsingEqualityMatchers</strong> class which is pretty much like JUnit Assert class, and the <strong>UsingExceptions</strong> class. Both also deserves your attention. Maybe someday I talk about them here. <img src='http://blog.m.artins.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/jbehave-matchers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Value Objects &amp; RoR</title>
		<link>http://blog.m.artins.net/value-objects-ror/</link>
		<comments>http://blog.m.artins.net/value-objects-ror/#comments</comments>
		<pubDate>Tue, 12 Jun 2007 01:14:28 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Domain-Driven Design]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=9</guid>
		<description><![CDATA[Currently I'm working on my personal project, aiming to increase my Ruby On Rails skills. It's quite a simple system for my dad's company and one of the features is to register his clients. I started it out writing the Specs and as I'm new to the Ruby world, doubts started to pop inside my [...]]]></description>
			<content:encoded><![CDATA[<p>Currently I'm working on my personal project, aiming to increase my Ruby On Rails skills. It's quite a simple system for my dad's company and one of the features is to register his clients. I started it out writing the <a href="http://rspec.rubyforge.org/">Specs</a> and as I'm new to the Ruby world, doubts started to pop inside my head. I was wondering how to use <a href="http://www.darrenhobbs.com/archives/2007/04/strong_typing_a.html">Value Objects</a> ( Eric Evans definition, please! ) integrated with RoR, something I can do with Java as shown below:</p>
<pre name="code" class="java">
public class Phone() {
    private int code;
    private int number;
    ....
}
</pre>
<pre name="code" class="java">
public class Client() {
    private String name;
    private Phone home;
    private Phone mobile;
    ....
}
</pre>
<p>Chatting with <a href="http://lixo.org">Carlos Villela</a>, he advised me to take a look at <code>composed_of</code> feature, that it would help me get the solution for my problem. The final result is shown below. I'm definitely not used to the Ruby syntax yet, for me it's still a bit confusing.</p>
<pre name="code" class="ruby">
class Phone
  attr_reader :code, :number
  def initialize(code, number)
      @code, @number = code, number
  end

  def ==(other)
      code==other.code &#038;& number==other.number
  end
end
</pre>
<pre name="code" class="ruby">
class Client < ActiveRecord::Base
  composed_of :home, :class_name => "Phone",
        :mapping => [ %w(home_code code), %w(home_number number) ]
  composed_of :mobile, :class_name => "Phone",
        :mapping => [ %w(mob_code code), %w(mob_number number) ]
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/value-objects-ror/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[WTF] Eureka!</title>
		<link>http://blog.m.artins.net/wtf-eureka/</link>
		<comments>http://blog.m.artins.net/wtf-eureka/#comments</comments>
		<pubDate>Thu, 25 Jan 2007 22:21:42 +0000</pubDate>
		<dc:creator>Alexandre Martins</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Smells]]></category>
		<category><![CDATA[WTF]]></category>

		<guid isPermaLink="false">http://blog.m.artins.net/?p=3</guid>
		<description><![CDATA[If you think you know how to work out the age of a person, based on his date of birth, it'd be better to review your concepts about implementing this functionality. Enjoy the code!! public UserImpl( UserTO user, String status ) { _user = user; _status = status; _age = 0; Calendar today = Calendar.getInstance(); [...]]]></description>
			<content:encoded><![CDATA[<p>If you think you know how to work out the age of a person, based on his date of birth, it'd be better to review your concepts about implementing this functionality. Enjoy the code!!</p>
<pre name="code" class="java">
    public UserImpl( UserTO user, String status ) {
        _user = user;
        _status = status;

        _age = 0;
        Calendar today = Calendar.getInstance();
        Calendar birthdate = Calendar.getInstance();
        birthdate.setTimeInMillis( getBirthdate().getTime() );
        birthdate.roll( Calendar.YEAR, 1 );
        while ( today.after( birthdate ) ) {
            birthdate.roll( Calendar.YEAR, 1 );
            _age++;
        }
    }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.m.artins.net/wtf-eureka/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
