Support mocking of stripe outbound RPCs for unit tests
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 30/100
Research direction
The current entry point is the static Customer.create(customerCreateParamsObj) call; compare it with the requested stripeFactoryObj.customerService().create(...) design and inspect how StripeMock handles outbound requests. Completion means providing a constructor- or factory-based API that can be supplied through DI and mocked or verified without StripeMock.
Written by the indexing model from the issue text.
Description
Is your feature request related to a problem? Please describe.
When writing unit tests, there is a need to avoid outbound RPCs to another server. Today the Stripe API uses static methods and global (or request) config parameters, but there does not seem to be a way to mock the request/verify the request without running StripeMock, which is perhaps too large for a java unit test.
Describe the solution you'd like
If there was a constructor/factory based approach to constructing the stripe api, then we would be able to mock this away in our DI layer.
Today
Customer.create(customerCreateParamsObj);
Desirable alternatives
stripeFactoryObj.customerService().create(customerCreateParamsObj);
In my code I would likely provide CustomerService via DI, and then call like such:
customerService.create(customerCreateParamsObj);
This way I would be able to provide a Mockito implementation for CustomerService and setup mocks/verifications.
Describe alternatives you've considered
My solution until this is supported will be to wrap every Stripe API in a class/method and indirectly call the stripe API.
Alternatively it seems clients could use Mockito to mock static methods, though this approach is less desirable.
Additional context
No response
- Dominant language
- Java
- Stars
- 1k
- Forks
- 406
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 20
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from stripe/stripe-java
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
stripe/stripe-java#2280 · 3 comments ·
-
feature-request future
Difficulty 4/5 3-5 days Newbie friendliness 42/100
stripe/stripe-java#2024 · 5 comments · 3 reactions ·
-
feature-request future
Difficulty 3/5 1-2 days Newbie friendliness 45/100
stripe/stripe-java#2012 · 5 comments ·
-
feature-request future
Difficulty 5/5 Over a week Newbie friendliness 25/100
stripe/stripe-java#1964 · 1 comment ·
-
feature-request future
Difficulty 5/5 Over a week Newbie friendliness 35/100
stripe/stripe-java#1905 · 7 comments · 7 reactions ·
All issues in stripe/stripe-java
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
bug needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 1/5 Under an hour Newbie friendliness 94/100
objectionary/hone-maven-plugin#1061 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
spring-projects/spring-modulith#1895 ·