Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • team13/tdat1006
  • eivindrt/tdat1006
  • alexholt/idatt1002
  • elinang/idatt1002
  • surya/idatt1002
  • kjellit/idata-1002-demo-project
  • eskillr/idatt1002
  • G1-06/idatt-1002-2022-1-06
  • emillaa/idatt1002
  • andreksv/idatt-1002-2023-9
  • melane/idatt-1002-2023-5
  • ramtinfs/idatt1002
  • surya/idatx1005
  • itatt1005_2024_group15/purchase-planner
  • systemutvikling-gruppe-19/idatt-1005-2024-group-19
15 results
Show changes
Commits on Source (2)
package no.ntnu.idatt1002.demo.data;
public enum Category {
FOOD,
CLOTHES,
OTHER,
}
package no.ntnu.idatt1002.demo.data;
public class Item {
private Category category;
private String description = "";
private float price;
public Item (Category category, float price){
if(category == null || price <= 1.0f) {
throw new IllegalArgumentException("The item must have a category and a price.");
} else {
this.category = category;
this.price = price;
}
}
public Item (Category category, String description, float price){
this(category, price);
this.description=description;
}
public Category getCategory() {
return category;
}
public void setCategory(Category category) {
this.category = category;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public float getPrice() {
return price;
}
public void setPrice(float price) {
this.price = price;
}
/* @Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (obj.getClass() != this.getClass()) {
return false;
}
final Item otherItem = (Item) obj;
return true;
*//*return Objects.equals(true);*//*
}*/
}
package no.ntnu.idatt1002.demo.data;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class ItemTest {
@Test
@DisplayName("The Item constructor throws exceptions when it should.")
void constructorThrows(){
Exception noCategory = assertThrows(IllegalArgumentException.class, () -> new Item(null, "description", 89.9f));
assertEquals("The item must have a category and a price.", noCategory.getMessage());
Exception noPrice = assertThrows(IllegalArgumentException.class, () -> new Item(Category.OTHER, "description", 0f));
assertEquals("The item must have a category and a price.", noPrice.getMessage());
};
@Test
@DisplayName("The Item constructor does not throw exceptions when it should not.")
void constructorDoesThrow() {
assertDoesNotThrow(() -> new Item(Category.OTHER, "descriotion", 59.9f));
}
}
\ No newline at end of file