parent
c545955856
commit
1fa6523125
|
|
@ -3,13 +3,24 @@ package de.th_mannheim.informatik.shop.backend;
|
||||||
public class Produkt {
|
public class Produkt {
|
||||||
String name;
|
String name;
|
||||||
double preis;
|
double preis;
|
||||||
|
|
||||||
public Produkt(String name, double preis) {
|
public Produkt(String name, double preis) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.preis = preis;
|
this.preis = preis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return this.name + " " + this.preis + " Euro.";
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue