Commit 46d9a61d authored by Antoine Hazebrouck's avatar Antoine Hazebrouck

refactor ingredients

parent fa03581c
...@@ -3,6 +3,7 @@ package imt; ...@@ -3,6 +3,7 @@ package imt;
import imt.ingredients.Consigne; import imt.ingredients.Consigne;
import imt.ingredients.Ingredient; import imt.ingredients.Ingredient;
import imt.ingredients.Legume; import imt.ingredients.Legume;
import imt.ingredients.Plat;
import imt.ingredients.ViandePoisson; import imt.ingredients.ViandePoisson;
public class Application { public class Application {
......
package imt.ingredients; package imt.ingredients;
public class Autre extends Ingredient { import lombok.Data;
private int calories; import lombok.EqualsAndHashCode;
private boolean bio;
public Autre(int idIngredient, String nomIngredient, int calories, boolean bio) {
super(idIngredient, nomIngredient);
this.calories = calories;
this.bio = bio;
}
public int getCalories() {
return calories;
}
public void setCalories(int calories) { @EqualsAndHashCode(callSuper = true)
this.calories = calories; @Data
} public class Autre extends Ingredient {
public boolean getBio() {
return bio;
}
public void setBio(boolean bio) { public Autre(int idIngredient, String nomIngredient, int quantité, int calories, boolean bio,
this.bio = bio; Consigne[] consignes) {
} super(idIngredient, nomIngredient, quantité, calories, bio, consignes);
}
public String toString() {
return super.toString() + " Autre [calories=" + calories + ", bio=" + bio + "]";
}
} }
package imt.ingredients; package imt.ingredients;
public class Epice extends Ingredient{ import lombok.Data;
private Boolean bio; import lombok.EqualsAndHashCode;
public Epice(int idIngredient, String nomIngredient, Boolean bio) { @EqualsAndHashCode(callSuper = true)
super(idIngredient, nomIngredient); @Data
this.bio = bio; public class Epice extends Ingredient {
}
public Boolean getBio() { public Epice(int idIngredient, String nomIngredient, int quantité, int calories, boolean bio,
return bio; Consigne[] consignes) {
} super(idIngredient, nomIngredient, quantité, 0, bio, consignes);
}
public void setBio(Boolean bio) {
this.bio = bio;
}
public String toString() {
return super.toString() + " Epice [bio=" + bio + "]";
}
} }
package imt.ingredients; package imt.ingredients;
public class Ingredient { import lombok.Data;
private int idIngredient;
private String nomIngredient; @Data
private int quantité; public abstract class Ingredient {
private Consigne[] consignes; private final int idIngredient;
private final String nomIngredient;
public Ingredient(int idIngredient, String nomIngredient) { private final int quantité;
this.idIngredient = idIngredient; private final int calories;
this.nomIngredient = nomIngredient; private final boolean bio;
this.quantité = 0; private final Consigne[] consignes;
this.consignes = null;
}
public int getIdIngredient() {
return idIngredient;
}
public void setIdIngredient(int idIngredient) {
this.idIngredient = idIngredient;
}
public String getNomIngredient() {
return nomIngredient;
}
public void setNomIngredient(String nomIngredient) {
this.nomIngredient = nomIngredient;
}
public int getQuantité() {
return quantité;
}
public void setQuantité(int quantité) {
this.quantité = quantité;
}
public Consigne[] getConsignes() {
return consignes;
}
public void setConsignes(Consigne[] consignes) {
this.consignes = consignes;
}
public String toString() {
String strConsigne = "";
for (int i = 0; i < consignes.length; i++) {
strConsigne += consignes[i].toString()+", ";
}
return "Ingredient [idIngredient=" + idIngredient + ", nomIngredient=" + nomIngredient + ", Consignes=" + strConsigne + "]";
}
} }
package imt.ingredients; package imt.ingredients;
public class Legume extends Ingredient{ import lombok.Data;
private int calories; import lombok.EqualsAndHashCode;
private boolean bio;
public Legume(int idIngredient, String nomIngredient, int calories, boolean bio) { @EqualsAndHashCode(callSuper = true)
super(idIngredient, nomIngredient); @Data
this.calories = calories; public class Legume extends Ingredient {
this.bio = bio; private final int fibres;
}
public int getCalories() { public Legume(int idIngredient, String nomIngredient, int quantité, int calories, boolean bio,
return calories; Consigne[] consignes, int fibres) {
} super(idIngredient, nomIngredient, quantité, calories, bio, consignes);
this.fibres = fibres;
}
public void setCalories(int calories) {
this.calories = calories;
}
public boolean getBio() {
return bio;
}
public void setBio(boolean bio) {
this.bio = bio;
}
public String toString() {
return super.toString() + " Legume [calories=" + calories + ", bio=" + bio + "]";
}
} }
package imt.ingredients; package imt.ingredients;
public class ViandePoisson extends Ingredient{ import lombok.Data;
private int calories; import lombok.EqualsAndHashCode;
private int gras;
@EqualsAndHashCode(callSuper = true)
public ViandePoisson(int idIngredient, String nomIngredient, int calories, int gras) { @Data
super(idIngredient, nomIngredient); public class ViandePoisson extends Ingredient {
this.calories = calories; private final int gras;
this.gras = gras;
} public ViandePoisson(int idIngredient, String nomIngredient, int quantité, int calories, boolean bio,
Consigne[] consignes, int gras) {
public int getCalories() { super(idIngredient, nomIngredient, quantité, calories, bio, consignes);
return calories; this.gras = gras;
} }
public void setCalories(int calories) {
this.calories = calories;
}
public int getGras() {
return gras;
}
public void setGras(int gras) {
this.gras = gras;
}
public String toString() {
return super.toString() + " Viande/Poisson [calories=" + calories + ", gras=" + gras + "]";
}
} }
\ No newline at end of file
package imt.ingredients;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
public class IngredientTest {
public static final Ingredient STEAK = new ViandePoisson(1, "steak", 1, 10, true, null, 0);
public static final Ingredient OIGNON = new Legume(2, "oignon", 1, 20, true, null, 0);
public static final Ingredient AUTRE = new Autre(3, "autre", 1, 30, false, null);
@Test
void epice_apportent_zero_calories() {
Ingredient epice = new Epice(1, "poivre", 1, 10, false, null);
assertThat(epice.getCalories()).isEqualTo(0);
}
@Test
void le_reste_apporte_des_calories() {
assertThat(STEAK.getCalories()).isEqualTo(10);
assertThat(OIGNON.getCalories()).isEqualTo(20);
assertThat(AUTRE.getCalories()).isEqualTo(30);
}
}
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