Commit 301aab31 authored by LucasDANIELE's avatar LucasDANIELE
Browse files

Tests de la piece

parent dd1249d3
package fr.insarouen.asi.prog.asiaventure.elements.structure;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.hamcrest.core.IsEqual;
import org.junit.Test;
import fr.insarouen.asi.prog.asiaventure.*;
import fr.insarouen.asi.prog.asiaventure.elements.*;
import fr.insarouen.asi.prog.asiaventure.elements.objets.*;
import fr.insarouen.asi.prog.asiaventure.elements.vivants.*;
import fr.insarouen.asi.prog.asiaventure.elements.structure.*;
import static org.hamcrest.core.AllOf.allOf;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.*;
public class TestPiece{
private Monde monde;
private String nom;
private Piece piece;
@Before
public void init()throws NomDEntiteDejaUtiliseDansLeMondeException, EntiteDejaDansUnAutreMondeException {
monde = new Monde("monde");
nom = "Chambre";
piece = new Piece(monde, nom);
}
@Test(expected = NomDEntiteDejaUtiliseDansLeMondeException.class)
public void creationDoublonPiece() throws NomDEntiteDejaUtiliseDansLeMondeException{
Piece p1 = new Piece(monde, nom);
}
@Test
public void deposerTest() throws NomDEntiteDejaUtiliseDansLeMondeException{
Objet o = new Objet("GelHydro",monde){
public boolean estDeplacable(){
return true;
}
};
piece.deposer(o);
assertThat(piece.contientObjet(o),IsEqual.equalTo(true));
}
@Test
public void retirerTest() throws NomDEntiteDejaUtiliseDansLeMondeException,ObjetAbsentDeLaPieceException,ObjetNonDeplacableException {
Objet o = new Objet("GelHydro",monde){
public boolean estDeplacable(){
return true;
}
};
piece.deposer(o);
assertThat(piece.contientObjet(o),IsEqual.equalTo(true));
piece.retirer(o);
assertThat(piece.contientObjet(o),IsEqual.equalTo(false));
piece.deposer(o);
assertThat(piece.contientObjet(o),IsEqual.equalTo(true));
piece.retirer(o.getNom());
assertThat(piece.contientObjet(o),IsEqual.equalTo(false));
}
@Test
public void contientObjetTest() throws NomDEntiteDejaUtiliseDansLeMondeException, ObjetAbsentDeLaPieceException, ObjetNonDeplacableException{
Objet o = new Objet("GelHydro",monde){
public boolean estDeplacable(){
return true;
}
};
assertThat(piece.contientObjet(o), IsEqual.equalTo(false));
assertThat(piece.contientObjet(o.getNom()), IsEqual.equalTo(false));
piece.deposer(o);
assertThat(piece.contientObjet(o), IsEqual.equalTo(true));
assertThat(piece.contientObjet(o.getNom()), IsEqual.equalTo(true));
piece.retirer(o);
}
@Test
public void getObjets() throws NomDEntiteDejaUtiliseDansLeMondeException{
Objet o1 = new Objet("GelHydro",monde){
public boolean estDeplacable(){
return true;
}
};
Objet o2 = new Objet("Masque",monde){
public boolean estDeplacable(){
return true;
}
};
Objet [] o = new Objet[2];
o[0]=o1;
o[1]=o2;
piece.deposer(o1);
piece.deposer(o2);
assertThat(piece.getObjets(),IsEqual.equalTo(o));
}
@Test
public void entrerTest() throws NomDEntiteDejaUtiliseDansLeMondeException, VivantAbsentDeLaPieceException{
Objet o = new Objet("GelHydro",monde){
public boolean estDeplacable(){
return true;
}
};
Vivant v = new Vivant("v", monde, 10, 10, null, o){};
piece.entrer(v);
assertThat(piece.contientVivant(v),IsEqual.equalTo(true));
piece.sortir(v);
}
@Test
public void sortirTest() throws NomDEntiteDejaUtiliseDansLeMondeException,VivantAbsentDeLaPieceException {
Objet o = new Objet("GelHydro",monde){
public boolean estDeplacable(){
return true;
}
};
Vivant v = new Vivant("v", monde, 10, 10, null, o){};
piece.entrer(v);
assertThat(piece.contientVivant(v),IsEqual.equalTo(true));
piece.sortir(v);
assertThat(piece.contientVivant(v),IsEqual.equalTo(false));
piece.entrer(v);
assertThat(piece.contientVivant(v),IsEqual.equalTo(true));
piece.sortir(v.getNom());
assertThat(piece.contientVivant(v),IsEqual.equalTo(false));
}
@Test
public void contientVivantTest() throws NomDEntiteDejaUtiliseDansLeMondeException, VivantAbsentDeLaPieceException{
Objet o = new Objet("GelHydro",monde){
public boolean estDeplacable(){
return true;
}
};
Vivant v = new Vivant("v", monde, 10, 10, null, o){};
assertThat(piece.contientVivant(v),IsEqual.equalTo(false));
assertThat(piece.contientVivant(v.getNom()),IsEqual.equalTo(false));
piece.entrer(v);
assertThat(piece.contientVivant(v),IsEqual.equalTo(true));
assertThat(piece.contientVivant(v.getNom()),IsEqual.equalTo(true));
piece.sortir(v);
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment