Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sprachschulsystem
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Jan Pokorný
Sprachschulsystem
Commits
e409b61d
There was an error fetching the commit references. Please try again later.
Commit
e409b61d
authored
1 year ago
by
Dominika Zemanovičová
Browse files
Options
Downloads
Patches
Plain Diff
Fix ExerciseFacadeTest
parent
90a072d9
No related branches found
No related tags found
3 merge requests
!31
M2
,
!30
M2 exercise
,
!29
M2 exercise
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
application/module-exercise/src/test/java/org/fuseri/moduleexercise/exercise/ExerciseFacadeTest.java
+29
-36
29 additions, 36 deletions
...rg/fuseri/moduleexercise/exercise/ExerciseFacadeTest.java
with
29 additions
and
36 deletions
application/module-exercise/src/test/java/org/fuseri/moduleexercise/exercise/ExerciseFacadeTest.java
+
29
−
36
View file @
e409b61d
package
org.fuseri.moduleexercise.exercise
;
import
org.fuseri.model.dto.common.Result
;
import
org.fuseri.model.dto.exercise.ExerciseDto
;
import
org.fuseri.model.dto.exercise.ExerciseCreateDto
;
import
org.fuseri.model.dto.exercise.ExerciseDto
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
;
...
...
@@ -22,85 +21,79 @@ import static org.mockito.Mockito.when;
@SpringBootTest
@AutoConfigureMockMvc
public
class
ExerciseFacadeTest
{
private
final
ExerciseDto
exerciseDto
=
new
ExerciseDto
();
private
final
ExerciseCreateDto
exerciseCreateDto
=
new
ExerciseCreateDto
(
"name"
,
"desc"
,
2
,
1
);
private
final
Exercise
exercise
=
new
Exercise
();
class
ExerciseFacadeTest
{
@Autowired
ExerciseFacade
f
acade
;
ExerciseFacade
exerciseF
acade
;
@MockBean
ExerciseService
s
ervice
;
ExerciseService
exerciseS
ervice
;
@MockBean
ExerciseMapper
m
apper
;
ExerciseMapper
exerciseM
apper
;
private
final
ExerciseDto
exerciseDto
=
new
ExerciseDto
();
private
final
ExerciseCreateDto
exerciseCreateDto
=
new
ExerciseCreateDto
(
"name"
,
"desc"
,
2
,
1
);
private
final
Exercise
exercise
=
new
Exercise
();
@Test
void
create
()
{
when
(
exerciseMapper
.
fromCreateDto
(
exerciseCreateDto
)).
thenReturn
(
exercise
);
when
(
exerciseService
.
create
(
exercise
)).
thenReturn
(
exercise
);
when
(
exerciseMapper
.
toDto
(
exercise
)).
thenReturn
(
exerciseDto
);
when
(
mapper
.
fromCreateDto
(
exerciseCreateDto
)).
thenReturn
(
exercise
);
when
(
service
.
create
(
exercise
)).
thenReturn
(
exercise
);
when
(
mapper
.
toDto
(
exercise
)).
thenReturn
(
exerciseDto
);
ExerciseDto
actualDto
=
facade
.
create
(
exerciseCreateDto
);
ExerciseDto
actualDto
=
exerciseFacade
.
create
(
exerciseCreateDto
);
assertEquals
(
exerciseDto
,
actualDto
);
}
@Test
void
testFindById
()
{
L
ong
id
=
0
L
;
l
ong
id
=
1
L
;
when
(
s
ervice
.
find
(
id
)).
thenReturn
(
exercise
);
when
(
m
apper
.
toDto
(
exercise
)).
thenReturn
(
exerciseDto
);
when
(
exerciseS
ervice
.
find
(
id
)).
thenReturn
(
exercise
);
when
(
exerciseM
apper
.
toDto
(
exercise
)).
thenReturn
(
exerciseDto
);
ExerciseDto
actualDto
=
f
acade
.
find
(
id
);
ExerciseDto
actualDto
=
exerciseF
acade
.
find
(
id
);
assertNotNull
(
actualDto
);
assertEquals
(
exerciseDto
,
actualDto
);
}
@Test
void
testFindAll
()
{
int
page
=
0
;
Pageable
pageable
=
PageRequest
.
of
(
0
,
10
);
Page
<
Exercise
>
exercisePage
=
new
PageImpl
<>(
List
.
of
(
exercise
),
pageable
,
0
);
Result
<
ExerciseDto
>
expectedPageDto
=
new
Result
<>();
Page
<
ExerciseDto
>
expectedPageDto
=
new
PageImpl
<>(
List
.
of
(
exerciseDto
));
when
(
s
ervice
.
findAll
(
page
)).
thenReturn
(
exercisePage
);
when
(
m
apper
.
to
Result
(
exercisePage
)).
thenReturn
(
expectedPageDto
);
when
(
exerciseS
ervice
.
findAll
(
page
)).
thenReturn
(
exercisePage
);
when
(
exerciseM
apper
.
to
DtoPage
(
exercisePage
)).
thenReturn
(
expectedPageDto
);
Result
<
ExerciseDto
>
actualPageDto
=
f
acade
.
findAll
(
page
);
Page
<
ExerciseDto
>
actualPageDto
=
exerciseF
acade
.
findAll
(
page
);
assertEquals
(
expectedPageDto
,
actualPageDto
);
}
@Test
void
update
()
{
L
ong
id
=
1L
;
when
(
m
apper
.
fromCreateDto
(
exerciseCreateDto
)).
thenReturn
(
exercise
);
when
(
s
ervice
.
update
(
exercise
)).
thenReturn
(
exercise
);
when
(
m
apper
.
toDto
(
exercise
)).
thenReturn
(
exerciseDto
);
l
ong
id
=
1L
;
when
(
exerciseM
apper
.
fromCreateDto
(
exerciseCreateDto
)).
thenReturn
(
exercise
);
when
(
exerciseS
ervice
.
update
(
id
,
exercise
)).
thenReturn
(
exercise
);
when
(
exerciseM
apper
.
toDto
(
exercise
)).
thenReturn
(
exerciseDto
);
ExerciseDto
actualDto
=
f
acade
.
update
(
id
,
exerciseCreateDto
);
ExerciseDto
actualDto
=
exerciseF
acade
.
update
(
id
,
exerciseCreateDto
);
assertEquals
(
exerciseDto
,
actualDto
);
}
@Test
void
testDelete
()
{
L
ong
id
=
1L
;
f
acade
.
delete
(
id
);
verify
(
s
ervice
).
delete
(
id
);
l
ong
id
=
1L
;
exerciseF
acade
.
delete
(
id
);
verify
(
exerciseS
ervice
).
delete
(
id
);
}
}
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