public void test_should_handle_runtime_error_properly() {
   // given
   givenExceptionWhileRequestingWebService();
   // when
   ExchangeRate downloadedRate = downloadRate("USD", "SGD");
   // then
   assertFalse(downloadedRate.isOk());
   assertRate(downloadedRate, "USD", "SGD");
   assertEquals("Unable to get exchange rates: Timeout", downloadedRate.getErrorMessage());
 }
 public void test_should_skip_unknown_currency() {
   // given
   givenResponseFromWebService(
       anyUrl(), "Exception: Unable to convert ToCurrency to Currency\r\nStacktrace...");
   // when
   ExchangeRate rate = downloadRate("USD", "AAA");
   // then
   assertFalse(rate.isOk());
   assertRate(rate, "USD", "AAA");
 }
 public void test_should_handle_error_from_webservice_properly() {
   // given
   givenResponseFromWebService(
       anyUrl(), "System.IO.IOException: There is not enough space on the disk.\r\nStacktrace...");
   // when
   ExchangeRate downloadedRate = downloadRate("USD", "SGD");
   // then
   assertFalse(downloadedRate.isOk());
   assertEquals(
       "Something wrong with the exchange rates provider. Response from the service - System.IO.IOException: There is not enough space on the disk.",
       downloadedRate.getErrorMessage());
 }
Example #4
0
  public String exchange(String from, String to, double account) {
    if (from == null && to == null) {
      return "0.00";
    }

    double result = account;

    if (!from.equals(to)) {

      result = account * rate.getRate(from, to);
    }
    DecimalFormat df = new DecimalFormat("#.00");
    return df.format(result);
  }
 public synchronized boolean equals(java.lang.Object obj) {
   if (!(obj instanceof ExchangeRate)) return false;
   ExchangeRate other = (ExchangeRate) obj;
   if (obj == null) return false;
   if (this == obj) return true;
   if (__equalsCalc != null) {
     return (__equalsCalc == obj);
   }
   __equalsCalc = obj;
   boolean _equals;
   _equals =
       true
           && ((this.id == null && other.getId() == null)
               || (this.id != null && this.id.equals(other.getId())))
           && ((this.currencyCode == null && other.getCurrencyCode() == null)
               || (this.currencyCode != null && this.currencyCode.equals(other.getCurrencyCode())))
           && ((this.refreshRate == null && other.getRefreshRate() == null)
               || (this.refreshRate != null && this.refreshRate.equals(other.getRefreshRate())))
           && ((this.direction == null && other.getDirection() == null)
               || (this.direction != null && this.direction.equals(other.getDirection())))
           && ((this.exchangeRate == null && other.getExchangeRate() == null)
               || (this.exchangeRate != null
                   && this.exchangeRate.equals(other.getExchangeRate())));
   __equalsCalc = null;
   return _equals;
 }