CryptopiaErrorAdapter { public static ExchangeException adapt(CryptopiaException e) { String message = e.getError(); if (StringUtils.isEmpty(message)) { return new ExchangeException("Operation failed without any error message"); } if (MARKET_NOT_FOUND_PATTERN.matcher(message).matches()) { return new CurrencyPairNotValidException(message); } return new ExchangeException(message); }  static ExchangeException adapt(CryptopiaException e);  }
@Test public void adapt_wrongMarket() { CryptopiaException e = new CryptopiaException(); e.setError("Market STRG_BTC not found"); ExchangeException adapted = CryptopiaErrorAdapter.adapt(e); assertThat(adapted).isExactlyInstanceOf(CurrencyPairNotValidException.class); }
@Test public void adapt_unrecognizedErrorMessage() { CryptopiaException e = new CryptopiaException(); e.setError("Some other error message"); ExchangeException adapted = CryptopiaErrorAdapter.adapt(e); assertThat(adapted).isExactlyInstanceOf(ExchangeException.class); }
@Test public void adapt_noErrorMessage() { ExchangeException adapted = CryptopiaErrorAdapter.adapt(new CryptopiaException()); assertThat(adapted).isExactlyInstanceOf(ExchangeException.class); }