test: add unit tests for DeviceCodeOAuthFlow by neo1027144-creator · Pull Request #739 · a2aproject/a2a-java · GitHub
Skip to content

test: add unit tests for DeviceCodeOAuthFlow - #739

Merged
ehsavoie merged 1 commit into
a2aproject:mainfrom
neo1027144-creator:issue-607
May 5, 2026
Merged

ehsavoie merged 1 commit into
a2aproject:mainfrom
neo1027144-creator:issue-607

Conversation

@neo1027144-creator

Copy link
Copy Markdown
Contributor

Add unit tests for DeviceCodeOAuthFlow record class.

Test cases:

  • Construction with all fields populated
  • Null refreshUrl (optional field)
  • Empty scopes map
  • Null validation for required fields (deviceAuthorizationUrl, tokenUrl, scopes)
  • Record equality and hashCode consistency

Follows the same testing patterns as FileWithBytesTest.

Fixes #607

@gemini-code-assist

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread spec/src/test/java/io/a2a/spec/DeviceCodeOAuthFlowTest.java Outdated
Comment thread spec/src/test/java/io/a2a/spec/DeviceCodeOAuthFlowTest.java Outdated
@ehsavoie

ehsavoie commented Apr 1, 2026

Copy link
Copy Markdown
Collaborator

@neo1027144-creator can you please fix the gemini code review

@neo1027144-creator

Copy link
Copy Markdown
Contributor Author

Sorry for the delayed response — I've just addressed the review feedback.
Thanks for the reminder!

@ehsavoie

@neo1027144-creator

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces unit tests for the DeviceCodeOAuthFlow class, covering object construction, parameter validation, and basic equality. The feedback suggests enhancing the test suite by adding a test for the immutability of the scopes map to ensure defensive copying and expanding the equality and hash code tests to include more comprehensive edge cases such as type mismatches and null checks.

@neo1027144-creator

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request ensures the immutability of the DeviceCodeOAuthFlow record by implementing a defensive copy of the scopes map during construction. It also introduces a new test class, DeviceCodeOAuthFlowTest, which provides comprehensive coverage for valid and invalid construction scenarios, equality checks, and immutability verification. I have no feedback to provide as no review comments were present.

@@ -33,5 +33,6 @@ public record DeviceCodeOAuthFlow(String deviceAuthorizationUrl, String tokenUrl
Assert.checkNotNullParam("deviceAuthorizationUrl", deviceAuthorizationUrl);
Assert.checkNotNullParam("tokenUrl", tokenUrl);
Assert.checkNotNullParam("scopes", scopes);
scopes = Map.copyOf(scopes);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this 'work' but public Map<String, String> scopes() should be overriden to return Map.copyOf(scopes)

@ehsavoie

Copy link
Copy Markdown
Collaborator

@neo1027144-creator Would you mind rebasing and fixing my comment.

Test cases:
- Construction with all fields populated
- Null refreshUrl (optional field)
- Empty scopes map with full field assertions
- Null validation for required fields (deviceAuthorizationUrl, tokenUrl, scopes)
- Record equality, hashCode consistency, and inequality edge cases
- Scopes map immutability (defensive copy via Map.copyOf)

Also fix: override scopes() to return Map.copyOf(scopes) for defensive copying

Fixes a2aproject#607
@neo1027144-creator

Copy link
Copy Markdown
Contributor Author

Hi @ehsavoie, I've rebased onto the latest main and addressed your review comment. I've overridden scopes() to return Map.copyOf(scopes) as you suggested. I also kept the Map.copyOf(scopes) in the compact constructor to ensure the record's internal field is disconnected from the original mutable map reference (without this, external modifications to the original map would still be visible through the overridden accessor). Thanks for the review!

@ehsavoie

Copy link
Copy Markdown
Collaborator

@ehsavoie
ehsavoie merged commit c7e04c6 into a2aproject:main May 5, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Missing tests for DeviceCodeOAuthFlow

2 participants