Advertisement
Scorpionh

BCO TP2 EXO3

Apr 10th, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.42 KB | None | 0 0
  1. // COMMANDE
  2. package Commande;
  3.  
  4.  
  5.  
  6. public class Commande {
  7.     int numero;
  8.     boolean estPayee;
  9.     boolean estLivree;
  10.    
  11.     public Commande (int num) {
  12.         this.numero = num;
  13.         this.estPayee = false;
  14.         this.estLivree = false;
  15.     }
  16.    
  17.     public boolean estPayee () {
  18.         return this.estPayee;
  19.     }
  20.    
  21.     public void payer () {
  22.         this.estPayee = true;
  23.     }
  24.    
  25.     public void rembourser () {
  26.         if (this.estlivree == false)
  27.             this.estPayee = false;
  28.     }
  29.    
  30.     public boolean estLivree () {
  31.         return this.estLivree;
  32.     }
  33.    
  34.     public void livraison () {
  35.         this.estLivree = true;
  36.     }
  37. }
  38.  
  39.  
  40. //ENUM
  41. package Commande;
  42.  
  43. public enum EtatsCommande {
  44.     Payee,
  45.     NonPayee,
  46.     Livre
  47. }
  48.  
  49.  
  50. //TEST
  51.  
  52. package Commande;
  53.  
  54. import static org.junit.Assert.*;
  55.  
  56. import org.junit.Test;
  57.  
  58.  
  59. public class TestCommande {
  60.    
  61.     private EtatsCommande getEtatCommande (Commande uneCommande) {
  62.         if (uneCommande.estPayee () == false) //&& uneCommande.estLivree() == false)
  63.             return EtatsCommande.NonPayee;
  64.         else {
  65.             if (uneCommande.estLivree == true)
  66.                 return EtatsCommande.Livre;
  67.             else
  68.                 return EtatsCommande.Payee;
  69.         }
  70.            
  71.     }
  72.         @Test
  73.         public void testEtatInitial () {
  74.             // Given
  75.             Commande com = new Commande (1);
  76.             // Then
  77.             assertEquals (EtatsCommande.NonPayee, this.getEtatCommande(com));
  78.         }
  79.  
  80.        
  81.         @Test
  82.         public void testTransitionPayer () {
  83.             // Given
  84.             Commande com = new Commande (1);
  85.             // When
  86.             com.payer ();
  87.             // Then
  88.             assertEquals (EtatsCommande.Payee, this.getEtatCommande (com));
  89.         }
  90.        
  91.         @Test
  92.         public void testTransitionRembourser () {
  93.             // Given
  94.             Commande com = new Commande (2);
  95.             // When
  96.             com.rembourser ();
  97.             // Then
  98.             assertNotEquals (EtatsCommande.Payee, this.getEtatCommande (com));
  99.         }
  100.  
  101.         @Test
  102.         public void testTransitionPayerLivrer () {
  103.             Commande com = new Commande (3);
  104.             // When
  105.             com.payer ();
  106.             com.livraison();
  107.             assertEquals(EtatsCommande.Livre, this.getEtatCommande(com));
  108.         }
  109.        
  110.         @Test
  111.         public void testTransitionNonpayerLivrer() {
  112.             Commande com = new Commande (4);
  113.             // When
  114.             com.livraison();
  115.             assertNotEquals(EtatsCommande.Livre, this.getEtatCommande(com));
  116.         }
  117.        
  118.         @Test
  119.         public void testTransitionPayerLivrerRembourser () { // DON'T WORK Reste dans l'état livré et payé
  120.             Commande com = new Commande (5);
  121.             // When
  122.             com.payer ();
  123.             com.livraison();
  124.             com.rembourser();
  125.             assertEquals(EtatsCommande.Payee, this.getEtatCommande(com));
  126.         }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement