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
9f27a5d5
There was an error fetching the commit references. Please try again later.
Commit
9f27a5d5
authored
1 year ago
by
Dominika Zemanovičová
Browse files
Options
Downloads
Patches
Plain Diff
Fix AnswerFacadeTest
parent
8d41e821
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/AnswerFacadeTest.java
+18
-56
18 additions, 56 deletions
...va/org/fuseri/moduleexercise/answer/AnswerFacadeTest.java
with
18 additions
and
56 deletions
application/module-exercise/src/test/java/org/fuseri/moduleexercise/answer/AnswerFacadeTest.java
+
18
−
56
View file @
9f27a5d5
...
@@ -2,90 +2,52 @@ package org.fuseri.moduleexercise.answer;
...
@@ -2,90 +2,52 @@ package org.fuseri.moduleexercise.answer;
import
org.fuseri.model.dto.exercise.AnswerCreateDto
;
import
org.fuseri.model.dto.exercise.AnswerCreateDto
;
import
org.fuseri.model.dto.exercise.AnswerDto
;
import
org.fuseri.model.dto.exercise.AnswerDto
;
import
org.fuseri.model.dto.exercise.AnswerInQuestionCreateDto
;
import
org.fuseri.model.dto.exercise.AnswersCreateDto
;
import
org.fuseri.model.dto.exercise.QuestionUpdateDto
;
import
org.fuseri.moduleexercise.exercise.Exercise
;
import
org.fuseri.moduleexercise.exercise.Exercise
;
import
org.fuseri.moduleexercise.question.Question
;
import
org.fuseri.moduleexercise.question.Question
;
import
org.fuseri.moduleexercise.question.QuestionService
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
java.util.HashSet
;
import
java.util.HashSet
;
import
java.util.List
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
Mockito
.
when
;
@SpringBootTest
@SpringBootTest
public
class
AnswerFacadeTest
{
class
AnswerFacadeTest
{
private
final
Exercise
exercise
=
new
Exercise
();
private
final
Question
question
=
new
Question
(
"text"
,
new
HashSet
<>(),
exercise
);
private
final
AnswerDto
answerDto
=
new
AnswerDto
(
"name"
,
true
);
private
final
AnswerCreateDto
answerCreateDto
=
new
AnswerCreateDto
(
"name"
,
true
,
1L
);
private
final
AnswerInQuestionCreateDto
inQuestionCreateDto
=
new
AnswerInQuestionCreateDto
(
"name"
,
true
);
private
final
AnswersCreateDto
answersCreateDto
=
new
AnswersCreateDto
(
1L
,
List
.
of
(
inQuestionCreateDto
));
private
final
QuestionUpdateDto
questionUpdateDto
=
QuestionUpdateDto
.
builder
().
build
();
private
final
Answer
answer
=
new
Answer
(
"name"
,
true
,
question
);
@MockBean
AnswerRepository
repository
;
@Autowired
@Autowired
AnswerFacade
f
acade
;
private
AnswerFacade
answerF
acade
;
@MockBean
@MockBean
AnswerService
s
ervice
;
private
AnswerService
answerS
ervice
;
@MockBean
@MockBean
QuestionService
questionService
;
private
AnswerMapper
answerMapper
;
@MockBean
private
final
AnswerDto
answerDto
=
new
AnswerDto
(
"name"
,
true
);
AnswerMapper
mapper
;
private
final
AnswerCreateDto
answerCreateDto
=
new
AnswerCreateDto
(
"name"
,
true
,
1L
);
@Test
private
final
Question
question
=
new
Question
(
"text"
,
new
HashSet
<>(),
new
Exercise
());
void
create
()
{
private
final
Answer
answer
=
new
Answer
(
"name"
,
true
,
question
);
long
id
=
1
;
when
(
service
.
find
(
id
)).
thenReturn
(
answer
);
when
(
mapper
.
fromCreateDto
(
inQuestionCreateDto
)).
thenReturn
(
answer
);
when
(
service
.
create
(
answer
)).
thenReturn
(
answer
);
when
(
mapper
.
toDto
(
answer
)).
thenReturn
(
answerDto
);
when
(
questionService
.
find
(
id
)).
thenReturn
(
question
);
when
(
mapper
.
toDtoList
(
List
.
of
(
answer
))).
thenReturn
(
List
.
of
(
answerDto
));
var
actualDto
=
facade
.
createMultiple
(
answersCreateDto
);
assertEquals
(
List
.
of
(
answerDto
),
actualDto
);
}
@Test
@Test
void
update
()
{
void
update
()
{
Long
id
=
1L
;
long
id
=
1L
;
when
(
repository
.
existsById
(
id
)).
thenReturn
(
true
);
when
(
answerMapper
.
fromCreateDto
(
answerCreateDto
)).
thenReturn
(
answer
);
when
(
service
.
find
(
id
)).
thenReturn
(
answer
);
when
(
answerService
.
update
(
id
,
answer
)).
thenReturn
(
answer
);
when
(
mapper
.
fromCreateDto
(
answerCreateDto
)).
thenReturn
(
answer
);
when
(
answerMapper
.
toDto
(
answer
)).
thenReturn
(
answerDto
);
when
(
service
.
update
(
answer
)).
thenReturn
(
answer
);
when
(
mapper
.
toDto
(
answer
)).
thenReturn
(
answerDto
);
AnswerDto
actualDto
=
facade
.
update
(
id
,
answerCreateDto
);
AnswerDto
actualDto
=
answerFacade
.
update
(
id
,
answerCreateDto
);
assertEquals
(
answerDto
,
actualDto
);
assertEquals
(
answerDto
,
actualDto
);
}
}
@Test
@Test
void
testDelete
()
{
void
delete
()
{
Long
id
=
1L
;
long
id
=
1L
;
when
(
service
.
find
(
id
)).
thenReturn
(
answer
);
answerFacade
.
delete
(
id
);
when
(
questionService
.
find
(
answer
.
getId
())).
thenReturn
(
question
);
verify
(
answerService
).
delete
(
id
);
facade
.
delete
(
id
);
verify
(
service
).
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