未验证 提交 bad7f771 编写于 作者: J Jesse Wilson 提交者: GitHub

Merge pull request #3047 from square/jakew/mockit-NO/2019-03-07

Remove use of Mockito
......@@ -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>
......
......@@ -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>
......
......@@ -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>
......
......@@ -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 {
......
......@@ -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> {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册