July 2014
Intermediate to advanced
314 pages
6h 25m
English
A stub delivers indirect inputs to the caller when the stub's methods are called. Stubs are programmed only for the test scope. Stubs may record other information such as the number of times the methods were invoked and so on.
Account transactions should be rolled back if the ATM's money dispenser fails to dispense money. How can we test this when we don't have the ATM machine, or how can we simulate a scenario where the dispenser fails? We can do this using the following code:
public interface Dispenser { void dispense(BigDecimal amount) throws DispenserFailed; } public class AlwaysFailingDispenserStub implements Dispenser{ public void dispense(BigDecimal amount) throws DispenserFailed{ throw new DispenserFailed (ErrorType.HARDWARE,"not responding"); ...Read now
Unlock full access