Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
带水的鱼儿
spring-framework
提交
bcb05804
S
spring-framework
项目概览
带水的鱼儿
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
bcb05804
编写于
6月 15, 2021
作者:
S
Sam Brannen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish DefaultPathContainerTests
上级
3c8074b6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
35 deletion
+30
-35
spring-web/src/test/java/org/springframework/http/server/DefaultPathContainerTests.java
...pringframework/http/server/DefaultPathContainerTests.java
+30
-35
未找到文件。
spring-web/src/test/java/org/springframework/http/server/DefaultPathContainerTests.java
浏览文件 @
bcb05804
/*
* Copyright 2002-20
19
the original author or authors.
* Copyright 2002-20
21
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.
...
...
@@ -13,12 +13,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.springframework.http.server
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -30,12 +28,14 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link DefaultPathContainer}.
*
* @author Rossen Stoyanchev
* @author Sam Brannen
*/
public
class
DefaultPathContainerTests
{
class
DefaultPathContainerTests
{
@Test
public
void
pathSegment
()
{
void
pathSegment
()
{
// basic
testPathSegment
(
"cars"
,
"cars"
,
new
LinkedMultiValueMap
<>());
...
...
@@ -48,7 +48,7 @@ public class DefaultPathContainerTests {
}
@Test
public
void
pathSegmentParams
()
throws
Exception
{
void
pathSegmentParams
()
{
// basic
LinkedMultiValueMap
<
String
,
String
>
params
=
new
LinkedMultiValueMap
<>();
params
.
add
(
"colors"
,
"red"
);
...
...
@@ -74,15 +74,14 @@ public class DefaultPathContainerTests {
}
private
void
testPathSegment
(
String
rawValue
,
String
valueToMatch
,
MultiValueMap
<
String
,
String
>
params
)
{
PathContainer
container
=
PathContainer
.
parsePath
(
rawValue
);
if
(
""
.
equals
(
rawValue
))
{
assertThat
(
container
.
elements
()
.
size
()).
isEqualTo
(
0
);
assertThat
(
container
.
elements
()
).
isEmpty
(
);
return
;
}
assertThat
(
container
.
elements
()
.
size
()).
isEqualTo
(
1
);
assertThat
(
container
.
elements
()
).
hasSize
(
1
);
PathSegment
segment
=
(
PathSegment
)
container
.
elements
().
get
(
0
);
assertThat
(
segment
.
value
()).
as
(
"value: '"
+
rawValue
+
"'"
).
isEqualTo
(
rawValue
);
...
...
@@ -91,40 +90,36 @@ public class DefaultPathContainerTests {
}
@Test
public
void
path
()
{
void
path
()
{
// basic
testPath
(
"/a/b/c"
,
"/a/b/c"
,
Arrays
.
asList
(
"/"
,
"a"
,
"/"
,
"b"
,
"/"
,
"c"
)
);
testPath
(
"/a/b/c"
,
"/a/b/c"
,
"/"
,
"a"
,
"/"
,
"b"
,
"/"
,
"c"
);
// root path
testPath
(
"/"
,
"/"
,
Collections
.
singletonList
(
"/"
)
);
testPath
(
"/"
,
"/"
,
"/"
);
// empty path
testPath
(
""
,
""
,
Collections
.
emptyList
()
);
testPath
(
"%20%20"
,
"%20%20"
,
Collections
.
singletonList
(
"%20%20"
)
);
testPath
(
""
,
""
);
testPath
(
"%20%20"
,
"%20%20"
,
"%20%20"
);
// trailing slash
testPath
(
"/a/b/"
,
"/a/b/"
,
Arrays
.
asList
(
"/"
,
"a"
,
"/"
,
"b"
,
"/"
)
);
testPath
(
"/a/b//"
,
"/a/b//"
,
Arrays
.
asList
(
"/"
,
"a"
,
"/"
,
"b"
,
"/"
,
"/"
)
);
testPath
(
"/a/b/"
,
"/a/b/"
,
"/"
,
"a"
,
"/"
,
"b"
,
"/"
);
testPath
(
"/a/b//"
,
"/a/b//"
,
"/"
,
"a"
,
"/"
,
"b"
,
"/"
,
"/"
);
// extra slashes and spaces
testPath
(
"/%20"
,
"/%20"
,
Arrays
.
asList
(
"/"
,
"%20"
)
);
testPath
(
"//%20/%20"
,
"//%20/%20"
,
Arrays
.
asList
(
"/"
,
"/"
,
"%20"
,
"/"
,
"%20"
)
);
testPath
(
"/%20"
,
"/%20"
,
"/"
,
"%20"
);
testPath
(
"//%20/%20"
,
"//%20/%20"
,
"/"
,
"/"
,
"%20"
,
"/"
,
"%20"
);
}
private
void
testPath
(
String
input
,
PathContainer
.
Options
options
,
String
value
,
List
<
String
>
expectedElements
)
{
PathContainer
path
=
PathContainer
.
parsePath
(
input
,
options
);
private
void
testPath
(
String
input
,
String
value
,
String
...
expectedElements
)
{
PathContainer
path
=
PathContainer
.
parsePath
(
input
,
PathContainer
.
Options
.
HTTP_PATH
);
assertThat
(
path
.
value
()).
as
(
"value: '"
+
input
+
"'"
).
isEqualTo
(
value
);
assertThat
(
path
.
elements
().
stream
().
map
(
PathContainer
.
Element
::
value
).
collect
(
Collectors
.
toList
()))
.
as
(
"elements: "
+
input
).
isEqualTo
(
expectedElements
);
}
private
void
testPath
(
String
input
,
String
value
,
List
<
String
>
expectedElements
)
{
testPath
(
input
,
PathContainer
.
Options
.
HTTP_PATH
,
value
,
expectedElements
);
assertThat
(
path
.
elements
()).
map
(
PathContainer
.
Element
::
value
).
as
(
"elements: "
+
input
)
.
containsExactly
(
expectedElements
);
}
@Test
public
void
subPath
()
{
void
subPath
()
{
// basic
PathContainer
path
=
PathContainer
.
parsePath
(
"/a/b/c"
);
assertThat
(
path
.
subPath
(
0
)).
isSameAs
(
path
);
...
...
@@ -141,15 +136,15 @@ public class DefaultPathContainerTests {
}
@Test
// gh-23310
public
void
pathWithCustomSeparator
()
{
void
pathWithCustomSeparator
()
{
PathContainer
path
=
PathContainer
.
parsePath
(
"a.b%2Eb.c"
,
PathContainer
.
Options
.
MESSAGE_ROUTE
);
List
<
String
>
decodedSegments
=
path
.
elements
().
stream
()
.
filter
(
e
->
e
instanceof
PathSegment
)
.
map
(
e
->
((
PathSegment
)
e
).
valueToMatch
()
)
.
collect
(
Collectors
.
toList
()
);
Stream
<
String
>
decodedSegments
=
path
.
elements
().
stream
()
.
filter
(
PathSegment
.
class
::
isInstance
)
.
map
(
PathSegment
.
class
::
cast
)
.
map
(
PathSegment:
:
valueToMatch
);
assertThat
(
decodedSegments
).
isEqualTo
(
Arrays
.
asList
(
"a"
,
"b.b"
,
"c"
)
);
assertThat
(
decodedSegments
).
containsExactly
(
"a"
,
"b.b"
,
"c"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录