Archive for December 2009
Using EasyMock to unit test Tapestry components and pages
Currently I’m working on a client project where we use Tapestry 5.1 as our web framework. We want to test well so we are using Tapestry’s PageTester to write unit tests for pages and components. If you do that, you’ll quickly run into the issue of how to inject services into your pages and components without creating an application module in each and every test class.
A while back Russell Brown posted on the Tapestry mailing list a description of a simple solution to this. In November Russell and I emailed and he was kind enough to share his solution on gist.github.com.
This is an example of how I use it in a unit test for a component:
public class ProductsInCategoryDisplayTest {
@Mock
private CategoryRepository categoryRepository ;
@Test
public void getProductsForCategory() {
ProductsInCategoryDisplay display = new ProductsInCategoryDisplay() ;
Category selectedCategory = new Category(1, "Category", "SEO Text for Category") ;
EasyMockHelper helper = new EasyMockHelper(this, display) ;
EasyMock.expect(categoryRepository.getCategoryProducts(selectedCategory, true, null)).andStubReturn(new ArrayList()) ;
helper.replayMocks() ;
display.setCategory(selectedCategory) ;
Collection products = display.getProducts() ;
assertNotNull(products) ;
}
}
The @Mock annotation marks CategoryRepository as something that should be mocked and injected. new EasyMockHelper(this, display) lets the helper know that it should look for mocks in the test class and that display is the place where to inject them into.
The rest is regular setting of expectations for EasyMock. Finally the helper gets told to replay the mocks and the it all works.
Setting up a tree nursery
Panama has a lot of native fruit trees but you hardly can buy any fresh fruit in the supermarkets. Recently there was even an article in a local newspaper about the topic. It said that in Panama there was no culture of eating fruits or using them for drinks. What sells best is imported apples and grapes. And those are quite expensive. The article lists a huge number of native fruit trees that could be cultivated. Here is that list:
Naranja, Limon, Marañon, Papaya, Maracuyá, Guanábana, Mango, Aguacate, Tamarindo, Nance, Mamey, Níspero, Mamón, Naranja dulce, Toronja, Jobo, Ciruela, Anón, Caimito, Jobito, Mangotín, Guaba
All those names are in Spanish. I’m sure I will write more about each soon but for now to learn more I have to say “Google is your friend”. ;-)
We had the idea before but with some additional stimulus by the newspaper article we put some of it in motion today. Luis and Celis, our gardener, built a little tree nursery in the backyard of our house.
The green cloth is to break the wind which dries out the top soil during the dry season. They cleaned the floor and made it even so that we have a lot of space for a good number of little tree seedlings in bags.
We won’t buy the seeds but instead get them from our neighbors who have fruit trees. Luis and Celis have been collecting and drying some themselves over the last few weeks.
Over the next few days Luis will install water pipes to extend the existing irrigation system.
While I write this post it is blowing heavily outside. That’s typical for the dry season. Let’s see how that little project looks tomorrow. It is placed in an area with some tall trees around it. Those should break the wind a bit and avoid major damage. We’ll see tomorrow whether it works out.
The seedlings will be planted on the farm once the legal issues have been solved. Trees don’t grow over night and even for their first 30 cm it takes a while. So we have time and once the issues have been solved we can do some fun work to start with. In a year or two we will have our own fruit basket. If it’s three years, that’s fine with me too. One has to look forward and think positive.
Homemade offroad trailer
There are many trailers of all kinds. But if you are in the market for a trailer that is suitable for river crossings, you won’t probably find none. After building two small trailers Luis and I started to think about a high offroad trailer. The small trailers are meant to be horse drawn and are intented to extract wood from the forest. We built them ahead of time expecting to need them for a fried who owns a teak plantation but we never got to use them due to difficulties with the terrain (too wet and muddy). There will be some good use for those small trailers on the farm in the near future I hope.
So here is the first picture of our offroad trailer. The thing is made of parts of the scrapyard plus rectangular metal tubes from the local hardware store and two new shocks. The shocks came in yellow which was very convenient. The tires are 31″ and were on the Jeep before.
The trailer’s platform is very high on purpose so that it stays off the water when crossing a river. On the next tire change the old tires from the Jeep, which are now 33″, will be put on the trailer. That way we recycle a bit.
Today we used it for the first time to move those mahagony planks we cut three months ago at a nearby farm. They have been cut using a chainsaw mill and are 1″, 2″ and 3″ thick. The wood has been drying outside the whole time. Interestingly the sapwood is full of termite holes but the heartwood has none. We are planning to build a little coffee table out of some of that beautiful mahagony wood.
This is the hitch with the trailer attached to it. All that is homemade as well. The whole trailer and accessories was all built from scratch and driven by imagination.







