Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
05c270d9
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
05c270d9
编写于
8月 23, 2019
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ensure TransactionalSqlScriptsSpringRuleTests is purely JUnit 4
上级
742cb90d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
22 deletion
+29
-22
spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalSqlScriptsTests.java
...ework/test/context/jdbc/TransactionalSqlScriptsTests.java
+4
-7
spring-test/src/test/java/org/springframework/test/context/junit4/rules/TransactionalSqlScriptsSpringRuleTests.java
.../junit4/rules/TransactionalSqlScriptsSpringRuleTests.java
+25
-15
未找到文件。
spring-test/src/test/java/org/springframework/test/context/jdbc/TransactionalSqlScriptsTests.java
浏览文件 @
05c270d9
...
...
@@ -17,7 +17,6 @@
package
org.springframework.test.context.jdbc
;
import
org.junit.jupiter.api.MethodOrderer
;
import
org.junit.jupiter.api.Order
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.TestMethodOrder
;
...
...
@@ -31,21 +30,19 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
* @since 4.1
*/
@SpringJUnitConfig
(
EmptyDatabaseConfig
.
class
)
@TestMethodOrder
(
MethodOrderer
.
OrderAnnotation
.
class
)
@TestMethodOrder
(
MethodOrderer
.
Alphanumeric
.
class
)
@Sql
({
"schema.sql"
,
"data.sql"
})
@DirtiesContext
public
class
TransactionalSqlScriptsTests
extends
AbstractTransactionalTests
{
class
TransactionalSqlScriptsTests
extends
AbstractTransactionalTests
{
@Test
@Order
(
1
)
public
void
classLevelScripts
()
{
void
classLevelScripts
()
{
assertNumUsers
(
1
);
}
@Test
@Sql
({
"recreate-schema.sql"
,
"data.sql"
,
"data-add-dogbert.sql"
})
@Order
(
2
)
public
void
methodLevelScripts
()
{
void
methodLevelScripts
()
{
assertNumUsers
(
2
);
}
...
...
spring-test/src/test/java/org/springframework/test/context/junit4/rules/TransactionalSqlScriptsSpringRuleTests.java
浏览文件 @
05c270d9
...
...
@@ -27,23 +27,30 @@ import org.junit.runner.RunWith;
import
org.junit.runners.JUnit4
;
import
org.junit.runners.MethodSorters
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.test.annotation.DirtiesContext
;
import
org.springframework.test.context.ContextConfiguration
;
import
org.springframework.test.context.jdbc.EmptyDatabaseConfig
;
import
org.springframework.test.context.jdbc.Sql
;
import
org.springframework.test.context.jdbc.TransactionalSqlScriptsTests
;
import
org.springframework.test.jdbc.JdbcTestUtils
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* This class is a
n extension of {@link TransactionalSqlScriptsTests}
*
that has been modified to use {@link SpringClassRule} and
* {@link SpringMethodRule}.
* This class is a
JUnit 4 based copy of
*
{@link org.springframework.test.context.jdbc.TransactionalSqlScriptsTests}
*
that has been modified to use {@link SpringClassRule} and
{@link SpringMethodRule}.
*
* @author Sam Brannen
* @since 4.2
*/
@RunWith
(
JUnit4
.
class
)
// Note: @FixMethodOrder is NOT @Inherited.
@ContextConfiguration
(
classes
=
EmptyDatabaseConfig
.
class
)
@FixMethodOrder
(
MethodSorters
.
NAME_ASCENDING
)
// Overriding @Sql declaration to reference scripts using relative path.
@Sql
({
"../../jdbc/schema.sql"
,
"../../jdbc/data.sql"
})
public
class
TransactionalSqlScriptsSpringRuleTests
extends
TransactionalSqlScriptsTests
{
@DirtiesContext
public
class
TransactionalSqlScriptsSpringRuleTests
{
@ClassRule
public
static
final
SpringClassRule
springClassRule
=
new
SpringClassRule
();
...
...
@@ -54,24 +61,27 @@ public class TransactionalSqlScriptsSpringRuleTests extends TransactionalSqlScri
@Rule
public
Timeout
timeout
=
Timeout
.
builder
().
withTimeout
(
10
,
TimeUnit
.
SECONDS
).
build
();
@Autowired
JdbcTemplate
jdbcTemplate
;
/**
* Redeclared to ensure that {@code @FixMethodOrder} is properly applied.
*/
@Test
@Override
public
void
classLevelScripts
()
{
assertNumUsers
(
1
);
}
/**
* Overriding {@code @Sql} declaration to reference scripts using relative path.
*/
@Test
@Sql
({
"../../jdbc/drop-schema.sql"
,
"../../jdbc/schema.sql"
,
"../../jdbc/data.sql"
,
"../../jdbc/data-add-dogbert.sql"
})
@Override
public
void
methodLevelScripts
()
{
assertNumUsers
(
2
);
}
private
void
assertNumUsers
(
int
expected
)
{
assertThat
(
countRowsInTable
(
"user"
)).
as
(
"Number of rows in the 'user' table."
).
isEqualTo
(
expected
);
}
private
int
countRowsInTable
(
String
tableName
)
{
return
JdbcTestUtils
.
countRowsInTable
(
this
.
jdbcTemplate
,
tableName
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录