- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 101
Open
Description
I faced something strange when instantiating CurrencyUnit from the currencyCode string.
Some strings like "X*", "X+|" and others were allowed to create a currency.
Here is a small test to exemplify the situation and some comparison with java.util.Currency:
  @Test
  void monetaCurrencyUnit() {
    // SOME STRANGE STRINGS ARE ALLOWED! The test PASSED
    Monetary.getCurrency("X*");
    Monetary.getCurrency("X*|helloWorld");
    Monetary.getCurrency("X+|\u0019F\"CW:'NEvS�\u0017N\u000BL\u001B ~K\u0001");
  }
  @Test
  void monetaCurrencyUnitLowerHistorical() {
    // This fails as I was expecting, and that led me think that the Moneta impl of currency is more sound.
    // Because on the other hand, when using java.util.Currency, it works.
    Monetary.getCurrency("EUr");
  }
  @Test
  void jdkCurrency() {
    // Both throw exception as I would expect (not the case in Moneta `CurrencyUnit`: `Monetary.getCurrency()`)
    java.util.Currency.getInstance("X*");
    java.util.Currency.getInstance("X+|\u0019F\"CW:'NEvS�\u0017N\u000BL\u001B ~K\u0001");
  }
  @Test
  void jdkCurrencyLowerHistorical() {
    // I was not expecting this, but only some currencies work when the last char is lowercase like:
    java.util.Currency.getInstance("ESp"); // YUm ok, BEf ok, DEm ok, ADp ok (they're all historical currencies), EUr also works
  }Metadata
Metadata
Assignees
Labels
No labels