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
Merge requests
!26
An error occurred while fetching the assigned milestone of the selected merge_request.
M2 user tests
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
M2 user tests
M2-user-tests
into
M2-user
Overview
0
Commits
5
Pipelines
1
Changes
1
Merged
Dominika Zemanovičová
requested to merge
M2-user-tests
into
M2-user
1 year ago
Overview
0
Commits
5
Pipelines
1
Changes
1
Expand
0
0
Merge request reports
Viewing commit
2f399898
Prev
Next
Show latest version
1 file
+
76
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
2f399898
Introduce UserServiceTest
· 2f399898
Dominika Zemanovičová
authored
1 year ago
application/module-language-school/src/test/java/org/fuseri/modulelanguageschool/user/UserServiceTest.java
0 → 100644
+
76
−
0
Options
package
org.fuseri.modulelanguageschool.user
;
import
org.fuseri.modulelanguageschool.course.Course
;
import
org.fuseri.modulelanguageschool.course.Language
;
import
org.fuseri.modulelanguageschool.course.ProficiencyLevel
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.boot.test.mock.mockito.MockBean
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Set
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.
assertEquals
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyLong
;
import
static
org
.
mockito
.
Mockito
.
verify
;
import
static
org
.
mockito
.
Mockito
.
when
;
@SpringBootTest
class
UserServiceTest
{
@Autowired
private
UserService
userService
;
@MockBean
private
UserRepository
userRepository
;
private
static
final
User
USER
=
new
User
(
"xnovak"
,
UserType
.
STUDENT
,
"1234fak"
,
"xnovak@emample.com"
,
"Peter"
,
"Novak"
,
new
Address
(),
Set
.
of
(),
new
HashMap
<>());
private
static
final
Course
COURSE
=
new
Course
(
"AJ1"
,
10
,
Language
.
ENGLISH
,
ProficiencyLevel
.
B2
);
private
static
final
List
<
Course
>
COURSE_LIST
=
List
.
of
(
COURSE
);
private
static
final
User
USER_WITH_ENROLLED_COURSE
=
new
User
(
"xnovak"
,
UserType
.
STUDENT
,
"1234fak"
,
"xnovak@emample.com"
,
"Peter"
,
"Novak"
,
new
Address
(),
Set
.
of
(
COURSE
),
Map
.
of
());
@Test
void
find
()
{
when
(
userRepository
.
findById
(
anyLong
())).
thenReturn
(
Optional
.
of
(
USER
));
User
actualUser
=
userService
.
find
(
anyLong
());
assertEquals
(
USER
,
actualUser
);
}
@Test
void
getEnrolled
()
{
Long
id
=
1L
;
when
(
userRepository
.
getEnrolled
(
anyLong
())).
thenReturn
(
COURSE_LIST
);
List
<
Course
>
actualCourses
=
userService
.
getEnrolled
(
id
);
assertEquals
(
COURSE_LIST
,
actualCourses
);
}
@Test
void
getFinished
()
{
long
id
=
1L
;
when
(
userRepository
.
getFinished
(
anyLong
())).
thenReturn
(
COURSE_LIST
);
List
<
Course
>
actualCourses
=
userService
.
getFinished
(
id
);
assertEquals
(
COURSE_LIST
,
actualCourses
);
}
@Test
void
addLanguageProficiency
()
{
long
id
=
1L
;
Language
language
=
Language
.
ENGLISH
;
ProficiencyLevel
proficiencyLevel
=
ProficiencyLevel
.
B2
;
when
(
userRepository
.
findById
(
id
)).
thenReturn
(
Optional
.
of
(
USER
));
when
(
userRepository
.
save
(
any
(
User
.
class
))).
thenReturn
(
USER_WITH_ENROLLED_COURSE
);
User
updatedUser
=
userService
.
addLanguageProficiency
(
id
,
language
,
proficiencyLevel
);
assertEquals
(
USER_WITH_ENROLLED_COURSE
,
updatedUser
);
verify
(
userRepository
).
findById
(
id
);
verify
(
userRepository
).
save
(
any
(
User
.
class
));
}
}
\ No newline at end of file
Loading