| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
package biz.xsoftware.examples.basic; |
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
public class SysUnderTest { |
| 14 | |
|
| 15 | |
private CreditAuthorizationSvc creditSvc; |
| 16 | |
private GiftCardAccountSvc giftSvc; |
| 17 | |
|
| 18 | |
|
| 19 | |
|
| 20 | |
|
| 21 | 5 | public SysUnderTest(CreditAuthorizationSvc c, GiftCardAccountSvc g) { |
| 22 | 5 | creditSvc = c; |
| 23 | 5 | giftSvc = g; |
| 24 | 5 | } |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
public void buyGiftCard(String user, double usDollars) { |
| 30 | 5 | creditSvc.takeMoney(user, usDollars); |
| 31 | |
|
| 32 | |
try { |
| 33 | 3 | giftSvc.putMoneyOnCard(456, usDollars); |
| 34 | 2 | } catch(Throwable e) { |
| 35 | 2 | creditSvc.returnMoney(user, usDollars); |
| 36 | 2 | throw new PurchaseException(e); |
| 37 | 1 | } |
| 38 | 1 | return; |
| 39 | |
} |
| 40 | |
} |