Skip to content

Commit a943a1b

Browse files
authored
Merge pull request mybatis#3277 from mawen12/feature-transaction-test
Add TransactionFactory, Transaction test cases
2 parents 266542a + dcca250 commit a943a1b

24 files changed

+884
-28
lines changed

src/test/java/org/apache/ibatis/reflection/wrapper/BeanWrapperUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*
3737
* @see BeanWrapper
3838
*/
39-
class BeanWrapperUnitTest extends ObjectWrapperBaseTest {
39+
class BeanWrapperUnitTest extends ObjectWrapperBase {
4040

4141
private RichType richType;
4242

src/test/java/org/apache/ibatis/reflection/wrapper/CollectionWrapperUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* @see CollectionWrapper
3939
*/
4040
@ExtendWith(MockitoExtension.class)
41-
class CollectionWrapperUnitTest extends ObjectWrapperBaseTest {
41+
class CollectionWrapperUnitTest extends ObjectWrapperBase {
4242

4343
@Mock
4444
private Collection<Object> collection;

src/test/java/org/apache/ibatis/reflection/wrapper/MapWrapperUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
*
4242
* @see MapWrapper
4343
*/
44-
class MapWrapperUnitTest extends ObjectWrapperBaseTest {
44+
class MapWrapperUnitTest extends ObjectWrapperBase {
4545

4646
@Mock
4747
private Map<String, Object> map;

src/test/java/org/apache/ibatis/reflection/wrapper/ObjectWrapperBaseTest.java renamed to src/test/java/org/apache/ibatis/reflection/wrapper/ObjectWrapperBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* @see ObjectWrapper
2525
*/
2626
@ExtendWith(MockitoExtension.class)
27-
abstract class ObjectWrapperBaseTest {
27+
abstract class ObjectWrapperBase {
2828

2929
abstract void shouldGet();
3030

src/test/java/org/apache/ibatis/scripting/xmltags/ChooseSqlNodeTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
*/
1616
package org.apache.ibatis.scripting.xmltags;
1717

18-
import static org.junit.jupiter.api.Assertions.assertTrue;
19-
import static org.mockito.Mockito.verify;
20-
import static org.mockito.Mockito.when;
21-
2218
import java.util.Arrays;
2319
import java.util.HashMap;
2420
import java.util.List;
@@ -27,6 +23,11 @@
2723
import org.junit.jupiter.api.BeforeEach;
2824
import org.junit.jupiter.api.Test;
2925

26+
import static org.junit.jupiter.api.Assertions.assertTrue;
27+
import static org.mockito.Mockito.verify;
28+
import static org.mockito.Mockito.when;
29+
30+
3031
/**
3132
* <pre>{@code
3233
* SELECT *
@@ -46,10 +47,9 @@
4647
* }</pre>
4748
*
4849
* @author <a href="[email protected]">mawen12</a>
49-
*
5050
* @see <a href="https://mybatis.org/mybatis-3/dynamic-sql.html#choose-when-otherwise">choose</a>
5151
*/
52-
class ChooseSqlNodeTest extends SqlNodeTest {
52+
class ChooseSqlNodeTest extends SqlNodeBase {
5353

5454
private static final String FIRST_TEXT = " AND title like #{title}";
5555
private static final String SECOND_TEXT = " AND author_name like #{author.username}";

src/test/java/org/apache/ibatis/scripting/xmltags/ForEachSqlNodeTest.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@
1515
*/
1616
package org.apache.ibatis.scripting.xmltags;
1717

18-
import static org.junit.jupiter.api.Assertions.assertEquals;
19-
import static org.junit.jupiter.api.Assertions.assertTrue;
20-
import static org.mockito.Mockito.*;
21-
2218
import java.util.Arrays;
2319
import java.util.HashMap;
2420
import java.util.List;
@@ -27,6 +23,13 @@
2723
import org.junit.jupiter.api.Test;
2824
import org.mockito.ArgumentCaptor;
2925

26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
import static org.mockito.Mockito.doNothing;
29+
import static org.mockito.Mockito.when;
30+
import static org.mockito.Mockito.verify;
31+
32+
3033
/**
3134
* <pre>{@code
3235
* SELECT *
@@ -39,10 +42,9 @@
3942
* }</pre>
4043
*
4144
* @author <a href="[email protected]">mawen12</a>
42-
*
4345
* @see <a href="https://mybatis.org/mybatis-3/dynamic-sql.html#foreach">foreach</a>
4446
*/
45-
class ForEachSqlNodeTest extends SqlNodeTest {
47+
class ForEachSqlNodeTest extends SqlNodeBase {
4648

4749
private SqlNode sqlNode;
4850

src/test/java/org/apache/ibatis/scripting/xmltags/IfSqlNodeTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
import static org.junit.jupiter.api.Assertions.assertFalse;
1919
import static org.junit.jupiter.api.Assertions.assertTrue;
20-
import static org.mockito.Mockito.*;
20+
import static org.mockito.Mockito.verify;
21+
import static org.mockito.Mockito.when;
22+
import static org.mockito.Mockito.never;
2123

2224
import java.util.HashMap;
2325

@@ -35,7 +37,7 @@
3537
*
3638
* @see <a href="https://mybatis.org/mybatis-3/dynamic-sql.html#if">if</a>
3739
*/
38-
class IfSqlNodeTest extends SqlNodeTest {
40+
class IfSqlNodeTest extends SqlNodeBase {
3941

4042
private static final String CONDITION = "title != null";
4143
private static final String TEXT = "AND title like #{title}";

src/test/java/org/apache/ibatis/scripting/xmltags/MixedSqlNodeTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@
1515
*/
1616
package org.apache.ibatis.scripting.xmltags;
1717

18-
import static org.mockito.Mockito.verify;
19-
2018
import java.util.Arrays;
2119

2220
import org.junit.jupiter.api.BeforeEach;
2321
import org.junit.jupiter.api.Test;
2422

23+
import static org.mockito.Mockito.verify;
24+
25+
2526
/**
2627
* @author <a href="[email protected]">mawen12</a>
2728
*/
28-
class MixedSqlNodeTest extends SqlNodeTest {
29+
class MixedSqlNodeTest extends SqlNodeBase {
2930

3031
private static final String FIRST_TEXT = "abc";
3132
private static final String SECOND_TEXT = "bcd";

src/test/java/org/apache/ibatis/scripting/xmltags/SetSqlNodeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*
4444
* @see <a href="https://mybatis.org/mybatis-3/dynamic-sql.html#trim-where-set">trim-where-set</a>
4545
*/
46-
class SetSqlNodeTest extends SqlNodeTest {
46+
class SetSqlNodeTest extends SqlNodeBase {
4747

4848
private static final String FIRST_TEXT = " username = #{username},";
4949
private static final String SECOND_TEXT = " password = #{password}";

src/test/java/org/apache/ibatis/scripting/xmltags/SqlNodeTest.java renamed to src/test/java/org/apache/ibatis/scripting/xmltags/SqlNodeBase.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222

2323
/**
2424
* @author <a href="[email protected]">mawen12</a>
25+
* @see SqlNode
2526
*/
2627
@ExtendWith(MockitoExtension.class)
27-
abstract class SqlNodeTest {
28+
abstract class SqlNodeBase {
2829

2930
@Mock
3031
protected Configuration configuration;

src/test/java/org/apache/ibatis/scripting/xmltags/StaticTextSqlNodeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
/**
2424
* @author <a href="[email protected]">mawen12</a>
2525
*/
26-
class StaticTextSqlNodeTest extends SqlNodeTest {
26+
class StaticTextSqlNodeTest extends SqlNodeBase {
2727

2828
private static final String TEXT = "select 1 from dual";
2929

src/test/java/org/apache/ibatis/scripting/xmltags/TextSqlNodeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
/**
2828
* @author <a href="[email protected]">mawen12</a>
2929
*/
30-
class TextSqlNodeTest extends SqlNodeTest {
30+
class TextSqlNodeTest extends SqlNodeBase {
3131

3232
private static final String TEXT = "select 1 from dual";
3333
private static final String DYNAMIC_TEXT = "select * from user where id = ${id}";

src/test/java/org/apache/ibatis/scripting/xmltags/TrimSqlNodeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*
4444
* @see <a href="https://mybatis.org/mybatis-3/dynamic-sql.html#trim-where-set">trim-where-set</a>
4545
*/
46-
class TrimSqlNodeTest extends SqlNodeTest {
46+
class TrimSqlNodeTest extends SqlNodeBase {
4747

4848
private static final String FIRST_TEXT = " AND id = #{id}";
4949
private static final String SECOND_TEXT = " AND name = #{name}";

src/test/java/org/apache/ibatis/scripting/xmltags/VarDeclSqlNodeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*
3636
* @see <a href="https://mybatis.org/mybatis-3/dynamic-sql.html#bind">bind</a>
3737
*/
38-
class VarDeclSqlNodeTest extends SqlNodeTest {
38+
class VarDeclSqlNodeTest extends SqlNodeBase {
3939

4040
private SqlNode sqlNode;
4141

src/test/java/org/apache/ibatis/scripting/xmltags/WhereSqlNodeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
*
4444
* @see <a href="https://mybatis.org/mybatis-3/dynamic-sql.html#trim-where-set">trim-where-set</a>
4545
*/
46-
class WhereSqlNodeTest extends SqlNodeTest {
46+
class WhereSqlNodeTest extends SqlNodeBase {
4747

4848
private static final String FIRST_TEXT = " AND id = #{id}";
4949
private static final String SECOND_TEXT = " AND name = #{name}";
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* Copyright 2009-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.transaction;
17+
18+
import org.junit.jupiter.api.extension.ExtendWith;
19+
import org.mockito.junit.jupiter.MockitoExtension;
20+
21+
import java.lang.reflect.Field;
22+
import java.sql.SQLException;
23+
24+
/**
25+
* @author <a href="[email protected]">mawen12</a>
26+
* @see TransactionFactory
27+
*/
28+
@ExtendWith(MockitoExtension.class)
29+
public abstract class TransactionFactoryBase {
30+
31+
public abstract void shouldSetProperties() throws Exception;
32+
33+
public abstract void shouldNewTransactionWithConnection() throws SQLException;
34+
35+
public abstract void shouldNewTransactionWithDataSource() throws Exception;
36+
37+
public static Object getValue(Field field, Object object) throws Exception {
38+
field.setAccessible(true);
39+
return field.get(object);
40+
}
41+
42+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* Copyright 2009-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.ibatis.transaction.jdbc;
17+
18+
import org.junit.jupiter.api.extension.ExtendWith;
19+
import org.mockito.junit.jupiter.MockitoExtension;
20+
21+
import java.sql.SQLException;
22+
23+
/**
24+
* @author <a href="[email protected]">mawen12</a>
25+
* @see JdbcTransaction
26+
*/
27+
@ExtendWith(MockitoExtension.class)
28+
abstract class JdbcTransactionBase {
29+
30+
abstract void shouldGetConnection() throws SQLException;
31+
32+
abstract void shouldCommitWhenConnectionIsNotAutoCommit() throws SQLException;
33+
34+
abstract void shouldAutoCommitWhenConnectionIsAutoCommit() throws SQLException;
35+
36+
abstract void shouldRollbackWhenConnectionIsNotAutoCommit() throws SQLException;
37+
38+
abstract void shouldAutoRollbackWhenConnectionIsAutoCommit() throws SQLException;
39+
40+
abstract void shouldCloseAndSetAutoCommitWhenConnectionIsNotAutoCommit() throws SQLException;
41+
42+
abstract void shouldCloseAndNotSetAutoCommitWhenConnectionIsAutoCommit() throws SQLException;
43+
44+
abstract void shouldReturnNullWhenGetTimeout() throws SQLException;
45+
}

0 commit comments

Comments
 (0)