Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
75a71acc
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 搜索 >>
提交
75a71acc
编写于
7月 04, 2017
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Upgrade to JUnit Jupiter 5.0 M5
Issue: SPR-15728
上级
9c935215
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
101 addition
and
100 deletion
+101
-100
build.gradle
build.gradle
+3
-3
spring-test/src/main/java/org/springframework/test/context/junit/jupiter/AbstractExpressionEvaluatingCondition.java
.../junit/jupiter/AbstractExpressionEvaluatingCondition.java
+6
-6
spring-test/src/main/java/org/springframework/test/context/junit/jupiter/DisabledIfCondition.java
...ework/test/context/junit/jupiter/DisabledIfCondition.java
+10
-28
spring-test/src/main/java/org/springframework/test/context/junit/jupiter/EnabledIfCondition.java
...mework/test/context/junit/jupiter/EnabledIfCondition.java
+10
-27
spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java
...framework/test/context/junit/jupiter/SpringExtension.java
+60
-25
spring-test/src/test/java/org/springframework/test/context/junit/jupiter/DisabledIfConditionTestCase.java
...st/context/junit/jupiter/DisabledIfConditionTestCase.java
+12
-11
未找到文件。
build.gradle
浏览文件 @
75a71acc
...
...
@@ -73,9 +73,9 @@ configure(allprojects) { project ->
ext
.
jspVersion
=
"2.3.2-b02"
ext
.
jtaVersion
=
"1.2"
ext
.
junitVersion
=
"4.12"
ext
.
junitVintageVersion
=
"4.12.0-M
4
"
ext
.
junitJupiterVersion
=
'5.0.0-M
4
'
ext
.
junitPlatformVersion
=
'1.0.0-M
4
'
ext
.
junitVintageVersion
=
"4.12.0-M
5
"
ext
.
junitJupiterVersion
=
'5.0.0-M
5
'
ext
.
junitPlatformVersion
=
'1.0.0-M
5
'
ext
.
log4jVersion
=
'2.8.2'
ext
.
nettyVersion
=
"4.1.12.Final"
ext
.
niomultipartVersion
=
"1.1.0"
...
...
spring-test/src/main/java/org/springframework/test/context/junit/jupiter/AbstractExpressionEvaluatingCondition.java
浏览文件 @
75a71acc
...
...
@@ -23,10 +23,10 @@ import java.util.function.Function;
import
org.apache.commons.logging.Log
;
import
org.apache.commons.logging.LogFactory
;
import
org.junit.jupiter.api.extension.ConditionEvaluationResult
;
import
org.junit.jupiter.api.extension.
Container
ExecutionCondition
;
import
org.junit.jupiter.api.extension.ExecutionCondition
;
import
org.junit.jupiter.api.extension.ExtensionContext
;
import
org.junit.jupiter.api.extension.TestExecutionCondition
;
import
org.springframework.beans.factory.config.BeanExpressionContext
;
import
org.springframework.beans.factory.config.BeanExpressionResolver
;
...
...
@@ -39,9 +39,9 @@ import org.springframework.util.Assert;
import
org.springframework.util.StringUtils
;
/**
* Abstract base class for implementations of {@link
ContainerExecutionCondition}
*
and {@link TestExecutionCondition} that evaluate expressions configured via
*
annotations to determine if a container
or test is enabled.
* Abstract base class for implementations of {@link
ExecutionCondition} that
*
evaluate expressions configured via annotations to determine if a container
* or test is enabled.
*
* <p>Expressions can be any of the following.
*
...
...
@@ -61,7 +61,7 @@ import org.springframework.util.StringUtils;
* @see EnabledIf
* @see DisabledIf
*/
abstract
class
AbstractExpressionEvaluatingCondition
implements
ContainerExecutionCondition
,
Test
ExecutionCondition
{
abstract
class
AbstractExpressionEvaluatingCondition
implements
ExecutionCondition
{
private
static
final
Log
logger
=
LogFactory
.
getLog
(
AbstractExpressionEvaluatingCondition
.
class
);
...
...
spring-test/src/main/java/org/springframework/test/context/junit/jupiter/DisabledIfCondition.java
浏览文件 @
75a71acc
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -17,24 +17,18 @@
package
org.springframework.test.context.junit.jupiter
;
import
org.junit.jupiter.api.extension.ConditionEvaluationResult
;
import
org.junit.jupiter.api.extension.ContainerExecutionCondition
;
import
org.junit.jupiter.api.extension.ContainerExtensionContext
;
import
org.junit.jupiter.api.extension.ExtensionContext
;
import
org.junit.jupiter.api.extension.TestExecutionCondition
;
import
org.junit.jupiter.api.extension.TestExtensionContext
;
/**
* {@code DisabledIfCondition} is a composite {@link ContainerExecutionCondition}
* and {@link TestExecutionCondition} that supports the {@link DisabledIf @DisabledIf}
* annotation when using the <em>Spring TestContext Framework</em> in conjunction
* with JUnit 5's <em>Jupiter</em> programming model.
* {@code DisabledIfCondition} is an {@link ExecutionCondition} that supports the
* {@link DisabledIf @DisabledIf} annotation when using the <em>Spring TestContext
* Framework</em> in conjunction with JUnit 5's <em>Jupiter</em> programming model.
*
* <p>Any attempt to use the {@code DisabledIfCondition} without the presence of
* {@link DisabledIf @DisabledIf} will result in an <em>enabled</em>
* {@link ConditionEvaluationResult}.
*
* @author Sam Brannen
* @author Tadaya Tsuyukubo
* @since 5.0
* @see DisabledIf
* @see EnabledIf
...
...
@@ -43,26 +37,14 @@ import org.junit.jupiter.api.extension.TestExtensionContext;
public
class
DisabledIfCondition
extends
AbstractExpressionEvaluatingCondition
{
/**
* Containers are disabled if {@code @DisabledIf} is present on the test class
* and the configured expression evaluates to {@code true}.
* Containers and tests are disabled if {@code @DisabledIf} is present on the
* corresponding test class or test method and the configured expression evaluates
* to {@code true}.
*/
@Override
public
ConditionEvaluationResult
evaluate
(
ContainerExtensionContext
context
)
{
return
evaluateDisabledIf
(
context
);
}
/**
* Tests are disabled if {@code @DisabledIf} is present on the test method
* and the configured expression evaluates to {@code true}.
*/
@Override
public
ConditionEvaluationResult
evaluate
(
TestExtensionContext
context
)
{
return
evaluateDisabledIf
(
context
);
}
private
ConditionEvaluationResult
evaluateDisabledIf
(
ExtensionContext
context
)
{
return
evaluateAnnotation
(
DisabledIf
.
class
,
DisabledIf:
:
expression
,
DisabledIf:
:
reason
,
DisabledIf:
:
loadContext
,
false
,
context
);
public
ConditionEvaluationResult
evaluateExecutionCondition
(
ExtensionContext
context
)
{
return
evaluateAnnotation
(
DisabledIf
.
class
,
DisabledIf:
:
expression
,
DisabledIf:
:
reason
,
DisabledIf:
:
loadContext
,
false
,
context
);
}
}
spring-test/src/main/java/org/springframework/test/context/junit/jupiter/EnabledIfCondition.java
浏览文件 @
75a71acc
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -17,17 +17,12 @@
package
org.springframework.test.context.junit.jupiter
;
import
org.junit.jupiter.api.extension.ConditionEvaluationResult
;
import
org.junit.jupiter.api.extension.ContainerExecutionCondition
;
import
org.junit.jupiter.api.extension.ContainerExtensionContext
;
import
org.junit.jupiter.api.extension.ExtensionContext
;
import
org.junit.jupiter.api.extension.TestExecutionCondition
;
import
org.junit.jupiter.api.extension.TestExtensionContext
;
/**
* {@code EnabledIfCondition} is a composite {@link ContainerExecutionCondition}
* and {@link TestExecutionCondition} that supports the {@link EnabledIf @EnabledIf}
* annotation when using the <em>Spring TestContext Framework</em> in conjunction
* with JUnit 5's <em>Jupiter</em> programming model.
* {@code EnabledIfCondition} is an {@link ExecutionCondition} that supports the
* {@link EnabledIf @EnabledIf} annotation when using the <em>Spring TestContext
* Framework</em> in conjunction with JUnit 5's <em>Jupiter</em> programming model.
*
* <p>Any attempt to use the {@code EnabledIfCondition} without the presence of
* {@link EnabledIf @EnabledIf} will result in an <em>enabled</em>
...
...
@@ -42,26 +37,14 @@ import org.junit.jupiter.api.extension.TestExtensionContext;
public
class
EnabledIfCondition
extends
AbstractExpressionEvaluatingCondition
{
/**
* Containers are enabled if {@code @EnabledIf} is present on the test class
* and the configured expression evaluates to {@code true}.
* Containers and tests are enabled if {@code @EnabledIf} is present on the
* corresponding test class or test method and the configured expression
* evaluates to {@code true}.
*/
@Override
public
ConditionEvaluationResult
evaluate
(
ContainerExtensionContext
context
)
{
return
evaluateEnabledIf
(
context
);
}
/**
* Tests are enabled if {@code @EnabledIf} is present on the test method
* and the configured expression evaluates to {@code true}.
*/
@Override
public
ConditionEvaluationResult
evaluate
(
TestExtensionContext
context
)
{
return
evaluateEnabledIf
(
context
);
}
private
ConditionEvaluationResult
evaluateEnabledIf
(
ExtensionContext
context
)
{
return
evaluateAnnotation
(
EnabledIf
.
class
,
EnabledIf:
:
expression
,
EnabledIf:
:
reason
,
EnabledIf:
:
loadContext
,
true
,
context
);
public
ConditionEvaluationResult
evaluateExecutionCondition
(
ExtensionContext
context
)
{
return
evaluateAnnotation
(
EnabledIf
.
class
,
EnabledIf:
:
expression
,
EnabledIf:
:
reason
,
EnabledIf:
:
loadContext
,
true
,
context
);
}
}
spring-test/src/main/java/org/springframework/test/context/junit/jupiter/SpringExtension.java
浏览文件 @
75a71acc
...
...
@@ -27,13 +27,11 @@ import org.junit.jupiter.api.extension.AfterTestExecutionCallback;
import
org.junit.jupiter.api.extension.BeforeAllCallback
;
import
org.junit.jupiter.api.extension.BeforeEachCallback
;
import
org.junit.jupiter.api.extension.BeforeTestExecutionCallback
;
import
org.junit.jupiter.api.extension.ContainerExtensionContext
;
import
org.junit.jupiter.api.extension.ExtensionContext
;
import
org.junit.jupiter.api.extension.ExtensionContext.Namespace
;
import
org.junit.jupiter.api.extension.ExtensionContext.Store
;
import
org.junit.jupiter.api.extension.ParameterContext
;
import
org.junit.jupiter.api.extension.ParameterResolver
;
import
org.junit.jupiter.api.extension.TestExtensionContext
;
import
org.junit.jupiter.api.extension.TestInstancePostProcessor
;
import
org.springframework.beans.factory.annotation.Autowired
;
...
...
@@ -52,6 +50,7 @@ import org.springframework.util.Assert;
*
* @author Sam Brannen
* @since 5.0
* @see org.springframework.test.context.junit.jupiter.EnabledIf
* @see org.springframework.test.context.junit.jupiter.DisabledIf
* @see org.springframework.test.context.junit.jupiter.SpringJUnitConfig
* @see org.springframework.test.context.junit.jupiter.web.SpringJUnitWebConfig
...
...
@@ -72,7 +71,7 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
* Delegates to {@link TestContextManager#beforeTestClass}.
*/
@Override
public
void
beforeAll
(
Container
ExtensionContext
context
)
throws
Exception
{
public
void
beforeAll
(
ExtensionContext
context
)
throws
Exception
{
getTestContextManager
(
context
).
beforeTestClass
();
}
...
...
@@ -80,12 +79,12 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
* Delegates to {@link TestContextManager#afterTestClass}.
*/
@Override
public
void
afterAll
(
Container
ExtensionContext
context
)
throws
Exception
{
public
void
afterAll
(
ExtensionContext
context
)
throws
Exception
{
try
{
getTestContextManager
(
context
).
afterTestClass
();
}
finally
{
context
.
getStore
(
NAMESPACE
).
remove
(
context
.
getTestClass
().
get
(
));
context
.
getStore
(
NAMESPACE
).
remove
(
getRequiredTestClass
(
context
));
}
}
...
...
@@ -101,9 +100,9 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
* Delegates to {@link TestContextManager#beforeTestMethod}.
*/
@Override
public
void
beforeEach
(
Test
ExtensionContext
context
)
throws
Exception
{
Object
testInstance
=
context
.
getTestInstance
(
);
Method
testMethod
=
context
.
getTestMethod
().
get
(
);
public
void
beforeEach
(
ExtensionContext
context
)
throws
Exception
{
Object
testInstance
=
getRequiredTestInstance
(
context
);
Method
testMethod
=
getRequiredTestMethod
(
context
);
getTestContextManager
(
context
).
beforeTestMethod
(
testInstance
,
testMethod
);
}
...
...
@@ -111,9 +110,9 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
* Delegates to {@link TestContextManager#beforeTestExecution}.
*/
@Override
public
void
beforeTestExecution
(
Test
ExtensionContext
context
)
throws
Exception
{
Object
testInstance
=
context
.
getTestInstance
(
);
Method
testMethod
=
context
.
getTestMethod
().
get
(
);
public
void
beforeTestExecution
(
ExtensionContext
context
)
throws
Exception
{
Object
testInstance
=
getRequiredTestInstance
(
context
);
Method
testMethod
=
getRequiredTestMethod
(
context
);
getTestContextManager
(
context
).
beforeTestExecution
(
testInstance
,
testMethod
);
}
...
...
@@ -121,10 +120,10 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
* Delegates to {@link TestContextManager#afterTestExecution}.
*/
@Override
public
void
afterTestExecution
(
Test
ExtensionContext
context
)
throws
Exception
{
Object
testInstance
=
context
.
getTestInstance
(
);
Method
testMethod
=
context
.
getTestMethod
().
get
(
);
Throwable
testException
=
context
.
get
Test
Exception
().
orElse
(
null
);
public
void
afterTestExecution
(
ExtensionContext
context
)
throws
Exception
{
Object
testInstance
=
getRequiredTestInstance
(
context
);
Method
testMethod
=
getRequiredTestMethod
(
context
);
Throwable
testException
=
context
.
get
Execution
Exception
().
orElse
(
null
);
getTestContextManager
(
context
).
afterTestExecution
(
testInstance
,
testMethod
,
testException
);
}
...
...
@@ -132,10 +131,10 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
* Delegates to {@link TestContextManager#afterTestMethod}.
*/
@Override
public
void
afterEach
(
Test
ExtensionContext
context
)
throws
Exception
{
Object
testInstance
=
context
.
getTestInstance
(
);
Method
testMethod
=
context
.
getTestMethod
().
get
(
);
Throwable
testException
=
context
.
get
Test
Exception
().
orElse
(
null
);
public
void
afterEach
(
ExtensionContext
context
)
throws
Exception
{
Object
testInstance
=
getRequiredTestInstance
(
context
);
Method
testMethod
=
getRequiredTestMethod
(
context
);
Throwable
testException
=
context
.
get
Execution
Exception
().
orElse
(
null
);
getTestContextManager
(
context
).
afterTestMethod
(
testInstance
,
testMethod
,
testException
);
}
...
...
@@ -149,11 +148,11 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
* that is annotated with {@code @Autowired}, Spring will assume the responsibility
* for resolving all parameters in the constructor. Consequently, no other registered
* {@link ParameterResolver} will be able to resolve parameters.
* @see #resolve
* @see #resolve
Parameter
* @see ParameterAutowireUtils#isAutowirable
*/
@Override
public
boolean
supports
(
ParameterContext
parameterContext
,
ExtensionContext
extensionContext
)
{
public
boolean
supports
Parameter
(
ParameterContext
parameterContext
,
ExtensionContext
extensionContext
)
{
Parameter
parameter
=
parameterContext
.
getParameter
();
Executable
executable
=
parameter
.
getDeclaringExecutable
();
return
(
executable
instanceof
Constructor
&&
...
...
@@ -165,14 +164,14 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
* Resolve a value for the {@link Parameter} in the supplied {@link ParameterContext} by
* retrieving the corresponding dependency from the test's {@link ApplicationContext}.
* <p>Delegates to {@link ParameterAutowireUtils#resolveDependency}.
* @see #supports
* @see #supports
Parameter
* @see ParameterAutowireUtils#resolveDependency
*/
@Override
@Nullable
public
Object
resolve
(
ParameterContext
parameterContext
,
ExtensionContext
extensionContext
)
{
public
Object
resolve
Parameter
(
ParameterContext
parameterContext
,
ExtensionContext
extensionContext
)
{
Parameter
parameter
=
parameterContext
.
getParameter
();
Class
<?>
testClass
=
extensionContext
.
getTestClass
().
get
(
);
Class
<?>
testClass
=
getRequiredTestClass
(
extensionContext
);
ApplicationContext
applicationContext
=
getApplicationContext
(
extensionContext
);
return
ParameterAutowireUtils
.
resolveDependency
(
parameter
,
testClass
,
applicationContext
);
}
...
...
@@ -195,9 +194,45 @@ public class SpringExtension implements BeforeAllCallback, AfterAllCallback, Tes
*/
private
static
TestContextManager
getTestContextManager
(
ExtensionContext
context
)
{
Assert
.
notNull
(
context
,
"ExtensionContext must not be null"
);
Class
<?>
testClass
=
context
.
getTestClass
().
get
(
);
Class
<?>
testClass
=
getRequiredTestClass
(
context
);
Store
store
=
context
.
getStore
(
NAMESPACE
);
return
store
.
getOrComputeIfAbsent
(
testClass
,
TestContextManager:
:
new
,
TestContextManager
.
class
);
}
/**
* Get the test class associated with the supplied {@code ExtensionContext}.
* @return the test class
* @throws IllegalStateException if the extension context does not contain
* a test class
*/
private
static
Class
<?>
getRequiredTestClass
(
ExtensionContext
context
)
throws
IllegalStateException
{
Assert
.
notNull
(
context
,
"ExtensionContext must not be null"
);
return
context
.
getTestClass
().
orElseThrow
(
()
->
new
IllegalStateException
(
"JUnit failed to supply the test class in the ExtensionContext"
));
}
/**
* Get the test instance associated with the supplied {@code ExtensionContext}.
* @return the test instance
* @throws IllegalStateException if the extension context does not contain
* a test instance
*/
private
static
Object
getRequiredTestInstance
(
ExtensionContext
context
)
throws
IllegalStateException
{
Assert
.
notNull
(
context
,
"ExtensionContext must not be null"
);
return
context
.
getTestInstance
().
orElseThrow
(
()
->
new
IllegalStateException
(
"JUnit failed to supply the test instance in the ExtensionContext"
));
}
/**
* Get the test method associated with the supplied {@code ExtensionContext}.
* @return the test method
* @throws IllegalStateException if the extension context does not contain
* a test method
*/
private
static
Method
getRequiredTestMethod
(
ExtensionContext
context
)
throws
IllegalStateException
{
Assert
.
notNull
(
context
,
"ExtensionContext must not be null"
);
return
context
.
getTestMethod
().
orElseThrow
(
()
->
new
IllegalStateException
(
"JUnit failed to supply the test method in the ExtensionContext"
));
}
}
spring-test/src/test/java/org/springframework/test/context/junit/jupiter/DisabledIfConditionTestCase.java
浏览文件 @
75a71acc
/*
* Copyright 2002-201
6
the original author or authors.
* Copyright 2002-201
7
the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
...
...
@@ -20,10 +20,11 @@ import java.lang.reflect.Method;
import
java.util.Optional
;
import
org.hamcrest.Matcher
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ConditionEvaluationResult
;
import
org.junit.jupiter.api.extension.ExtensionContext
;
import
org.junit.jupiter.api.extension.ExtensionContext.Store
;
import
org.junit.jupiter.api.extension.TestExtensionContext
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.test.context.TestContextManager
;
...
...
@@ -52,7 +53,7 @@ class DisabledIfConditionTestCase {
@Test
void
missingDisabledIf
()
{
assertResult
(
condition
.
evaluate
(
buildExtensionContext
(
"missingDisabledIf"
)),
false
,
assertResult
(
condition
.
evaluate
ExecutionCondition
(
buildExtensionContext
(
"missingDisabledIf"
)),
false
,
endsWith
(
"missingDisabledIf() is enabled since @DisabledIf is not present"
));
}
...
...
@@ -70,7 +71,7 @@ class DisabledIfConditionTestCase {
void
invalidExpressionEvaluationType
()
{
String
methodName
=
"nonBooleanOrStringExpression"
;
IllegalStateException
exception
=
assertThrows
(
IllegalStateException
.
class
,
()
->
condition
.
evaluate
(
buildExtensionContext
(
methodName
)));
()
->
condition
.
evaluate
ExecutionCondition
(
buildExtensionContext
(
methodName
)));
Method
method
=
ReflectionUtils
.
findMethod
(
getClass
(),
methodName
);
...
...
@@ -82,7 +83,7 @@ class DisabledIfConditionTestCase {
void
unsupportedStringEvaluationValue
()
{
String
methodName
=
"stringExpressionThatIsNeitherTrueNorFalse"
;
IllegalStateException
exception
=
assertThrows
(
IllegalStateException
.
class
,
()
->
condition
.
evaluate
(
buildExtensionContext
(
methodName
)));
()
->
condition
.
evaluate
ExecutionCondition
(
buildExtensionContext
(
methodName
)));
Method
method
=
ReflectionUtils
.
findMethod
(
getClass
(),
methodName
);
...
...
@@ -92,30 +93,30 @@ class DisabledIfConditionTestCase {
@Test
void
disabledWithCustomReason
()
{
assertResult
(
condition
.
evaluate
(
buildExtensionContext
(
"customReason"
)),
true
,
is
(
equalTo
(
"Because... 42!"
)));
assertResult
(
condition
.
evaluate
ExecutionCondition
(
buildExtensionContext
(
"customReason"
)),
true
,
is
(
equalTo
(
"Because... 42!"
)));
}
@Test
void
disabledWithDefaultReason
()
{
assertResult
(
condition
.
evaluate
(
buildExtensionContext
(
"defaultReason"
)),
true
,
assertResult
(
condition
.
evaluate
ExecutionCondition
(
buildExtensionContext
(
"defaultReason"
)),
true
,
endsWith
(
"defaultReason() is disabled because @DisabledIf(\"#{1 + 1 eq 2}\") evaluated to true"
));
}
@Test
void
notDisabledWithDefaultReason
()
{
assertResult
(
condition
.
evaluate
(
buildExtensionContext
(
"neverDisabledWithDefaultReason"
)),
false
,
endsWith
(
assertResult
(
condition
.
evaluate
ExecutionCondition
(
buildExtensionContext
(
"neverDisabledWithDefaultReason"
)),
false
,
endsWith
(
"neverDisabledWithDefaultReason() is enabled because @DisabledIf(\"false\") did not evaluate to true"
));
}
// -------------------------------------------------------------------------
private
Test
ExtensionContext
buildExtensionContext
(
String
methodName
)
{
private
ExtensionContext
buildExtensionContext
(
String
methodName
)
{
Class
<?>
testClass
=
SpringTestCase
.
class
;
Method
method
=
ReflectionUtils
.
findMethod
(
getClass
(),
methodName
);
Store
store
=
mock
(
Store
.
class
);
when
(
store
.
getOrComputeIfAbsent
(
any
(),
any
(),
any
())).
thenReturn
(
new
TestContextManager
(
testClass
));
TestExtensionContext
extensionContext
=
mock
(
Test
ExtensionContext
.
class
);
ExtensionContext
extensionContext
=
mock
(
ExtensionContext
.
class
);
when
(
extensionContext
.
getTestClass
()).
thenReturn
(
Optional
.
of
(
testClass
));
when
(
extensionContext
.
getElement
()).
thenReturn
(
Optional
.
of
(
method
));
when
(
extensionContext
.
getStore
(
any
())).
thenReturn
(
store
);
...
...
@@ -124,7 +125,7 @@ class DisabledIfConditionTestCase {
private
void
assertExpressionIsBlank
(
String
methodName
)
{
IllegalStateException
exception
=
assertThrows
(
IllegalStateException
.
class
,
()
->
condition
.
evaluate
(
buildExtensionContext
(
methodName
)));
()
->
condition
.
evaluate
ExecutionCondition
(
buildExtensionContext
(
methodName
)));
assertThat
(
exception
.
getMessage
(),
containsString
(
"must not be blank"
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录