예제 #1
0
  public void testConvert() throws Exception {
    expect(mockExchangeDas.findExchange(ENTITY_ID, 200))
        .andReturn(_mockCurrencyExchangeDTO("0.98"))
        .once();
    expect(mockExchangeDas.findExchange(ENTITY_ID, 201))
        .andReturn(_mockCurrencyExchangeDTO("1.20"))
        .once();
    replay(mockCurrencyDas, mockExchangeDas);

    // convert $20.00 CAD to AUD - approximated conversion rates ;)
    CurrencyBL bl = new CurrencyBL(mockCurrencyDas, mockExchangeDas);
    BigDecimal amount = bl.convert(200, 201, new BigDecimal("20.00"), ENTITY_ID);

    verify(mockCurrencyDas, mockExchangeDas);

    assertEquals(new BigDecimal("24.48979"), amount);
  }
예제 #2
0
  public void testConvertRepeatingDecimal() throws Exception {
    expect(mockExchangeDas.findExchange(ENTITY_ID, 200))
        .andReturn(_mockCurrencyExchangeDTO("3.00"))
        .once();
    expect(mockExchangeDas.findExchange(ENTITY_ID, 201))
        .andReturn(_mockCurrencyExchangeDTO("1.00"))
        .once();
    replay(mockCurrencyDas, mockExchangeDas);

    /*
       Pivot calculation will result in a value of 3.333333~ repeating, which will
       cause an ArithmeticException if not handled correctly.

       10.00 / 3.00 = 3.333333~
    */
    CurrencyBL bl = new CurrencyBL(mockCurrencyDas, mockExchangeDas);
    BigDecimal amount = bl.convert(200, 201, new BigDecimal("10.00"), ENTITY_ID);

    verify(mockCurrencyDas, mockExchangeDas);

    assertEquals(new BigDecimal("3.33"), amount);
  }