diff --git a/src/main/java/de/stklcode/pubtrans/ura/UraClient.java b/src/main/java/de/stklcode/pubtrans/ura/UraClient.java index d779557..35461c5 100644 --- a/src/main/java/de/stklcode/pubtrans/ura/UraClient.java +++ b/src/main/java/de/stklcode/pubtrans/ura/UraClient.java @@ -233,7 +233,7 @@ public class UraClient { line = br.readLine(); } } catch (IOException e) { - e.printStackTrace(); + throw new IllegalStateException("Failed to read from API", e); } return trips; } @@ -268,7 +268,7 @@ public class UraClient { } } } catch (IOException e) { - e.printStackTrace(); + throw new IllegalStateException("Failed to read from API", e); } return stops; } diff --git a/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java b/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java index 686ceb9..cfecff9 100644 --- a/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java +++ b/src/test/java/de/stklcode/pubtrans/ura/UraClientTest.java @@ -32,6 +32,7 @@ import java.util.Optional; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.Is.is; @@ -69,9 +70,13 @@ public class UraClientTest { throw new IOException("Provoked exception 1."); } }); - assertThat(new UraClient("mocked").getStops(), hasSize(0)); - PowerMockito.when(mockURL.openStream()).thenThrow(new IOException("Provoked exception 2.")); - assertThat(new UraClient("mocked").getStops(), hasSize(0)); + try { + new UraClient("mocked").getStops(); + } catch (RuntimeException e) { + assertThat(e, is(instanceOf(IllegalStateException.class))); + assertThat(e.getCause(), is(instanceOf(IOException.class))); + assertThat(e.getCause().getMessage(), is("Provoked exception 1.")); + } } @Test @@ -221,9 +226,13 @@ public class UraClientTest { throw new IOException("Provoked exception 1."); } }); - assertThat(new UraClient("mocked").getTrips(), hasSize(0)); - PowerMockito.when(mockURL.openStream()).thenThrow(new IOException("Provoked exception 2.")); - assertThat(new UraClient("mocked").getTrips(), hasSize(0)); + try { + new UraClient("mocked").getTrips(); + } catch (RuntimeException e) { + assertThat(e, is(instanceOf(IllegalStateException.class))); + assertThat(e.getCause(), is(instanceOf(IOException.class))); + assertThat(e.getCause().getMessage(), is("Provoked exception 1.")); + } } @Test