01: package net.sf.mockcreator;
02:
03: import java.util.Date;
04:
05: import net.sf.mockcreator.expectable.MockExpectables;
06: import net.sf.mockcreator.exceptions.MockException;
07:
08: public class DateToleranceTest extends TestCase {
09: MockExpectables mock;
10:
11: public DateToleranceTest(String name) {
12: super (name);
13: }
14:
15: public void setUp() throws Exception {
16: super .setUp();
17: mock = new MockExpectables();
18: }
19:
20: public void testTolerantExpect() throws Exception {
21: Date d1 = new Date();
22: Date d2 = new Date(d1.getTime() + 1);
23:
24: mock.expectTimestamp(d1);
25: try {
26: mock.timestamp(d2);
27: fail();
28: } catch (MockException ex) {
29:
30: }
31: }
32:
33: public void testTolerantExpectOneMilli() throws Exception {
34: Date d1 = new Date();
35: Date d2 = new Date(d1.getTime() + 1);
36:
37: MockCore.setTimeTolerance(1);
38:
39: mock.expectTimestamp(d1);
40: mock.timestamp(d2);
41: }
42:
43: public void testTolerantAccept() throws Exception {
44: Date d1 = new Date();
45: Date d2 = new Date(d1.getTime() + 1);
46:
47: MockCore.setTimeTolerance(1);
48:
49: mock.acceptTimestamp(d1);
50: mock.timestamp(d2);
51: }
52:
53: public void testTolerantDummy() throws Exception {
54: Date d1 = new Date();
55: Date d2 = new Date(d1.getTime() + 1);
56: Date d3 = new Date(d1.getTime() - 1);
57:
58: MockCore.setTimeTolerance(1);
59:
60: mock.expectZeroOrMoreTimestamp(d1);
61: mock.timestamp(d2);
62: mock.timestamp(d3);
63:
64: try {
65: mock.timestamp(new Date(d1.getTime() + 2));
66: fail();
67: } catch (MockException ex) {
68: }
69: }
70: }
|