#Fix - Cart Add bug fix
#TEST - Cart Test implemetiert #TEST - ProductsTest implementiertmain
parent
61252aae03
commit
fc3ef498e2
|
|
@ -23,8 +23,9 @@ public void addProduct(Product prod, int quantity){
|
||||||
pos.setQuantity(pos.getQuantity() + quantity); //Damit erhöhe ich quantity
|
pos.setQuantity(pos.getQuantity() + quantity); //Damit erhöhe ich quantity
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
positions.add(new CartPosition(prod, quantity));
|
|
||||||
}
|
}
|
||||||
|
positions.add(new CartPosition(prod, quantity));
|
||||||
}
|
}
|
||||||
public void updateProductQuantity(int prodID,int quantity) {
|
public void updateProductQuantity(int prodID,int quantity) {
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ public class Order {
|
||||||
private double totalBrutto;
|
private double totalBrutto;
|
||||||
private double shippingCost;
|
private double shippingCost;
|
||||||
private double finalTotal;
|
private double finalTotal;
|
||||||
|
//KI
|
||||||
|
private double mwstAmount7;
|
||||||
|
private double mwstAmount19;
|
||||||
|
|
||||||
|
|
||||||
public Order(String customerName, String address, List<CartPosition> positions) {
|
public Order(String customerName, String address, List<CartPosition> positions) {
|
||||||
|
|
@ -39,7 +42,7 @@ public class Order {
|
||||||
weight += pos.getProductWeight();
|
weight += pos.getProductWeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
//KI Ansatz
|
//Denk anstoss
|
||||||
if (weight <= 0.1) {
|
if (weight <= 0.1) {
|
||||||
shippingCost = 3.95;
|
shippingCost = 3.95;
|
||||||
} else if (weight <= 1.0) {
|
} else if (weight <= 1.0) {
|
||||||
|
|
|
||||||
|
|
@ -8,11 +8,12 @@ import shop.backend.Product;
|
||||||
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class ShopTUI {
|
public class ShopTUI {
|
||||||
private static OnlineShop onlineShop;
|
private static OnlineShop onlineShop;
|
||||||
private static Cart cart;
|
private static Cart cart;
|
||||||
|
private static Scanner scanner = new Scanner(System.in);
|
||||||
public static void main(String[] args) throws FileNotFoundException {
|
public static void main(String[] args) throws FileNotFoundException {
|
||||||
IO.println("\n+--------------------------------------+");
|
IO.println("\n+--------------------------------------+");
|
||||||
IO.println("| WELCOME TO THE ONLINE SHOP |");
|
IO.println("| WELCOME TO THE ONLINE SHOP |");
|
||||||
|
|
@ -49,7 +50,7 @@ public class ShopTUI {
|
||||||
int choice;
|
int choice;
|
||||||
do {
|
do {
|
||||||
menu();
|
menu();
|
||||||
choice = Integer.parseInt(IO.readln());
|
choice = scanner.nextInt();
|
||||||
switch (choice) {
|
switch (choice) {
|
||||||
case 1:
|
case 1:
|
||||||
showProducts();
|
showProducts();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,26 @@
|
||||||
package shop.backend;
|
package shop.backend;
|
||||||
|
|
||||||
class CartTest {
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
class CartTest {
|
||||||
|
private Cart cart;
|
||||||
|
private Product product1;
|
||||||
|
private Product product2;
|
||||||
|
@BeforeEach
|
||||||
|
public void testSetup() {
|
||||||
|
cart = new Cart();
|
||||||
|
product1 = new Product(1, "Product 1", 1.0, 10.0, 19.0, 100);
|
||||||
|
product2 = new Product(2, "Product 2", 2.0, 20.0, 7.0, 50);
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testAdd(){
|
||||||
|
cart.addProduct(product1,2);
|
||||||
|
cart.updateProductQuantity(1,5);
|
||||||
|
assertEquals(5, cart.getPositions().get(0).getQuantity());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -7,12 +7,25 @@ import static org.junit.jupiter.api.Assertions.*;
|
||||||
class ProductsTest {
|
class ProductsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testConstr(){
|
public void testGetters() {
|
||||||
Product p1 = new Product(1, "Bier", 2.2, 2.90,19,2);
|
|
||||||
assertEquals(0.19, p1.mwstCalc());
|
Product product = new Product(1, "Test Product", 1.5, 10.0, 19.0, 50);
|
||||||
|
assertEquals(1, product.getProdID());
|
||||||
|
assertEquals("Test Product", product.getName());
|
||||||
|
assertEquals(1.5, product.getTransportWeight());
|
||||||
|
assertEquals(10.0, product.getNetPrice());
|
||||||
|
assertEquals(19.0, product.getMwst());
|
||||||
|
assertEquals(50, product.getStock());
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void testEquals() {
|
||||||
|
Product product1 = new Product(1, "Bier", 1.5, 10.0, 19.0, 50);
|
||||||
|
Product product2 = new Product(2, "Bier", 2.0, 10.0, 7.0, 100);
|
||||||
|
Product product3 = new Product(3, "Mango", 1.5, 10.0, 19.0, 50);
|
||||||
|
assertTrue(product1.equals(product2));
|
||||||
|
assertFalse(product1.equals(product3));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue