package commande.etats;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;

import commande.Commande;
import commande.CommandeNonLivrableEx;
import commande.CommandeNonPayableException;
import commande.CommandeNonRemboursableEx;

class CommandeTest {

	private Commande c;

	@BeforeEach
	void init() {
		c = new Commande(1, new Creee(c));
	}

	@Test
	void test() {
		assertThrows(CommandeNonLivrableEx.class, new Executable() {

			@Override
			public void execute() throws Throwable {
				c.livrer();
			}

		});

		assertThrows(CommandeNonRemboursableEx.class, new Executable() {

			@Override
			public void execute() throws Throwable {
				c.rembourser();
			}

		});
		c.payer();
		assertEquals(c.getEtat(), "Payee");

		assertThrows(CommandeNonPayableException.class, new Executable() {

			@Override
			public void execute() throws Throwable {
				c.payer();
			}

		});
		
		c.livrer();
		assertEquals(c.getEtat(),"Livree");
		
		assertThrows(CommandeNonPayableException.class, new Executable() {

			@Override
			public void execute() throws Throwable {
				c.payer();
			}

		});
		
		assertThrows(CommandeNonRemboursableEx.class, new Executable() {

			@Override
			public void execute() throws Throwable {
				c.rembourser();
			}

		});
		
		assertThrows(CommandeNonLivrableEx.class, new Executable() {

			@Override
			public void execute() throws Throwable {
				c.livrer();
			}

		});
	}
	
	@Test
	void testRebourser() {
		c.payer();
		c.rembourser();
		assertEquals(c.getEtat(),"Creee");
	}

}
