Commit 1d1c7ecb authored by Karel Frajták's avatar Karel Frajták
Browse files

Unit tests

parent e09b3825
Pipeline #3791 passed with stage
in 34 seconds
[![pipeline status](https://gitlab.fel.cvut.cz/frajtak/eShop/badges/master/pipeline.svg)](https://gitlab.fel.cvut.cz/frajtak/eShop/commits/master) [![pipeline status](https://gitlab.fel.cvut.cz/frajtak/eShop/badges/master/pipeline.svg)](https://gitlab.fel.cvut.cz/frajtak/eShop/commits/master)
[![coverage report](https://gitlab.fel.cvut.cz/frajtak/eShop/badges/master/coverage.svg)](https://gitlab.fel.cvut.cz/frajtak/eShop/commits/master) [![coverage report](https://gitlab.fel.cvut.cz//eShop/badges/master/coverage.svg)](https://gitlab.fel.cvut.cz/frajtak/eShop/commits/master)frajtak
\ No newline at end of file \ No newline at end of file
...@@ -2,11 +2,11 @@ package cz.cvut.eshop.archive; ...@@ -2,11 +2,11 @@ package cz.cvut.eshop.archive;
import cz.cvut.eshop.shop.Item; import cz.cvut.eshop.shop.Item;
class ItemPurchaseArchiveEntry { public class ItemPurchaseArchiveEntry {
private final Item refItem; private final Item refItem;
private int soldCount; private int soldCount;
ItemPurchaseArchiveEntry(Item refItem) { public ItemPurchaseArchiveEntry(Item refItem) {
this.refItem = refItem; this.refItem = refItem;
soldCount = 1; soldCount = 1;
} }
......
package archive; package archive;
import org.junit.Test; import cz.cvut.eshop.archive.ItemPurchaseArchiveEntry;
import cz.cvut.eshop.archive.PurchasesArchive;
import cz.cvut.eshop.shop.Item;
import cz.cvut.eshop.shop.Order;
import cz.cvut.eshop.shop.ShoppingCart;
import cz.cvut.eshop.shop.StandardItem;
import org.junit.*;
import org.junit.runners.MethodSorters;
import java.util.HashMap;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.TestCase.assertEquals;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class PurchasesArchiveTest { public class PurchasesArchiveTest {
@Test
public void getHowManyTimesHasBeenItemSold_itemWasNotSoldBefore()
{
// setup
PurchasesArchive archive = new PurchasesArchive();
Item item = new StandardItem(1, "name", 3.14f,
"category", 12);
// act
int actual = archive.getHowManyTimesHasBeenItemSold(item);
// assert
assertEquals(0, actual);
}
@Test
public void getHowManyTimesHasBeenItemSold_itemWasSoldBefore_v1()
{
// setup
PurchasesArchive archive = new PurchasesArchive();
Item item = new StandardItem(1, "name", 3.14f,
"category", 12);
ShoppingCart cart = new ShoppingCart();
cart.addItem(item);
Order order = new Order(cart);
// act
archive.putOrderToPurchasesArchive(order);
int actual = archive.getHowManyTimesHasBeenItemSold(item);
// assert
assertEquals(1, actual);
}
@Test @Test
public void putOrderToPurchasesArchive_firstItemOfAKind() {} public void getHowManyTimesHasBeenItemSold_itemWasSoldBefore_v2()
{
// setup
Item item = new StandardItem(1, "name", 3.14f,
"category", 12);
HashMap<Integer, ItemPurchaseArchiveEntry> itemPurchaseArchiveEntryHashMap =
new HashMap<Integer, ItemPurchaseArchiveEntry>();
itemPurchaseArchiveEntryHashMap.put(1,
new ItemPurchaseArchiveEntry(item));
PurchasesArchive archive = new PurchasesArchive(
itemPurchaseArchiveEntryHashMap,
null
);
// act
int actual = archive.getHowManyTimesHasBeenItemSold(item);
// assert
assertEquals(1, actual);
}
@Test(expected = java.lang.NullPointerException.class)
public void getHowManyTimesHasBeenItemSold_itemIsNull()
{
// setup
PurchasesArchive archive = new PurchasesArchive();
// act
int actual = archive.getHowManyTimesHasBeenItemSold(null);
// assert
}
@BeforeClass
public static void beforeAll()
{
System.out.println("before all");
}
@AfterClass
public static void afterAll()
{
System.out.println("after all");
}
@Before
public void before()
{
System.out.println("before");
}
@After
public void after()
{
System.out.println("after");
}
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment