Java Code Examples for java.util.Currency#getAvailableCurrencies()

The following examples show how to use java.util.Currency#getAvailableCurrencies() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: USFederalReserveRateProviderTest.java    From javamoney-lib with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldHaveExchangeRates() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(DOLLAR);
    assertNotNull(currencyConversion);
    int count = 0;
    for (Currency currency : Currency.getAvailableCurrencies()) {
        MonetaryAmount money = Money.of(BigDecimal.ONE, currency.getCurrencyCode());
        try {
            MonetaryAmount result = currencyConversion.apply(money);
            assertTrue(result.getNumber().doubleValue() > 0);
            count++;
        } catch(Exception e) {
            //not a supported currency
        }
    }
    assertTrue(count >=24);
}
 
Example 2
Source File: CsvImporter.java    From fingen with Apache License 2.0 5 votes vote down vote up
private Cabbage parseCabbage(CsvImportCache cache, String vls[], int pos, Context context) throws Exception {
        Cabbage cabbage;
        if (pos >= 0 & pos < vls.length) {
            String code = vls[pos];
//            cabbage = CabbagesDAO.getInstance(context).getCabbageByCode(code);
            cabbage = cache.getCabbageByCode(code);
            if (cabbage.getID() < 0) {
                List<Currency> currencies = new ArrayList<>(Currency.getAvailableCurrencies());
                for (Currency currency : currencies) {
                    if (currency.getCurrencyCode().equals(code)) {
                        cabbage.setCode(code);
                        cabbage.setDecimalCount(2);
                        cabbage.setName(currency.getDisplayName());
                        cabbage.setSimbol(currency.getSymbol());
                        try {
                            cabbage = (Cabbage) CabbagesDAO.getInstance(context).createModel(cabbage);
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        } else {
            cabbage = new Cabbage();
        }
        return cabbage;
    }
 
Example 3
Source File: CurrencyTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
public void testGetAvailableCurrencies() throws Exception {
    Set<Currency> all = Currency.getAvailableCurrencies();
    // Confirm that a few well-known stable currencies are present.
    assertTrue(all.toString(), all.contains(Currency.getInstance("CHF")));
    assertTrue(all.toString(), all.contains(Currency.getInstance("EUR")));
    assertTrue(all.toString(), all.contains(Currency.getInstance("GBP")));
    assertTrue(all.toString(), all.contains(Currency.getInstance("JPY")));
    assertTrue(all.toString(), all.contains(Currency.getInstance("USD")));
}
 
Example 4
Source File: CurrencyComboBoxField.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
public CurrencyComboBoxField() {
    this.setWidth(WebThemes.FORM_CONTROL_WIDTH);
    Set<Currency> availableCurrencies = Currency.getAvailableCurrencies();
    this.setItems(availableCurrencies);
    this.setItemCaptionGenerator((ItemCaptionGenerator<Currency>) currency -> String.format("%s (%s)", currency.getDisplayName
            (UserUIContext.getUserLocale()), currency.getCurrencyCode()));
}
 
Example 5
Source File: MonetaryRoundingsTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for
 * {@link javax.money.Monetary#getRounding(javax.money.CurrencyUnit, String...)}
 * .
 */
@Test
public void testGetRoundingCurrencyUnit() {
    MonetaryAmount[] samples = new MonetaryAmount[]{
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("0.0000000001"))
                    .create(), Monetary.getDefaultAmountFactory().setCurrency("CHF")
            .setNumber(new BigDecimal("1.00000000000023")).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("1.1123442323"))
                    .create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("1.50000000000"))
                    .create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(new BigDecimal("-1.000000003"))
                    .create(), Monetary.getDefaultAmountFactory().setCurrency("CHF")
            .setNumber(new BigDecimal("-1.100232876532876389")).create(),
            Monetary.getDefaultAmountFactory().setCurrency("CHF")
                    .setNumber(new BigDecimal("-1.500000000000")).create()};
    for (MonetaryAmount sample : samples) {
        for (Currency currency : Currency.getAvailableCurrencies()) {
            CurrencyUnit cur = Monetary.getCurrency(currency.getCurrencyCode());
            // Omit test roundings, which are for testing only...
            if ("XXX".equals(cur.getCurrencyCode())) {
                continue;
            } else if ("CHF".equals(cur.getCurrencyCode())) {
                continue;
            }
            MonetaryOperator rounding = Monetary.getRounding(cur);
            BigDecimal dec = sample.getNumber().numberValue(BigDecimal.class);
            BigDecimal expected;
            if (cur.getDefaultFractionDigits() < 0) {
                expected = dec.setScale(0, RoundingMode.HALF_UP);
            } else {
                expected = dec.setScale(cur.getDefaultFractionDigits(), RoundingMode.HALF_UP);
            }
            MonetaryAmount r = sample.with(rounding);
            assertEquals(Monetary.getDefaultAmountFactory().setCurrency("CHF").setNumber(expected).create(),
                    r, "Rounding for: " + sample);
        }
    }
}
 
Example 6
Source File: BasicsTest.java    From javamoney-examples with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetProvidedCurrency() throws Exception {
    for (Currency cur : Currency.getAvailableCurrencies()) {
        assertNotNull(basics.getProvidedCurrency(cur.getCurrencyCode()));
    }
}