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
44df5327
There was an error fetching the commit references. Please try again later.
Commit
44df5327
authored
1 year ago
by
Dominika Zemanovičová
Browse files
Options
Downloads
Patches
Plain Diff
Fix ExerciseServiceTest
parent
63cbe6fc
No related branches found
No related tags found
3 merge requests
!31
M2
,
!30
M2 exercise
,
!29
M2 exercise
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
application/module-exercise/src/test/java/org/fuseri/moduleexercise/exercise/ExerciseServiceTest.java
+23
-27
23 additions, 27 deletions
...g/fuseri/moduleexercise/exercise/ExerciseServiceTest.java
with
23 additions
and
27 deletions
application/module-exercise/src/test/java/org/fuseri/moduleexercise/exercise/ExerciseServiceTest.java
+
23
−
27
View file @
44df5327
...
...
@@ -2,9 +2,6 @@ package org.fuseri.moduleexercise.exercise;
import
jakarta.persistence.EntityNotFoundException
;
import
org.fuseri.model.dto.exercise.ExerciseCreateDto
;
//import org.fuseri.modulelanguageschool.common.ResourceNotFoundException;
import
org.fuseri.model.dto.exercise.ExerciseDto
;
import
org.fuseri.moduleexercise.question.Question
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.BeforeEach
;
...
...
@@ -27,13 +24,13 @@ import static org.mockito.Mockito.when;
@SpringBootTest
public
class
ExerciseServiceTest
{
class
ExerciseServiceTest
{
@MockBean
ExerciseRepository
r
epository
;
ExerciseRepository
exerciseR
epository
;
@Autowired
ExerciseService
s
ervice
;
ExerciseService
exerciseS
ervice
;
Exercise
exercise
;
ExerciseCreateDto
exercise2
;
...
...
@@ -41,35 +38,34 @@ public class ExerciseServiceTest {
@BeforeEach
void
setup
()
{
exercise
=
new
Exercise
(
"idioms"
,
"exercise on basic idioms"
,
2
,
1L
,
new
HashSet
<
Question
>());
exercise
=
new
Exercise
(
"idioms"
,
"exercise on basic idioms"
,
2
,
1L
,
new
HashSet
<>());
exercise2
=
new
ExerciseCreateDto
(
"idioms1"
,
"exercise on intermediate idioms"
,
2
,
0
);
exercise3
=
new
ExerciseCreateDto
(
"idioms2"
,
"exercise on basic idioms"
,
1
,
0L
);
}
@Test
void
create
()
{
when
(
r
epository
.
save
(
exercise
)).
thenReturn
(
exercise
);
Exercise
result
=
s
ervice
.
create
(
exercise
);
when
(
exerciseR
epository
.
save
(
exercise
)).
thenReturn
(
exercise
);
Exercise
result
=
exerciseS
ervice
.
create
(
exercise
);
Assertions
.
assertEquals
(
exercise
,
result
);
verify
(
r
epository
).
save
(
exercise
);
verify
(
exerciseR
epository
).
save
(
exercise
);
}
@Test
void
notFound
()
{
when
(
r
epository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
empty
());
when
(
exerciseR
epository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
empty
());
Assertions
.
assertThrows
(
EntityNotFoundException
.
class
,
()
->
s
ervice
.
find
(
anyLong
()));
Assertions
.
assertThrows
(
EntityNotFoundException
.
class
,
()
->
exerciseS
ervice
.
find
(
anyLong
()));
}
@Test
void
find
()
{
when
(
r
epository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
of
(
exercise
));
when
(
exerciseR
epository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
of
(
exercise
));
Exercise
result
=
s
ervice
.
find
(
anyLong
());
Exercise
result
=
exerciseS
ervice
.
find
(
anyLong
());
Assertions
.
assertEquals
(
exercise
,
result
);
verify
(
r
epository
).
findById
(
anyLong
());
verify
(
exerciseR
epository
).
findById
(
anyLong
());
}
@Test
...
...
@@ -77,24 +73,24 @@ public class ExerciseServiceTest {
Pageable
pageable
=
PageRequest
.
of
(
0
,
10
);
Page
<
Exercise
>
page
=
new
PageImpl
<>(
Collections
.
emptyList
(),
pageable
,
0
);
when
(
r
epository
.
findAll
(
pageable
)).
thenReturn
(
page
);
Page
<
Exercise
>
result
=
s
ervice
.
findAll
(
0
);
when
(
exerciseR
epository
.
findAll
(
pageable
)).
thenReturn
(
page
);
Page
<
Exercise
>
result
=
exerciseS
ervice
.
findAll
(
0
);
Assertions
.
assertEquals
(
page
,
result
);
verify
(
r
epository
).
findAll
(
pageable
);
verify
(
exerciseR
epository
).
findAll
(
pageable
);
}
@Test
void
find
PerDiffPerCourse
()
{
void
find
ByCourseIdAndDifficulty
()
{
PageRequest
pageable
=
PageRequest
.
of
(
0
,
10
);
Page
<
Exercise
>
page
=
new
PageImpl
<>(
Collections
.
emptyList
(),
pageable
,
0
);
when
(
r
epository
.
fi
lterPerDifficultyPerCourse
(
pageable
,
1L
,
2
)).
thenReturn
(
page
);
when
(
exerciseR
epository
.
fi
ndByCourseIdAndDifficulty
(
1L
,
2
,
pageable
)).
thenReturn
(
page
);
Page
<
Exercise
>
result
=
s
ervice
.
find
PerDifficultyPerCourse
(
0
,
1L
,
2
);
Page
<
Exercise
>
result
=
exerciseS
ervice
.
find
ByCourseIdAndDifficulty
(
1L
,
2
,
0
);
Assertions
.
assertEquals
(
page
,
result
);
verify
(
r
epository
).
fi
lterPerDifficultyPerCourse
(
pageable
,
1L
,
2
);
verify
(
exerciseR
epository
).
fi
ndByCourseIdAndDifficulty
(
1L
,
2
,
pageable
);
}
...
...
@@ -103,13 +99,13 @@ public class ExerciseServiceTest {
PageRequest
pageable
=
PageRequest
.
of
(
0
,
10
);
Page
<
Question
>
page
=
new
PageImpl
<>(
Collections
.
emptyList
(),
pageable
,
0
);
when
(
r
epository
.
getQuestions
(
pageable
,
1L
)).
thenReturn
(
page
);
when
(
r
epository
.
existsById
(
1L
)).
thenReturn
(
true
);
when
(
exerciseR
epository
.
getQuestions
(
pageable
,
1L
)).
thenReturn
(
page
);
when
(
exerciseR
epository
.
existsById
(
1L
)).
thenReturn
(
true
);
Page
<
Question
>
result
=
s
ervice
.
getQuestions
(
1L
,
0
);
Page
<
Question
>
result
=
exerciseS
ervice
.
getQuestions
(
1L
,
0
);
Assertions
.
assertEquals
(
page
,
result
);
verify
(
r
epository
).
getQuestions
(
pageable
,
1L
);
verify
(
exerciseR
epository
).
getQuestions
(
pageable
,
1L
);
}
}
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