Add unit tests for error handling and authorization checks by devin-ai-integration[bot] · Pull Request #10 · jack-killian/Deere_OperationsCenterAPI-OAuth2-Java · GitHub
Skip to content

Add unit tests for error handling and authorization checks#10

Closed
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1768914493-add-error-handling-auth-tests
Closed

Add unit tests for error handling and authorization checks#10
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1768914493-add-error-handling-auth-tests

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Adds unit test coverage for error handling and authorization scenarios that were previously missing. The tests cover:

  • Error handling for valid transaction IDs: Tests for 404 (non-existent transaction), 400 (bad request), 500 (server error), and 503 (service unavailable) responses
  • Authorization checks: Tests for 401 (invalid/expired token) and 403 (forbidden - accessing private transactions, commenting without org access, insufficient scopes)

Changes include:

  • Added JUnit 5 and Mockito test dependencies to pom.xml
  • Added maven-surefire-plugin for running JUnit 5 tests
  • Created LoggingInterceptorTest.java with mocked HTTP response tests
  • Created RequestExceptionTest.java for error message formatting verification
  • Created ApiTest.java with documentation-style tests

Total: 47 tests passing

Review & Testing Checklist for Human

  • Review ApiTest.java critically - These tests verify string patterns against hardcoded sample messages rather than testing actual Api class behavior. This was a limitation due to Unirest's static methods being difficult to mock. Consider if this level of coverage is acceptable or if additional mocking infrastructure is needed.
  • Verify LoggingInterceptorTest covers the intended scenarios - This is the primary test file that actually tests error handling behavior with mocked HTTP responses
  • Run mvn clean test locally to confirm all 47 tests pass

Recommended test plan:

  1. Run mvn clean test and verify all tests pass
  2. Review the test names in LoggingInterceptorTest to ensure they align with the error scenarios you wanted covered

Notes

Link to Devin run: https://app.devin.ai/sessions/37e2d4e3bc8149699d346c9dc4331ef7
Requested by: @jack-killian

- Add JUnit 5 and Mockito test dependencies to pom.xml
- Add maven-surefire-plugin for running JUnit 5 tests
- Create LoggingInterceptorTest with tests for:
  - Error handling (404, 400, 500, 503 status codes)
  - Authorization checks (401, 403 for invalid/expired tokens)
  - Private transaction access (403 Forbidden scenarios)
- Create RequestExceptionTest with tests for:
  - Error message formatting for various HTTP error codes
  - Authorization error details (401, 403)
  - Transaction error scenarios
- Create ApiTest with documentation tests for expected error behaviors

Total: 47 tests covering error handling and authorization scenarios
Co-Authored-By: Jack <jack.l.killian@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

@devin-ai-integration

Copy link
Copy Markdown
Author

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.

0 participants