#Test Methoden implementiert für ONline shop, cart, product

main
Daniel Zikol 2025-12-15 11:53:33 +01:00
parent fc3ef498e2
commit 4d105abbf8
6 changed files with 43 additions and 6 deletions

View File

@ -2,9 +2,5 @@
Shop Testat
Genutzte JDK version ----> Java 25
public static void main(............) wird zu void main
System.out.print ist IO.print
Shop besteht aus resources und src
IML dateien werden gepushed, da ich kein aktives Build System nutze

View File

@ -83,3 +83,5 @@ https://softwareengineering.stackexchange.com/questions/347505/how-to-design-the
Shopping Cart Java Application (addToCart)
https://stackoverflow.com/questions/18473130/shopping-cart-java-application-addtocart
Arrange,act, assert
https://java-design-patterns.com/patterns/arrange-act-assert/

View File

@ -131,7 +131,7 @@ public class ShopTUI {
IO.println("\nYour shopping cart:");
IO.println("----------------------------------------");
for (CartPosition pos : cart.getPositions()) {
IO.println(pos);
IO.println(pos.getProduct());
}
IO.println("----------------------------------------");
IO.println(String.format("Product value (net): %6.2f €", tempOrder.getTotalNet()));

View File

@ -4,6 +4,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
class CartTest {
private Cart cart;
@ -23,4 +24,11 @@ class CartTest {
}
@Test
public void testClear() {
cart.addProduct(product1, 2);
cart.clear();
assertTrue(cart.isEmpty());
}
}

View File

@ -1,5 +1,33 @@
package shop.backend;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import static org.junit.jupiter.api.Assertions.*;
class OnlineShopTest {
private OnlineShop onlineShop;
@BeforeEach
public void setUp() {
onlineShop = new OnlineShop();
ArrayList<String> lines = new ArrayList<>();
lines.add("ID,Name,Gewicht,Nettopreis,MwSt,Lagerbestand");
lines.add("1,Product 1,1.0,10.0,19.0,100");
lines.add("2,Product 2,2.0,20.0,7.0,50");
onlineShop.loadProductsAndParse(lines);
}
@Test
public void testGetProdId() {
Product product = onlineShop.getProdId(1);
assertNotNull(product);
assertEquals("Product 1", product.getName());
Product notFound = onlineShop.getProdId(99);
assertNull(notFound);
}
}

View File

@ -1,5 +1,8 @@
package shop.backend;
class OrderTest {
//Array list
//Product attribute
}