Thursday
Jan222009

JMock vs EasyMock Smackdown

Lets see which of the two popular Java test object mocking tools is more straightforward. Cast your vote! (in comments)

with jMock
with EasyMock
you need to import

import org.jmock.Expectations;import static org.easymock.classextension.
EasyMock.createMock;
import static org.easymock.classextension.
EasyMock.expect;
import static org.easymock.classextension.
EasyMock.expectLastCall;
import static org.easymock.classextension.
EasyMock.replay;
import static org.easymock.classextension.
EasyMock.verify;
your test class needs to extend

MockObjectTestCaseTestCase
in setUp() method

mockedThing = mock(SomeInterface.class)mockedThing = createMock(SomeInterface.class)
to set expectations
checking(
new Expectations() {{
// this run does not throw
one(mockedThing).run();

// expect an exception
one(mockedThing).run();
will(throwException(new RuntimeException());

// expect multiple runs
exactly(4).of(mockedThing).getBlah();
}});

// since run() returns void
expect(mockedThing.run());

// or if the method returns non-void
expect(mockedThing.execute(SOMETHING))
.andReturns(SOMETHING_ELSE);

// expect an exception
mockedThing.run();expectLastCall().times(1).

andThrow(new RuntimeException());

// expect multiple runs
mockedThing.run();expectLastCall().times(1);

to put into replay mode

N/A
replay(mockedThing);
// only after this call the mock is usable
to use the mock in tests

RealThing realThing = new RealThing(mockedThing);

// this will call the mocked thing at some point
realThing.doSomething();

RealThing realThing = new RealThing(mockedThing);

// this will call the mocked thing at some point
realThing.doSomething();

to verify mock

N/A
verify(mockedThing);
// if you forget this, you will not know if the
// expectations were fulfilled
thread safe

???
mockedThing is not thread-safe.... use this
to make it so:
makeThreadSafe(mockedThing, true);

Monday
Jan192009

Who supported prop 8


eightmaps.com is a nice mashup of Google maps and prop 8 supporters. Zoom in to Castro and there he is -- a retired man who donated $300 to support prop 8. Seeing no prop 8 supporters in my neighborhood makes me feel warm and fuzzy about choosing the Mission to be my hood.

Sunday
Jan042009

Tourist Trap

Per wikipedia:
A
tourist trap is an establishment, or group of establishments, that has been created with the aim of attracting tourists and their money. Tourist traps will typically provide services, entertainment, souvenirs and other products for tourists to purchase, and these will often be at inflated prices (compared to the local economy).

The first thing we did in Italy was buying 2 train tickets from Fiumicino airport to Termini station. The ticket booth employee charged me 22 euros, took 50 euro bill and returned 18 euros. I asked for the other 10 euro, he looked at me disappointed and gave me my money. It seems like he is making good money this way, as there are many travelers that do not look twice at the change they get.

Another tourist trap we visited was a small restaurant in front of a hotel Alexandra about a block from Barberini square. This small restaurant called Alex cafe had a nice menu, professional looking staff, looking like a good place to eat at. We ordered 5.5 euro tea, 2 salads, some seafood pasta and mushroom risotto. The seafood stunk badly, and risotto was undercooked. We ate the salads, returned the main dishes and asked for a check. We ended up paying 35 Euro (plus tip) for the mediocre salads and a tea and headed out.

We then got an advice from a local who recommended we eat at Trastevere neighbourhood of Rome where locals hang out. We ate there twice, loved the food, ate a lot of it, and always payed 32 euros or less for 2 multi-course meals (salad, mussels, tea, beer, main dishes). The mussels are the best in Rome, they are served in a garlic sauce and they are to die for. The roasted chestnuts sold on the streets are also the best I had. They peel of easily and taste very sweet.

Sunday
Jan042009

Holiday travel from hell


Warning: lots of bitching in this blog post

After taking off 2 hours later than planned, we arrived to JFK too late to catch our connecting flight to London. No problems, (we thought) there were 2 more flights to London that same evening. First, we had to leave the secure area and come out to a check-in to get our new boarding passes, wait in a long line at the check-in, and then talk to a supervisor (who was overwhelmed by crying customers who apparently do not understand the reality of air travel). To our surprise, it turned out American Airlines booked 150 tickets for 120 passenger plane. 30 people had to stay at the airport all night to hope they can get on the plane the next day, the plane that was also overbooked. The 1 800 number they provided was "helpful"... we called and booked us 2 seats that were (according to the customer service person) definitely available. But the crew at the airport kept insisting that the plane is overbooked by 30 people and there are no seats available. Is this a software bug? Why do they give us conflicting information?

As the airline employee recommended, "come at least 5 hours before the take off tomorrow, so you have better chances getting on the plane". Of course, we had to pay for our hotel, since the flight delays were caused by the weather, not the airlines. The next day, we came to the airport 7 hours early, got our boarding passes and did our best not to go crazy waiting for our flight. Once we got on, we buckled up, and waited. Then we waited little more. And then some more. And then we waited for something to be fixed on the plane, then we waited (according to the pilot) for "some paperwork for the repairs that were just performed", and then we waited "just another 1.5 hours or so for our turn to defrost the wings" and then we waited another 1.5 hours to take off. Total, we were sitting on that plane for 5 hours before we even took off. Wearing 2 days old clothes, praying for the torture to end.

When we arrived to Heathrow, our bags were nowhere to be seen. American Airlines employee had no idea where bags can be, as they are not scanned at every city they fly through. We could fly to a moon in the 60s, and we still are unable to track our luggage in 2008! So there we were, in our 3 day old stinky clothes (slippers, sweatpants and sweatshirts) entering the winter London. We stayed 2 nights in London and did not get our bags. The phone number for baggage claim was not picked up and we left few voicemails. We also called a delivery company that delivers bags for American Airlines and the driver told us that the AA is not picking up calls since too many people are calling and complaining (AA employee told this to the delivery guy). So they are just sitting there, and not picking up calls. What a customer service.

Our bags reached us in Slovakia, at the midnight of Dec 24. We checked in on the 19th, and got our bags after 5 days. This is the 5th time I had my bags delayed. Based on my small sample (I fly few times a year), delayed luggage is more common than the statistics claim.

This picture shows how Brad dried his underwear while staying in London and waiting for his bag to arrive.

Wednesday
Dec172008

God Bless Ziplock Bags

After years of traveling back and forth between Europe and US, I learned a neat trick to organize the items in my carry on -- a wheel backpack full of thick double-zipper Ziplock 1 quart bags. How many of them? Ehm.....

  • one for hygienic stuff (yes, a woman has certain sanitary needs)
  • one for music (iPod, earphones, iPod charger, earphone splitter (if traveling in pair), iPod data cable)
  • one for edibles (chewing gums, medicine, TUMS, vitamins, 4 tea bags (never expect random restaurants to carry a good tea)
  • one for small electronics (European power adapter, camera, camera charger, camera USB cable, USB drive, phone, and phone charger)
  • one for tooth brush, little box with ear plugs, hair pins, ear rings
  • one for underwear & shirt for 1 day (experiencing lost luggage teaches you a lesson)
  • one for sunglasses and European wallet (hopefully containing enough Euros to get me to a hotel)
  • and finally our good old "TSA liquids bag"
All of this (plus a passport bag, laptop and few magazines... oh... and few empty plastic bags for stuff like gifts or receipts) fits into a regular wheel backpack which I use as a carry on. As a result, instead of searching through bunch of random junk in my backpack, all I need to answer is "Which bag is it in?".