1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.ibatis.transaction.managed;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19 import static org.junit.jupiter.api.Assertions.assertNull;
20 import static org.mockito.Mockito.never;
21 import static org.mockito.Mockito.verify;
22
23 import java.sql.Connection;
24 import java.sql.SQLException;
25
26 import org.apache.ibatis.transaction.Transaction;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29 import org.mockito.Mock;
30
31
32
33
34
35
36 class ManagedTransactionWithConnectionTest extends ManagedTransactionBase {
37
38 @Mock
39 private Connection connection;
40
41 private Transaction transaction;
42
43 @BeforeEach
44 void setup() {
45 this.transaction = new ManagedTransaction(connection, true);
46 }
47
48 @Override
49 @Test
50 void shouldGetConnection() throws SQLException {
51 Connection result = transaction.getConnection();
52
53 assertEquals(connection, result);
54 }
55
56 @Test
57 @Override
58 void shouldNotCommitWhetherConnectionIsAutoCommit() throws SQLException {
59 transaction.commit();
60
61 verify(connection, never()).commit();
62 verify(connection, never()).getAutoCommit();
63 }
64
65 @Test
66 @Override
67 void shouldNotRollbackWhetherConnectionIsAutoCommit() throws SQLException {
68 transaction.commit();
69
70 verify(connection, never()).rollback();
71 verify(connection, never()).getAutoCommit();
72 }
73
74 @Test
75 @Override
76 void shouldCloseWhenSetCloseConnectionIsTrue() throws SQLException {
77 transaction.close();
78
79 verify(connection).close();
80 }
81
82 @Test
83 @Override
84 void shouldNotCloseWhenSetCloseConnectionIsFalse() throws SQLException {
85 this.transaction = new ManagedTransaction(connection, false);
86
87 transaction.close();
88
89 verify(connection, never()).close();
90 }
91
92 @Test
93 @Override
94 void shouldReturnNullWhenGetTimeout() throws SQLException {
95 assertNull(transaction.getTimeout());
96 }
97
98 }