task4/solution02/test/org/apidesign/apifest08/test/ConvertorFactoryTest.java
changeset 61 58ec6da75f6f
parent 45 251d0ed461fb
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/task4/solution02/test/org/apidesign/apifest08/test/ConvertorFactoryTest.java	Sat Oct 11 23:38:46 2008 +0200
     1.3 @@ -0,0 +1,52 @@
     1.4 +package org.apidesign.apifest08.test;
     1.5 +
     1.6 +import static junit.framework.Assert.assertNotNull;
     1.7 +import static org.apidesign.apifest08.test.Task1Test.CZK;
     1.8 +import static org.apidesign.apifest08.test.Task1Test.USD;
     1.9 +import static org.junit.Assert.assertEquals;
    1.10 +import static org.junit.Assert.assertTrue;
    1.11 +import static org.junit.Assert.fail;
    1.12 +
    1.13 +import org.apidesign.apifest08.currency.Convertor;
    1.14 +import org.apidesign.apifest08.currency.ConvertorFactory;
    1.15 +import org.apidesign.apifest08.currency.MoneyImpl;
    1.16 +import org.junit.Test;
    1.17 +
    1.18 +
    1.19 +public class ConvertorFactoryTest {
    1.20 +	@Test(expected=NullPointerException.class)
    1.21 +	public void testNullSource()
    1.22 +	{
    1.23 +		ConvertorFactory.createConvertor(null, new MoneyImpl(1,USD));
    1.24 +	}
    1.25 +	@Test(expected=NullPointerException.class)
    1.26 +	public void testNullDestination()
    1.27 +	{
    1.28 +		ConvertorFactory.createConvertor(new MoneyImpl(17,CZK), null);
    1.29 +	}
    1.30 +	@Test
    1.31 +	public void testOk()
    1.32 +	{
    1.33 +		assertNotNull(ConvertorFactory.createConvertor(new MoneyImpl(17,CZK),  new MoneyImpl(1,USD)));
    1.34 +	}
    1.35 +	@Test
    1.36 +	public void testOkDecimalRate()
    1.37 +	{
    1.38 +		Convertor c = ConvertorFactory.createConvertor(new MoneyImpl(1,CZK),  new MoneyImpl(1d/17d,USD));
    1.39 +		assertNotNull(c);
    1.40 +		assertEquals(new MoneyImpl(17,CZK),c.convert(new MoneyImpl(1,USD), CZK));
    1.41 +	}
    1.42 +	@Test
    1.43 +	public void testZeroEquivalentRate()
    1.44 +	{
    1.45 +		try
    1.46 +		{
    1.47 +			ConvertorFactory.createConvertor(new MoneyImpl(1,CZK),  new MoneyImpl(0,USD));
    1.48 +			fail("Exception expected");
    1.49 +		}
    1.50 +		catch(IllegalArgumentException e)
    1.51 +		{
    1.52 +			assertTrue("OK",true);
    1.53 +		}
    1.54 +	}
    1.55 +}