SimpleCurrencyMatrix extends AbstractCurrencyMatrix { public void setFixedConversion(final Currency source, final Currency target, final double rate) { ArgumentChecker.notNull(source, "source"); ArgumentChecker.notNull(target, "target"); ArgumentChecker.notZero(0, 0, "rate"); if (source.equals(target)) { if (rate != 1.0) { throw new IllegalArgumentException("rate"); } return; } addConversion(source, target, CurrencyMatrixValue.of(rate)); }  void setFixedConversion(final Currency source, final Currency target, final double rate); void setCrossConversion(final Currency source, final Currency target, final Currency cross); void setLiveData(final Currency source, final Currency target, final ValueRequirement valueRequirement);  }
@Test public void testFixedConversion () { final SimpleCurrencyMatrix matrix = new SimpleCurrencyMatrix (); matrix.setFixedConversion (currencyUSD, currencyGBP, 1.6); assertEquals (CurrencyMatrixValue.of (1.6), matrix.getConversion(currencyUSD, currencyGBP)); assertEquals(CurrencyMatrixValue.of(1.0 / 1.6), matrix.getConversion(currencyGBP, currencyUSD)); assertNull(matrix.getConversion(currencyUSD, currencyEUR)); assertNull(matrix.getConversion(currencyEUR, currencyUSD)); assertEquals(2, matrix.getSourceCurrencies().size()); assertEquals(2, matrix.getTargetCurrencies().size()); }
@Test public void testIdentityInsert() { final SimpleCurrencyMatrix matrix = new SimpleCurrencyMatrix(); assertEquals(CurrencyMatrixValue.of(1.0), matrix.getConversion(currencyUSD, currencyUSD)); matrix.setFixedConversion(currencyUSD, currencyUSD, 1.0); assertEquals(CurrencyMatrixValue.of(1.0), matrix.getConversion(currencyUSD, currencyUSD)); assertTrue(matrix.getSourceCurrencies().isEmpty()); assertTrue(matrix.getTargetCurrencies().isEmpty()); }
@Test(expectedExceptions = IllegalArgumentException.class) public void testIllegalIdentityInsert() { final SimpleCurrencyMatrix matrix = new SimpleCurrencyMatrix(); matrix.setFixedConversion(currencyUSD, currencyUSD, 2.0); }