01: package com.mockrunner.test.connector;
02:
03: import com.mockrunner.mock.connector.cci.MockLocalTransaction;
04:
05: import junit.framework.TestCase;
06:
07: public class MockLocalTransactionTest extends TestCase {
08: private MockLocalTransaction transaction;
09:
10: protected void setUp() throws Exception {
11: transaction = new MockLocalTransaction();
12: }
13:
14: protected void tearDown() throws Exception {
15: transaction = null;
16: }
17:
18: public void testWasCalledMethods() throws Exception {
19: assertFalse(transaction.wasBeginCalled());
20: assertFalse(transaction.wasCommitCalled());
21: assertFalse(transaction.wasRollbackCalled());
22: transaction.begin();
23: assertTrue(transaction.wasBeginCalled());
24: assertFalse(transaction.wasCommitCalled());
25: assertFalse(transaction.wasRollbackCalled());
26: transaction.commit();
27: assertTrue(transaction.wasBeginCalled());
28: assertTrue(transaction.wasCommitCalled());
29: assertFalse(transaction.wasRollbackCalled());
30: transaction.begin();
31: assertTrue(transaction.wasBeginCalled());
32: assertFalse(transaction.wasCommitCalled());
33: assertFalse(transaction.wasRollbackCalled());
34: transaction.rollback();
35: assertTrue(transaction.wasBeginCalled());
36: assertFalse(transaction.wasCommitCalled());
37: assertTrue(transaction.wasRollbackCalled());
38: transaction.reset();
39: assertFalse(transaction.wasBeginCalled());
40: assertFalse(transaction.wasCommitCalled());
41: assertFalse(transaction.wasRollbackCalled());
42: }
43:
44: public void testgetNumberMethods() throws Exception {
45: assertEquals(0, transaction.getNumberBeginCalls());
46: assertEquals(0, transaction.getNumberCommitCalls());
47: assertEquals(0, transaction.getNumberRollbackCalls());
48: transaction.begin();
49: assertEquals(1, transaction.getNumberBeginCalls());
50: assertEquals(0, transaction.getNumberCommitCalls());
51: assertEquals(0, transaction.getNumberRollbackCalls());
52: transaction.begin();
53: assertEquals(2, transaction.getNumberBeginCalls());
54: assertEquals(0, transaction.getNumberCommitCalls());
55: assertEquals(0, transaction.getNumberRollbackCalls());
56: transaction.rollback();
57: assertEquals(2, transaction.getNumberBeginCalls());
58: assertEquals(0, transaction.getNumberCommitCalls());
59: assertEquals(1, transaction.getNumberRollbackCalls());
60: transaction.commit();
61: transaction.commit();
62: assertEquals(2, transaction.getNumberBeginCalls());
63: assertEquals(2, transaction.getNumberCommitCalls());
64: assertEquals(1, transaction.getNumberRollbackCalls());
65: transaction.commit();
66: assertEquals(2, transaction.getNumberBeginCalls());
67: assertEquals(3, transaction.getNumberCommitCalls());
68: assertEquals(1, transaction.getNumberRollbackCalls());
69: transaction.begin();
70: assertEquals(3, transaction.getNumberBeginCalls());
71: assertEquals(3, transaction.getNumberCommitCalls());
72: assertEquals(1, transaction.getNumberRollbackCalls());
73: transaction.reset();
74: assertEquals(0, transaction.getNumberBeginCalls());
75: assertEquals(0, transaction.getNumberCommitCalls());
76: assertEquals(0, transaction.getNumberRollbackCalls());
77: }
78: }
|