andrew's blog

Mockito in real world: ArgumentMatcher and ArgumentCapture

 Mockito really helps when you want to make white box testing. In addition to testing the results of some code, you can make sure that the code makes necessary method calls during its execution. 

For example, the following method prints the current time:

public MyClass {
  public void printTime(PrintStream ps) {
    ps.print("Current time is: ");
    Date now=new Date();
    SimpleDateFormat sdf=new SimpleDateFormat("hh:mm");
    ps.print(sdf.format(now));
  }
}

Let's try to test this code. We want to make sure the code calls PrintStream 2 times, ignore the first call and check that the second one is in correct format: two digits, colon(:) and another two digits.

I started with writing a custom ArgumentMatcher just to check there is a semicolon in a string:

summary of JavaEdge 2008

 Today I attended Java Edge, and want to share my impression while it's fresh in my memory.

  • Java for the cloud by Baruch Sadogursky

In 19 century every manufacturer was running their private electricity generator. Eventually people started to consume electricity provided by a few big companies. In the same way now the tendency will be to stop running our own servers and to use the computing power and the storage provided as a service. Today leading services are Google AppEngine, Amazon S3 and EC2, goGrid, AppNexus, FlexiScale. Soon there will be Microsoft Azure, and there are rumors about Yahoo Cloud.

Very important for today's crisis state of mind: fail cheap. That means that we don't spend a lot up front to buy servers, to pay for installations, etc.

Overall this area is very important and we must have our experts in it.

Syndicate content