Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
6cc6abd4
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 搜索 >>
提交
6cc6abd4
编写于
6月 24, 2019
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Test status quo for OrderComparator's PriorityOrdered support
See gh-23187
上级
4357749a
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
64 addition
and
17 deletion
+64
-17
spring-core/src/test/java/org/springframework/core/OrderComparatorTests.java
...t/java/org/springframework/core/OrderComparatorTests.java
+64
-17
未找到文件。
spring-core/src/test/java/org/springframework/core/OrderComparatorTests.java
浏览文件 @
6cc6abd4
...
...
@@ -28,6 +28,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Rick Evans
* @author Stephane Nicoll
* @author Juergen Hoeller
* @author Sam Brannen
*/
public
class
OrderComparatorTests
{
...
...
@@ -69,6 +70,40 @@ public class OrderComparatorTests {
assertThat
(
this
.
comparator
.
compare
(
new
Object
(),
new
Object
())).
isEqualTo
(
0
);
}
@Test
public
void
comparePriorityOrderedInstancesBefore
()
{
assertThat
(
this
.
comparator
.
compare
(
new
StubPriorityOrdered
(
100
),
new
StubPriorityOrdered
(
2000
))).
isEqualTo
(-
1
);
}
@Test
public
void
comparePriorityOrderedInstancesSame
()
{
assertThat
(
this
.
comparator
.
compare
(
new
StubPriorityOrdered
(
100
),
new
StubPriorityOrdered
(
100
))).
isEqualTo
(
0
);
}
@Test
public
void
comparePriorityOrderedInstancesAfter
()
{
assertThat
(
this
.
comparator
.
compare
(
new
StubPriorityOrdered
(
982300
),
new
StubPriorityOrdered
(
100
))).
isEqualTo
(
1
);
}
@Test
public
void
comparePriorityOrderedInstanceToStandardOrderedInstanceWithSamePriority
()
{
// PriorityOrdered wins in a tie.
assertThat
(
this
.
comparator
.
compare
(
new
StubPriorityOrdered
(
100
),
new
StubOrdered
(
100
))).
isEqualTo
(-
1
);
}
@Test
public
void
comparePriorityOrderedInstanceToStandardOrderedInstanceWithLowerPriority
()
{
// PriorityOrdered should not be taken into account.
assertThat
(
this
.
comparator
.
compare
(
new
StubPriorityOrdered
(
100
),
new
StubOrdered
(
200
))).
isEqualTo
(-
1
);
}
@Test
public
void
comparePriorityOrderedInstanceToStandardOrderedInstanceWithHigherPriority
()
{
// PriorityOrdered should probably not be taken into account, but it currently is.
// assertThat(this.comparator.compare(new StubPriorityOrdered(200), new StubOrdered(100))).isEqualTo(1);
assertThat
(
this
.
comparator
.
compare
(
new
StubPriorityOrdered
(
200
),
new
StubOrdered
(
100
))).
isEqualTo
(-
1
);
}
@Test
public
void
compareWithSimpleSourceProvider
()
{
Comparator
<
Object
>
customComparator
=
this
.
comparator
.
withSourceProvider
(
...
...
@@ -86,7 +121,7 @@ public class OrderComparatorTests {
@Test
public
void
compareWithSourceProviderArrayNoMatch
()
{
Comparator
<
Object
>
customComparator
=
this
.
comparator
.
withSourceProvider
(
new
TestSourceProvider
(
5L
,
new
Object
[]{
new
Object
(),
new
Object
()}));
new
TestSourceProvider
(
5L
,
new
Object
[]
{
new
Object
(),
new
Object
()}));
assertThat
(
customComparator
.
compare
(
new
Object
(),
5L
)).
isEqualTo
(
0
);
}
...
...
@@ -98,33 +133,25 @@ public class OrderComparatorTests {
}
private
static
final
class
TestSourceProvider
implements
OrderComparator
.
OrderSourceProvider
{
private
final
Object
target
;
private
static
class
StubOrdered
implements
Ordered
{
private
final
Object
orderSource
;
private
final
int
order
;
public
TestSourceProvider
(
Object
target
,
Object
orderSource
)
{
this
.
target
=
target
;
this
.
orderSource
=
orderSource
;
StubOrdered
(
int
order
)
{
this
.
order
=
order
;
}
@Override
public
Object
getOrderSource
(
Object
obj
)
{
if
(
target
.
equals
(
obj
))
{
return
orderSource
;
}
return
null
;
public
int
getOrder
()
{
return
this
.
order
;
}
}
private
static
final
class
StubOrdered
implements
Ordered
{
private
static
class
StubPriorityOrdered
implements
PriorityOrdered
{
private
final
int
order
;
public
StubOrdered
(
int
order
)
{
StubPriorityOrdered
(
int
order
)
{
this
.
order
=
order
;
}
...
...
@@ -134,4 +161,24 @@ public class OrderComparatorTests {
}
}
private
static
class
TestSourceProvider
implements
OrderComparator
.
OrderSourceProvider
{
private
final
Object
target
;
private
final
Object
orderSource
;
TestSourceProvider
(
Object
target
,
Object
orderSource
)
{
this
.
target
=
target
;
this
.
orderSource
=
orderSource
;
}
@Override
public
Object
getOrderSource
(
Object
obj
)
{
if
(
target
.
equals
(
obj
))
{
return
orderSource
;
}
return
null
;
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录