O'Reilly logo

Test-Driven Development with Mockito by Sujoy Acharya

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Refactoring legacy code

Such changes of legacy code without the safety net of a unit test coverage should be done with special care as we are not yet able to know if we broke something. Fortunately, there are usually coarse-grained tests somewhere—even if it's a manual one, stepping through a sequence of web pages for example.

There is the class PaymentHandler, which calculates the patient's due amount. To add a test for this class, we need to break the constructor chaining:

public class PaymentHandler extends BaseObject{ public PaymentHandler(Long objectId) { super(objectId); } public Map<Patient, Double> calculateDue(){ HashMap<Patient, List<Encounter>> hashMap = new HashMap<Patient, List<Encounter>>(); for(Encounter enc:DataAccessFacade.findAllUnprocessedEncounters()){ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required