From 403570f625dc48bd6718205e5558226cb59407d5 Mon Sep 17 00:00:00 2001 From: amihaiemil Date: Mon, 29 Aug 2022 19:10:11 +0300 Subject: [PATCH] #1294 more realistic BNR fallback exchange rate --- .../com/selfxdsd/core/projects/XmlBnr.java | 20 +++++++++++++------ .../core/projects/XmlBnrTestCase.java | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/self-core-impl/src/main/java/com/selfxdsd/core/projects/XmlBnr.java b/self-core-impl/src/main/java/com/selfxdsd/core/projects/XmlBnr.java index 71f17864..6cd6b2d7 100644 --- a/self-core-impl/src/main/java/com/selfxdsd/core/projects/XmlBnr.java +++ b/self-core-impl/src/main/java/com/selfxdsd/core/projects/XmlBnr.java @@ -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. */ @@ -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); } } @@ -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); } } } diff --git a/self-core-impl/src/test/java/com/selfxdsd/core/projects/XmlBnrTestCase.java b/self-core-impl/src/test/java/com/selfxdsd/core/projects/XmlBnrTestCase.java index bdda7d33..d4fb8f4b 100644 --- a/self-core-impl/src/test/java/com/selfxdsd/core/projects/XmlBnrTestCase.java +++ b/self-core-impl/src/test/java/com/selfxdsd/core/projects/XmlBnrTestCase.java @@ -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)) ); }