Skip to content
Snippets Groups Projects

Master

Closed Petr Kubelka requested to merge kubelpe1/eShop:master into master
4 files
+ 375
2
Compare changes
  • Side-by-side
  • Inline
Files
4
+ 110
0
package archive;
import cz.cvut.eshop.shop.Order;
import cz.cvut.eshop.shop.ShoppingCart;
import cz.cvut.eshop.shop.StandardItem;
import org.junit.Test;
import static junit.framework.TestCase.assertEquals;
public class OrderTest {
@Test
public void createOrderWithNoItemsOrderedTest() {
// setup
ShoppingCart cart = new ShoppingCart();
Order order = new Order(cart);
// act
order.create();
int numberOfItems = order.getItems().size();
// assert
assertEquals(numberOfItems,0);
}
@Test
public void oneItemAndDeleted() {
// setup
ShoppingCart cart = new ShoppingCart();
int num1 = 2122;
float num2 = 5411210;
int num3 = 4324;
String str1 = "PC";
String str2 = "PCs";
cart.addItem(new StandardItem(num1,str1,num2,str2,num3));
Order order = new Order(cart, 0);
order.getItems().remove(0);
// act
// assert
assertEquals(0, order.getItems().size());
}
@Test
public void oneItemInserted() {
// setup
ShoppingCart cart = new ShoppingCart();
cart.addItem(new StandardItem(79987, "Generic laptop", 20000, "laptops", 200));
Order order = new Order(cart, 0);
// act
// assert
assertEquals(1, order.getItems().size());
}
@Test
public void multipleItemsInserted() {
// setup
ShoppingCart cart = new ShoppingCart();
Order order = new Order(cart, 0);
int numberOfItems = 100;
//act
for (int i = 0; i < numberOfItems*2; i = i + 2) {
int num1 = i;
int num2 = i + 1;
float num3 = (float) (num1 + num2 + 0.5);
String str1 = (char) num1 + "";
String str2 = (char) num1 + "";
cart.addItem(new StandardItem(num1,str1,num3,str2,num2));
}
assertEquals(numberOfItems, order.getItems().size());
}
//TODO: metoda order.getTotalAmount() ma promennou int totalAmount, ktera scita floaty
@Test
public void testGetTotalAmount() {
// setup
ShoppingCart cart = new ShoppingCart();
Order order = new Order(cart, 0);
int numberOfItems = 100;
float price = 0;
//act
for (int i = 0; i < numberOfItems*2; i = i + 2) {
int num1 = i;
int num2 = i + 1;
float num3 = (float) (num1 + num2 + 0.31315);
price += num3;
String str1 = (char) num1 + "";
String str2 = (char) num1 + "";
cart.addItem(new StandardItem(num1,str1,num3,str2,num2));
}
assertEquals(price, order.getTotalAmount());
}
}