提交 73b88a40 编写于 作者: J Jake Wharton

Throw normal IOException when canceled to match OkHttp.

上级 c342d650
......@@ -16,7 +16,6 @@
package retrofit2.mock;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
......@@ -59,7 +58,7 @@ final class BehaviorCall<T> implements Call<T> {
try {
Thread.sleep(sleepMs);
} catch (InterruptedException e) {
callback.onFailure(new InterruptedIOException("canceled"));
callback.onFailure(new IOException("canceled"));
return false;
}
}
......@@ -68,7 +67,7 @@ final class BehaviorCall<T> implements Call<T> {
@Override public void run() {
if (canceled) {
callback.onFailure(new InterruptedIOException("canceled"));
callback.onFailure(new IOException("canceled"));
} else if (behavior.calculateIsFailure()) {
if (delaySleep()) {
callback.onFailure(behavior.failureException());
......@@ -114,7 +113,7 @@ final class BehaviorCall<T> implements Call<T> {
try {
latch.await();
} catch (InterruptedException e) {
throw new InterruptedIOException("canceled");
throw new IOException("canceled");
}
Response<T> response = responseRef.get();
if (response != null) return response;
......
......@@ -17,7 +17,6 @@
package retrofit2.mock;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
......@@ -222,8 +221,8 @@ public final class MockRetrofitTest {
try {
call.execute();
fail();
} catch (InterruptedIOException e) {
assertThat(e).hasMessage("canceled");
} catch (IOException e) {
assertThat(e).isExactlyInstanceOf(IOException.class).hasMessage("canceled");
}
}
......@@ -252,7 +251,7 @@ public final class MockRetrofitTest {
call.cancel();
assertTrue(latch.await(1, SECONDS));
assertThat(failureRef.get()).isInstanceOf(InterruptedIOException.class).hasMessage("canceled");
assertThat(failureRef.get()).isExactlyInstanceOf(IOException.class).hasMessage("canceled");
}
@Test public void syncCanceledBeforeStart() throws IOException {
......@@ -266,8 +265,8 @@ public final class MockRetrofitTest {
try {
call.execute();
fail();
} catch (InterruptedIOException e) {
assertThat(e).hasMessage("canceled");
} catch (IOException e) {
assertThat(e).isExactlyInstanceOf(IOException.class).hasMessage("canceled");
}
}
......@@ -293,6 +292,6 @@ public final class MockRetrofitTest {
});
assertTrue(latch.await(1, SECONDS));
assertThat(failureRef.get()).isInstanceOf(InterruptedIOException.class).hasMessage("canceled");
assertThat(failureRef.get()).isExactlyInstanceOf(IOException.class).hasMessage("canceled");
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册