correction get et set de Property
This commit is contained in:
@@ -21,26 +21,22 @@ public class Exterior extends PartImpl {
|
||||
colorSet.add("gray");
|
||||
}
|
||||
|
||||
private String color;
|
||||
|
||||
public Exterior(String name, CategoryImpl category, int price){
|
||||
super(new PartTypeImpl(name,Engine.class, category),price);
|
||||
|
||||
Set<String> l = new HashSet<String>();
|
||||
l.add("red");
|
||||
this.addProperty("color", () -> getColor(), p -> setColor(p), colorSet);
|
||||
this.addProperty("color", () -> getColor(), c -> setColor(c), colorSet);
|
||||
}
|
||||
|
||||
|
||||
public String getColor(){
|
||||
String result = "white";
|
||||
Optional<String> color = this.getProperty("color");
|
||||
if(color.isPresent()){
|
||||
result = color.get();
|
||||
}
|
||||
return result;
|
||||
return this.color;
|
||||
}
|
||||
|
||||
public void setColor(String newColor){
|
||||
this.setProperty("color",newColor);
|
||||
this.color = newColor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,8 +221,8 @@ public class test {
|
||||
|
||||
@Test
|
||||
public void test_PropertyInteriorColor(){
|
||||
XS.setColor("red");
|
||||
assertTrue(XS.getColor()=="red");
|
||||
XS.setProperty("color","red");
|
||||
assertTrue(XS.getProperty("color").get()=="red");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user