Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wd1105040417
retrofit
提交
bad7f771
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 搜索 >>
未验证
提交
bad7f771
编写于
3月 07, 2019
作者:
J
Jesse Wilson
提交者:
GitHub
3月 07, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3047 from square/jakew/mockit-NO/2019-03-07
Remove use of Mockito
上级
cbadc8f1
acd41d18
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
222 addition
and
202 deletion
+222
-202
pom.xml
pom.xml
+0
-6
retrofit-mock/pom.xml
retrofit-mock/pom.xml
+0
-5
retrofit/pom.xml
retrofit/pom.xml
+0
-5
retrofit/src/test/java/retrofit2/CallTest.java
retrofit/src/test/java/retrofit2/CallTest.java
+8
-12
retrofit/src/test/java/retrofit2/DefaultCallAdapterFactoryTest.java
...rc/test/java/retrofit2/DefaultCallAdapterFactoryTest.java
+22
-52
retrofit/src/test/java/retrofit2/RetrofitTest.java
retrofit/src/test/java/retrofit2/RetrofitTest.java
+192
-122
未找到文件。
pom.xml
浏览文件 @
bad7f771
...
...
@@ -75,7 +75,6 @@
<!-- Test Dependencies -->
<junit.version>
4.12
</junit.version>
<assertj.version>
1.7.0
</assertj.version>
<mockito.version>
1.9.5
</mockito.version>
<robolectric.version>
3.8
</robolectric.version>
</properties>
...
...
@@ -195,11 +194,6 @@
<artifactId>
assertj-core
</artifactId>
<version>
${assertj.version}
</version>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-core
</artifactId>
<version>
${mockito.version}
</version>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
...
...
retrofit-mock/pom.xml
浏览文件 @
bad7f771
...
...
@@ -35,11 +35,6 @@
<artifactId>
assertj-core
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-core
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
<build>
...
...
retrofit/pom.xml
浏览文件 @
bad7f771
...
...
@@ -56,11 +56,6 @@
<artifactId>
assertj-core
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.mockito
</groupId>
<artifactId>
mockito-core
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
...
...
retrofit/src/test/java/retrofit2/CallTest.java
浏览文件 @
bad7f771
...
...
@@ -47,8 +47,6 @@ import static okhttp3.mockwebserver.SocketPolicy.DISCONNECT_DURING_RESPONSE_BODY
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
verifyNoMoreInteractions
;
import
static
retrofit2
.
TestingUtils
.
repeat
;
public
final
class
CallTest
{
...
...
@@ -371,11 +369,11 @@ public final class CallTest {
}
@Test
public
void
http204SkipsConverter
()
throws
IOException
{
final
Converter
<
ResponseBody
,
String
>
converter
=
spy
(
new
Converter
<
ResponseBody
,
String
>()
{
@Override
public
String
convert
(
ResponseBody
value
)
throws
IOException
{
return
value
.
string
();
final
Converter
<
ResponseBody
,
String
>
converter
=
new
Converter
<
ResponseBody
,
String
>()
{
@Override
public
String
convert
(
ResponseBody
value
)
{
throw
new
AssertionError
();
}
}
)
;
};
Retrofit
retrofit
=
new
Retrofit
.
Builder
()
.
baseUrl
(
server
.
url
(
"/"
))
.
addConverterFactory
(
new
ToStringConverterFactory
()
{
...
...
@@ -393,15 +391,14 @@ public final class CallTest {
Response
<
String
>
response
=
example
.
getString
().
execute
();
assertThat
(
response
.
code
()).
isEqualTo
(
204
);
assertThat
(
response
.
body
()).
isNull
();
verifyNoMoreInteractions
(
converter
);
}
@Test
public
void
http205SkipsConverter
()
throws
IOException
{
final
Converter
<
ResponseBody
,
String
>
converter
=
spy
(
new
Converter
<
ResponseBody
,
String
>()
{
@Override
public
String
convert
(
ResponseBody
value
)
throws
IOException
{
return
value
.
string
();
final
Converter
<
ResponseBody
,
String
>
converter
=
new
Converter
<
ResponseBody
,
String
>()
{
@Override
public
String
convert
(
ResponseBody
value
)
{
throw
new
AssertionError
();
}
}
)
;
};
Retrofit
retrofit
=
new
Retrofit
.
Builder
()
.
baseUrl
(
server
.
url
(
"/"
))
.
addConverterFactory
(
new
ToStringConverterFactory
()
{
...
...
@@ -419,7 +416,6 @@ public final class CallTest {
Response
<
String
>
response
=
example
.
getString
().
execute
();
assertThat
(
response
.
code
()).
isEqualTo
(
205
);
assertThat
(
response
.
body
()).
isNull
();
verifyNoMoreInteractions
(
converter
);
}
@Test
public
void
converterBodyDoesNotLeakContentInIntermediateBuffers
()
throws
IOException
{
...
...
retrofit/src/test/java/retrofit2/DefaultCallAdapterFactoryTest.java
浏览文件 @
bad7f771
...
...
@@ -21,16 +21,14 @@ import java.lang.annotation.Annotation;
import
java.lang.reflect.Type
;
import
java.util.List
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.atomic.AtomicBoolean
;
import
okhttp3.Request
;
import
org.jetbrains.annotations.NotNull
;
import
org.junit.Test
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
junit
.
Assert
.
assertTrue
;
import
static
org
.
junit
.
Assert
.
fail
;
import
static
org
.
mockito
.
Matchers
.
any
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
spy
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verifyNoMoreInteractions
;
@SuppressWarnings
(
"unchecked"
)
public
final
class
DefaultCallAdapterFactoryTest
{
...
...
@@ -39,13 +37,11 @@ public final class DefaultCallAdapterFactoryTest {
private
final
Retrofit
retrofit
=
new
Retrofit
.
Builder
()
.
baseUrl
(
"http://localhost:1"
)
.
build
();
private
final
Callback
<
String
>
callback
=
mock
(
Callback
.
class
);
private
final
Executor
callbackExecutor
=
spy
(
new
Executor
()
{
@Override
public
void
execute
(
Runnable
runnable
)
{
runnable
.
run
();
private
final
CallAdapter
.
Factory
factory
=
new
DefaultCallAdapterFactory
(
new
Executor
()
{
@Override
public
void
execute
(
@NotNull
Runnable
command
)
{
command
.
run
();
}
});
private
final
CallAdapter
.
Factory
factory
=
new
DefaultCallAdapterFactory
(
callbackExecutor
);
@Test
public
void
rawTypeThrows
()
{
try
{
...
...
@@ -74,68 +70,42 @@ public final class DefaultCallAdapterFactoryTest {
(
CallAdapter
<
String
,
Call
<
String
>>)
factory
.
get
(
returnType
,
NO_ANNOTATIONS
,
retrofit
);
final
Response
<
String
>
response
=
Response
.
success
(
"Hi"
);
Call
<
String
>
call
=
adapter
.
adapt
(
new
EmptyCall
()
{
@Override
public
Response
<
String
>
execute
()
throws
IOException
{
@Override
public
Response
<
String
>
execute
()
{
return
response
;
}
});
assertThat
(
call
.
execute
()).
isSameAs
(
response
);
}
@Test
public
void
adaptedCallEnqueueUsesExecutorForSuccessCallback
()
{
Type
returnType
=
new
TypeToken
<
Call
<
String
>>()
{}.
getType
();
CallAdapter
<
String
,
Call
<
String
>>
adapter
=
(
CallAdapter
<
String
,
Call
<
String
>>)
factory
.
get
(
returnType
,
NO_ANNOTATIONS
,
retrofit
);
final
Response
<
String
>
response
=
Response
.
success
(
"Hi"
);
EmptyCall
originalCall
=
new
EmptyCall
()
{
@Override
public
void
enqueue
(
Callback
<
String
>
callback
)
{
callback
.
onResponse
(
this
,
response
);
}
};
Call
<
String
>
call
=
adapter
.
adapt
(
originalCall
);
call
.
enqueue
(
callback
);
verify
(
callbackExecutor
).
execute
(
any
(
Runnable
.
class
));
verify
(
callback
).
onResponse
(
call
,
response
);
}
@Test
public
void
adaptedCallEnqueueUsesExecutorForFailureCallback
()
{
@Test
public
void
adaptedCallCloneDeepCopy
()
{
Type
returnType
=
new
TypeToken
<
Call
<
String
>>()
{}.
getType
();
CallAdapter
<
String
,
Call
<
String
>>
adapter
=
(
CallAdapter
<
String
,
Call
<
String
>>)
factory
.
get
(
returnType
,
NO_ANNOTATIONS
,
retrofit
);
final
Throwable
throwable
=
new
IOException
();
EmptyCall
originalCall
=
new
EmptyCall
()
{
@Override
public
void
enqueue
(
Callback
<
String
>
callback
)
{
callback
.
onFailure
(
this
,
throwable
);
final
AtomicBoolean
cloned
=
new
AtomicBoolean
();
Call
<
String
>
delegate
=
new
EmptyCall
()
{
@Override
public
Call
<
String
>
clone
()
{
cloned
.
set
(
true
);
return
this
;
}
};
Call
<
String
>
call
=
adapter
.
adapt
(
originalCall
);
call
.
enqueue
(
callback
);
verify
(
callbackExecutor
).
execute
(
any
(
Runnable
.
class
));
verifyNoMoreInteractions
(
callbackExecutor
);
verify
(
callback
).
onFailure
(
call
,
throwable
);
verifyNoMoreInteractions
(
callback
);
}
@Test
public
void
adaptedCallCloneDeepCopy
()
{
Type
returnType
=
new
TypeToken
<
Call
<
String
>>()
{}.
getType
();
CallAdapter
<
String
,
Call
<
String
>>
adapter
=
(
CallAdapter
<
String
,
Call
<
String
>>)
factory
.
get
(
returnType
,
NO_ANNOTATIONS
,
retrofit
);
Call
<
String
>
delegate
=
mock
(
Call
.
class
);
Call
<
String
>
call
=
adapter
.
adapt
(
delegate
);
Call
<
String
>
cloned
=
call
.
clone
();
assertThat
(
cloned
).
isNotSameAs
(
call
);
verify
(
delegate
).
clone
();
verifyNoMoreInteractions
(
delegate
);
assertThat
(
call
.
clone
()).
isNotSameAs
(
call
);
assertTrue
(
cloned
.
get
());
}
@Test
public
void
adaptedCallCancel
()
{
Type
returnType
=
new
TypeToken
<
Call
<
String
>>()
{}.
getType
();
CallAdapter
<
String
,
Call
<
String
>>
adapter
=
(
CallAdapter
<
String
,
Call
<
String
>>)
factory
.
get
(
returnType
,
NO_ANNOTATIONS
,
retrofit
);
Call
<
String
>
delegate
=
mock
(
Call
.
class
);
final
AtomicBoolean
canceled
=
new
AtomicBoolean
();
Call
<
String
>
delegate
=
new
EmptyCall
()
{
@Override
public
void
cancel
()
{
canceled
.
set
(
true
);
}
};
Call
<
String
>
call
=
adapter
.
adapt
(
delegate
);
call
.
cancel
();
verify
(
delegate
).
cancel
();
verifyNoMoreInteractions
(
delegate
);
assertTrue
(
canceled
.
get
());
}
static
class
EmptyCall
implements
Call
<
String
>
{
...
...
retrofit/src/test/java/retrofit2/RetrofitTest.java
浏览文件 @
bad7f771
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录