Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
9cee70ff
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 搜索 >>
提交
9cee70ff
编写于
3月 20, 2014
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish ComponentScanParserTests and clean up warnings
上级
ad09f1b5
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
33 deletion
+37
-33
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserTests.java
...ramework/context/annotation/ComponentScanParserTests.java
+37
-33
未找到文件。
spring-context/src/test/java/org/springframework/context/annotation/ComponentScanParserTests.java
浏览文件 @
9cee70ff
...
...
@@ -16,13 +16,6 @@
package
org.springframework.context.annotation
;
import
static
org
.
hamcrest
.
CoreMatchers
.
is
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.
assertFalse
;
import
static
org
.
junit
.
Assert
.
assertNotNull
;
import
static
org
.
junit
.
Assert
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
java.lang.annotation.ElementType
;
import
java.lang.annotation.Retention
;
import
java.lang.annotation.RetentionPolicy
;
...
...
@@ -30,7 +23,6 @@ import java.lang.annotation.Target;
import
org.junit.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.ApplicationContext
;
import
org.springframework.context.ConfigurableApplicationContext
;
import
org.springframework.context.support.ClassPathXmlApplicationContext
;
import
org.springframework.context.support.GenericXmlApplicationContext
;
...
...
@@ -41,6 +33,9 @@ import org.springframework.core.type.filter.TypeFilter;
import
example.profilescan.ProfileAnnotatedComponent
;
import
example.scannable.AutowiredQualifierFooService
;
import
static
org
.
hamcrest
.
CoreMatchers
.*;
import
static
org
.
junit
.
Assert
.*;
/**
* @author Mark Fisher
* @author Juergen Hoeller
...
...
@@ -49,62 +44,67 @@ import example.scannable.AutowiredQualifierFooService;
*/
public
class
ComponentScanParserTests
{
private
ClassPathXmlApplicationContext
loadContext
(
String
path
)
{
return
new
ClassPathXmlApplicationContext
(
path
,
getClass
());
}
@Test
public
void
testAspectJTypeFilter
()
{
ApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"org/springframework/context/annotation/aspectjTypeFilterTests.xml"
);
public
void
aspectJTypeFilter
()
{
ClassPathXmlApplicationContext
context
=
loadContext
(
"aspectjTypeFilterTests.xml"
);
assertTrue
(
context
.
containsBean
(
"fooServiceImpl"
));
assertTrue
(
context
.
containsBean
(
"stubFooDao"
));
assertFalse
(
context
.
containsBean
(
"scopedProxyTestBean"
));
context
.
close
();
}
@Test
public
void
testNonMatchingResourcePattern
()
{
ApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"org/springframework/context/annotation/nonMatchingResourcePatternTests.xml"
);
public
void
nonMatchingResourcePattern
()
{
ClassPathXmlApplicationContext
context
=
loadContext
(
"nonMatchingResourcePatternTests.xml"
);
assertFalse
(
context
.
containsBean
(
"fooServiceImpl"
));
context
.
close
();
}
@Test
public
void
testMatchingResourcePattern
()
{
ApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"org/springframework/context/annotation/matchingResourcePatternTests.xml"
);
public
void
matchingResourcePattern
()
{
ClassPathXmlApplicationContext
context
=
loadContext
(
"matchingResourcePatternTests.xml"
);
assertTrue
(
context
.
containsBean
(
"fooServiceImpl"
));
context
.
close
();
}
@Test
public
void
testComponentScanWithAutowiredQualifier
()
{
ApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"org/springframework/context/annotation/componentScanWithAutowiredQualifierTests.xml"
);
public
void
componentScanWithAutowiredQualifier
()
{
ClassPathXmlApplicationContext
context
=
loadContext
(
"componentScanWithAutowiredQualifierTests.xml"
);
AutowiredQualifierFooService
fooService
=
(
AutowiredQualifierFooService
)
context
.
getBean
(
"fooService"
);
assertTrue
(
fooService
.
isInitCalled
());
assertEquals
(
"bar"
,
fooService
.
foo
(
123
));
context
.
close
();
}
@Test
public
void
testCustomAnnotationUsedForBothComponentScanAndQualifier
()
{
ApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"org/springframework/context/annotation/customAnnotationUsedForBothComponentScanAndQualifierTests.xml"
);
public
void
customAnnotationUsedForBothComponentScanAndQualifier
()
{
ClassPathXmlApplicationContext
context
=
loadContext
(
"customAnnotationUsedForBothComponentScanAndQualifierTests.xml"
);
KustomAnnotationAutowiredBean
testBean
=
(
KustomAnnotationAutowiredBean
)
context
.
getBean
(
"testBean"
);
assertNotNull
(
testBean
.
getDependency
());
context
.
close
();
}
@Test
public
void
testCustomTypeFilter
()
{
ApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
"org/springframework/context/annotation/customTypeFilterTests.xml"
);
public
void
customTypeFilter
()
{
ClassPathXmlApplicationContext
context
=
loadContext
(
"customTypeFilterTests.xml"
);
KustomAnnotationAutowiredBean
testBean
=
(
KustomAnnotationAutowiredBean
)
context
.
getBean
(
"testBean"
);
assertNotNull
(
testBean
.
getDependency
());
context
.
close
();
}
@Test
public
void
testC
omponentScanRespectsProfileAnnotation
()
{
public
void
c
omponentScanRespectsProfileAnnotation
()
{
String
xmlLocation
=
"org/springframework/context/annotation/componentScanRespectsProfileAnnotationTests.xml"
;
{
// should exclude the profile-annotated bean if active profiles remains unset
GenericXmlApplicationContext
context
=
new
GenericXmlApplicationContext
();
context
.
load
(
xmlLocation
);
context
.
refresh
();
assertThat
(
context
.
containsBean
(
ProfileAnnotatedComponent
.
BEAN_NAME
),
is
(
false
));
context
.
close
();
}
{
// should include the profile-annotated bean with active profiles set
GenericXmlApplicationContext
context
=
new
GenericXmlApplicationContext
();
...
...
@@ -112,23 +112,24 @@ public class ComponentScanParserTests {
context
.
load
(
xmlLocation
);
context
.
refresh
();
assertThat
(
context
.
containsBean
(
ProfileAnnotatedComponent
.
BEAN_NAME
),
is
(
true
));
context
.
close
();
}
{
// ensure the same works for AbstractRefreshableApplicationContext impls too
ConfigurableApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
new
String
[]{
xmlLocation
},
false
);
ConfigurableApplicationContext
context
=
new
ClassPathXmlApplicationContext
(
new
String
[]
{
xmlLocation
},
false
);
context
.
getEnvironment
().
setActiveProfiles
(
ProfileAnnotatedComponent
.
PROFILE_NAME
);
context
.
refresh
();
assertThat
(
context
.
containsBean
(
ProfileAnnotatedComponent
.
BEAN_NAME
),
is
(
true
));
context
.
close
();
}
}
@Target
({
ElementType
.
TYPE
,
ElementType
.
FIELD
})
@Target
({
ElementType
.
TYPE
,
ElementType
.
FIELD
})
@Retention
(
RetentionPolicy
.
RUNTIME
)
public
static
@interface
CustomAnnotation
{
}
/**
* Intentionally spelling "custom" with a "k" since there are numerous
* classes in this package named *Custom*.
...
...
@@ -139,17 +140,20 @@ public class ComponentScanParserTests {
@CustomAnnotation
private
KustomAnnotationDependencyBean
dependency
;
public
KustomAnnotationDependencyBean
getDependency
()
{
return
this
.
dependency
;
}
}
/**
* Intentionally spelling "custom" with a "k" since there are numerous
* classes in this package named *Custom*.
*/
@CustomAnnotation
public
static
class
KustomAnnotationDependencyBean
{
}
public
static
class
CustomTypeFilter
implements
TypeFilter
{
/**
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录