Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
ShoppingCartBackend
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
snamdeo
ShoppingCartBackend
Commits
97983b66
Commit
97983b66
authored
Sep 06, 2022
by
snamdeo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Commiting after adding test cases to increase code coverage
parent
adb72695
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
7 deletions
+15
-7
Customer.java
src/main/java/com/altimetrik/poc/dto/Customer.java
+2
-1
OrderDetails.java
src/main/java/com/altimetrik/poc/dto/OrderDetails.java
+2
-0
ShoppingCartControllerTest.java
...altimetrik/poc/controller/ShoppingCartControllerTest.java
+3
-2
ShoppingCartServicesTest.java
...com/altimetrik/poc/services/ShoppingCartServicesTest.java
+8
-4
No files found.
src/main/java/com/altimetrik/poc/dto/Customer.java
View file @
97983b66
...
...
@@ -35,7 +35,8 @@ public class Customer {
private
Integer
valetAmount
;
public
Customer
(
String
firstName
,
String
lastName
,
String
emailId
,
Integer
valetAmount
)
{
public
Customer
(
Integer
id
,
String
firstName
,
String
lastName
,
String
emailId
,
Integer
valetAmount
)
{
this
.
id
=
id
;
this
.
firstName
=
firstName
;
this
.
lastName
=
lastName
;
this
.
emailId
=
emailId
;
...
...
src/main/java/com/altimetrik/poc/dto/OrderDetails.java
View file @
97983b66
package
com
.
altimetrik
.
poc
.
dto
;
import
com.altimetrik.poc.dto.Customer
;
import
lombok.AllArgsConstructor
;
import
lombok.Builder
;
import
lombok.Data
;
...
...
@@ -21,6 +22,7 @@ public class OrderDetails {
private
Integer
shippingPrice
;
private
Integer
totalPrice
;
private
Integer
itemsPrice
;
private
Integer
reference
;
private
Integer
[]
productIds
;
@ManyToOne
private
Customer
customer
;
...
...
src/test/java/com/altimetrik/poc/controller/ShoppingCartControllerTest.java
View file @
97983b66
...
...
@@ -25,7 +25,7 @@ class ShoppingCartControllerTest {
public
void
getProducts
(){
when
(
shoppingCartServices
.
getProducts
()).
thenReturn
(
Stream
.
of
(
new
OrderDetails
(
300
,
3761
,
0
,
0
,
42
,
342
,
new
Integer
[
2
],
new
Customer
())).
collect
(
Collectors
.
toList
()));
new
OrderDetails
(
300
,
3761
,
0
,
0
,
42
,
342
,
667
,
new
Integer
[
2
],
new
Customer
())).
collect
(
Collectors
.
toList
()));
assertEquals
(
"200 OK"
,
shoppingCartController
.
getProducts
().
getStatusCode
().
toString
());
...
...
@@ -33,7 +33,8 @@ class ShoppingCartControllerTest {
@Test
public
void
addProducts
(){
OrderDetails
pd
=
new
OrderDetails
(
300
,
3721
,
4356
,
6456
,
6565
,
454
,
new
Integer
[
43
],
new
Customer
());
OrderDetails
pd
=
new
OrderDetails
(
300
,
3721
,
4356
,
6456
,
6565
,
454
,
667
,
new
Integer
[
43
],
new
Customer
());
Customer
c
=
new
Customer
();
shoppingCartController
.
addProducts
(
pd
);
verify
(
shoppingCartServices
,
times
(
1
)).
addProducts
(
pd
);
}
...
...
src/test/java/com/altimetrik/poc/services/ShoppingCartServicesTest.java
View file @
97983b66
...
...
@@ -3,6 +3,7 @@ import com.altimetrik.poc.dto.Customer;
import
com.altimetrik.poc.dto.OrderDetails
;
import
com.altimetrik.poc.dto.ProductDetails
;
import
com.altimetrik.poc.repository.ShoppingCartRepository
;
import
com.altimetrik.poc.repository.UserLoggedInRepository
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
...
...
@@ -24,6 +25,9 @@ public class ShoppingCartServicesTest {
@Autowired
ShoppingCartServices
shoppingCartServices
;
@MockBean
UserLoggedInRepository
userLoggedInRepository
;
@MockBean
List
<
ProductDetails
>
lpd
;
...
...
@@ -32,7 +36,7 @@ public class ShoppingCartServicesTest {
when
(
shoppingCartRepository
.
findAll
()).
thenReturn
(
Stream
.
of
(
new
OrderDetails
(
300
,
3761
,
0
,
0
,
42
,
342
,
new
Integer
[
2
],
new
Customer
())).
collect
(
Collectors
.
toList
()));
new
OrderDetails
(
123
,
300
,
3761
,
0
,
0
,
42
,
342
,
new
Integer
[
2
],
new
Customer
())).
collect
(
Collectors
.
toList
()));
assertEquals
(
1
,
shoppingCartServices
.
getProducts
().
size
());
...
...
@@ -40,9 +44,9 @@ public class ShoppingCartServicesTest {
}
@Test
public
void
addProducts
(){
OrderDetails
pd
=
new
OrderDetails
(
300
,
3721
,
4356
,
6456
,
6565
,
454
,
new
Integer
[
43
],
new
Customer
());
Customer
c
=
new
Customer
(
1
,
"Shishir"
,
"Namdeo"
,
"shishirnamdeo220@gmail.com"
,
0
);
when
(
userLoggedInRepository
.
findByReference
(
Customer
.
refer
)).
thenReturn
(
c
);
OrderDetails
pd
=
new
OrderDetails
(
123
,
3721
,
4356
,
6456
,
6565
,
454
,
667
,
new
Integer
[
43
],
new
Customer
());
shoppingCartServices
.
addProducts
(
pd
);
verify
(
shoppingCartRepository
,
times
(
1
)).
save
(
pd
);
...
...
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