Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
backend
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
idatt2106-v23-03
backend
Commits
f6091c78
Commit
f6091c78
authored
1 year ago
by
Birk Øvstetun Narvhus
Browse files
Options
Downloads
Patches
Plain Diff
fixed test
parent
3f88bbe2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/ntnu/idatt2016/v233/SmartMat/controller/product/ProductControllerTest.java
+16
-3
16 additions, 3 deletions
...33/SmartMat/controller/product/ProductControllerTest.java
with
16 additions
and
3 deletions
src/test/java/ntnu/idatt2016/v233/SmartMat/controller/product/ProductControllerTest.java
+
16
−
3
View file @
f6091c78
package
ntnu.idatt2016.v233.SmartMat.controller.product
;
import
ntnu.idatt2016.v233.SmartMat.dto.request.ProductRequest
;
import
ntnu.idatt2016.v233.SmartMat.entity.product.Category
;
import
ntnu.idatt2016.v233.SmartMat.entity.product.Product
;
import
ntnu.idatt2016.v233.SmartMat.service.product.CategoryService
;
import
ntnu.idatt2016.v233.SmartMat.service.product.ProductService
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.extension.ExtendWith
;
...
...
@@ -16,6 +18,7 @@ import java.util.Optional;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertFalse
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
when
;
@ExtendWith
(
MockitoExtension
.
class
)
...
...
@@ -24,6 +27,9 @@ public class ProductControllerTest {
@Mock
private
ProductService
productService
;
@Mock
private
CategoryService
categoryService
;
@InjectMocks
private
ProductController
productController
;
...
...
@@ -33,12 +39,15 @@ public class ProductControllerTest {
ProductRequest
productRequest
=
ProductRequest
.
builder
()
.
ean
(
123L
)
.
name
(
"Test Product"
)
.
description
(
"A test product"
)
.
description
(
"A test product
kylling
"
)
.
image
(
"http://test.com/image.jpg"
)
.
build
();
when
(
productService
.
getProductById
(
123L
)).
thenReturn
(
Optional
.
empty
());
when
(
productService
.
getProductVolume
(
123L
)).
thenReturn
(
Optional
.
of
(
List
.
of
(
"1"
,
"kg"
)));
when
(
categoryService
.
getCategoryByName
(
anyString
())).
thenReturn
(
Optional
.
of
(
Category
.
builder
()
.
categoryName
(
"Kjøtt"
)
.
build
()));
// Act
ResponseEntity
<
Product
>
response
=
productController
.
createProduct
(
productRequest
);
...
...
@@ -48,7 +57,7 @@ public class ProductControllerTest {
assertEquals
(
HttpStatus
.
OK
,
response
.
getStatusCode
());
assertEquals
(
123L
,
product
.
getEan
());
assertEquals
(
"Test Product"
,
product
.
getName
());
assertEquals
(
"A test product"
,
product
.
getDescription
());
assertEquals
(
"A test product
kylling
"
,
product
.
getDescription
());
assertEquals
(
"http://test.com/image.jpg"
,
product
.
getUrl
());
assertEquals
(
"kg"
,
product
.
getUnit
());
assertEquals
(
1.0
,
product
.
getAmount
());
...
...
@@ -60,11 +69,14 @@ public class ProductControllerTest {
ProductRequest
productRequest
=
ProductRequest
.
builder
()
.
ean
(
123L
)
.
name
(
"Test Product"
)
.
description
(
"A test product"
)
.
description
(
"A test product
kylling
"
)
.
image
(
"http://test.com/image.jpg"
)
.
build
();
when
(
productService
.
getProductById
(
123L
)).
thenReturn
(
Optional
.
of
(
new
Product
()));
when
(
categoryService
.
getCategoryByName
(
anyString
())).
thenReturn
(
Optional
.
of
(
Category
.
builder
()
.
categoryName
(
"Kjøtt"
)
.
build
()));
// Act
ResponseEntity
<
Product
>
response
=
productController
.
createProduct
(
productRequest
);
...
...
@@ -80,6 +92,7 @@ public class ProductControllerTest {
Product
product
=
new
Product
();
product
.
setEan
(
123L
);
product
.
setName
(
"Test Product"
);
product
.
setDescription
(
"A test kylling"
);
when
(
productService
.
getProductById
(
123L
)).
thenReturn
(
Optional
.
of
(
product
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment