getAvailableCurrencies ( )源码实例Demo

java.util.Currency#getAvailableCurrencies ( )源码实例Demo

下面列出了java.util.Currency#getAvailableCurrencies ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@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);
}
 
源代码2 项目: fingen   文件: CsvImporter.java
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;
    }
 
源代码3 项目: j2objc   文件: CurrencyTest.java
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")));
}
 
源代码4 项目: mycollab   文件: CurrencyComboBoxField.java
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()));
}
 
源代码5 项目: jsr354-ri   文件: MonetaryRoundingsTest.java
/**
 * 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);
        }
    }
}
 
源代码6 项目: javamoney-examples   文件: BasicsTest.java
@Test
public void testGetProvidedCurrency() throws Exception {
    for (Currency cur : Currency.getAvailableCurrencies()) {
        assertNotNull(basics.getProvidedCurrency(cur.getCurrencyCode()));
    }
}