Skip to content
Snippets Groups Projects

Product.java perustestit ja virheilmoitukset

Merged lassipii requested to merge Lbranch into master
2 files
+ 46
19
Compare changes
  • Side-by-side
  • Inline
Files
2
@@ -4,22 +4,22 @@ import javax.persistence.*;
@Entity
@Table(name = "Tuote")
public class Product{
public class Product {
@Id
@Column(name = "ID", updatable = false, nullable = false)
private int id;
@Column(name="Nimi")
private String name;
@Column(name="Kuvaus")
@Column(name = "Nimi")
private String name;
@Column(name = "Kuvaus")
private String description;
@Column(name="Hinta")
@Column(name = "Hinta")
private int price;
@Column(name="Varastomäärä")
@Column(name = "Varastomäärä")
private int stock;
public Product(){
public Product() {
}
@@ -31,39 +31,49 @@ public class Product{
this.stock = stock;
}
public int getId() { return id; }
public int getId() {
return id;
}
public void setId(int id) { this.id = id; }
public void setId(int id) {
this.id = id;
}
public String getName() {
public String getName() {
return name;
}
public void setName(String name) {
public void setName(String name) {
this.name = name;
}
public String getDescription() {
public String getDescription() {
return description;
}
public void setDescription(String description) {
public void setDescription(String description) {
this.description = description;
}
public int getPrice() {
public int getPrice() {
return price;
}
public void setPrice(int price) {
public void setPrice(int price) {
if(price<0){
throw new RuntimeException("Negative price for a product is not accepted");
}
this.price = price;
}
public int getStock() {
public int getStock() {
return stock;
}
public void setStock(int stock) {
public void setStock(int stock) {
if(stock<0){
throw new RuntimeException("Negative stock for a product is not accepted");
}
this.stock = stock;
}
@@ -74,8 +84,12 @@ public class Product{
@Override
public boolean equals(Object o) {
if (o == null) { return false; }
if (o.getClass() != this.getClass()) { return false; }
if (o == null) {
return false;
}
if (o.getClass() != this.getClass()) {
return false;
}
final Product product = (Product) o;
Loading