Util { public static boolean isNetworkProblem(final Throwable ex) { if (ex == null) { return false; } else if (ex instanceof SocketTimeoutException || ex instanceof SocketException) { return true; } else { return isNetworkProblem(ex.getCause()); } } private  Util(); static Date toDate(final LocalDate localDate); static Date toDate(final OffsetDateTime offsetDateTime); static Date toDate(final ZonedDateTime zonedDateTime); static String identifyLoan(final LoanBased event); static Map<String, Object> getLoanData(final Loan loan); static Map<String, Object> getDelinquencyData(final Investment investment); static Map<String, Object> getLoanData(final Investment i, final Loan l); static Map<String, Object> summarizePortfolioStructure(final PortfolioOverview portfolioOverview); static Map<String, Object> summarizePortfolioStructure(final ExtendedPortfolioOverview portfolioOverview); static boolean isNetworkProblem(final Throwable ex); static Map<String, Object> getDelinquentData(final Investment i, final Loan loan, final LocalDate date); static String stackTraceToString(final Throwable t); static String obfuscateEmailAddress(final String username);  }
@Test void isSocketTimeout() { final Throwable t = new SocketTimeoutException("Testing"); assertThat(Util.isNetworkProblem(t)).isTrue(); final Throwable t2 = new IllegalStateException(t); assertThat(Util.isNetworkProblem(t2)).isTrue(); final Throwable t3 = new IllegalStateException(); assertThat(Util.isNetworkProblem(t3)).isFalse(); assertThat(Util.isNetworkProblem(null)).isFalse(); }
@Test void isSocket() { final Throwable t = new SocketException("Testing"); assertThat(Util.isNetworkProblem(t)).isTrue(); final Throwable t2 = new IllegalStateException(t); assertThat(Util.isNetworkProblem(t2)).isTrue(); final Throwable t3 = new IllegalStateException(); assertThat(Util.isNetworkProblem(t3)).isFalse(); assertThat(Util.isNetworkProblem(null)).isFalse(); }