correction get et set de Property

This commit is contained in:
trochas
2024-12-04 17:18:27 +01:00
parent e68e2771ed
commit f9c6059067
2 changed files with 6 additions and 10 deletions

View File

@@ -21,26 +21,22 @@ public class Exterior extends PartImpl {
colorSet.add("gray"); colorSet.add("gray");
} }
private String color;
public Exterior(String name, CategoryImpl category, int price){ public Exterior(String name, CategoryImpl category, int price){
super(new PartTypeImpl(name,Engine.class, category),price); super(new PartTypeImpl(name,Engine.class, category),price);
Set<String> l = new HashSet<String>(); Set<String> l = new HashSet<String>();
l.add("red"); l.add("red");
this.addProperty("color", () -> getColor(), p -> setColor(p), colorSet); this.addProperty("color", () -> getColor(), c -> setColor(c), colorSet);
} }
public String getColor(){ public String getColor(){
String result = "white"; return this.color;
Optional<String> color = this.getProperty("color");
if(color.isPresent()){
result = color.get();
}
return result;
} }
public void setColor(String newColor){ public void setColor(String newColor){
this.setProperty("color",newColor); this.color = newColor;
} }
} }

View File

@@ -221,8 +221,8 @@ public class test {
@Test @Test
public void test_PropertyInteriorColor(){ public void test_PropertyInteriorColor(){
XS.setColor("red"); XS.setProperty("color","red");
assertTrue(XS.getColor()=="red"); assertTrue(XS.getProperty("color").get()=="red");
} }