Skip to content

Commit 07ba3c1

Browse files
committed
Refactor UserServiceTest for improved readability and consistency
- Cleaned up import statements and organized them for better clarity. - Removed unnecessary whitespace and formatted code for consistency. - Simplified assertions and method calls for better readability. - Consolidated multiple lines into single lines where appropriate. - Enhanced comments for clarity and understanding of test cases. - Updated OAuth2TestConfiguration to streamline client registration methods. - Improved TestFixtures for better organization and readability of test data. - Updated testing documentation for clarity and consistency in formatting.
1 parent 4525648 commit 07ba3c1

6 files changed

Lines changed: 242 additions & 375 deletions

File tree

src/main/java/com/digitalsanctuary/spring/user/listener/AuthenticationEventLIstener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@Slf4j
1717
@RequiredArgsConstructor
1818
@Component
19-
public class AuthenticationEventLIstener {
19+
public class AuthenticationEventListener {
2020

2121
final private LoginAttemptService loginAttemptService;
2222

src/test/java/com/digitalsanctuary/spring/user/listener/AuthenticationEventListenerTest.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AuthenticationEventListenerTest {
3131
private LoginAttemptService loginAttemptService;
3232

3333
@InjectMocks
34-
private AuthenticationEventLIstener authenticationEventListener;
34+
private AuthenticationEventListener authenticationEventListener;
3535

3636
private Authentication authentication;
3737
private String username;
@@ -99,8 +99,7 @@ class FailureEventTests {
9999
void onFailure_handlesBadCredentials() {
100100
// Given
101101
BadCredentialsException exception = new BadCredentialsException("Bad credentials");
102-
AbstractAuthenticationFailureEvent event = new AuthenticationFailureBadCredentialsEvent(
103-
authentication, exception);
102+
AbstractAuthenticationFailureEvent event = new AuthenticationFailureBadCredentialsEvent(authentication, exception);
104103

105104
// When
106105
authenticationEventListener.onFailure(event);
@@ -114,8 +113,7 @@ void onFailure_handlesBadCredentials() {
114113
void onFailure_handlesAccountDisabled() {
115114
// Given
116115
DisabledException exception = new DisabledException("Account disabled");
117-
AbstractAuthenticationFailureEvent event = new AuthenticationFailureDisabledEvent(
118-
authentication, exception);
116+
AbstractAuthenticationFailureEvent event = new AuthenticationFailureDisabledEvent(authentication, exception);
119117

120118
// When
121119
authenticationEventListener.onFailure(event);
@@ -129,8 +127,7 @@ void onFailure_handlesAccountDisabled() {
129127
void onFailure_handlesAccountLocked() {
130128
// Given
131129
LockedException exception = new LockedException("Account locked");
132-
AbstractAuthenticationFailureEvent event = new AuthenticationFailureLockedEvent(
133-
authentication, exception);
130+
AbstractAuthenticationFailureEvent event = new AuthenticationFailureLockedEvent(authentication, exception);
134131

135132
// When
136133
authenticationEventListener.onFailure(event);
@@ -146,8 +143,7 @@ void onFailure_handlesNullAuthenticationName() {
146143
Authentication nullAuth = mock(Authentication.class);
147144
when(nullAuth.getName()).thenReturn(null);
148145
BadCredentialsException exception = new BadCredentialsException("Bad credentials");
149-
AbstractAuthenticationFailureEvent event = new AuthenticationFailureBadCredentialsEvent(
150-
nullAuth, exception);
146+
AbstractAuthenticationFailureEvent event = new AuthenticationFailureBadCredentialsEvent(nullAuth, exception);
151147

152148
// When
153149
authenticationEventListener.onFailure(event);
@@ -182,8 +178,7 @@ void mixedSuccessAndFailureEvents() {
182178
// Given
183179
AuthenticationSuccessEvent successEvent = new AuthenticationSuccessEvent(authentication);
184180
BadCredentialsException exception = new BadCredentialsException("Bad credentials");
185-
AbstractAuthenticationFailureEvent failureEvent = new AuthenticationFailureBadCredentialsEvent(
186-
authentication, exception);
181+
AbstractAuthenticationFailureEvent failureEvent = new AuthenticationFailureBadCredentialsEvent(authentication, exception);
187182

188183
// When
189184
authenticationEventListener.onFailure(failureEvent);
@@ -200,14 +195,13 @@ void events_differentUsers() {
200195
// Given
201196
String user1 = "user1@example.com";
202197
String user2 = "user2@example.com";
203-
198+
204199
Authentication auth1 = new UsernamePasswordAuthenticationToken(user1, "password");
205200
Authentication auth2 = new UsernamePasswordAuthenticationToken(user2, "password");
206-
201+
207202
AuthenticationSuccessEvent successEvent1 = new AuthenticationSuccessEvent(auth1);
208203
BadCredentialsException exception = new BadCredentialsException("Bad credentials");
209-
AbstractAuthenticationFailureEvent failureEvent2 = new AuthenticationFailureBadCredentialsEvent(
210-
auth2, exception);
204+
AbstractAuthenticationFailureEvent failureEvent2 = new AuthenticationFailureBadCredentialsEvent(auth2, exception);
211205

212206
// When
213207
authenticationEventListener.onSuccess(successEvent1);
@@ -218,4 +212,4 @@ void events_differentUsers() {
218212
verify(loginAttemptService).loginFailed(user2);
219213
}
220214
}
221-
}
215+
}

0 commit comments

Comments
 (0)