Skip to content
Permalink
Browse files

Remove use of Mockito

It wasn't used for anything interesting and I prefer not having it around to tempt contributors to add new usages of it.
  • Loading branch information...
JakeWharton committed Mar 7, 2019
1 parent cbadc8f commit acd41d18eb9780e0150f50650209fc5732e888b5
@@ -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 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 @@
}

@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 @@
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 @@
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.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 @@
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 @@
(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> {
Oops, something went wrong.

0 comments on commit acd41d1

Please sign in to comment.
You can’t perform that action at this time.