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
41fcf1d6
There was an error fetching the commit references. Please try again later.
Commit
41fcf1d6
authored
1 year ago
by
Dominika Zemanovičová
Browse files
Options
Downloads
Patches
Plain Diff
Fix AnswerServiceTest
parent
77e2bcb2
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/answer/AnswerServiceTest.java
+14
-18
14 additions, 18 deletions
...a/org/fuseri/moduleexercise/answer/AnswerServiceTest.java
with
14 additions
and
18 deletions
application/module-exercise/src/test/java/org/fuseri/moduleexercise/answer/AnswerServiceTest.java
+
14
−
18
View file @
41fcf1d6
...
...
@@ -3,7 +3,6 @@ package org.fuseri.moduleexercise.answer;
import
jakarta.persistence.EntityNotFoundException
;
import
org.fuseri.moduleexercise.exercise.Exercise
;
import
org.fuseri.moduleexercise.question.Question
;
import
org.fuseri.moduleexercise.question.QuestionRepository
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -20,23 +19,21 @@ import static org.mockito.Mockito.verify;
import
static
org
.
mockito
.
Mockito
.
when
;
@SpringBootTest
public
class
AnswerServiceTest
{
@MockBean
AnswerRepository
repository
;
@MockBean
QuestionRepository
questionRepository
;
class
AnswerServiceTest
{
@Autowired
AnswerService
service
;
@MockBean
AnswerRepository
answerRepository
;
Answer
answer
;
Question
question
;
Exercise
exercise
;
@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
);
answer
=
new
Answer
(
"text"
,
false
,
question
);
}
...
...
@@ -44,39 +41,38 @@ public class AnswerServiceTest {
@Test
void
create
()
{
when
(
r
epository
.
save
(
answer
)).
thenReturn
(
answer
);
when
(
answerR
epository
.
save
(
answer
)).
thenReturn
(
answer
);
Answer
result
=
service
.
create
(
answer
);
Assertions
.
assertEquals
(
answer
,
result
);
verify
(
r
epository
).
save
(
answer
);
verify
(
answerR
epository
).
save
(
answer
);
}
@Test
void
notFound
()
{
when
(
repository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
empty
());
when
(
answerRepository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
empty
());
Assertions
.
assertThrows
(
EntityNotFoundException
.
class
,
()
->
service
.
find
(
anyLong
()));
}
@Test
void
find
()
{
when
(
r
epository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
of
(
answer
));
when
(
answerR
epository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
of
(
answer
));
Answer
result
=
service
.
find
(
anyLong
());
Assertions
.
assertEquals
(
answer
,
result
);
verify
(
r
epository
).
findById
(
anyLong
());
verify
(
answerR
epository
).
findById
(
anyLong
());
}
@Test
void
findByQuestionId
()
{
void
find
All
ByQuestionId
()
{
long
id
=
1
;
List
<
Answer
>
list
=
Collections
.
emptyList
();
when
(
r
epository
.
existsById
(
id
)).
thenReturn
(
true
);
when
(
r
epository
.
findByQuestionId
(
id
)).
thenReturn
(
list
);
when
(
answerR
epository
.
existsById
(
id
)).
thenReturn
(
true
);
when
(
answerR
epository
.
findByQuestionId
(
id
)).
thenReturn
(
list
);
List
<
Answer
>
result
=
service
.
findAllByQuestionId
(
1L
);
Assertions
.
assertEquals
(
list
,
result
);
verify
(
r
epository
).
findByQuestionId
(
id
);
verify
(
answerR
epository
).
findByQuestionId
(
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