Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
user-manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
OZG-Cloud
app
user-manager
Commits
7891bb86
Commit
7891bb86
authored
7 months ago
by
OZGCloud
Browse files
Options
Downloads
Patches
Plain Diff
OZG-3539 OZG-6824 improve code tests
parent
b4f40a2c
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
user-manager-server/src/test/java/de/ozgcloud/user/settings/UserSettingsResourceTest.java
+22
-34
22 additions, 34 deletions
...a/de/ozgcloud/user/settings/UserSettingsResourceTest.java
with
22 additions
and
34 deletions
user-manager-server/src/test/java/de/ozgcloud/user/settings/UserSettingsResourceTest.java
+
22
−
34
View file @
7891bb86
...
...
@@ -205,15 +205,25 @@ class UserSettingsResourceTest {
private
final
UserSettings
userSettings
=
UserSettingsTestFactory
.
create
();
private
final
UserSettings
updatedUserSettings
=
UserSettingsTestFactory
.
create
();
@BeforeEach
void
mockAccess
()
{
doNothing
().
when
(
resource
).
checkUserAccess
(
anyString
());
}
@Test
void
shouldCheckAccess
()
{
when
(
userSettingsService
.
updateByUserId
(
USER_ID
,
userSettings
)).
thenReturn
(
Optional
.
of
(
updatedUserSettings
));
when
(
resourceAssembler
.
toResource
(
any
(),
anyString
(),
anyString
())).
thenReturn
(
new
HalEntityWrapper
(
null
));
resource
.
putUserSettings
(
USER_ID
,
userSettings
);
verify
(
resource
).
checkUserAccess
(
USER_ID
);
}
@DisplayName
(
"with empty body"
)
@Nested
class
TestOnEmptyBody
{
@BeforeEach
void
mockAccess
()
{
doNothing
().
when
(
resource
).
checkUserAccess
(
anyString
());
}
@Test
void
shouldThrowFunctionalExceptionOnMissingBody
()
{
assertThatExceptionOfType
(
FunctionalException
.
class
).
isThrownBy
(()
->
resource
.
putUserSettings
(
USER_ID
,
null
))
...
...
@@ -223,50 +233,28 @@ class UserSettingsResourceTest {
@Nested
class
TestUserIdNotExist
{
@BeforeEach
void
mockAccess
()
{
doNothing
().
when
(
resource
).
checkUserAccess
(
anyString
());
}
@Test
void
shouldThrowFunctionalExceptionIfInvalidUserId
()
{
var
user
=
UserSettingsTestFactory
.
create
();
assertThatExceptionOfType
(
FunctionalException
.
class
)
.
isThrownBy
(()
->
resource
.
putUserSettings
(
"wrong_id"
,
user
))
.
withMessageStartingWith
(
"Functional error: Invalid user id"
);
}
void
shouldThrowFunctionalException
()
{
when
(
userSettingsService
.
updateByUserId
(
USER_ID
,
userSettings
)).
thenReturn
(
Optional
.
empty
());
@Test
void
shouldThrowFunctionalExceptionIfEmptyUserId
()
{
var
user
=
UserSettingsTestFactory
.
create
();
assertThatExceptionOfType
(
FunctionalException
.
class
)
.
isThrownBy
(()
->
resource
.
putUserSettings
(
""
,
user
))
.
isThrownBy
(()
->
resource
.
putUserSettings
(
USER_ID
,
userSettings
))
.
withMessageStartingWith
(
"Functional error: Invalid user id"
);
}
}
@DisplayName
(
"with filled body"
)
@Nested
class
TestFilledBody
{
@BeforeEach
void
mockAccess
()
{
doNothing
().
when
(
resource
).
checkUserAccess
(
anyString
());
when
(
userSettingsService
.
updateByUserId
(
anyString
(),
any
(
UserSettings
.
class
))).
thenReturn
(
Optional
.
of
(
updatedUserSettings
));
}
@Test
void
shouldCheckAccess
()
{
when
(
resourceAssembler
.
toResource
(
any
(),
anyString
(),
anyString
())).
thenReturn
(
new
HalEntityWrapper
(
null
));
resource
.
putUserSettings
(
USER_ID
,
userSettings
);
verify
(
resource
).
checkUserAccess
(
USER_ID
);
void
setUp
()
{
when
(
userSettingsService
.
updateByUserId
(
USER_ID
,
userSettings
)).
thenReturn
(
Optional
.
of
(
updatedUserSettings
));
}
@Test
void
shouldCallUserSettingsService
()
{
when
(
resourceAssembler
.
toResource
(
any
(),
anyString
(),
anyString
()
)).
thenReturn
(
new
HalEntityWrapper
(
null
));
when
(
resourceAssembler
.
toResource
(
updatedUserSettings
,
USER_ID
,
USER_MANAGER_URL
)).
thenReturn
(
new
HalEntityWrapper
(
null
));
resource
.
putUserSettings
(
USER_ID
,
userSettings
);
...
...
@@ -276,7 +264,7 @@ class UserSettingsResourceTest {
@Test
void
shouldCallResourceAssembler
()
{
when
(
resourceAssembler
.
toResource
(
any
(),
anyString
(),
anyString
()
)).
thenReturn
(
new
HalEntityWrapper
(
null
));
when
(
resourceAssembler
.
toResource
(
updatedUserSettings
,
USER_ID
,
USER_MANAGER_URL
)).
thenReturn
(
new
HalEntityWrapper
(
null
));
resource
.
putUserSettings
(
USER_ID
,
userSettings
);
...
...
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