test: add unit tests for DeviceCodeOAuthFlow#739
test: add unit tests for DeviceCodeOAuthFlow#739neo1027144-creator wants to merge 1 commit intoa2aproject:mainfrom
Conversation
Add DeviceCodeOAuthFlowTest with tests covering: - Construction with all fields - Null refreshUrl (optional field) - Empty scopes map - Null validation for required fields (deviceAuthorizationUrl, tokenUrl, scopes) - Record equality and hashCode Fixes a2aproject#607
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the robustness of the DeviceCodeOAuthFlow record by introducing a dedicated suite of unit tests. These tests validate the record's behavior across various construction scenarios, ensuring correct handling of both required and optional fields, proper null validation, and consistent equals and hashCode implementations. This work directly contributes to the stability and reliability of the OAuth flow mechanisms. Highlights
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds a comprehensive set of unit tests for the DeviceCodeOAuthFlow record class. The tests cover construction, null validation for required fields, handling of optional fields, and record equality. The implementation is solid. I've provided a couple of suggestions to make the tests even more robust: one to enhance the assertions in the empty scopes test for better consistency, and another to expand the equality test to include inequality checks, which will provide more complete validation of the record's behavior.
| DeviceCodeOAuthFlow flow = new DeviceCodeOAuthFlow(DEVICE_AUTH_URL, TOKEN_URL, null, Map.of()); | ||
|
|
||
| assertNotNull(flow.scopes()); | ||
| assertEquals(0, flow.scopes().size()); |
There was a problem hiding this comment.
This test only asserts properties of the scopes field. For completeness and consistency with other tests in this class (like testConstruction_withAllFields), it's better to assert the state of all fields of the constructed object. This makes the test more robust against future regressions.
Map<String, String> emptyScopes = Map.of();
DeviceCodeOAuthFlow flow = new DeviceCodeOAuthFlow(DEVICE_AUTH_URL, TOKEN_URL, null, emptyScopes);
assertEquals(DEVICE_AUTH_URL, flow.deviceAuthorizationUrl());
assertEquals(TOKEN_URL, flow.tokenUrl());
assertNull(flow.refreshUrl());
assertEquals(emptyScopes, flow.scopes());| void testEquality_sameValues() { | ||
| DeviceCodeOAuthFlow flow1 = new DeviceCodeOAuthFlow(DEVICE_AUTH_URL, TOKEN_URL, REFRESH_URL, SCOPES); | ||
| DeviceCodeOAuthFlow flow2 = new DeviceCodeOAuthFlow(DEVICE_AUTH_URL, TOKEN_URL, REFRESH_URL, SCOPES); | ||
|
|
||
| assertEquals(flow1, flow2); | ||
| assertEquals(flow1.hashCode(), flow2.hashCode()); | ||
| } |
There was a problem hiding this comment.
The test for equality is good, but it only covers the case where objects are equal. To make the test suite more robust and fully validate the behavior of the record's equals and hashCode methods, it's beneficial to also include checks for inequality. I suggest renaming the test to reflect its expanded scope and adding assertions for a case where the objects are expected to be unequal.
Note: You will need to add import static org.junit.jupiter.api.Assertions.assertNotEquals; for this suggestion.
void testEqualityAndHashCode() {
DeviceCodeOAuthFlow flow1 = new DeviceCodeOAuthFlow(DEVICE_AUTH_URL, TOKEN_URL, REFRESH_URL, SCOPES);
DeviceCodeOAuthFlow flow2 = new DeviceCodeOAuthFlow(DEVICE_AUTH_URL, TOKEN_URL, REFRESH_URL, SCOPES);
DeviceCodeOAuthFlow flow3WithNullRefresh = new DeviceCodeOAuthFlow(DEVICE_AUTH_URL, TOKEN_URL, null, SCOPES);
// Test for equality with same values
assertEquals(flow1, flow2);
assertEquals(flow1.hashCode(), flow2.hashCode());
// Test for inequality with different values
assertNotEquals(flow1, flow3WithNullRefresh);
}
Add unit tests for DeviceCodeOAuthFlow record class.
Test cases:
Follows the same testing patterns as FileWithBytesTest.
Fixes #607