Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Jan Novák
eShop
Commits
06cbc763
Commit
06cbc763
authored
Oct 28, 2018
by
Karel Frajták
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'Ukol1' into 'master'
Ukol1 See merge request
frajtak/eShop!18
parents
8f01acb7
5e0ad0d3
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
132 additions
and
5 deletions
+132
-5
src/main/java/cz/cvut/eshop/shop/Order.java
src/main/java/cz/cvut/eshop/shop/Order.java
+1
-1
src/main/java/cz/cvut/eshop/shop/ShoppingCart.java
src/main/java/cz/cvut/eshop/shop/ShoppingCart.java
+4
-4
src/test/java/cz/cvut/eshop/shop/OrderTest.java
src/test/java/cz/cvut/eshop/shop/OrderTest.java
+49
-0
src/test/java/cz/cvut/eshop/shop/ShoppingCartTest.java
src/test/java/cz/cvut/eshop/shop/ShoppingCartTest.java
+62
-0
src/test/java/cz/cvut/eshop/shop/StandardItemTest.java
src/test/java/cz/cvut/eshop/shop/StandardItemTest.java
+16
-0
No files found.
src/main/java/cz/cvut/eshop/shop/Order.java
View file @
06cbc763
...
...
@@ -88,7 +88,7 @@ public class Order {
}
public
float
getTotalAmount
()
{
in
t
totalAmount
=
0
;
floa
t
totalAmount
=
0
;
// spocitat vernostni body za polozky v nak. voziku
for
(
Item
item
:
items
)
{
totalAmount
+=
item
.
getPrice
();
...
...
src/main/java/cz/cvut/eshop/shop/ShoppingCart.java
View file @
06cbc763
...
...
@@ -42,7 +42,7 @@ public class ShoppingCart {
*/
public
void
removeItem
(
int
itemID
)
{
for
(
int
i
=
items
.
size
()
-
1
;
i
<=
0
;
i
--
)
{
for
(
int
i
=
0
;
i
<
items
.
size
()
;
i
++
)
{
Item
temp_item
=
(
Item
)
items
.
get
(
i
);
if
(
temp_item
.
getID
()
==
itemID
)
{
items
.
remove
(
i
);
...
...
@@ -61,9 +61,9 @@ public class ShoppingCart {
*
* @return total price with discount
*/
public
in
t
getTotalPrice
()
{
in
t
total
=
0
;
for
(
int
i
=
items
.
size
()
-
1
;
i
<=
0
;
i
--
)
{
public
floa
t
getTotalPrice
()
{
floa
t
total
=
0
f
;
for
(
int
i
=
0
;
i
<
items
.
size
()
;
i
++
)
{
Item
temp_item
=
(
Item
)
items
.
get
(
i
);
total
+=
temp_item
.
getPrice
();
}
...
...
src/test/java/cz/cvut/eshop/shop/OrderTest.java
0 → 100644
View file @
06cbc763
package
cz.cvut.eshop.shop
;
import
org.junit.Before
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
public
class
OrderTest
{
ShoppingCart
shoppingCart
=
new
ShoppingCart
();
Order
order
;
Customer
customer
=
new
Customer
(
0
);
@Before
public
void
fillShoppingCartAndCreateOrderAndAddCustomer
()
{
Item
item
=
new
StandardItem
(
1
,
"bread"
,
4.50f
,
"food"
,
3
);
Item
item2
=
new
StandardItem
(
2
,
"apple"
,
2.50f
,
"food"
,
5
);
shoppingCart
.
addItem
(
item
);
shoppingCart
.
addItem
(
item2
);
order
=
new
Order
(
shoppingCart
);
order
.
setCustomer
(
customer
);
}
@Test
public
void
create_orderCreatedFromShoppingCardBefore_shouldSetLoyaltyPointToCustomer
()
{
order
.
create
();
assertEquals
(
8
,
customer
.
getLoyaltyPoints
());
}
@Test
public
void
applyDiscount_usingSC
()
{
order
.
create
();
order
.
applyDiscount
();
float
discount
=
(
float
)
(
0.2
*
8
);
float
price
=
7
-
discount
;
assertEquals
(
price
,
order
.
getTotalAmount
(),
0.05f
);
}
@Test
public
void
getTotalAmount_usingSameSC_shouldBe7
()
{
assertEquals
(
7
f
,
order
.
getTotalAmount
(),
0.05f
);
}
}
\ No newline at end of file
src/test/java/cz/cvut/eshop/shop/ShoppingCartTest.java
0 → 100644
View file @
06cbc763
package
cz.cvut.eshop.shop
;
import
org.junit.Test
;
import
java.util.Iterator
;
import
static
org
.
junit
.
Assert
.*;
public
class
ShoppingCartTest
{
@Test
public
void
getCartItems_insertNewAndGet_shouldReturnInsertedOne
()
{
ShoppingCart
shCart
=
new
ShoppingCart
();
Item
item
=
new
StandardItem
(
1
,
"bread"
,
4.50f
,
"food"
,
3
);
shCart
.
addItem
(
item
);
assertEquals
(
1
,
shCart
.
getCartItems
().
size
());
Iterator
<
Item
>
it
=
shCart
.
getCartItems
().
iterator
();
assertEquals
(
item
.
getID
(),
it
.
next
().
getID
());
assertFalse
(
it
.
hasNext
());
}
@Test
public
void
removeItem_insertAndRemove_itemsSizeShouldBeZero
()
{
ShoppingCart
shCart
=
new
ShoppingCart
();
Item
item
=
new
StandardItem
(
1
,
"bread"
,
4.50f
,
"food"
,
3
);
shCart
.
addItem
(
item
);
assertEquals
(
1
,
shCart
.
getCartItems
().
size
());
shCart
.
removeItem
(
item
.
getID
());
assertEquals
(
0
,
shCart
.
getCartItems
().
size
());
}
@Test
public
void
getItemsCount_insertTwoItems_shouldBeTwo
()
{
ShoppingCart
shCart
=
new
ShoppingCart
();
Item
item
=
new
StandardItem
(
1
,
"bread"
,
4.50f
,
"food"
,
3
);
shCart
.
addItem
(
item
);
shCart
.
addItem
(
item
);
assertEquals
(
2
,
shCart
.
getItemsCount
());
}
@Test
public
void
getTotalPrice_insertOneItem_shouldBeSameAsItemPrice
()
{
ShoppingCart
shCart
=
new
ShoppingCart
();
Item
item
=
new
StandardItem
(
1
,
"bread"
,
4.50f
,
"food"
,
3
);
shCart
.
addItem
(
item
);
assertEquals
(
item
.
getPrice
(),
shCart
.
getTotalPrice
(),
0.05f
);
}
@Test
public
void
getTotalPrice_insertNone_shouldBeZero
()
{
ShoppingCart
shCart
=
new
ShoppingCart
();
assertEquals
(
0
f
,
shCart
.
getTotalPrice
(),
0.05f
);
}
}
\ No newline at end of file
src/test/java/cz/cvut/eshop/shop/StandardItemTest.java
0 → 100644
View file @
06cbc763
package
cz.cvut.eshop.shop
;
import
org.junit.Test
;
import
static
org
.
junit
.
Assert
.*;
public
class
StandardItemTest
{
@Test
public
void
copy_copyItem_shouldReturnSameItem
()
{
StandardItem
item
=
new
StandardItem
(
1
,
"Name"
,
9.68f
,
"Vegetable"
,
5
);
StandardItem
copyItem
=
item
.
copy
();
assertEquals
(
item
,
copyItem
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment