Java Code Examples for javax.money.convert.CurrencyConversion#apply()

The following examples show how to use javax.money.convert.CurrencyConversion#apply() . 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: ECBHistoric90RateProviderTest.java    From jsr354-ri with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSetTimeInLocalDateTime2() {

	LocalDate localDate = LocalDate.now().minusDays(90)
			.with(TemporalAdjusters.next(DayOfWeek.FRIDAY));

	ConversionQuery conversionQuery = ConversionQueryBuilder.of()
			.setTermCurrency(EURO).set(localDate).build();
	CurrencyConversion currencyConversion = provider
			.getCurrencyConversion(conversionQuery);
	assertNotNull(currencyConversion);
	MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
	MonetaryAmount result = currencyConversion.apply(money);

	assertEquals(result.getCurrency(), EURO);
	assertTrue(result.getNumber().doubleValue() > 0);

}
 
Example 2
Source File: USFederalReserveRateProviderTest.java    From javamoney-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnsSameTawainValue() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(TAIWAN_DOLLAR);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, TAIWAN_DOLLAR);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), TAIWAN_DOLLAR);
    assertEquals(result.getNumber().numberValue(BigDecimal.class), BigDecimal.TEN);

}
 
Example 3
Source File: ECBCurrentRateProviderTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertsBrazilianToDollar() {
    CurrencyConversion currencyConversion = provider
            .getCurrencyConversion(DOLLAR);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), DOLLAR);
    assertTrue(result.getNumber().doubleValue() > 0);

}
 
Example 4
Source File: ECBHistoricRateProviderTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertsDollarToEuro() {
    CurrencyConversion currencyConversion = provider
            .getCurrencyConversion(EURO);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), EURO);
    assertTrue(result.getNumber().doubleValue() > 0);

}
 
Example 5
Source File: YahooRateProviderTest.java    From javamoney-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertsDollarToBrazilian() {
    CurrencyConversion currencyConversion = provider
            .getCurrencyConversion(BRAZILIAN_REAL);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), BRAZILIAN_REAL);
    assertTrue(result.getNumber().doubleValue() > 0);

}
 
Example 6
Source File: ECBCurrentRateProviderTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnsSameBrazilianValue() {
    CurrencyConversion currencyConversion = provider
            .getCurrencyConversion(BRAZILIAN_REAL);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), BRAZILIAN_REAL);
    assertEquals(result.getNumber().numberValue(BigDecimal.class),
            BigDecimal.TEN);

}
 
Example 7
Source File: IMFRateProviderTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertsEuroToDollar() {
    CurrencyConversion currencyConversion = provider
            .getCurrencyConversion(DOLLAR);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, EURO);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), DOLLAR);
    assertTrue(result.getNumber().doubleValue() > 0);

}
 
Example 8
Source File: YahooRateProviderTest.java    From javamoney-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertsDollarToEuro() {
    CurrencyConversion currencyConversion = provider
            .getCurrencyConversion(EURO);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), EURO);
    assertTrue(result.getNumber().doubleValue() > 0);

}
 
Example 9
Source File: IMFHistoricRateProviderTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertsBrazilianToDollar() {
    CurrencyConversion currencyConversion = provider
            .getCurrencyConversion(DOLLAR);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), DOLLAR);
    assertTrue(result.getNumber().doubleValue() > 0);

}
 
Example 10
Source File: YahooRateProviderTest.java    From javamoney-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnsSameBrazilianValue() {
    CurrencyConversion currencyConversion = provider
            .getCurrencyConversion(BRAZILIAN_REAL);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), BRAZILIAN_REAL);
    assertEquals(result.getNumber().numberValue(BigDecimal.class),
            BigDecimal.TEN);

}
 
Example 11
Source File: IMFHistoricRateProviderTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnsSameBrazilianValue() {
    CurrencyConversion currencyConversion = provider
            .getCurrencyConversion(BRAZILIAN_REAL);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), BRAZILIAN_REAL);
    assertEquals(result.getNumber().numberValue(BigDecimal.class),
            BigDecimal.TEN);

}
 
Example 12
Source File: IMFHistoricRateProviderTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = MonetaryException.class)
public void shouldReturnErrorWhenDoesNotFindTheExchangeRate() {

	LocalDate localDate = YearMonth.of(2011, Month.JANUARY).atDay(9);
	ConversionQuery conversionQuery = ConversionQueryBuilder.of()
			.set(localDate).setTermCurrency(EURO).build();
	CurrencyConversion currencyConversion = provider
			.getCurrencyConversion(conversionQuery);
	assertNotNull(currencyConversion);
	MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
	currencyConversion.apply(money);
	fail();
}
 
Example 13
Source File: USFederalReserveRateProviderTest.java    From javamoney-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertTaiwanToEuro() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(EURO);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, TAIWAN_DOLLAR);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), EURO);
    assertTrue(result.getNumber().doubleValue() > 0);

}
 
Example 14
Source File: USFederalReserveRateProviderTest.java    From javamoney-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertCanadaToDollar() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(DOLLAR);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, CANADA_DOLLAR);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), DOLLAR);
    assertTrue(result.getNumber().doubleValue() > 0);
}
 
Example 15
Source File: IMFRateProviderTest.java    From jsr354-ri with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertsDollarToEuro() {
    CurrencyConversion currencyConversion = provider
            .getCurrencyConversion(EURO);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), EURO);
    assertTrue(result.getNumber().doubleValue() > 0);

}
 
Example 16
Source File: USFederalReserveRateProviderTest.java    From javamoney-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertsEuroToDollar() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(DOLLAR);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, EURO);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), DOLLAR);
    assertTrue(result.getNumber().doubleValue() > 0);
}
 
Example 17
Source File: USFederalReserveRateProviderTest.java    From javamoney-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldConvertsDollarToEuro() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(EURO);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), EURO);
    assertTrue(result.getNumber().doubleValue() > 0);
}
 
Example 18
Source File: USFederalReserveRateProviderTest.java    From javamoney-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnsSameEuroValue() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(EURO);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, EURO);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), EURO);
    assertEquals(result.getNumber().numberValue(BigDecimal.class), BigDecimal.TEN);

}
 
Example 19
Source File: USFederalReserveRateProviderTest.java    From javamoney-lib with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnsSameDollarValue() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(DOLLAR);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
    MonetaryAmount result = currencyConversion.apply(money);

    assertEquals(result.getCurrency(), DOLLAR);
    assertEquals(result.getNumber().numberValue(BigDecimal.class), BigDecimal.TEN);

}
 
Example 20
Source File: ExchangeMB.java    From javamoney-examples with Apache License 2.0 4 votes vote down vote up
public void exchange() {
	CurrencyConversion currencyConversion = provider.getCurrencyConversion(bean.getCurrencyTo());
	MonetaryAmount result = currencyConversion.apply(bean.getMounetaryFrom());
	bean.setResult(result);
}