Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // COMMANDE
- package Commande;
- public class Commande {
- int numero;
- boolean estPayee;
- boolean estLivree;
- public Commande (int num) {
- this.numero = num;
- this.estPayee = false;
- this.estLivree = false;
- }
- public boolean estPayee () {
- return this.estPayee;
- }
- public void payer () {
- this.estPayee = true;
- }
- public void rembourser () {
- if (this.estlivree == false)
- this.estPayee = false;
- }
- public boolean estLivree () {
- return this.estLivree;
- }
- public void livraison () {
- this.estLivree = true;
- }
- }
- //ENUM
- package Commande;
- public enum EtatsCommande {
- Payee,
- NonPayee,
- Livre
- }
- //TEST
- package Commande;
- import static org.junit.Assert.*;
- import org.junit.Test;
- public class TestCommande {
- private EtatsCommande getEtatCommande (Commande uneCommande) {
- if (uneCommande.estPayee () == false) //&& uneCommande.estLivree() == false)
- return EtatsCommande.NonPayee;
- else {
- if (uneCommande.estLivree == true)
- return EtatsCommande.Livre;
- else
- return EtatsCommande.Payee;
- }
- }
- @Test
- public void testEtatInitial () {
- // Given
- Commande com = new Commande (1);
- // Then
- assertEquals (EtatsCommande.NonPayee, this.getEtatCommande(com));
- }
- @Test
- public void testTransitionPayer () {
- // Given
- Commande com = new Commande (1);
- // When
- com.payer ();
- // Then
- assertEquals (EtatsCommande.Payee, this.getEtatCommande (com));
- }
- @Test
- public void testTransitionRembourser () {
- // Given
- Commande com = new Commande (2);
- // When
- com.rembourser ();
- // Then
- assertNotEquals (EtatsCommande.Payee, this.getEtatCommande (com));
- }
- @Test
- public void testTransitionPayerLivrer () {
- Commande com = new Commande (3);
- // When
- com.payer ();
- com.livraison();
- assertEquals(EtatsCommande.Livre, this.getEtatCommande(com));
- }
- @Test
- public void testTransitionNonpayerLivrer() {
- Commande com = new Commande (4);
- // When
- com.livraison();
- assertNotEquals(EtatsCommande.Livre, this.getEtatCommande(com));
- }
- @Test
- public void testTransitionPayerLivrerRembourser () { // DON'T WORK Reste dans l'état livré et payé
- Commande com = new Commande (5);
- // When
- com.payer ();
- com.livraison();
- com.rembourser();
- assertEquals(EtatsCommande.Payee, this.getEtatCommande(com));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement