Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
9543384d
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 搜索 >>
提交
9543384d
编写于
2月 16, 2017
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid deprecated comparators in tests
Issue: SPR-14779
上级
f90cd770
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
35 deletion
+27
-35
spring-beans/src/test/java/org/springframework/beans/support/PropertyComparatorTests.java
...pringframework/beans/support/PropertyComparatorTests.java
+16
-22
spring-core/src/test/java/org/springframework/util/comparator/CompoundComparatorTests.java
...ingframework/util/comparator/CompoundComparatorTests.java
+3
-2
spring-core/src/test/java/org/springframework/util/comparator/InvertibleComparatorTests.java
...gframework/util/comparator/InvertibleComparatorTests.java
+8
-11
未找到文件。
spring-beans/src/test/java/org/springframework/beans/support/PropertyComparatorTests.java
浏览文件 @
9543384d
/*
* 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.
...
...
@@ -16,16 +16,14 @@
package
org.springframework.beans.support
;
import
org.junit.Test
;
import
java.util.Comparator
;
import
org.
springframework.util.comparator.CompoundComparator
;
import
org.
junit.Test
;
import
static
org
.
junit
.
Assert
.*;
/**
* Unit tests for {@link PropertyComparator}
*
* @see org.springframework.util.comparator.ComparatorTests
* Unit tests for {@link PropertyComparator}.
*
* @author Keith Donald
* @author Chris Beams
...
...
@@ -40,7 +38,7 @@ public class PropertyComparatorTests {
Dog
dog2
=
new
Dog
();
dog2
.
setNickName
(
"biscy"
);
PropertyComparator
c
=
new
PropertyComparator
(
"nickName"
,
false
,
true
);
PropertyComparator
<
Dog
>
c
=
new
PropertyComparator
<>
(
"nickName"
,
false
,
true
);
assertTrue
(
c
.
compare
(
dog
,
dog2
)
>
0
);
assertTrue
(
c
.
compare
(
dog
,
dog
)
==
0
);
assertTrue
(
c
.
compare
(
dog2
,
dog
)
<
0
);
...
...
@@ -50,15 +48,13 @@ public class PropertyComparatorTests {
public
void
testPropertyComparatorNulls
()
{
Dog
dog
=
new
Dog
();
Dog
dog2
=
new
Dog
();
PropertyComparator
c
=
new
PropertyComparator
(
"nickName"
,
false
,
true
);
PropertyComparator
<
Dog
>
c
=
new
PropertyComparator
<>
(
"nickName"
,
false
,
true
);
assertTrue
(
c
.
compare
(
dog
,
dog2
)
==
0
);
}
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testCompoundComparator
()
{
CompoundComparator
<
Dog
>
c
=
new
CompoundComparator
<>();
c
.
addComparator
(
new
PropertyComparator
(
"lastName"
,
false
,
true
));
Comparator
<
Dog
>
c
=
new
PropertyComparator
<>(
"lastName"
,
false
,
true
);
Dog
dog1
=
new
Dog
();
dog1
.
setFirstName
(
"macy"
);
...
...
@@ -70,19 +66,17 @@ public class PropertyComparatorTests {
assertTrue
(
c
.
compare
(
dog1
,
dog2
)
==
0
);
c
.
addComparator
(
new
PropertyComparator
(
"firstName"
,
false
,
true
));
c
=
c
.
thenComparing
(
new
PropertyComparator
<>
(
"firstName"
,
false
,
true
));
assertTrue
(
c
.
compare
(
dog1
,
dog2
)
>
0
);
dog2
.
setLastName
(
"konikk dog"
);
assertTrue
(
c
.
compare
(
dog2
,
dog1
)
>
0
);
}
@SuppressWarnings
(
"unchecked"
)
@Test
public
void
testCompoundComparatorInvert
()
{
CompoundComparator
<
Dog
>
c
=
new
CompoundComparator
<>();
c
.
addComparator
(
new
PropertyComparator
(
"lastName"
,
false
,
true
));
c
.
addComparator
(
new
PropertyComparator
(
"firstName"
,
false
,
true
));
Comparator
<
Dog
>
c
=
(
new
PropertyComparator
<
Dog
>(
"lastName"
,
false
,
true
)).
thenComparing
(
new
PropertyComparator
<>(
"firstName"
,
false
,
true
));
Dog
dog1
=
new
Dog
();
dog1
.
setFirstName
(
"macy"
);
dog1
.
setLastName
(
"grayspots"
);
...
...
@@ -92,7 +86,7 @@ public class PropertyComparatorTests {
dog2
.
setLastName
(
"grayspots"
);
assertTrue
(
c
.
compare
(
dog1
,
dog2
)
>
0
);
c
.
invertOrder
();
c
=
c
.
reversed
();
assertTrue
(
c
.
compare
(
dog1
,
dog2
)
<
0
);
}
...
...
@@ -106,11 +100,6 @@ public class PropertyComparatorTests {
private
String
lastName
;
@Override
public
int
compareTo
(
Object
o
)
{
return
nickName
.
compareTo
(((
Dog
)
o
).
nickName
);
}
public
String
getNickName
()
{
return
nickName
;
}
...
...
@@ -134,6 +123,11 @@ public class PropertyComparatorTests {
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
@Override
public
int
compareTo
(
Object
o
)
{
return
this
.
nickName
.
compareTo
(((
Dog
)
o
).
nickName
);
}
}
}
spring-core/src/test/java/org/springframework/util/comparator/CompoundComparatorTests.java
浏览文件 @
9543384d
/*
* 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.
...
...
@@ -23,12 +23,13 @@ import org.junit.Test;
import
org.junit.rules.ExpectedException
;
/**
* Test for {@link Comp
arable
Comparator}.
* Test for {@link Comp
ound
Comparator}.
*
* @author Keith Donald
* @author Chris Beams
* @author Phillip Webb
*/
@Deprecated
public
class
CompoundComparatorTests
{
@Rule
...
...
spring-core/src/test/java/org/springframework/util/comparator/InvertibleComparatorTests.java
浏览文件 @
9543384d
/*
* 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.
...
...
@@ -30,10 +30,11 @@ import static org.junit.Assert.*;
* @author Chris Beams
* @author Phillip Webb
*/
@Deprecated
public
class
InvertibleComparatorTests
{
private
Comparator
<
Integer
>
comparator
=
new
ComparableComparator
<>();
private
final
Comparator
<
Integer
>
comparator
=
new
ComparableComparator
<>();
@Test
(
expected
=
IllegalArgumentException
.
class
)
public
void
shouldNeedComparator
()
throws
Exception
{
...
...
@@ -47,16 +48,14 @@ public class InvertibleComparatorTests {
@Test
public
void
shouldDefaultToAscending
()
throws
Exception
{
InvertibleComparator
<
Integer
>
invertibleComparator
=
new
InvertibleComparator
<>(
comparator
);
InvertibleComparator
<
Integer
>
invertibleComparator
=
new
InvertibleComparator
<>(
comparator
);
assertThat
(
invertibleComparator
.
isAscending
(),
is
(
true
));
assertThat
(
invertibleComparator
.
compare
(
1
,
2
),
is
(-
1
));
}
@Test
public
void
shouldInvert
()
throws
Exception
{
InvertibleComparator
<
Integer
>
invertibleComparator
=
new
InvertibleComparator
<>(
comparator
);
InvertibleComparator
<
Integer
>
invertibleComparator
=
new
InvertibleComparator
<>(
comparator
);
assertThat
(
invertibleComparator
.
isAscending
(),
is
(
true
));
assertThat
(
invertibleComparator
.
compare
(
1
,
2
),
is
(-
1
));
invertibleComparator
.
invertOrder
();
...
...
@@ -66,15 +65,13 @@ public class InvertibleComparatorTests {
@Test
public
void
shouldCompareAscending
()
throws
Exception
{
InvertibleComparator
<
Integer
>
invertibleComparator
=
new
InvertibleComparator
<>(
comparator
,
true
);
InvertibleComparator
<
Integer
>
invertibleComparator
=
new
InvertibleComparator
<>(
comparator
,
true
);
assertThat
(
invertibleComparator
.
compare
(
1
,
2
),
is
(-
1
));
}
@Test
public
void
shouldCompareDescending
()
throws
Exception
{
InvertibleComparator
<
Integer
>
invertibleComparator
=
new
InvertibleComparator
<>(
comparator
,
false
);
InvertibleComparator
<
Integer
>
invertibleComparator
=
new
InvertibleComparator
<>(
comparator
,
false
);
assertThat
(
invertibleComparator
.
compare
(
1
,
2
),
is
(
1
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录