Skip to content

Commit

Permalink
#1294 more realistic BNR fallback exchange rate
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Aug 29, 2022
1 parent e1c324d commit 403570f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@
*/
public final class XmlBnr implements Bnr {

/**
* Fallback exchange rate we use in case the API call fails.
*/
public static final int FALLBACK_EXCHANGE_RATE = 485;

/**
* Logger.
*/
Expand Down Expand Up @@ -92,8 +97,11 @@ public BigDecimal euroToRon() {
LOG.error(
"[BNR] Could not get EUR-RON exchange rate: ", ex
);
LOG.error("[BNR] Returning 492 as default exchange rate.");
return BigDecimal.valueOf(492);
LOG.error(
"[BNR] Returning " + FALLBACK_EXCHANGE_RATE
+ " as default exchange rate."
);
return BigDecimal.valueOf(FALLBACK_EXCHANGE_RATE);
}
}

Expand Down Expand Up @@ -125,12 +133,12 @@ private BigDecimal readEurFromXml(final String xml) {
.multiply(BigDecimal.valueOf(100));
}
}
LOG.warn("[BNR] EUR-RON not found! Returning 492 as default.");
return BigDecimal.valueOf(492);
LOG.warn("[BNR] EUR-RON not found! Returning " + FALLBACK_EXCHANGE_RATE + " as default.");
return BigDecimal.valueOf(FALLBACK_EXCHANGE_RATE);
} catch (final Exception ex) {
LOG.error("[BNR] Exception while parsing XML: ", ex);
LOG.error("[BNR] Returning 492 as default exchange rate.");
return BigDecimal.valueOf(492);
LOG.error("[BNR] Returning " + FALLBACK_EXCHANGE_RATE + " as default exchange rate.");
return BigDecimal.valueOf(FALLBACK_EXCHANGE_RATE);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void getsEurToRonFromBnr() {
public void getsFallbackEurToRonFromBnr() {
MatcherAssert.assertThat(
new XmlBnr(URI.create("http://localhost:12345")).euroToRon(),
Matchers.equalTo(BigDecimal.valueOf(492))
Matchers.equalTo(BigDecimal.valueOf(XmlBnr.FALLBACK_EXCHANGE_RATE))
);
}

Expand Down

0 comments on commit 403570f

Please sign in to comment.