Skip to content

test: add unit tests for DeviceCodeOAuthFlow#739

Open
neo1027144-creator wants to merge 1 commit intoa2aproject:mainfrom
neo1027144-creator:issue-607
Open

test: add unit tests for DeviceCodeOAuthFlow#739
neo1027144-creator wants to merge 1 commit intoa2aproject:mainfrom
neo1027144-creator:issue-607

Conversation

@neo1027144-creator
Copy link

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

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
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Unit Test Introduction: Added comprehensive unit tests for the DeviceCodeOAuthFlow record class.
  • Test Coverage: Included test cases for full field population, null refreshUrl handling, empty scopes, null validation for required fields (deviceAuthorizationUrl, tokenUrl, scopes), and equals/hashCode consistency.
  • Pattern Adherence: Followed established testing patterns, similar to FileWithBytesTest.
  • Issue Resolution: Addressed and fixed issue [Bug]: Missing tests for DeviceCodeOAuthFlow #607.
Activity
  • The pull request was created, and no human activity has occurred yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

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

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 on lines +49 to +52
DeviceCodeOAuthFlow flow = new DeviceCodeOAuthFlow(DEVICE_AUTH_URL, TOKEN_URL, null, Map.of());

assertNotNull(flow.scopes());
assertEquals(0, flow.scopes().size());
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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());

Comment on lines +74 to +80
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());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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);
    }

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