Mike's Site: Mocking with JodaTime's DateTime and Google Guava's Supplier
January 17, 2012 Introduction If you're a seasoned unit tester, you've learned to take note when you see any code working with time, concurrency, random, persistence and disc I/O. The reason for this is that tests can be very brittle and sometimes down-right impossible to test properly. This post will show how to abstract out "time" by injecting a replacement for it in the consumer. This post will be using Spring 3 as the Dependency Injection container, though Guice , other DI containers or constructor/setters on POJOs would work as well. I will also ignore Locales since the focus is on the injection of the DateTime, not DateTime itself. Existing code You've been handed a piece of code to unit test (or you are creating one and this is your first stab at it). Our first piece of code, only one class: (This class is a Spring 3.Read full article from Mike's Site: Mocking with JodaTime's DateTime and Google Guava's Supplier
No comments:
Post a Comment