package tests; import oqube.salestaxes.Imported; import oqube.salestaxes.Item; import oqube.salestaxes.Sales; import oqube.salestaxes.SalesTax; import junit.framework.Assert; import org.junit.Test; public class SalesTest { @Test(expected=IllegalArgumentException.class) public void casAddException() { /* L'argument good ne doit pas être null. * Or cela ne lui pose aucun problème de passer null */ Sales sales = new Sales(); sales.add(null); } @Test public void casAddCorrect() { /* OK */ Sales sales = new Sales(); Sales res = sales.add(new SalesTax(new Item("chocolat", 2))); Assert.assertSame(sales, res); } @Test public void casPriceCorrect1() { /* Produits avec taxes */ Sales sales = new Sales(); sales = sales.add(new SalesTax(new Item("chocolat", 2))); sales = sales.add(new Imported(new Item("CD", 10))); Assert.assertEquals(12.7, sales.price(), 0); } @Test public void casPriceCorrect2() { /* Produits sans taxes */ Sales sales = new Sales(); sales = sales.add(new Item("chocolat", 2)); sales = sales.add(new Item("CD", 10)); Assert.assertEquals(12, sales.price(), 0); } @Test public void casPriceIncorrect() { /* Produits avec taxes */ Sales sales = new Sales(); sales = sales.add(new SalesTax(new Item("chocolat", 2))); sales = sales.add(new Imported(new Item("CD", 20))); Assert.assertFalse(Double.compare(22, sales.price()) == 0); } @Test public void casTaxesCorrect() { Sales sales = new Sales(); sales = sales.add(new SalesTax(new Item("chocolat", 2))); sales = sales.add(new Imported(new Item("CD", 100))); Assert.assertEquals(5.2, sales.taxes(), 0); } @Test public void casTaxesIncorrect() { Sales sales = new Sales(); sales = sales.add(new SalesTax(new Item("chocolat", 2))); sales = sales.add(new Imported(new Item("CD", 100))); Assert.assertFalse(Double.compare(2.2, sales.taxes()) == 0); } }