Friday
Jan232009

Are you scared yet?

Gerald Celente predicts a major economic depression, tax rebellions, food riots, and by 2012 people will worry about food for Christmas rather than gifts. He predicts that local governments will keep raising taxes to get as much money from public as possible.
Soon, people will have food-producing gardens, and the only thing that can save us must be comparable to an invention of the wheel. He predicts revolutionary advances in renewable energy technologies, medical science, and a shift towards holistic healing practices and a crash of the overpriced college education system.

So buy some gold and then dust off your gardening gear and plant some food!

Friday
Jan232009

Guice 1.0 vs 2.0

The Guice 2.0 contains lots of neat improvements. It removes lots of unnecessary boilerplate and allows to write more compact Guice modules. Here is an example of how a confusing binding can be refactored into a simple provider method.

Example using Guice 1.0:
@Override
protected void configure() {
bind(new TypeLiteral<List<string>>(){})
  .annotatedWith(TagsToProcess.class)
  .toProvider(TagsProvider.class);
}

The same example using Guice 2.0:
@Provides @TagsToProcess
public List<string> provideTags(@Named("tags") String tags) {
  return ImmutableList.of(StringUtil.splitAndTrim(tags, ","));
}

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.