Skip to content
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

Add test utility class for getting RecordedRequests from an OkHttp MockWebServer #492

Closed
sleberknight opened this issue Jun 13, 2024 · 0 comments · Fixed by #499
Closed
Assignees
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Milestone

Comments

@sleberknight
Copy link
Member

sleberknight commented Jun 13, 2024

The test utilities should (initially) provide a way to:

  • get a "required" RecordedRequest, or throw an IllegalStateException without blocking indefinitely like the MockWebServer#takeRequest() method does
  • get a RecordedRequest or return an empty Optional if one is not available
  • get a RecordedRequest or return null if one is not available
  • assert that there are no more RecordedRequest available (using AssertJ assertions)

None of these should make you catch InterruptedException like the MockWebServer#takeRequest methods do. Instead, wrap with an unchecked exception or catch and return null, Optional.empty(), throw an exception, etc. Since these are test utilities, ignoring InterruptedException isn't a big deal.

Maybe also provide a few methods with specific timeouts like I did in MockWebServerExtensions.kt, for example takeRequestWith1SecTimeout.

Also consider adding similar methods to the urlWithoutTrailingSlashAsString methods in MockWebServerExtensions.kt. We can't make them extensions as in Kotlin, but they're still useful.

@sleberknight sleberknight added the new feature A new feature such as a new class, method, package, group of classes, etc. label Jun 13, 2024
@sleberknight sleberknight added this to the 3.5.0 milestone Jun 19, 2024
@sleberknight sleberknight self-assigned this Jun 19, 2024
sleberknight added a commit that referenced this issue Jun 19, 2024
Add test utility class for getting RecordedRequests from an OkHttp MockWebServer.

Closes #492
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature A new feature such as a new class, method, package, group of classes, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant