Commit 7394913a authored by Tomáš Hamsa's avatar Tomáš Hamsa
Browse files

Code cleanup&refactor

parent 46db1852
......@@ -2,7 +2,10 @@ package cz.cvut.eshop;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import cz.cvut.eshop.archive.ItemPurchaseArchiveEntry;
import cz.cvut.eshop.archive.PurchasesArchive;
import cz.cvut.eshop.shop.Item;
import cz.cvut.eshop.shop.Order;
......@@ -19,8 +22,9 @@ public class TestData {
return new StandardItem(1, "testItem", 3.5f, "testCategory", 10);
}
public static PurchasesArchive createEmptyPurchaseArchive() {
return new PurchasesArchive();
public static PurchasesArchive createPurchaseArchive(Integer id, ItemPurchaseArchiveEntry orderArchive) {
HashMap<Integer, ItemPurchaseArchiveEntry> itemArchive = new HashMap<>(Collections.singletonMap(id, orderArchive));
return new PurchasesArchive(itemArchive, new ArrayList<>(1));
}
public static Order createOrder(Item... items) {
......
......@@ -7,7 +7,7 @@ public class ItemPurchaseArchiveEntryTest extends AbstractArchiveTest {
@Test
public void testGetCountHowManyTimesHasBeenSold() {
Assert.assertEquals("Incorrect sold count in empty storage", 1, itemArchive.getCountHowManyTimesHasBeenSold());
Assert.assertEquals("Incorrect sold count in empty archive", 1, itemArchive.getCountHowManyTimesHasBeenSold());
}
@Test
......@@ -33,6 +33,6 @@ public class ItemPurchaseArchiveEntryTest extends AbstractArchiveTest {
private void compareIncrement(int difference) {
int soldCount = itemArchive.getCountHowManyTimesHasBeenSold();
itemArchive.increaseCountHowManyTimesHasBeenSold(difference);
Assert.assertEquals("Different sold count for " + difference + " increment", soldCount + difference, itemArchive.getCountHowManyTimesHasBeenSold());
Assert.assertEquals("Incorrect sold count for " + difference + " increment", soldCount + difference, itemArchive.getCountHowManyTimesHasBeenSold());
}
}
\ No newline at end of file
......@@ -4,9 +4,6 @@ import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import org.junit.Assert;
import org.junit.Before;
......@@ -25,10 +22,9 @@ public class PurchasesArchiveTest extends AbstractArchiveTest {
@Before
public void setUp() {
super.setUp();
emptyArchive = TestData.createEmptyPurchaseArchive();
emptyArchive = new PurchasesArchive();
notEmptyArchive = TestData.createPurchaseArchive(item.getID(), itemArchive);
order = TestData.createOrder(item);
HashMap<Integer, ItemPurchaseArchiveEntry> items = new HashMap<>(Collections.singletonMap(item.getID(), itemArchive));
notEmptyArchive = new PurchasesArchive(items, new ArrayList<>(1));
}
@Test
......@@ -64,7 +60,6 @@ public class PurchasesArchiveTest extends AbstractArchiveTest {
@Test(expected = NullPointerException.class)
public void testPutOrderToPurchasesArchiveNull() {
TestData.createOrder();
emptyArchive.putOrderToPurchasesArchive(null);
}
......
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