01 package fr.isae.bank;
02
03 import org.junit.*;
04 import static org.junit.Assert.*;
05
06 /**
07 * Unit Test for class CompteCourant.
08 *
09 *
10 * Created: Wed Nov 30 22:28:22 2005
11 *
12 * @author <a href="mailto:garion@isae.fr">Christophe Garion</a>
13 * @version 1.0
14 */
15 public class CompteCourantTest extends CompteSimpleTest {
16
17 private CompteCourant cc;
18 private Historique hist;
19 private String[] tabC = {"depot cheque 1", "depot cheque 2", "depot cheque 3"};
20 private double[] tabMC = {100, 200, 300};
21 private String[] tabD = {"retrait 1", "retrait 2", "retrait 3"};
22 private double[] tabMD = {20, 20, 40};
23
24 protected CompteSimple createCompte(Personne p, double solde) {
25 return new CompteCourant(p, solde);
26 }
27
28 @Before public void setUp() {
29 super.setUp();
30 this.cc = new CompteCourant(new Personne("Christophe", "Garion", true),
31 1000);
32 this.hist = this.cc.getHistorique();
33 }
34
35 @Test public void testCrediterWithIntitule() {
36 this.cc.crediter("depot cheque", 100);
37 Assert.assertEquals(1100, this.cc.getSolde(), 0.0);
38 }
39
40 @Test public void testDebiterWithIntitule() {
41 this.cc.debiter("retrait", 300);
42 Assert.assertEquals(700, this.cc.getSolde(), 0.0);
43 }
44
45 @Test public void testHistoriqueCreation() {
46 for (String intitule : this.hist) {
47 Assert.assertEquals("depot initial", intitule);
48 Assert.assertEquals(1000, this.hist.get(intitule), 0.0);
49 }
50 }
51
52 @Test public void testHistoriqueCrediter() {
53 for (int i = 0; i < this.tabC.length; i++) {
54 this.cc.crediter(tabC[i], tabMC[i]);
55 }
56
57 int i = 0;
58 for (String intitule : this.hist) {
59 if (!intitule.equals("depot initial")) {
60 Assert.assertEquals(tabC[i], intitule);
61 Assert.assertEquals(tabMC[i], this.hist.get(intitule), 0.0);
62 i++;
63 }
64 }
65 }
66
67 @Test public void testHistoriqueDebiter() {
68 for (int i = 0; i < this.tabD.length; i++) {
69 this.cc.crediter(tabD[i], tabMD[i]);
70 }
71
72 int i = 0;
73 for (String intitule : this.hist) {
74 if (!intitule.equals("depot initial")) {
75 Assert.assertEquals(tabD[i], intitule);
76 Assert.assertEquals(tabMD[i], this.hist.get(intitule), 0.0);
77 i++;
78 }
79 }
80 }
81 }
|