japod@34
|
1 |
package org.apidesign.apifest08.currency;
|
japod@34
|
2 |
|
japod@34
|
3 |
import static junit.framework.Assert.assertEquals;
|
japod@34
|
4 |
import static junit.framework.Assert.assertFalse;
|
japod@34
|
5 |
import static junit.framework.Assert.assertTrue;
|
japod@34
|
6 |
import static junit.framework.Assert.fail;
|
japod@34
|
7 |
import static org.apidesign.apifest08.test.Task1Test.CZK;
|
japod@34
|
8 |
import static org.apidesign.apifest08.test.Task1Test.SKK;
|
japod@34
|
9 |
import static org.apidesign.apifest08.test.Task1Test.USD;
|
japod@34
|
10 |
|
japod@34
|
11 |
import org.junit.Test;
|
japod@34
|
12 |
|
japod@34
|
13 |
public class CompositeConvertorTest {
|
japod@34
|
14 |
private static final ExtendedConvertor USD_CZK_CONVERTOR = ConvertorFactory.createConvertor(new MoneyImpl(1,USD), new MoneyImpl(17,CZK));
|
japod@34
|
15 |
private static final ExtendedConvertor SKK_CZK_CONVERTOR = ConvertorFactory.createConvertor(new MoneyImpl(100,SKK), new MoneyImpl(80,CZK));
|
japod@34
|
16 |
|
japod@34
|
17 |
@Test
|
japod@34
|
18 |
public void testCompose()
|
japod@34
|
19 |
{
|
japod@34
|
20 |
ExtendedConvertor convertor = new CompositeConvertor(USD_CZK_CONVERTOR, SKK_CZK_CONVERTOR);
|
japod@34
|
21 |
assertTrue(convertor.isConversionSupported(CZK, SKK));
|
japod@34
|
22 |
assertTrue(convertor.isConversionSupported(CZK, USD));
|
japod@34
|
23 |
assertFalse(convertor.isConversionSupported(SKK, USD));
|
japod@34
|
24 |
assertEquals(new MoneyImpl(10,SKK), convertor.convert(new MoneyImpl(8,CZK), SKK));
|
japod@34
|
25 |
assertEquals(new MoneyImpl(2,USD), convertor.convert(new MoneyImpl(34,CZK), USD));
|
japod@34
|
26 |
try
|
japod@34
|
27 |
{
|
japod@34
|
28 |
convertor.convert(new MoneyImpl(34,SKK), USD);
|
japod@34
|
29 |
fail("Exception expected");
|
japod@34
|
30 |
}
|
japod@34
|
31 |
catch(IllegalArgumentException e)
|
japod@34
|
32 |
{
|
japod@34
|
33 |
assertTrue("Ok", true);
|
japod@34
|
34 |
}
|
japod@34
|
35 |
}
|
japod@34
|
36 |
@Test
|
japod@34
|
37 |
public void testEmpty()
|
japod@34
|
38 |
{
|
japod@34
|
39 |
ExtendedConvertor convertor = new CompositeConvertor();
|
japod@34
|
40 |
assertFalse(convertor.isConversionSupported(SKK, USD));
|
japod@34
|
41 |
try
|
japod@34
|
42 |
{
|
japod@34
|
43 |
convertor.convert(new MoneyImpl(34,SKK), USD);
|
japod@34
|
44 |
fail("Exception expected");
|
japod@34
|
45 |
}
|
japod@34
|
46 |
catch(IllegalArgumentException e)
|
japod@34
|
47 |
{
|
japod@34
|
48 |
assertTrue("Ok", true);
|
japod@34
|
49 |
}
|
japod@34
|
50 |
}
|
japod@34
|
51 |
@Test(expected=NullPointerException.class)
|
japod@34
|
52 |
public void testCreateNull()
|
japod@34
|
53 |
{
|
japod@34
|
54 |
new CompositeConvertor(USD_CZK_CONVERTOR, null);
|
japod@34
|
55 |
}
|
japod@34
|
56 |
}
|