Beispielhafte equals-Methode bei Produkt eingefügt und mit Testfall

überprüft
main
hummel 2025-12-09 10:36:46 +01:00
parent c545955856
commit 1fa6523125
2 changed files with 30 additions and 2 deletions

View File

@ -12,4 +12,15 @@ public class Produkt {
public String toString() {
return this.name + " " + this.preis + " Euro.";
}
public boolean equals(Object o) {
if (!(o instanceof Produkt))
return false;
if (!this.name.equals(((Produkt)o).name)
|| this.preis != ((Produkt)o).preis)
return false;
return true;
}
}

View File

@ -0,0 +1,17 @@
package de.th_mannheim.informatik.shop.backend;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
class ProduktTest {
@Test
void test() {
Produkt p1 = new Produkt("Wein", 3.50);
Produkt p2 = new Produkt("Wein", 3.50);
assertTrue(p1.equals(p2));
}
}