diff --git a/retrofit-mock/src/main/java/retrofit2/mock/BehaviorCall.java b/retrofit-mock/src/main/java/retrofit2/mock/BehaviorCall.java index 7913d0752fa7d266c55c68e4854fa5099ea31fdd..8c1dad5c94408253a2abadcca15d7453bc492f97 100644 --- a/retrofit-mock/src/main/java/retrofit2/mock/BehaviorCall.java +++ b/retrofit-mock/src/main/java/retrofit2/mock/BehaviorCall.java @@ -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 implements Call { 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 implements Call { @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 implements Call { try { latch.await(); } catch (InterruptedException e) { - throw new InterruptedIOException("canceled"); + throw new IOException("canceled"); } Response response = responseRef.get(); if (response != null) return response; diff --git a/retrofit-mock/src/test/java/retrofit2/mock/MockRetrofitTest.java b/retrofit-mock/src/test/java/retrofit2/mock/MockRetrofitTest.java index a2767792d615d8db2faf64f93ebd760c2ea140d4..3e091483bceca8c577a8217d4a331e0e745d0ec9 100644 --- a/retrofit-mock/src/test/java/retrofit2/mock/MockRetrofitTest.java +++ b/retrofit-mock/src/test/java/retrofit2/mock/MockRetrofitTest.java @@ -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"); } }