Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
eShop
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
37
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Karel Frajták
eShop
Merge requests
!7
Master
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Master
kubelpe1/eShop:master
into
master
Overview
0
Commits
6
Pipelines
1
Changes
4
Closed
Petr Kubelka
requested to merge
kubelpe1/eShop:master
into
master
6 years ago
Overview
0
Commits
6
Pipelines
1
Changes
4
Expand
1
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
e5747c82
6 commits,
6 years ago
4 files
+
375
−
2
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
src/test/java/archive/OrderTest.java
0 → 100644
+
110
−
0
Options
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
());
}
}