Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wd1105040417
retrofit
提交
5e957e41
R
retrofit
项目概览
wd1105040417
/
retrofit
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
retrofit
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
5e957e41
编写于
8月 11, 2018
作者:
J
Jesse Wilson
提交者:
GitHub
8月 11, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2849 from NightlyNexus/eric.more-checks
Fix error message for out-of-order parameters.
上级
4a048cc0
23994c32
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
86 addition
and
3 deletion
+86
-3
retrofit/src/main/java/retrofit2/RequestFactory.java
retrofit/src/main/java/retrofit2/RequestFactory.java
+17
-2
retrofit/src/test/java/retrofit2/RequestFactoryTest.java
retrofit/src/test/java/retrofit2/RequestFactoryTest.java
+69
-1
未找到文件。
retrofit/src/main/java/retrofit2/RequestFactory.java
浏览文件 @
5e957e41
...
...
@@ -127,6 +127,8 @@ final class RequestFactory {
boolean
gotBody
;
boolean
gotPath
;
boolean
gotQuery
;
boolean
gotQueryName
;
boolean
gotQueryMap
;
boolean
gotUrl
;
String
httpMethod
;
boolean
hasBody
;
...
...
@@ -322,7 +324,13 @@ final class RequestFactory {
throw
parameterError
(
method
,
p
,
"@Path parameters may not be used with @Url."
);
}
if
(
gotQuery
)
{
throw
parameterError
(
method
,
p
,
"A @Url parameter must not come after a @Query"
);
throw
parameterError
(
method
,
p
,
"A @Url parameter must not come after a @Query."
);
}
if
(
gotQueryName
)
{
throw
parameterError
(
method
,
p
,
"A @Url parameter must not come after a @QueryName."
);
}
if
(
gotQueryMap
)
{
throw
parameterError
(
method
,
p
,
"A @Url parameter must not come after a @QueryMap."
);
}
if
(
relativeUrl
!=
null
)
{
throw
parameterError
(
method
,
p
,
"@Url cannot be used with @%s URL"
,
httpMethod
);
...
...
@@ -344,6 +352,12 @@ final class RequestFactory {
if
(
gotQuery
)
{
throw
parameterError
(
method
,
p
,
"A @Path parameter must not come after a @Query."
);
}
if
(
gotQueryName
)
{
throw
parameterError
(
method
,
p
,
"A @Path parameter must not come after a @QueryName."
);
}
if
(
gotQueryMap
)
{
throw
parameterError
(
method
,
p
,
"A @Path parameter must not come after a @QueryMap."
);
}
if
(
gotUrl
)
{
throw
parameterError
(
method
,
p
,
"@Path parameters may not be used with @Url."
);
}
...
...
@@ -395,7 +409,7 @@ final class RequestFactory {
boolean
encoded
=
query
.
encoded
();
Class
<?>
rawParameterType
=
Utils
.
getRawType
(
type
);
gotQuery
=
true
;
gotQuery
Name
=
true
;
if
(
Iterable
.
class
.
isAssignableFrom
(
rawParameterType
))
{
if
(!(
type
instanceof
ParameterizedType
))
{
throw
parameterError
(
method
,
p
,
rawParameterType
.
getSimpleName
()
...
...
@@ -421,6 +435,7 @@ final class RequestFactory {
}
else
if
(
annotation
instanceof
QueryMap
)
{
Class
<?>
rawParameterType
=
Utils
.
getRawType
(
type
);
gotQueryMap
=
true
;
if
(!
Map
.
class
.
isAssignableFrom
(
rawParameterType
))
{
throw
parameterError
(
method
,
p
,
"@QueryMap parameter type must be Map."
);
}
...
...
retrofit/src/test/java/retrofit2/RequestFactoryTest.java
浏览文件 @
5e957e41
...
...
@@ -1005,6 +1005,40 @@ public final class RequestFactoryTest {
}
}
@Test
public
void
getWithQueryNameThenPathThrows
()
{
class
Example
{
@GET
(
"/foo/bar/{ping}/"
)
//
Call
<
ResponseBody
>
method
(
@QueryName
String
kit
,
@Path
(
"ping"
)
String
ping
)
{
throw
new
AssertionError
();
}
}
try
{
buildRequest
(
Example
.
class
,
"kat"
,
"pong"
);
fail
();
}
catch
(
IllegalArgumentException
e
)
{
assertThat
(
e
).
hasMessage
(
"A @Path parameter must not come after a @QueryName. (parameter #2)\n"
+
" for method Example.method"
);
}
}
@Test
public
void
getWithQueryMapThenPathThrows
()
{
class
Example
{
@GET
(
"/foo/bar/{ping}/"
)
//
Call
<
ResponseBody
>
method
(
@QueryMap
Map
<
String
,
String
>
queries
,
@Path
(
"ping"
)
String
ping
)
{
throw
new
AssertionError
();
}
}
try
{
buildRequest
(
Example
.
class
,
Collections
.
singletonMap
(
"kit"
,
"kat"
),
"pong"
);
fail
();
}
catch
(
IllegalArgumentException
e
)
{
assertThat
(
e
).
hasMessage
(
"A @Path parameter must not come after a @QueryMap. (parameter #2)\n"
+
" for method Example.method"
);
}
}
@Test
public
void
getWithPathAndQueryQuestionMarkParam
()
{
class
Example
{
@GET
(
"/foo/bar/{ping}/"
)
//
...
...
@@ -1444,7 +1478,41 @@ public final class RequestFactoryTest {
buildRequest
(
Example
.
class
,
"hey"
,
"foo/bar/"
);
fail
();
}
catch
(
IllegalArgumentException
e
)
{
assertThat
(
e
).
hasMessage
(
"A @Url parameter must not come after a @Query (parameter #2)\n"
assertThat
(
e
).
hasMessage
(
"A @Url parameter must not come after a @Query. (parameter #2)\n"
+
" for method Example.method"
);
}
}
@Test
public
void
getWithQueryNameThenUrlThrows
()
{
class
Example
{
@GET
Call
<
ResponseBody
>
method
(
@QueryName
String
name
,
@Url
String
url
)
{
throw
new
AssertionError
();
}
}
try
{
buildRequest
(
Example
.
class
,
Collections
.
singletonMap
(
"kit"
,
"kat"
),
"foo/bar/"
);
fail
();
}
catch
(
IllegalArgumentException
e
)
{
assertThat
(
e
).
hasMessage
(
"A @Url parameter must not come after a @QueryName. (parameter #2)\n"
+
" for method Example.method"
);
}
}
@Test
public
void
getWithQueryMapThenUrlThrows
()
{
class
Example
{
@GET
Call
<
ResponseBody
>
method
(
@QueryMap
Map
<
String
,
String
>
queries
,
@Url
String
url
)
{
throw
new
AssertionError
();
}
}
try
{
buildRequest
(
Example
.
class
,
Collections
.
singletonMap
(
"kit"
,
"kat"
),
"foo/bar/"
);
fail
();
}
catch
(
IllegalArgumentException
e
)
{
assertThat
(
e
).
hasMessage
(
"A @Url parameter must not come after a @QueryMap. (parameter #2)\n"
+
" for method Example.method"
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录