-
Notifications
You must be signed in to change notification settings - Fork 6k
Add Equals and HashCode methods for better comparison. #16842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
768602b
95e04fa
0ba7b86
b15a831
8582ef6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.LinkedHashMap; | ||
import java.util.LinkedHashSet; | ||
|
@@ -28,8 +29,7 @@ | |
|
||
import org.springframework.security.oauth2.core.AuthorizationGrantType; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; | ||
import static org.assertj.core.api.Assertions.*; | ||
|
||
/** | ||
* Tests for {@link OAuth2AuthorizationRequest}. | ||
|
@@ -365,4 +365,49 @@ public void buildWhenAdditionalParametersContainsNullThenAuthorizationRequestUri | |
+ "item1=null&item2=value2"); | ||
} | ||
|
||
@Test | ||
public void equalsTrueTest() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you please ensure this test populates every available field to ensure they are all accounted for in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi, |
||
OAuth2AuthorizationRequest authorizationRequest1 = TestOAuth2AuthorizationRequests.request() | ||
.authorizationRequestUri("https://example.com") | ||
.additionalParameters( | ||
Collections.singletonMap("someAdditionalParameterKey", "someAdditionalParameterValue")) | ||
.parameters((parametersMap) -> parametersMap.put("someParameterKey", "someParameterValue")) | ||
.scope("someScope") | ||
.build(); | ||
|
||
OAuth2AuthorizationRequest authorizationRequest2 = TestOAuth2AuthorizationRequests.request() | ||
.authorizationRequestUri("https://example.com") | ||
.additionalParameters( | ||
Collections.singletonMap("someAdditionalParameterKey", "someAdditionalParameterValue")) | ||
.parameters((parametersMap) -> parametersMap.put("someParameterKey", "someParameterValue")) | ||
.scope("someScope") | ||
.build(); | ||
|
||
assertThat(authorizationRequest1).isEqualTo(authorizationRequest2); | ||
} | ||
|
||
@Test | ||
public void hashCodeTest() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you please ensure this test populates every available field to ensure they are all accounted for in the |
||
OAuth2AuthorizationRequest authorizationRequest1 = TestOAuth2AuthorizationRequests.request() | ||
.authorizationRequestUri("https://example.com") | ||
.additionalParameters( | ||
Collections.singletonMap("someAdditionalParameterKey", "someAdditionalParameterValue")) | ||
.parameters((parametersMap) -> parametersMap.put("someParameterKey", "someParameterValue")) | ||
.scope("someScope") | ||
.build(); | ||
|
||
OAuth2AuthorizationRequest authorizationRequest2 = TestOAuth2AuthorizationRequests.request() | ||
.authorizationRequestUri("https://example.com") | ||
.additionalParameters( | ||
Collections.singletonMap("someAdditionalParameterKey", "someAdditionalParameterValue")) | ||
.parameters((parametersMap) -> parametersMap.put("someParameterKey", "someParameterValue")) | ||
.scope("someScope") | ||
.build(); | ||
|
||
int authorizationRequest1HashCode = authorizationRequest1.hashCode(); | ||
int authorizationRequest2HashCode = authorizationRequest2.hashCode(); | ||
|
||
assertThat(authorizationRequest1HashCode).isEqualTo(authorizationRequest2HashCode); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend updating import settings for your IDE to not collapse imports, as this style of import will fail the build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do that but it is the desired behavior as stated here