GOOS Book Distilled Part 12
A follow through of the great book Growing Object-Oriented Software, Guided by Tests with code
This is a series of blog posts going through the great book Growing Object Oriented Software Guided By Tests, typing in code chapter by chapter, trying to add some of my own understanding where things may not be easy to grasp in the book. I highly recommand you get a copy of the book and follow along with me. Happy coding.
In this post, we start Chapter 16 Sniping for Multiple Items.
A Tale of Two Items
First an acceptance test.
The test is very similar to one auction item.
-
Create 2
FakeAuctionServer
s. -
Start selling on both auction servers.
-
Application start bidding in two auctions. Asserts both auction servers receive join request.
-
Auction server 1 reports other bidder bidding, then asserts that it receives a higher bid from application.
-
Auction server 2 reports other bidder bidding, then asserts that it receives a hight bid from application.
-
Auction server 1 reports the price where application as the current bidder, asserts that the application shows
WINNING
. -
Auction server 2 reports the price where application as the current bidder, asserts that the application shows
WINNING
. -
Both auction servers announces close.
-
Asserts that both auction has won in the application
The ApplicationRunner
Now we need to pass the following to the main()
:
-
Credentials for the XMPP Connection, including
XMPP_HOSTNAME
,SNIPER_ID
andSNIPER_PASSWORD
. -
The auctions'
item-id
s.
A Diversion, Fixing the Failure Message
Use hasProperty
method in hamcrest to create a better error message.
assertThat(message, hasProperty("body", messageMatcher));
/**
* Creates a matcher that matches when the examined object has a JavaBean property
* with the specified name.
* <p/>
* For example:
* <pre>assertThat(myBean, hasProperty("foo"))</pre>
*
* @param propertyName
* the name of the JavaBean property that examined beans should possess
*/
public static <T> org.hamcrest.Matcher<T> hasProperty(java.lang.String propertyName) {
return org.hamcrest.beans.HasProperty.<T>hasProperty(propertyName);
}
Restructuring the Main
Change the Main
so that it extracts the auction servers and joins all of them.
Extending the TableModel
Now the SnipersTableModel
needs to hold a list of SnaperSnapshot
s. And a method to add one on the Swing’s thread.
Add 2 unit tests: 1. notifiesListenersWhenAddingASniper 2. holdsSnipersInAdditionOrder
Now the acceptance test should pass.
Share this post
Twitter
Google+
Facebook
Reddit
LinkedIn
StumbleUpon
Email