While working with the LookupHelper class, I noticed two mock variables repeatedly created across various tests. To simplify the code, I propose a small refactor to eliminate these redundancies, which could reduce the code by 30 lines.
Repetitive Mock AuthenticationProvider Creation: The creation of a mock AuthenticationProvider object repeated in 9 test cases.
Repetitive Mock LoginPageModel Creation: The creation of a mock LoginPageModel object repeated in 12 test cases.
Specifically, here is the refactoring method I propose:
Creating a mock for AuthenticationProvider currently looks like this:
final AuthenticationProvider authenticationProvider = Mockito.mock(AuthenticationProvider.class); // Before Refactoring
when(authenticationProvider.isAuthenticated(serverUrl)).thenReturn(Auth); // Before Refactoring
doNothing().when(authenticationProvider).authenticateAsync(anyString(), any(AuthenticationListener.class)); // Before Refactoring
I introduced a method, createMockAuthenticationProvider:
final LoginPageModel loginPageModel = Mockito.mock(LoginPageModel.class); // Before Refactoring
when(loginPageModel.getServerName()).thenReturn(serverUrl); // Before Refactoring
This is the code after the refactoring:
final LoginPageModel loginPageModel = createMockLoginPageModel(null);
The refactor reduced the test cases by 30 lines of code, and I believe these changes will improve code readability.
Hi there!
While working with the
LookupHelper
class, I noticed two mock variables repeatedly created across various tests. To simplify the code, I propose a small refactor to eliminate these redundancies, which could reduce the code by 30 lines.Repetitive Mock AuthenticationProvider Creation: The creation of a mock
AuthenticationProvider
object repeated in 9 test cases.Repetitive Mock LoginPageModel Creation: The creation of a mock
LoginPageModel
object repeated in 12 test cases.Specifically, here is the refactoring method I propose:
Creating a mock for
AuthenticationProvider
currently looks like this:I introduced a method,
createMockAuthenticationProvider
:With this method, creating a mock
AuthenticationProvider
becomes:Similarly, for
LoginPageModel
, I introduced a method,createMockLoginPageModel
as follows:This is the code before the refactoring:
This is the code after the refactoring:
The refactor reduced the test cases by 30 lines of code, and I believe these changes will improve code readability.