01: package com.mockrunner.example.struts;
02:
03: import java.util.HashMap;
04: import java.util.Map;
05:
06: /**
07: * Mock implementation of {@link OrderManager}.
08: * Used in the test {@link OrderActionTest}.
09: */
10: public class MockOrderManager extends OrderManager {
11: private Map products = new HashMap();
12:
13: public MockOrderManager() {
14:
15: }
16:
17: public void setStock(String id, int amount) {
18: products.put(id, new Integer(amount));
19: }
20:
21: public int getStock(String id) {
22: Integer amount = (Integer) products.get(id);
23: if (null == amount)
24: return 0;
25: return amount.intValue();
26: }
27:
28: public void order(String id, int amount) {
29: int available = getStock(id);
30: if (available < amount)
31: throw new RuntimeException("not enough in stock");
32: Integer newStock = new Integer(available - amount);
33: products.put(id, newStock);
34: }
35:
36: }
|