Skip to content

Commit 8e2522b

Browse files
πŸ“ Add docstrings to refactor/318-siteuser-test-fixture-module
Docstrings generation was requested by @Gyuhyeok99. * #319 (comment) The following files were modified: * `src/test/java/com/example/solidconnection/siteuser/fixture/SiteUserFixture.java` * `src/test/java/com/example/solidconnection/siteuser/fixture/SiteUserFixtureBuilder.java`
1 parent 8a84535 commit 8e2522b

File tree

2 files changed

+250
-0
lines changed

2 files changed

+250
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package com.example.solidconnection.siteuser.fixture;
2+
3+
import com.example.solidconnection.siteuser.domain.AuthType;
4+
import com.example.solidconnection.siteuser.domain.SiteUser;
5+
import com.example.solidconnection.type.Role;
6+
import lombok.RequiredArgsConstructor;
7+
import org.springframework.boot.test.context.TestComponent;
8+
import org.springframework.security.crypto.password.PasswordEncoder;
9+
10+
@TestComponent
11+
@RequiredArgsConstructor
12+
public class SiteUserFixture {
13+
14+
private final SiteUserFixtureBuilder siteUserFixtureBuilder;
15+
private final PasswordEncoder passwordEncoder;
16+
17+
/**
18+
* Creates a default test user with preset email, nickname, role, and password.
19+
*
20+
* @return a SiteUser instance representing a standard test user
21+
*/
22+
public SiteUser ν…ŒμŠ€νŠΈ_μœ μ €() {
23+
return siteUserFixtureBuilder.siteUser()
24+
.email("test@example.com")
25+
.authType(AuthType.EMAIL)
26+
.nickname("ν…ŒμŠ€νŠΈμœ μ €")
27+
.profileImageUrl("profileImageUrl")
28+
.role(Role.MENTEE)
29+
.password("password123")
30+
.create();
31+
}
32+
33+
/**
34+
* Creates a test user with a unique email based on the given index and the specified nickname.
35+
*
36+
* @param index the numeric value to include in the user's email address for uniqueness
37+
* @param nickname the nickname to assign to the user
38+
* @return a new SiteUser instance with the specified nickname and a unique email
39+
*/
40+
public SiteUser ν…ŒμŠ€νŠΈ_μœ μ €(int index, String nickname) {
41+
return siteUserFixtureBuilder.siteUser()
42+
.email("test" + index + " @example.com")
43+
.authType(AuthType.EMAIL)
44+
.nickname(nickname)
45+
.profileImageUrl("profileImageUrl")
46+
.role(Role.MENTEE)
47+
.password("password123")
48+
.create();
49+
}
50+
51+
/**
52+
* Creates a test user with the specified email and authentication type.
53+
*
54+
* @param email the email address for the test user
55+
* @param authType the authentication type for the test user
56+
* @return a SiteUser instance with the given email and auth type, default nickname, profile image URL, mentee role, and password
57+
*/
58+
public SiteUser ν…ŒμŠ€νŠΈ_μœ μ €(String email, AuthType authType) {
59+
return siteUserFixtureBuilder.siteUser()
60+
.email(email)
61+
.authType(authType)
62+
.nickname("ν…ŒμŠ€νŠΈμœ μ €")
63+
.profileImageUrl("profileImageUrl")
64+
.role(Role.MENTEE)
65+
.password("password123")
66+
.create();
67+
}
68+
69+
/**
70+
* Creates a test user with the specified email and password, encoding the password.
71+
*
72+
* @param email the email address for the test user
73+
* @param password the raw password to be encoded for the test user
74+
* @return a SiteUser instance with the given email and encoded password, default nickname, profile image URL, and mentee role
75+
*/
76+
public SiteUser ν…ŒμŠ€νŠΈ_μœ μ €(String email, String password) {
77+
return siteUserFixtureBuilder.siteUser()
78+
.email(email)
79+
.authType(AuthType.EMAIL)
80+
.nickname("ν…ŒμŠ€νŠΈμœ μ €")
81+
.profileImageUrl("profileImageUrl")
82+
.role(Role.MENTEE)
83+
.password(passwordEncoder.encode(password))
84+
.create();
85+
}
86+
87+
/**
88+
* Creates a test user with a duplicated nickname for testing nickname collision scenarios.
89+
*
90+
* @return a SiteUser instance with a fixed email, nickname "μ€‘λ³΅λ‹‰λ„€μž„", and default attributes
91+
*/
92+
public SiteUser 쀑볡_λ‹‰λ„€μž„_ν…ŒμŠ€νŠΈ_μœ μ €() {
93+
return siteUserFixtureBuilder.siteUser()
94+
.email("duplicated@example.com")
95+
.authType(AuthType.EMAIL)
96+
.nickname("μ€‘λ³΅λ‹‰λ„€μž„")
97+
.profileImageUrl("profileImageUrl")
98+
.role(Role.MENTEE)
99+
.password("password123")
100+
.create();
101+
}
102+
103+
/**
104+
* Creates a test user with a custom profile image URL and password.
105+
*
106+
* @return a SiteUser instance with email "customProfile@example.com", nickname "μ»€μŠ€ν…€ν”„λ‘œν•„", role MENTEE, authentication type EMAIL, profile image URL "profile/profileImageUrl", and password "customPassword123"
107+
*/
108+
public SiteUser μ»€μŠ€ν…€_ν”„λ‘œν•„_ν…ŒμŠ€νŠΈ_μœ μ €() {
109+
return siteUserFixtureBuilder.siteUser()
110+
.email("customProfile@example.com")
111+
.authType(AuthType.EMAIL)
112+
.nickname("μ»€μŠ€ν…€ν”„λ‘œν•„")
113+
.profileImageUrl("profile/profileImageUrl")
114+
.role(Role.MENTEE)
115+
.password("customPassword123")
116+
.create();
117+
}
118+
119+
/**
120+
* Creates a test admin user with predefined email, nickname, profile image URL, and password.
121+
*
122+
* @return a SiteUser instance representing an admin user for testing purposes
123+
*/
124+
public SiteUser ν…ŒμŠ€νŠΈ_μ–΄λ“œλ―Ό() {
125+
return siteUserFixtureBuilder.siteUser()
126+
.email("admin@example.com")
127+
.authType(AuthType.EMAIL)
128+
.nickname("ν…ŒμŠ€νŠΈμ–΄λ“œλ―Ό")
129+
.profileImageUrl("profileImageUrl")
130+
.role(Role.ADMIN)
131+
.password("admin123")
132+
.create();
133+
}
134+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
package com.example.solidconnection.siteuser.fixture;
2+
3+
import com.example.solidconnection.siteuser.domain.AuthType;
4+
import com.example.solidconnection.siteuser.domain.SiteUser;
5+
import com.example.solidconnection.siteuser.repository.SiteUserRepository;
6+
import com.example.solidconnection.type.PreparationStatus;
7+
import com.example.solidconnection.type.Role;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.boot.test.context.TestComponent;
10+
11+
@TestComponent
12+
@RequiredArgsConstructor
13+
public class SiteUserFixtureBuilder {
14+
15+
private final SiteUserRepository siteUserRepository;
16+
17+
private String email;
18+
private AuthType authType;
19+
private String nickname;
20+
private String profileImageUrl;
21+
private Role role;
22+
private String password;
23+
24+
/**
25+
* Creates a new instance of the builder with the same repository for fresh configuration.
26+
*
27+
* @return a new SiteUserFixtureBuilder instance
28+
*/
29+
public SiteUserFixtureBuilder siteUser() {
30+
return new SiteUserFixtureBuilder(siteUserRepository);
31+
}
32+
33+
/**
34+
* Sets the email address for the SiteUser being built.
35+
*
36+
* @param email the email address to assign
37+
* @return this builder instance for method chaining
38+
*/
39+
public SiteUserFixtureBuilder email(String email) {
40+
this.email = email;
41+
return this;
42+
}
43+
44+
/**
45+
* Sets the authentication type for the user being built.
46+
*
47+
* @param authType the authentication type to assign
48+
* @return this builder instance for method chaining
49+
*/
50+
public SiteUserFixtureBuilder authType(AuthType authType) {
51+
this.authType = authType;
52+
return this;
53+
}
54+
55+
/**
56+
* Sets the nickname for the SiteUser being built.
57+
*
58+
* @param nickname the nickname to assign
59+
* @return this builder instance for method chaining
60+
*/
61+
public SiteUserFixtureBuilder nickname(String nickname) {
62+
this.nickname = nickname;
63+
return this;
64+
}
65+
66+
/**
67+
* Sets the profile image URL for the SiteUser being built.
68+
*
69+
* @param profileImageUrl the URL of the user's profile image
70+
* @return this builder instance for method chaining
71+
*/
72+
public SiteUserFixtureBuilder profileImageUrl(String profileImageUrl) {
73+
this.profileImageUrl = profileImageUrl;
74+
return this;
75+
}
76+
77+
/**
78+
* Sets the role for the SiteUser being built.
79+
*
80+
* @param role the user role to assign
81+
* @return this builder instance for method chaining
82+
*/
83+
public SiteUserFixtureBuilder role(Role role) {
84+
this.role = role;
85+
return this;
86+
}
87+
88+
/**
89+
* Sets the password for the SiteUser being built.
90+
*
91+
* @param password the password to assign
92+
* @return this builder instance for method chaining
93+
*/
94+
public SiteUserFixtureBuilder password(String password) {
95+
this.password = password;
96+
return this;
97+
}
98+
99+
/**
100+
* Builds and persists a new SiteUser entity using the configured attributes.
101+
*
102+
* @return the persisted SiteUser instance
103+
*/
104+
public SiteUser create() {
105+
SiteUser siteUser = new SiteUser(
106+
email,
107+
nickname,
108+
profileImageUrl,
109+
PreparationStatus.CONSIDERING,
110+
role,
111+
authType,
112+
password
113+
);
114+
return siteUserRepository.save(siteUser);
115+
}
116+
}

0 commit comments

Comments
Β (0)