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
a9401b42
There was an error fetching the commit references. Please try again later.
Commit
a9401b42
authored
1 year ago
by
Dominika Zemanovičová
Browse files
Options
Downloads
Patches
Plain Diff
Fix QuestionServiceTest
parent
cc4bb1a5
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/question/QuestionServiceTest.java
+31
-14
31 additions, 14 deletions
...g/fuseri/moduleexercise/question/QuestionServiceTest.java
with
31 additions
and
14 deletions
application/module-exercise/src/test/java/org/fuseri/moduleexercise/question/QuestionServiceTest.java
+
31
−
14
View file @
a9401b42
package
org.fuseri.moduleexercise.question
;
import
jakarta.persistence.EntityNotFoundException
;
import
org.fuseri.moduleexercise.answer.Answer
;
import
org.fuseri.moduleexercise.exercise.Exercise
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.BeforeEach
;
...
...
@@ -10,21 +11,20 @@ import org.springframework.boot.test.context.SpringBootTest;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
java.util.HashSet
;
import
java.util.Optional
;
import
java.util.Set
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyLong
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@SpringBootTest
public
class
QuestionServiceTest
{
class
QuestionServiceTest
{
@MockBean
QuestionRepository
r
epository
;
QuestionRepository
questionR
epository
;
@Autowired
QuestionService
s
ervice
;
QuestionService
questionS
ervice
;
Exercise
exercise
;
Question
question
;
...
...
@@ -32,7 +32,7 @@ public class QuestionServiceTest {
@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
<>());
question
=
new
Question
(
"text"
,
new
HashSet
<>(),
exercise
);
question1
=
new
Question
(
"text2"
,
new
HashSet
<>(),
exercise
);
}
...
...
@@ -40,27 +40,44 @@ public class QuestionServiceTest {
@Test
void
create
()
{
when
(
r
epository
.
save
(
question
)).
thenReturn
(
question
);
Question
result
=
s
ervice
.
create
(
question
);
when
(
questionR
epository
.
save
(
question
)).
thenReturn
(
question
);
Question
result
=
questionS
ervice
.
create
(
question
);
Assertions
.
assertEquals
(
question
,
result
);
verify
(
r
epository
).
save
(
question
);
verify
(
questionR
epository
).
save
(
question
);
}
@Test
void
notFound
()
{
when
(
r
epository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
empty
());
when
(
questionR
epository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
empty
());
Assertions
.
assertThrows
(
EntityNotFoundException
.
class
,
()
->
s
ervice
.
find
(
anyLong
()));
Assertions
.
assertThrows
(
EntityNotFoundException
.
class
,
()
->
questionS
ervice
.
find
(
anyLong
()));
}
@Test
void
find
()
{
when
(
r
epository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
of
(
question
));
when
(
questionR
epository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
of
(
question
));
Question
result
=
s
ervice
.
find
(
anyLong
());
Question
result
=
questionS
ervice
.
find
(
anyLong
());
Assertions
.
assertEquals
(
question
,
result
);
verify
(
r
epository
).
findById
(
anyLong
());
verify
(
questionR
epository
).
findById
(
anyLong
());
}
@Test
void
patchUpdateWithoutAnswers
()
{
when
(
questionRepository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
of
(
question
));
when
(
questionRepository
.
save
(
question
)).
thenReturn
(
question
);
Question
result
=
questionService
.
patchUpdateWithoutAnswers
(
anyLong
(),
question
);
Assertions
.
assertEquals
(
question
,
result
);
}
@Test
void
addAnswers
()
{
Set
<
Answer
>
answers
=
Set
.
of
(
new
Answer
(
"BA"
,
true
,
question
));
question
.
setAnswers
(
answers
);
when
(
questionRepository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
of
(
question
));
when
(
questionRepository
.
save
(
question
)).
thenReturn
(
question
);
Question
result
=
questionService
.
patchUpdateWithoutAnswers
(
anyLong
(),
question
);
Assertions
.
assertEquals
(
question
,
result
);
}
}
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